package runs import ( "context" "log/slog" "testing" "github.com/google/uuid" "github.com/samcharles93/archie-core/modules/governance" "github.com/samcharles93/archie-core/modules/runs/internal/store" ) // cancelFake records what a cancel asked storage for. type cancelFake struct { orgID string id uuid.UUID by string } func (f *cancelFake) Cancel(_ context.Context, orgID string, id uuid.UUID, by string) error { f.orgID, f.id, f.by = orgID, id, by return nil } // TestCancelRecordsWhoAsked guards #2100: cancelling a run left no entry in the // run's trail, so the trail could not say when a run stopped, or who stopped // it. The principal making the request is what the entry must name. func TestCancelRecordsWhoAsked(t *testing.T) { db := &cancelFake{} e := newEngine(store.New(nil), nil, slog.New(slog.DiscardHandler), Options{}) e.cancel = db id := uuid.New() ctx := governance.WithPrincipal(t.Context(), governance.Principal{IdentityID: "sam", Org: "org-sys"}) if err := e.Cancel(ctx, "org-sys", id); err != nil { t.Fatal(err) } if db.by != "sam" { t.Fatalf("cancel recorded by %q, want the principal that asked", db.by) } if db.id != id || db.orgID != "org-sys" { t.Fatalf("cancel asked storage for %s in %s, want %s in org-sys", db.id, db.orgID, id) } }