| 💾 Saved. d722711 k33g 7h ago | 1 | package ui |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // stubSink is the smallest Sink that can carry a working directory. |
| 10 | type stubSink struct{ cwd string } |
| 11 | |
| 12 | func (stubSink) Text(string) {} |
| 13 | func (stubSink) ToolStart(ToolEvent) {} |
| 14 | func (stubSink) Allow(context.Context, ToolEvent) bool { return true } |
| 15 | func (stubSink) ToolRunning(string) {} |
| 16 | func (stubSink) ToolEnd(string, ToolResult) {} |
| 17 | func (s stubSink) WorkDir() string { return s.cwd } |
| 18 | |
| 19 | // With no sink — the terminal front end — Resolve must be the identity: part |
| 20 | // 10's behaviour, paths relative to the process, unchanged. |
| 21 | func TestResolveWithoutSinkIsIdentity(t *testing.T) { |
| 22 | SetActive(nil) |
| 23 | for _, p := range []string{"hello/main.go", "../x", "/abs/path"} { |
| 24 | if got := Resolve(p); got != p { |
| 25 | t.Errorf("Resolve(%q) = %q, want unchanged", p, got) |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // With a sink, a relative path follows the SESSION's working directory — the |
| 31 | // project open in the editor — and an absolute one is left alone. |
| 32 | func TestResolveWithSinkFollowsTheSession(t *testing.T) { |
| 33 | SetActive(stubSink{cwd: "/work/project"}) |
| 34 | defer SetActive(nil) |
| 35 | |
| 36 | if got := Resolve("hello/main.go"); got != "/work/project/hello/main.go" { |
| 37 | t.Errorf("relative path: got %q", got) |
| 38 | } |
| 39 | if got := Resolve("/etc/hosts"); got != "/etc/hosts" { |
| 40 | t.Errorf("absolute path must not move: got %q", got) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // Call IDs must never repeat: an ACP client correlates tool_call and |
| 45 | // tool_call_update by them, and a duplicate would merge two calls in its UI. |
| 46 | func TestNextCallIDNeverRepeats(t *testing.T) { |
| 47 | a, b := NextCallID(), NextCallID() |
| 48 | if a == b { |
| 49 | t.Fatalf("two calls, same id: %q", a) |
| 50 | } |
| 51 | if !strings.HasPrefix(a, "call_") { |
| 52 | t.Fatalf("unexpected shape: %q", a) |
| 53 | } |
| 54 | } |