package runner import ( "context" "os" "path/filepath" "testing" "amadan.net/oficina/equipo/internal/equipo/team" "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/runnerproto" ) type supervisorAPI struct { order *[]string fail bool } func (a *supervisorAPI) Call(_ context.Context, op string, q runnerproto.RunnerRequest, out any) error { *a.order = append(*a.order, op) if a.fail { return provider.ErrUncertain } return nil } func cleanupFixture(t *testing.T) (*Supervisor, *attemptState, any, *[]string) { t.Helper() dir := t.TempDir() os.Chmod(dir, 0700) j, err := OpenJournal(context.Background(), filepath.Join(dir, "journal.db")) if err != nil { t.Fatal(err) } t.Cleanup(func() { j.Close() }) order := []string{} api := &supervisorAPI{order: &order} s := &Supervisor{journal: j, api: api, clock: hostClock{}, states: map[string]*attemptState{}} r := &attemptState{Claim: RunClaim{Assignment: runnerproto.Assignment{ID: "assignment", Kind: "step", StepKey: "reproduce"}, ClaimResponse: runnerproto.ClaimResponse{Scope: team.Scope{Account: "team", Job: 1}, Handle: team.Handle{Attempt: 1, Fence: 1, Runner: "runner"}}}, Owner: ProcessOwner{Attempt: 1, Fence: 1, Marker: "marker", AgentID: "agent", Workspace: provider.Workspace{ServerID: "server", WorkspaceID: "workspace", Path: t.TempDir()}}, Agent: provider.Agent{ServerID: "server", AgentID: "agent"}, Phase: "completed"} s.states[attemptKey(r.Claim.Scope, r.Claim.Handle)] = r if err := s.save(context.Background(), r); err != nil { t.Fatal(err) } return s, r, nil, &order }