Files
archie/internal/infrastructure/staterpc/attribution_test.go
T
sam 5c91575166 feat(pr-review): operator/chat trigger queues a pr-review task
review_pr self-omitted since 7299b923 deleted the synchronous reviewer it
called. It is rebuilt on the task enqueue path everything else uses: the
tool resolves the identity's configured repo, then queues a pr-review task
naming the pull request through the workflow's declared pr_number input,
which is the same generic input mechanism a watched-repos binding uses.

That input has to reach the store with the task, so
EnqueueChatTaskRequest gains inputs_json and the tasks insert writes the
inputs column directly. StampTaskBinding no longer writes it: the insert is
now the column's only writer, and a chat task must not acquire binding
provenance just to carry an input.

ChatPRReviewer, its result shape and the reviewer wiring are deleted with
the path they served.
2026-09-28 18:24:36 +10:00

72 lines
2.4 KiB
Go

package staterpc
import (
"testing"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
)
// TestEventAttributionSurvivesTheStateStoreBoundary runs the same insert through
// the local adapter and through a bufconn-backed gRPC client, because that hop is
// where the attribution was being lost: the daemon records the event and the State
// Store holds it, so a field the contract does not carry is a field the record
// never has.
//
// The failure this pins is specific and was live: the actor was named inside the
// event's detail text while actor_id, actor_kind and principal_id were all empty,
// so an audit query reading the columns found nothing and "who approved this"
// meant parsing a human-readable string. An in-process test passed throughout,
// because it never crossed this boundary.
func TestEventAttributionSurvivesTheStateStoreBoundary(t *testing.T) {
const (
actorID = "70000000-0000-5000-8000-000000000001"
principalID = "70000000-0000-5000-8000-000000000002"
actorKind = "bot"
)
for _, mode := range []string{"local", "grpc"} {
t.Run(mode, func(t *testing.T) {
ctx := t.Context()
local := pgstore.Open(t)
var c contract = local
if mode == "grpc" {
c = remoteTaskStore(t, local, nil, nil)
}
task, err := c.EnqueueChatTask(ctx, "acme", "widget", "title", "body", "implement", "", nil)
if err != nil || task == nil {
t.Fatalf("EnqueueChatTask = (%+v, %v)", task, err)
}
recorded := events.Event{
Kind: events.KindAgentApproved,
TaskID: task.ID,
ActorID: actorID,
ActorKind: actorKind,
PrincipalID: principalID,
Detail: "approved by an agent, authorised by a person",
}
if _, err := c.InsertEvent(ctx, recorded); err != nil {
t.Fatalf("InsertEvent: %v", err)
}
got, err := c.TaskEvents(ctx, task.ID)
if err != nil {
t.Fatalf("TaskEvents: %v", err)
}
if len(got) != 1 {
t.Fatalf("TaskEvents returned %d events, want 1", len(got))
}
event := got[0]
if event.ActorID != actorID || event.ActorKind != actorKind || event.PrincipalID != principalID {
t.Fatalf("attribution did not cross the boundary: actor=%q kind=%q principal=%q",
event.ActorID, event.ActorKind, event.PrincipalID)
}
if event.Kind != events.KindAgentApproved {
t.Fatalf("kind = %q, want %q", event.Kind, events.KindAgentApproved)
}
})
}
}