oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package claude
2
3import (
4 "encoding/json"
5 "errors"
6 "fmt"
7 "slices"
8 "testing"
9
10 "amadan.net/oficina/equipo/internal/runner/provider"
11)
12
13// glanceActions are every launch action but the glance.
14var glanceOthers = []string{"coordinate", "converse", "assist", "reproduce", "scope", "recommend", "investigate", "research", "implement", "copy", "design", "review", "inspect", provider.ResearchStepAction, "answer"}
15
16// The glance (the Assistant's instant first line) runs with no tool at
17// all: --tools "", only the permission callback, which allows nothing,
18// the workspace read-only, and any tool asked for is refused. It mirrors
19// TestAssistLaunchPinsSixTools with zero.
20func TestGlanceLaunchHasNoTools(t *testing.T) {
21 profile, err := provider.Profile(provider.GlanceAction)
22 if err != nil {
23 t.Fatal(err)
24 }
25 if !profile.ReadOnly || len(profile.Tools()) != 0 || profile.Submission != "" {
26 t.Fatalf("profile %+v tools %v", profile, profile.Tools())
27 }
28 b := provider.Binding{Provider: "claude", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"}
29 in := provider.PolicyInputs{Action: provider.GlanceAction, Tools: profile.MCPTools()}
30 got, err := PolicyInputs(b, in, profile.Specialist, "claude-opus-5-5")
31 if err != nil {
32 t.Fatal(err)
33 }
34 if !slices.Equal(got.Tools, []string{"mcp__equipo__permission"}) {
35 t.Fatalf("tools %v", got.Tools)
36 }
37 if i := slices.Index(got.Argv, "--tools"); i < 0 || got.Argv[i+1] != "" {
38 t.Fatalf("argv %q", got.Argv)
39 }
40 var settings struct {
41 Permissions struct{ Allow, Ask []string }
42 Sandbox struct {
43 Filesystem struct{ DenyWrite []string } `json:"filesystem"`
44 }
45 }
46 if json.Unmarshal(got.Settings, &settings) != nil || len(settings.Permissions.Allow) != 0 || !slices.Contains(settings.Sandbox.Filesystem.DenyWrite, "/workspace") {
47 t.Fatalf("settings %s", got.Settings)
48 }
49 if len(settings.Permissions.Ask) != 0 {
50 t.Fatalf("native ask rules %q", settings.Permissions.Ask)
51 }
52 for _, tool := range []string{"mcp__equipo__ask_person", "mcp__equipo__look", "mcp__equipo__use", "mcp__equipo__read_notes", "mcp__equipo__submit_answer", "mcp__equipo__submit_findings", "Read"} {
53 more := in
54 more.Tools = []string{tool}
55 if _, err := PolicyInputs(b, more, profile.Specialist, "claude-opus-5-5"); !errors.Is(err, provider.ErrPolicy) {
56 t.Fatalf("a glance with %s: %v", tool, err)
57 }
58 }
59 for _, specialist := range []string{"Coordinator", "Engineering", "Reviewer", provider.ResearchSpecialist} {
60 if _, err := PolicyInputs(b, in, specialist, "claude-opus-5-5"); err == nil {
61 t.Fatalf("a glance ran as %s", specialist)
62 }
63 }
64 // The init frame of a glance: exactly no tool, on the small model.
65 policy := provider.Policy{Manifest: mustJSON(t, map[string]any{"Action": provider.GlanceAction, "Tools": got.Tools})}
66 init := func(model string, tools []string) []byte {
67 return mustJSON(t, map[string]any{"claude_code_version": Version, "model": model, "permissionMode": "default", "tools": tools, "skills": []string{}, "plugins": []any{}, "mcp_servers": []any{map[string]string{"name": "equipo", "status": "connected"}}})
68 }
69 if err := ValidateInit(policy, "claude-opus-5-5", init(GlanceModel, []string{})); err != nil {
70 t.Fatalf("a glance's init: %v", err)
71 }
72 if err := ValidateInit(policy, "claude-opus-5-5", init("claude-opus-5-5", []string{})); err == nil {
73 t.Fatal("a glance ran on the connection's own model")
74 }
75 if err := ValidateInit(policy, "claude-opus-5-5", init(GlanceModel, []string{"mcp__equipo__look"})); err == nil {
76 t.Fatal("a glance's init reported a tool")
77 }
78}
79
80// Only the glance launches the small model: the connection's bound
81// model stays the session's identity (the thread policy, the selection),
82// argv asks for claude-haiku-5-5, and every other action runs on the
83// bound model, whatever it is. Nothing can name the small model: it is
84// not an input.
85func TestOnlyGlanceUsesTheSmallModel(t *testing.T) {
86 if GlanceModel != "claude-haiku-5-5" || provider.GlanceModel("claude") != GlanceModel {
87 t.Fatalf("glance model %q %q", GlanceModel, provider.GlanceModel("claude"))
88 }
89 b := provider.Binding{Provider: "claude", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"}
90 model := func(action, bound string) (string, threadPolicy) {
91 t.Helper()
92 profile, err := provider.Profile(action)
93 if err != nil {
94 t.Fatal(err)
95 }
96 got, err := PolicyInputs(b, provider.PolicyInputs{Action: action, Tools: profile.MCPTools()}, profile.Specialist, bound)
97 if err != nil {
98 t.Fatalf("%s: %v", action, err)
99 }
100 var tp threadPolicy
101 if json.Unmarshal(got.ThreadPolicy, &tp) != nil {
102 t.Fatal("thread policy")
103 }
104 i := slices.Index(got.Argv, "--model")
105 if slices.Contains(got.Argv, "--effort") && action == provider.GlanceAction {
106 t.Fatalf("a glance asks for an effort: %q", got.Argv)
107 }
108 return got.Argv[i+1], tp
109 }
110 for _, bound := range []string{"claude-opus-5-5", "claude-sonnet-5-5"} {
111 if got, tp := model(provider.GlanceAction, bound); got != GlanceModel || tp.Model != bound {
112 t.Fatalf("glance on %s: argv %s, thread %s", bound, got, tp.Model)
113 }
114 for _, action := range glanceOthers {
115 if got, tp := model(action, bound); got != bound || tp.Model != bound {
116 t.Fatalf("%s on %s ran %s (thread %s)", action, bound, got, tp.Model)
117 }
118 }
119 }
120 if got := provider.LaunchModel("assist", "claude", "claude-opus-5-5"); got != "claude-opus-5-5" {
121 t.Fatalf("assist launches %s", got)
122 }
123 if got := provider.LaunchModel(provider.GlanceAction, "pi", "tensorx-1"); got != "tensorx-1" {
124 t.Fatalf("a glance on a provider without a small model launches %s", got)
125 }
126}
127
128func mustJSON(t *testing.T, v any) []byte {
129 t.Helper()
130 raw, err := json.Marshal(v)
131 if err != nil {
132 t.Fatal(fmt.Sprint(err))
133 }
134 return raw
135}
136