Files
archie/modules/runs/cancel_test.go
T
sam a101b64703 fix(runs): a cancelled run's trail records who stopped it (#2100)
Cancelling a run moved it and the runs it called to cancelled and wrote nothing
to either trail, so a stopped run could not say when it stopped or who asked.

The stop now returns the runs it stopped and records one cancel entry on each,
in the same transaction, naming the principal that asked. The entry is a step
named cancel with the caller's identity, so the run detail shows it with the
rest of the trail.
2026-11-27 19:24:19 +11:00

45 lines
1.3 KiB
Go

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)
}
}