package equipotest import ( "bytes" "context" "encoding/json" "errors" "io" "log/slog" "math" "net/http/httptest" "path/filepath" "testing" "time" "amadan.net/oficina/equipo/internal/equipo" "amadan.net/oficina/equipo/internal/equipo/team" "amadan.net/oficina/equipo/internal/runner" "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/runnerproto" "amadan.net/rastrillo/rastrillo/db" "amadan.net/rastrillo/rastrillo/migrate" "gorm.io/gorm" ) func fixtureEvent(f runnerFixture, id string, seq int64) runnerproto.Event { return runnerproto.Event{Version: 2, ID: id, TaskID: f.a.TaskID, AssignmentID: f.a.ID, Scope: f.claim.Scope, Handle: f.claim.Handle, ServerID: "server", AgentID: "agent", SessionID: "session", Epoch: "epoch", Sequence: &seq, Kind: "timeline", Payload: json.RawMessage(`{"text":"hello"}`), SourceTime: time.Date(2026, 11, 2, 0, 0, 0, 0, time.UTC)} } func eventValidators(f runnerFixture) { f.x.SetRunnerValidators(equipo.RunnerValidators{Events: func(context.Context, equipo.Assignment, equipo.RunnerRequest) error { return nil }}) } func TestRunnerEventReplay(t *testing.T) { f := runnerFixtureNew(t, true) eventValidators(f) e := fixtureEvent(f, "one", 1) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) e.ID = "alias" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) if n := scalar(t, f.d, "SELECT count(*) FROM runner_events"); n != 1 { t.Fatal("replay duplicated effect", n) } if n := scalar(t, f.d, "SELECT count(*) FROM audit_events WHERE kind='runner.event'"); n != 1 { t.Fatal("replay duplicated audit", n) } e.Payload = json.RawMessage(`{"text":"changed"}`) if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("changed duplicate accepted") } e = fixtureEvent(f, "other", 2) e.Handle.Fence++ if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("wrong fence accepted") } e = fixtureEvent(f, "other", 2) p := f.principal p.Person = "other@example.com" if f.s.IngestRunnerEvent(connectionContext, p, e) == nil { t.Fatal("wrong principal accepted") } } func TestTimelineEpochReplacement(t *testing.T) { f := runnerFixtureNew(t, true) seedHistoricalTaskIsolation(t, f.connectionFixture, f.a.TaskID) eventValidators(f) e := fixtureEvent(f, "old", 1) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) e = fixtureEvent(f, "replace", 0) e.Kind = "timeline_replacement" e.Sequence = nil e.Epoch = "new" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) q := f.request() q.Intent = &team.IntentSpec{Key: "blocked", Operation: team.OpProviderCall, Payload: json.RawMessage(`{}`)} if _, err := f.x.Mutate(connectionContext, f.principal, "intend", q); err == nil { t.Fatal("gap admitted work") } e = fixtureEvent(f, "new", 1) e.Epoch = "new" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) if n := scalar(t, f.d, "SELECT count(*) FROM runner_events"); n != 3 { t.Fatal("replacement deleted evidence", n) } var epoch, iso string executionMust(t, f.d.Writer().QueryRow("SELECT epoch,isolation FROM runner_timelines").Scan(&epoch, &iso)) if epoch != "new" { t.Fatal("projection retained old epoch", epoch) } var isolation team.IsolationSnapshot executionMust(t, json.Unmarshal([]byte(iso), &isolation)) if !isolation.RunnerTainted { t.Fatal("replacement stripped exposure") } } func eventTurn(t *testing.T, f runnerFixture) team.ActionID { t.Helper() q := f.request() q.Intent = &team.IntentSpec{Key: "turn", Operation: team.OpProviderCall, Payload: json.RawMessage(`{}`), Reserve: team.Usage{InputTokens: 100, OutputTokens: 100}} result, err := f.x.Mutate(connectionContext, f.principal, "intend", q) executionMust(t, err) q.Intent = nil q.ActionID = result.(team.ActionID) q.RequestID = "admit" _, err = f.x.Mutate(connectionContext, f.principal, "admit", q) executionMust(t, err) return q.ActionID } func completionEvent(f runnerFixture, id team.ActionID) runnerproto.Event { e := fixtureEvent(f, "completed", 1) e.Kind = "turn_completed" e.Sequence = nil e.TurnID = "turn" e.ActionID = id e.Payload = json.RawMessage(`{"event":{"type":"turn_completed","provider":"claude","turnId":"turn","usage":{"inputTokens":10,"cachedInputTokens":3,"outputTokens":2,"totalCostUsd":0.0673131}}}`) return e } func completionValidators(f runnerFixture, usage *team.Usage) { f.x.SetRunnerValidators(equipo.RunnerValidators{Events: func(context.Context, equipo.Assignment, equipo.RunnerRequest) error { return nil }, Receipt: func(context.Context, equipo.Assignment, equipo.RunnerRequest) (team.Receipt, error) { return team.Receipt{ID: "turn-receipt", Outcome: team.OutcomeSuccess, Usage: usage}, nil }}) } func TestRunnerEventReplayAtomicSettlement(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) e := completionEvent(f, id) u := &team.Usage{Calls: 1, InputTokens: 13, CachedInputTokens: 3, OutputTokens: 2, CostUnavailable: true} completionValidators(f, u) executionMust(t, f.d.G.Callback().Create().Before("gorm:create").Register("task12_crash", func(tx *gorm.DB) { if tx.Statement.Table == "audit_events" { if ev, ok := tx.Statement.Dest.(*equipo.AuditEvent); ok && ev.Kind == "runner.event" { tx.AddError(errors.New("injected task12 failure")) } } })) if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("audit failure accepted") } executionMust(t, f.d.G.Callback().Create().Remove("task12_crash")) if scalar(t, f.d, "SELECT count(*) FROM runner_events") != 0 || scalar(t, f.d, "SELECT count(*) FROM runner_timelines") != 0 || scalar(t, f.d, "SELECT count(*) FROM reservations WHERE state='settled'") != 0 { t.Fatal("partial event transaction committed") } action, err := f.x.Core.GetAction(connectionContext, e.Scope, id) executionMust(t, err) if action.State != team.ActionDispatching { t.Fatal("core receipt escaped rollback") } executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) for i := 0; i < 3; i++ { executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) } rows, err := f.x.Core.Reservations(connectionContext, e.Scope) executionMust(t, err) if len(rows) != 1 || rows[0].Settled != *u { t.Fatal("replayed charge", rows) } if scalar(t, f.d, "SELECT count(*) FROM runner_events") != 1 || scalar(t, f.d, "SELECT count(*) FROM audit_events WHERE kind='runner.event'") != 1 { t.Fatal("duplicate acceptance") } } func TestRunnerEventReplayMissingAndLateAfterCancel(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) e := completionEvent(f, id) completionValidators(f, nil) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) rows, err := f.x.Core.Reservations(connectionContext, e.Scope) executionMust(t, err) if rows[0].State != team.ReservationSettled || rows[0].Settled != rows[0].Reserved { t.Fatal("missing usage refunded") } q := f.request() q.RequestID = "next" q.Intent = &team.IntentSpec{Key: "next", Operation: team.OpProviderCall, Payload: json.RawMessage(`{}`), Reserve: team.Usage{InputTokens: 1, OutputTokens: 1}} if _, err = f.x.Mutate(connectionContext, f.principal, "intend", q); err != nil { t.Fatal("completed unknown usage blocked remaining headroom", err) } _, err = f.x.Core.Cancel(connectionContext, e.Scope, ownerAddress, "cancel") executionMust(t, err) completionValidators(f, &team.Usage{Calls: 1, InputTokens: 13, CachedInputTokens: 3, OutputTokens: 2, CostUnavailable: true}) e.ID = "late" e.RequestID = "late-observation" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) job, err := f.x.Core.GetJob(connectionContext, e.Scope) executionMust(t, err) if job.State != team.JobCancelled { t.Fatal("late usage changed cancellation", job.State) } rows, err = f.x.Core.Reservations(connectionContext, e.Scope) executionMust(t, err) if rows[0].State != team.ReservationSettled || rows[0].Settled.InputTokens != rows[0].Reserved.InputTokens { t.Fatal("late usage did not settle", rows) } } func TestRunnerEventReplayArtifactRequest(t *testing.T) { f := runnerFixtureNew(t, true) f.x.SetRunnerValidators(equipo.RunnerValidators{Artifact: func(context.Context, equipo.Assignment, equipo.RunnerRequest) error { return nil }}) q := f.request() q.Artifact = &team.ArtifactSpec{Role: team.RoleReproduction, MediaType: "text/plain", Payload: []byte("repro")} first, err := f.x.Mutate(connectionContext, f.principal, "artifacts", q) executionMust(t, err) second, err := f.x.Mutate(connectionContext, f.principal, "artifacts", q) executionMust(t, err) if first.(team.Artifact).ID != second.(team.Artifact).ID || scalar(t, f.d, "SELECT count(*) FROM artifacts") != 1 { t.Fatal("artifact replay created semantic duplicate") } q.Artifact.Payload = []byte("changed") if _, err = f.x.Mutate(connectionContext, f.principal, "artifacts", q); err == nil { t.Fatal("artifact key reused for changed payload") } } func TestRunnerEventReplayHTTP(t *testing.T) { f := runnerFixtureNew(t, true) eventValidators(f) e := fixtureEvent(f, "wire", 1) q := f.request() q.RequestID = e.ID raw, err := runnerproto.Marshal(e) executionMust(t, err) q.Event = raw body, err := runnerproto.Marshal(q) executionMust(t, err) req := httptest.NewRequest("POST", "/events", bytes.NewReader(body)) req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+runnerBearerFor(t, f)) w := httptest.NewRecorder() f.s.RunnerHandler().ServeHTTP(w, req) if w.Code != 200 { t.Fatal("event endpoint", w.Code, w.Body.String()) } } func reopenEventFixture(t *testing.T, f *runnerFixture) { t.Helper() var path string executionMust(t, f.d.Writer().QueryRow("SELECT file FROM pragma_database_list WHERE name='main'").Scan(&path)) executionMust(t, f.x.Core.Close()) executionMust(t, f.d.Close()) d, err := db.Open(path, slog.New(slog.NewTextHandler(io.Discard, nil))) executionMust(t, err) t.Cleanup(func() { d.Close() }) f.d = d _, err = migrate.Apply(connectionContext, d, equipo.BootSchema) executionMust(t, err) f.s = equipo.NewStore(d, equipo.WithRunnerClock(f.clock), equipo.WithVerifiedIsolationTuples([]team.IsolationTuple{connectionTuple(f.reports[0]), connectionTuple(f.reports[1])})) f.x, err = f.s.AttachExecution(connectionContext, path, team.Options{Clock: f.clock, Authority: equipo.NewAuthority(f.s, f.clock)}) executionMust(t, err) x := f.x t.Cleanup(func() { x.Core.Close() }) } func TestRunnerJournalServerCommitBeforeACK(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) e := completionEvent(f, id) path := filepath.Join(t.TempDir(), "private", "journal.db") j, err := runner.OpenJournal(connectionContext, path) executionMust(t, err) profile := runner.UsageProfile{Version: 1, Provider: "claude", PaseoVersion: "0.14.0", TokenSemantics: "turn", InputSemantics: "exclusive", CostSemantics: "cumulative", Subscription: true} agent := provider.Agent{ServerID: e.ServerID, AgentID: e.AgentID, ProviderSessionID: e.SessionID} executionMust(t, j.Append(connectionContext, e)) acc, err := j.Usage(connectionContext, agent, profile) executionMust(t, err) u := acc.ObservePaseo(provider.RecordedEvent{Kind: e.Kind, ServerID: e.ServerID, AgentID: e.AgentID, ProviderSessionID: e.SessionID, TurnID: e.TurnID, Payload: e.Payload}) if u == nil { t.Fatal("journal did not restore usage") } completionValidators(f, u) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) executionMust(t, j.Close()) for i := 0; i < 2; i++ { reopenEventFixture(t, &f) j, err = runner.OpenJournal(connectionContext, path) executionMust(t, err) acc, err = j.Usage(connectionContext, agent, profile) executionMust(t, err) if math.Abs(acc.EstimatedCostUSD()-0.0673131) > 1e-10 { t.Fatal("reopen lost usage baseline") } completionValidators(f, u) rows, err := j.Pending(connectionContext, 10) executionMust(t, err) if len(rows) != 1 { t.Fatal("commit before ACK lost retry") } executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, rows[0])) executionMust(t, j.Close()) } j, err = runner.OpenJournal(connectionContext, path) executionMust(t, err) defer j.Close() pump := runner.EventPump{Journal: j, Contain: func(context.Context) error { return nil }, Upload: func(ctx context.Context, e runner.Event) error { return f.s.IngestRunnerEvent(ctx, f.principal, e) }} executionMust(t, pump.Flush(connectionContext, 10)) if scalar(t, f.d, "SELECT count(*) FROM runner_events") != 1 || scalar(t, f.d, "SELECT count(*) FROM audit_events WHERE kind='runner.event'") != 1 || scalar(t, f.d, "SELECT count(*) FROM reservations WHERE state='settled'") != 1 { t.Fatal("reopen duplicated effects") } pending, err := j.Pending(connectionContext, 10) executionMust(t, err) if len(pending) != 0 { t.Fatal("accepted event not ACKed") } } func TestRunnerEventReplayValidationAndRollback(t *testing.T) { f := runnerFixtureNew(t, true) e := fixtureEvent(f, "one", 1) if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("missing event validator accepted") } eventValidators(f) for _, field := range []string{"scope", "task", "assignment", "runner", "session", "sequence", "payload", "time"} { t.Run(field, func(t *testing.T) { bad := e switch field { case "scope": bad.Scope.Account = "other" case "task": bad.TaskID = "other" case "assignment": bad.AssignmentID = "other" case "runner": bad.Handle.Runner = "other" case "session": bad.SessionID = "" case "sequence": n := int64(-1) bad.Sequence = &n case "payload": bad.Payload = []byte(`invalid`) case "time": bad.SourceTime = time.Time{} } if f.s.IngestRunnerEvent(connectionContext, f.principal, bad) == nil { t.Fatal("invalid event accepted", field) } }) } executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) e.ID = "alias" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) n := int64(2) e.Sequence = &n if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("event alias reused for new sequence") } executionMust(t, f.s.RevokeRunner(connectionContext, ownerActor, f.principal.RunnerID, 1)) e = fixtureEvent(f, "one", 1) if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("revoked principal replay accepted") } } func TestRunnerEventReplayProviderWire(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) e := completionEvent(f, id) completionValidators(f, nil) q := f.request() q.RequestID = e.ID q.ActionID = id raw, err := runnerproto.Marshal(e) executionMust(t, err) q.Event = raw if status := runnerHTTP(t, f, "events", runnerBearerFor(t, f), q); status != 200 { t.Fatal("provider payload rejected by wire codec", status) } } func TestRunnerEventReplayControlEpoch(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) e := completionEvent(f, id) completionValidators(f, nil) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) e.Epoch = "replacement" e.ID = "history-control" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) if scalar(t, f.d, "SELECT count(*) FROM runner_events") != 1 { t.Fatal("control duplicated across epochs") } } func TestTimelineEpochHistoricalExposure(t *testing.T) { f := runnerFixtureNew(t, true) seedHistoricalTaskIsolation(t, f.connectionFixture, f.a.TaskID) eventValidators(f) e := fixtureEvent(f, "exposure", 1) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) mustSQL(t, f.d, `UPDATE runner_events SET isolation='{"status":"confined"}',body=json_set(body,'$.isolation',json('{"status":"confined"}'))`) mustSQL(t, f.d, `UPDATE runner_timelines SET isolation='{"status":"confined"}'`) executionMust(t, f.x.Sync(connectionContext)) var raw, body, projection string executionMust(t, f.d.Writer().QueryRow("SELECT isolation,body FROM runner_events").Scan(&raw, &body)) executionMust(t, f.d.Writer().QueryRow("SELECT isolation FROM runner_timelines").Scan(&projection)) for _, value := range []string{raw, projection} { var iso team.IsolationSnapshot executionMust(t, json.Unmarshal([]byte(value), &iso)) if !iso.RunnerTainted { t.Fatal("running event lost newly observed exposure") } } var restored runnerproto.Event executionMust(t, json.Unmarshal([]byte(body), &restored)) if !restored.Isolation.RunnerTainted { t.Fatal("event body lost exposure") } } func TestTimelineEpochUnknownOutcome(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) eventValidators(f) e := fixtureEvent(f, "gap", 0) e.Sequence = nil e.Kind = "timeline_gap" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) e.ID = "ready" e.Kind = "timeline_ready" executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) q := f.request() q.RequestID = "next" q.Intent = &team.IntentSpec{Key: "next", Operation: team.OpProviderCall, Payload: json.RawMessage(`{}`), Reserve: team.Usage{InputTokens: 1, OutputTokens: 1}} if _, err := f.x.Mutate(connectionContext, f.principal, "intend", q); err == nil { t.Fatal("refetch invented completion for unknown action") } e = completionEvent(f, id) completionValidators(f, nil) executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) if _, err := f.x.Mutate(connectionContext, f.principal, "intend", q); err != nil { t.Fatal("known completion cannot use remaining headroom", err) } } func TestRunnerEventReplayCompletionNeedsReceipt(t *testing.T) { f := runnerFixtureNew(t, true) id := eventTurn(t, f) eventValidators(f) e := completionEvent(f, id) if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("uncorroborated completion accepted") } if scalar(t, f.d, "SELECT count(*) FROM runner_events") != 0 { t.Fatal("uncorroborated event committed") } } func TestRunnerEventReplayAssignedIsolation(t *testing.T) { f := runnerFixtureNew(t, true) seedHistoricalTaskIsolation(t, f.connectionFixture, f.a.TaskID) eventValidators(f) e := fixtureEvent(f, "assigned", 1) e.Isolation = team.IsolationSnapshot{Status: "confined"} executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) var raw string executionMust(t, f.d.Writer().QueryRow("SELECT body FROM runner_events").Scan(&raw)) var saved runnerproto.Event executionMust(t, json.Unmarshal([]byte(raw), &saved)) if !saved.Isolation.RunnerTainted || len(saved.Isolation.AcknowledgementIDs) == 0 { t.Fatal("event did not retain assigned isolation at commit") } } func fixtureEventRequest(t *testing.T, f runnerFixture, q equipo.RunnerRequest) json.RawMessage { t.Helper() event := fixtureEvent(f, q.RequestID, 1) event.Scope = q.Scope event.Handle = q.Handle event.AssignmentID = q.AssignmentID event.ActionID = q.ActionID raw, err := runnerproto.Marshal(event) executionMust(t, err) return raw } func TestTimelineEpochChangedReset(t *testing.T) { f := runnerFixtureNew(t, true) eventValidators(f) e := fixtureEvent(f, "reset", 0) e.Kind = "timeline_replacement" e.Sequence = nil executionMust(t, f.s.IngestRunnerEvent(connectionContext, f.principal, e)) e.Epoch = "different" if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("replacement ID accepted a different target epoch") } } func TestDirectCompletionServerCommitBeforeACK(t *testing.T) { for _, mode := range []string{"completed-known", "completed-unknown", "failed-unknown", "chunked-known"} { t.Run(mode, func(t *testing.T) { f := runnerFixtureNew(t, true, true) id := eventTurn(t, f) e := completionEvent(f, id) e.Kind = "turn.completed" u := &team.Usage{Calls: 1, InputTokens: 28254, OutputTokens: 142, CostUnavailable: true} if mode == "failed-unknown" { e.Kind = "turn.failed" } if mode == "completed-unknown" || mode == "failed-unknown" { u = nil } var payloadErr error e.Payload, payloadErr = json.Marshal(struct { Usage *team.Usage `json:"usage"` }{u}) executionMust(t, payloadErr) if mode == "chunked-known" { e.Payload = []byte(`{"chunks":"durable-envelope","count":2,"kind":"turn.completed","usage":{"calls":1,"input_tokens":28254,"output_tokens":142,"cost_unavailable":true}}`) } for _, field := range []string{"fence", "attempt", "action", "runner", "scope", "usage"} { bad := e switch field { case "fence": bad.Handle.Fence++ case "attempt": bad.Handle.Attempt++ case "action": bad.ActionID++ case "runner": bad.Handle.Runner = "foreign" case "scope": bad.Scope.Account = "foreign" case "usage": bad.Payload = []byte(`{"usage":"unknown"}`) } if f.s.IngestRunnerEvent(connectionContext, f.principal, bad) == nil { t.Fatal("foreign completion accepted", field) } } path := filepath.Join(t.TempDir(), "private", "journal.db") j, err := runner.OpenJournal(connectionContext, path) executionMust(t, err) pump := runner.EventPump{Journal: j, Contain: func(context.Context) error { return nil }, Upload: func(ctx context.Context, event runnerproto.Event) error { if err := f.s.IngestRunnerEvent(ctx, f.principal, event); err != nil { return err } return errors.New("lost ACK after server commit") }} executionMust(t, pump.Append(connectionContext, e, nil)) if pump.Flush(connectionContext, 10) == nil { t.Fatal("lost acknowledgement ignored") } executionMust(t, j.Close()) j, err = runner.OpenJournal(connectionContext, path) executionMust(t, err) defer j.Close() pump.Journal = j pump.Upload = func(ctx context.Context, event runnerproto.Event) error { return f.s.IngestRunnerEvent(ctx, f.principal, event) } executionMust(t, pump.Flush(connectionContext, 10)) rows, err := f.x.Core.Reservations(connectionContext, e.Scope) executionMust(t, err) if len(rows) != 1 { t.Fatal("reservation count", len(rows)) } expected := rows[0].Reserved if u != nil { expected = *u } if rows[0].State != team.ReservationSettled || rows[0].Settled != expected { t.Fatalf("direct receipt lost or duplicated: %+v", rows) } if scalar(t, f.d, "SELECT count(*) FROM runner_events") != 1 || scalar(t, f.d, "SELECT count(*) FROM audit_events WHERE kind='runner.event'") != 1 { t.Fatal("replay repeated event effects") } action, err := f.x.Core.GetAction(connectionContext, e.Scope, id) executionMust(t, err) wantOutcome := team.OutcomeSuccess if mode == "failed-unknown" { wantOutcome = team.OutcomeFailure } if action.Receipt == nil || action.Receipt.Outcome != wantOutcome || (action.Receipt.Usage == nil) != (u == nil) { t.Fatalf("receipt changed outcome or usage certainty: %+v", action.Receipt) } e.ID = "bad-direct" e.TurnID = "" e.ActionID = 0 if f.s.IngestRunnerEvent(connectionContext, f.principal, e) == nil { t.Fatal("direct completion lacks turn authority") } }) } }