package thin import ( "context" "encoding/json" "slices" "strings" "testing" "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/specialist" "amadan.net/oficina/equipo/internal/wire" ) // Task 17 (dynamic specialists slice 1): the coordinator's surface for // routing to Design, as places added its tools: the schemas and their // descriptions, the Claude allowlist, provider.ConverseTools, // wire.MutationKinds, the opening's sentence and a new house rule; and // the bound specialist_added continuation as the runner runs it. func converseTool(t *testing.T, name string) map[string]any { t.Helper() for _, tool := range converseTools { if m := tool.(map[string]any); m["name"] == name { return m } } t.Fatalf("no %s", name) return nil } // TestCoordinatorDesignSurface: start_task takes an optional specialist // id, propose_specialist offers design-v1 (scoped to one project) beside // research-v1, status says it lists the specialists, every tool is in // the Claude allowlist and provider.ConverseTools with its mutation kind, // and the opening routes visual design to Design under a new house rule. func TestCoordinatorDesignSurface(t *testing.T) { start := converseTool(t, wire.ToolStartTask) schema := start["inputSchema"].(map[string]any) if p, ok := schema["properties"].(map[string]any)["specialist"]; !ok || p.(map[string]string)["type"] != "string" || slices.Contains(schema["required"].([]string), "specialist") { t.Fatalf("start_task's specialist: %v", schema) } if d := start["description"].(string); !strings.Contains(d, "specialist") || !strings.Contains(d, "status") { t.Fatalf("start_task's description: %s", d) } propose := converseTool(t, wire.ToolProposeSpecialist) enum := propose["inputSchema"].(map[string]any)["properties"].(map[string]any)["profile"].(map[string]any)["enum"].([]string) if !slices.Equal(enum, []string{specialist.ProfileResearch, specialist.ProfileDesign}) { t.Fatalf("profiles %v", enum) } d := propose["description"].(string) for _, want := range []string{"design-v1", `["branch.edit", "page.render"]`, `["render_page", "submit_candidate", "ask_person"]`, "project"} { if !strings.Contains(d, want) { t.Fatalf("propose_specialist's description lacks %q: %s", want, d) } } // The menu's own capabilities and tools, as the description names them. p, _ := specialist.Lookup(specialist.ProfileDesign) caps, _ := json.Marshal(p.Capabilities) tools, _ := json.Marshal(p.Tools) if !strings.Contains(strings.ReplaceAll(d, ", ", ","), string(caps)) || !strings.Contains(strings.ReplaceAll(d, ", ", ","), string(tools)) { t.Fatalf("the menu's design-v1 is %s %s", caps, tools) } if d := converseTool(t, wire.ToolStatus)["description"].(string); !strings.Contains(d, "specialists") { t.Fatalf("status: %s", d) } for _, name := range []string{wire.ToolStatus, wire.ToolStartTask, wire.ToolProposeSpecialist} { if !slices.Contains(provider.ConverseTools(), name) || !slices.Contains(wire.ConverseTools, name) { t.Fatalf("%s is not a converse tool", name) } } for _, name := range []string{wire.ToolStartTask, wire.ToolProposeSpecialist} { if wire.MutationKinds[name] == "" || !slices.Contains(wire.WriteTools, name) { t.Fatalf("%s is not a designated mutation", name) } } o := opening("p@example.com", nil) for _, want := range []string{"Visual design, layout, themes and mockups go to Design", "status lists", "\"specialist\"", "propose_specialist with profile design-v1", "say in one line why"} { if !strings.Contains(o, want) { t.Fatalf("the opening lacks %q", want) } } if houseRule == "2026-11-26.1" { t.Fatal("the opening's rule changed without a new house rule") } } // TestSpecialistAddedTurnRuns: the bound continuation is framed with the // instance's own labelled opening (never as the person's newest // message), it is not held to the 24-call budget of a turn that only // looks around, and it never marks the desk moved in. func TestSpecialistAddedTurnRuns(t *testing.T) { desk, err := OpenDesk(t.TempDir(), "p@example.com") if err != nil { t.Fatal(err) } opening := "[Equipo's record, not the person's words: Paul added Design for a project.]\nThe person's own words, quoted: \"Calmer\"" c := &coordBase{person: "p@example.com", desk: desk, profile: profileFor(wire.LaneCoordinator)} for _, fresh := range []bool{true, false} { frame, _ := c.prompt(fresh, TurnInput{Person: "p@example.com", TurnID: "t1", Kind: wire.TurnSpecialistAdded, Text: opening}, nil) if !strings.HasSuffix(frame, opening) || strings.Contains(frame, "Newest message") { t.Fatalf("fresh %v frame:\n%s", fresh, frame) } } // A person turn's frame is as before. if frame, _ := c.prompt(true, TurnInput{Person: "p@example.com", TurnID: "t2", Kind: wire.TurnPerson, Text: "Hi"}, nil); !strings.Contains(frame, "Newest message:\nHi") { t.Fatalf("a person turn:\n%s", frame) } if lookingAround(wire.TurnSpecialistAdded) || lookingAround(wire.TurnPerson) || !lookingAround(wire.TurnMoveIn) || !lookingAround(wire.TurnExplore) || !lookingAround(wire.TurnTeamUpdate) { t.Fatal("the looking-around turns") } calls := 0 c.o.Tools = func(context.Context, string, string, int64, string, string, json.RawMessage) toolReply { calls++ return toolReply{Text: "ok"} } c.turn, c.attempt, c.turnCtx, c.kind, c.calls = "t1", 1, context.Background(), wire.TurnSpecialistAdded, moveInCalls+5 if out := c.toolReply(context.Background(), wire.ToolReadFile, "u1", json.RawMessage(`{}`)); out.Text != "ok" || calls != 1 { t.Fatalf("the continuation was held to the budget: %+v", out) } c.kind = wire.TurnMoveIn if out := c.toolReply(context.Background(), wire.ToolReadFile, "u2", json.RawMessage(`{}`)); out.Text != toolNoBudget || calls != 1 { t.Fatalf("a move-in past its budget: %+v", out) } if settles(wire.TurnSpecialistAdded) || settles(wire.TurnPerson) || !settles(wire.TurnMoveIn) || !settles(wire.TurnExplore) { t.Fatal("settled after a continuation") } }