跳到主要内容

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

浏览文件

windows_display_connection_unix_test.go

54 行 · 1.7 KB历史下载
1//go:build !windows
2
3package workbench
4
5import (
6 "context"
7 "errors"
8 "net"
9 "os/exec"
10 "testing"
11)
12
13func TestDesktopViewerConnectionReplacementEndsTheOneHoldingInput(t *testing.T) {
14 cat, err := exec.LookPath("cat")
15 if err != nil {
16 t.Skip("needs cat as a stand-in relay")
17 }
18 open := func() (*nativeWindowConnection, error) {
19 ctx, cancel := context.WithCancel(context.Background())
20 return startWindowConnection(exec.CommandContext(ctx, cat), cancel)
21 }
22 first, err := open()
23 if err != nil {
24 t.Fatal(err)
25 }
26 connection := &desktopViewerConnection{current: first}
27 if err := connection.request(map[string]any{"action": "frame"}, nil); err != nil {
28 t.Fatal(err)
29 }
30 if err := connection.replace(open); err != nil {
31 t.Fatal(err)
32 }
33 // The guest releases a viewer's keys when its connection ends.
34 if first.cmd.ProcessState == nil {
35 t.Fatal("the connection holding input is still open")
36 }
37 if connection.current == first || connection.request(map[string]any{"action": "frame"}, nil) != nil {
38 t.Fatal("the viewer has no working connection")
39 }
40 failure := errors.New("relay unavailable")
41 if err := connection.replace(func() (*nativeWindowConnection, error) { return nil, failure }); err != failure {
42 t.Fatalf("failed replacement hidden: %v", err)
43 }
44 if connection.request(map[string]any{"action": "frame"}, nil) != nil {
45 t.Fatal("a failed replacement closed the working connection")
46 }
47 second := connection.current
48 connection.Close()
49 var late *nativeWindowConnection
50 err = connection.replace(func() (*nativeWindowConnection, error) { late, err = open(); return late, err })
51 if !errors.Is(err, net.ErrClosed) || second.cmd.ProcessState == nil || late == nil || late.cmd.ProcessState == nil {
52 t.Fatalf("a closed viewer kept a guest connection: %v", err)
53 }
54}