package provider import ( "encoding/json" "slices" "testing" ) // The Research step's launch profile (spec ยง4): its own action and // specialist, exactly the research-v1 tools, and nothing of the legacy // "research" action (which reads a workspace with native tools). func TestResearchStepProfile(t *testing.T) { p, err := Profile(ResearchStepAction) if err != nil { t.Fatal(err) } if ResearchStepAction != "research_step" || p.Specialist != ResearchSpecialist || p.Specialist == "Research" || p.Render || p.ReadOnly { t.Fatalf("profile %+v", p) } if got := p.Tools(); !slices.Equal(got, []string{"submit_findings", "keep_image"}) { t.Fatalf("tools %v", got) } if got := p.MCPTools(); !slices.Equal(got, []string{"mcp__equipo__submit_findings", "mcp__equipo__keep_image"}) { t.Fatalf("MCP tools %v", got) } legacy, err := Profile("research") if err != nil || legacy.Specialist != "Research" || !slices.Equal(legacy.Tools(), []string{"submit_answer", "ask_person"}) { t.Fatalf("legacy research changed: %+v %v", legacy, err) } if !ResearchAction(ResearchStepAction) || ResearchAction("research") || CoordinatorAction(ResearchStepAction) { t.Fatal("research action predicates") } } func manifestPolicy(action string) Policy { raw, _ := json.Marshal(map[string]any{"Action": action}) return Policy{Manifest: raw, ManifestHash: ManifestDigest(raw)} } // Policy.Research and Policy.ResearchReader read the manifest's action, // integrity-checked as Converse and Coordinator are: a manifest that // does not match its hash is neither. func TestPolicyResearchPredicates(t *testing.T) { for _, c := range []struct { action string research, reader bool }{ {ResearchStepAction, true, false}, {"implement", false, true}, {"inspect", false, true}, {"research", false, false}, {"converse", false, false}, {"coordinate", false, false}, {"answer", false, false}, {"", false, false}, } { p := manifestPolicy(c.action) if p.Research() != c.research || p.ResearchReader() != c.reader { t.Fatalf("%q: research=%v reader=%v", c.action, p.Research(), p.ResearchReader()) } if c.action == ResearchStepAction && (p.Coordinator() || p.Converse()) { t.Fatal("research step is not a coordinator") } tampered := p tampered.ManifestHash = ManifestDigest([]byte(`{}`)) if tampered.Research() || tampered.ResearchReader() { t.Fatalf("%q: tampered manifest trusted", c.action) } } } // BuildPolicy pins a Research launch's native tools as it does the // coordinator's: none beyond what the provider registers for MCP. func TestResearchStepNativeToolsPinned(t *testing.T) { b, in := policyFixture(t) in.Action = ResearchStepAction profile, _ := Profile(in.Action) in.Tools = profile.MCPTools() if _, err := BuildPolicy(b, in); err == nil { t.Fatal("research launch without its pinned native tools accepted") } in.NativeTools = CoordinatorNativeTools("codex") if _, err := BuildPolicy(b, in); err != nil { t.Fatalf("pinned research native tools refused: %v", err) } in.NativeTools = append(in.NativeTools, "shell") if _, err := BuildPolicy(b, in); err == nil { t.Fatal("research launch with a shell accepted") } }