跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

notify_test.go

32 行 · 1.2 KB历史下载
1package limaembed
2
3import (
4 "bytes"
5 "strings"
6 "testing"
7)
8
9// Events pass through as written; a forwarded port, or one refused because
10// the host uses it, is told, once each.
11func TestEventWatch(t *testing.T) {
12 var out bytes.Buffer
13 var told []string
14 e := newEventWatch(&out, "proj-1a2b3c4d")
15 e.notify = func(title, msg string) { told = append(told, title+": "+msg) }
16 in := `{"status":{"running":true}}
17{"status":{"portForward":{"type":"forwarding","protocol":"tcp","guestAddr":"127.0.0.1:5173","hostAddr":"127.0.0.1:5173"}}}
18{"status":{"portForward":{"type":"failed","protocol":"tcp","guestAddr":"127.0.0.1:5432","hostAddr":"127.0.0.1:5432","error":"in use"}}}
19{"status":{"portForward":{"type":"forwarding","hostAddr":"not an address"}}}
20`
21 // Split across writes, as a pipe may.
22 e.Write([]byte(in[:40]))
23 e.Write([]byte(in[40:]))
24 if out.String() != in {
25 t.Errorf("events changed: %q", out.String())
26 }
27 want := "agent-vm: proj-1a2b3c4d: The VM now serves 127.0.0.1:5173 on this machine.\n" +
28 "agent-vm: proj-1a2b3c4d: Not forwarded: 127.0.0.1:5432 is in use on this machine."
29 if strings.Join(told, "\n") != want {
30 t.Errorf("told:\n%s", strings.Join(told, "\n"))
31 }
32}