package claude import ( "amadan.net/oficina/equipo/internal/runner/provider" "context" "encoding/json" "slices" "strings" "testing" "time" ) func TestHookEventsAndNativeAskPolicy(t *testing.T) { f := fixtureFor(t, "Engineering") var m manifest if err := json.Unmarshal(f.launch.Policy.Manifest, &m); err != nil { t.Fatal(err) } if !slices.Contains(m.Argv, "--include-hook-events") { t.Error("hook events not requested") } var settings struct{ Permissions struct{ Ask, Allow []string } } if err := json.Unmarshal(m.Settings, &settings); err != nil { t.Fatal(err) } for _, tool := range []string{"Read", "Glob", "Grep", "Write", "Edit"} { rule := tool + "(//workspace/**)" if !slices.Contains(settings.Permissions.Ask, rule) || slices.Contains(settings.Permissions.Allow, rule) { t.Errorf("%s can bypass symlink callback", tool) } } } func TestHookEventFlagBoundToPolicy(t *testing.T) { f := fixtureFor(t, "Engineering") in := f.inputs in.Argv = slices.DeleteFunc(slices.Clone(in.Argv), func(arg string) bool { return arg == "--include-hook-events" }) changed, err := provider.BuildPolicy(f.launch.Binding, in) if err != nil { t.Fatal(err) } if changed.Hash == f.launch.Policy.Hash { t.Fatal("hook flag absent from policy hash") } if _, err = f.l.validatePolicy(f.launch.Binding, changed); err == nil { t.Fatal("missing hook-event flag accepted") } } // TestNoShellCommandIsAMarker: the person-approval controls were shell // commands whose printed text a live-gate harness read as evidence // (printf equipo-cert-allow, printf equipo-cert-deny). That harness went // with the certification evidence (bbf490ed); nothing reads the text now, // and a shell rule could never keep a sandboxed command from printing it. // No Bash ask rule remains: no command's text means anything to Equipo. func TestNoShellCommandIsAMarker(t *testing.T) { f := fixtureFor(t, "Engineering") var settings struct { Permissions struct{ Ask []string } Sandbox map[string]any } if err := json.Unmarshal(f.inputs.Settings, &settings); err != nil { t.Fatal(err) } for _, ask := range settings.Permissions.Ask { if strings.HasPrefix(ask, "Bash") { t.Errorf("shell ask rule %q", ask) } } if settings.Sandbox["autoAllowBashIfSandboxed"] != true || settings.Sandbox["allowUnsandboxedCommands"] != false { t.Fatal("ordinary sandbox policy changed") } } func TestWorkspaceFileControlsStayAutomatic(t *testing.T) { f := fixtureFor(t, "Engineering") session, events := openFixture(t, f) f.l.mu.Lock() state, _ := f.l.state(session) state.active = true state.turn = provider.Turn{ID: "turn"} f.l.mu.Unlock() for tool, input := range map[string]string{ "Read": `{"file_path":"/workspace/ordinary.txt"}`, "Write": `{"file_path":"/workspace/ordinary.txt","content":"ordinary"}`, "Edit": `{"file_path":"/workspace/ordinary.txt","old_string":"ordinary","new_string":"updated"}`, "Glob": `{"path":"/workspace","pattern":"*.txt"}`, "Grep": `{"path":"/workspace","pattern":"ordinary"}`, } { t.Run(tool, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() raw, _ := json.Marshal(permissionRequest{Tool: tool, Input: json.RawMessage(input)}) reply, err := f.l.Permission(ctx, session, raw) var answer struct{ Behavior string } if err != nil || json.Unmarshal(reply, &answer) != nil || answer.Behavior != "allow" { t.Fatalf("workspace action reached person: %s %v", reply, err) } select { case ev := <-events: t.Fatalf("workspace approval published: %s", ev.Payload) default: } }) } }