package claude import ( "context" "encoding/json" "os" "path/filepath" "slices" "testing" "time" "amadan.net/oficina/equipo/internal/runner/provider" ) func TestProtectedPermissionNeverAsks(t *testing.T) { f := fixtureFor(t, "Engineering") s, events := openFixture(t, f) f.l.mu.Lock() st, _ := f.l.state(s) st.active = true st.turn = provider.Turn{ID: "turn"} f.l.mu.Unlock() if err := os.Symlink("/home/runner", filepath.Join(f.launch.Workspace, "alias")); err != nil { t.Fatal(err) } for _, path := range []string{"~/.credentials.json", "~other/sentinel", "/home/runner/auth", "/home/other/sentinel", "/egress/sentinel", "/tool/equipo.sock", "/proc/1/root/home/runner/auth", "/dev/fd/0", "/workspace/alias/auth", "../home/runner/auth"} { t.Run(path, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() raw, _ := json.Marshal(permissionRequest{Tool: "Read", Input: marshalProbe(map[string]string{"file_path": path})}) reply, err := f.l.Permission(ctx, s, raw) var answer struct{ Behavior string } if err != nil || json.Unmarshal(reply, &answer) != nil || answer.Behavior != "deny" { t.Errorf("protected path did not deny immediately: %s %v", reply, err) } select { case ev := <-events: t.Errorf("protected path reached human: %s", ev.Kind) default: } if _, err := permissionResult(permissionRequest{Tool: "Read", Input: marshalProbe(map[string]string{"file_path": path})}, provider.Answer{Behavior: "allow"}, f.launch.Policy); err == nil { t.Error("protected path can be approved") } }) } } func marshalProbe(v any) json.RawMessage { raw, _ := json.Marshal(v); return raw } func TestHostHomeNativeDeny(t *testing.T) { f := fixtureFor(t, "Engineering") var m manifest json.Unmarshal(f.launch.Policy.Manifest, &m) var settings struct { Permissions struct{ Deny []string } Sandbox struct{ Filesystem struct{ DenyRead []string } } } json.Unmarshal(m.Settings, &settings) if !slices.Contains(settings.Permissions.Deny, "Read(//home/**)") || !slices.Contains(settings.Sandbox.Filesystem.DenyRead, "/home") { t.Fatal("host homes not denied") } }