package runner import ( "context" "errors" "testing" "amadan.net/oficina/equipo/internal/equipo/team" "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/runner/workspace" "amadan.net/oficina/equipo/internal/runnerproto" ) // No release certifies a policy, so the only route this runner launches // is its own person's, in owner mode, confined, on this runner. Every // other selection is refused before an account or a workspace is opened. func TestLaunchRefusesAnyoneButTheOwner(t *testing.T) { owner := runnerproto.Selection{Provider: "claude", Person: "ana", RunnerID: "runner-1", Isolation: team.IsolationSnapshot{Mode: "owner mode", Status: "confined"}} if !ownerRoute("ana", "runner-1", owner) { t.Fatal("the owner's confined route is not an owner route") } r := &Runtime{cfg: configFixture(t), api: &HTTPInstance{bearer: runnerproto.RunnerCredential{Person: "ana", RunnerID: "runner-1"}}} for name, change := range map[string]func(*runnerproto.Selection){ "another person": func(s *runnerproto.Selection) { s.Person = "ben" }, "no person": func(s *runnerproto.Selection) { s.Person = "" }, "another runner": func(s *runnerproto.Selection) { s.RunnerID = "runner-2" }, "no runner": func(s *runnerproto.Selection) { s.RunnerID = "" }, "tainted runner": func(s *runnerproto.Selection) { s.Isolation.RunnerTainted = true }, "not confined": func(s *runnerproto.Selection) { s.Isolation.Status = "unconfined" }, "no mode": func(s *runnerproto.Selection) { s.Isolation.Mode = "" }, "a verified mode": func(s *runnerproto.Selection) { s.Isolation.Mode = "verified" }, } { t.Run(name, func(t *testing.T) { s := owner change(&s) if ownerRoute("ana", "runner-1", s) { t.Fatal("an owner route") } // A named mode that is not the owner's is an identity error; no // mode at all used to mean "certified", and is now refused. want := provider.ErrUncertified if s.Isolation.Mode != "" { want = provider.ErrIdentity } claim := RunClaim{Assignment: runnerproto.Assignment{StepKey: "implement", Selection: s}} if _, cleanup, err := r.directLaunch(context.Background(), claim, workspace.Workspace{Path: t.TempDir()}, &ToolProxy{}); !errors.Is(err, want) || cleanup != nil { t.Fatalf("direct launch: %v, cleanup %v", err, cleanup != nil) } coordinator := runnerproto.CoordinatorClaim{Brief: runnerproto.RunnerBrief{Selection: s}, Binding: runnerproto.CoordinatorBinding{Person: s.Person}} if _, cleanup, err := r.coordinatorLaunch(context.Background(), coordinator, &ToolProxy{}); !errors.Is(err, want) || cleanup != nil { t.Fatalf("coordinator launch: %v, cleanup %v", err, cleanup != nil) } }) } // With no instance connection there is no owner to match. if _, _, err := (&Runtime{cfg: r.cfg}).directLaunch(context.Background(), RunClaim{Assignment: runnerproto.Assignment{StepKey: "implement", Selection: runnerproto.Selection{Provider: "claude", Person: "ana", RunnerID: "runner-1", Isolation: team.IsolationSnapshot{Status: "confined"}}}}, workspace.Workspace{}, &ToolProxy{}); !errors.Is(err, provider.ErrUncertified) { t.Fatalf("launch without an instance: %v", err) } }