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 "amadan.net/oficina/equipo/internal/runner/provider"
5 "bytes"
6 "context"
7 "encoding/json"
8 "slices"
9 "strings"
10 "testing"
11 "time"
12)
13
14func TestClaudeEngineeringWorkspaceCallback(t *testing.T) {
15 f := fixtureFor(t, "Engineering")
16 var settings struct {
17 Sandbox map[string]any
18 Permissions struct{ Allow, Deny, Ask []string }
19 }
20 json.Unmarshal(f.inputs.Settings, &settings)
21 if settings.Sandbox["autoAllowBashIfSandboxed"] != true || settings.Sandbox["allowUnsandboxedCommands"] != false || settings.Sandbox["failIfUnavailable"] != true {
22 t.Fatal("sandboxed Bash requires a person or weakens containment")
23 }
24 for _, tool := range []string{"Write", "Edit", "Read", "Glob", "Grep"} {
25 if !slices.Contains(settings.Permissions.Ask, tool+"(//workspace/**)") || slices.Contains(settings.Permissions.Allow, tool+"(//workspace/**)") {
26 t.Fatal("workspace tool bypasses the callback", tool)
27 }
28 }
29 if slices.Contains(settings.Permissions.Allow, "Write") || len(settings.Permissions.Deny) == 0 {
30 t.Fatal("unscoped write or removed denials")
31 }
32}
33func TestClaudePreflightExitDiagnostic(t *testing.T) {
34 f := fixtureFor(t, "Engineering")
35 f.host.mode = "sandbox"
36 _, err := f.l.Open(context.Background(), f.launch)
37 if err == nil || !strings.Contains(err.Error(), "exit=1") || !strings.Contains(err.Error(), "Sandbox required but unavailable") {
38 t.Fatalf("missing CLI diagnostic: %v", err)
39 }
40}
41func TestClaudeOutOfWorkspaceOriginalAction(t *testing.T) {
42 f := fixtureFor(t, "Engineering")
43 raw, err := permissionResult(permissionRequest{Tool: "Write", Input: json.RawMessage(`{"file_path":"/outside/file","content":"x"}`)}, provider.Answer{Behavior: "allow"}, f.launch.Policy)
44 if err != nil || !strings.Contains(string(raw), "/outside/file") {
45 t.Fatal("explicit original action refused", err)
46 }
47}
48
49func TestClaudeNativeAuthorization(t *testing.T) {
50 f := fixtureFor(t, "Engineering")
51 s, events := openFixture(t, f)
52 f.l.mu.Lock()
53 state, _ := f.l.state(s)
54 state.active = true
55 state.turn = provider.Turn{ID: "turn"}
56 f.l.mu.Unlock()
57 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
58 defer cancel()
59 raw := json.RawMessage(`{"tool_name":"Write","tool_use_id":"outside","input":{"file_path":"/outside/file","content":"x"}}`)
60 done := make(chan error, 1)
61 go func() { _, err := f.l.Permission(ctx, s, raw); done <- err }()
62 ev := <-events
63 answer := provider.Answer{RequestID: ev.RequestID, TurnID: "turn", Behavior: "allow", Authorize: func(context.Context, provider.Event) error { return provider.ErrIdentity }}
64 if err := f.l.Respond(ctx, s, answer); err == nil {
65 t.Fatal("revoked approval accepted")
66 }
67 called := false
68 answer.Authorize = func(_ context.Context, got provider.Event) error {
69 called = true
70 if !bytes.Equal(got.Payload, raw) {
71 t.Fatal("request changed")
72 }
73 return nil
74 }
75 if err := f.l.Respond(ctx, s, answer); err != nil {
76 t.Fatal(err)
77 }
78 if !called {
79 t.Fatal("authority not checked")
80 }
81 if err := <-done; err != nil {
82 t.Fatal(err)
83 }
84}
85