bots-garden/mini-mepublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/bots-garden/mini-me.git
git clone ssh://git@rickub.com/bots-garden/mini-me.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

ui_test.go · 54 lines · 1.8 KBGo Blame HistoryRaw
💾 Saved. d722711 k33g 4h ago1package ui
2
3import (
4 "context"
5 "strings"
6 "testing"
7)
8
9// stubSink is the smallest Sink that can carry a working directory.
10type stubSink struct{ cwd string }
11
12func (stubSink) Text(string) {}
13func (stubSink) ToolStart(ToolEvent) {}
14func (stubSink) Allow(context.Context, ToolEvent) bool { return true }
15func (stubSink) ToolRunning(string) {}
16func (stubSink) ToolEnd(string, ToolResult) {}
17func (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.
21func 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.
32func 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.
46func 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}