跳到主要内容

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

浏览文件

basic_test.go

90 行 · 2.4 KB历史下载
1//go:build windows
2
3package e2e
4
5import (
6 "context"
7 "io"
8 "net"
9 "net/http"
10 "os"
11 "os/exec"
12 "strings"
13 "time"
14
15 winio "github.com/Microsoft/go-winio"
16
17 . "github.com/onsi/ginkgo"
18 . "github.com/onsi/gomega"
19)
20
21var timeout = 1 * time.Minute
22
23var _ = Describe("connectivity", func() {
24 It("proxy exits as requested, without a kill", func() {
25 err := startProxy()
26 Expect(err).ShouldNot(HaveOccurred())
27
28 var pid, tid uint32
29 for i := 0; i < 20; i++ {
30 pid, tid, err = readTid()
31 if err == nil && tid != 0 {
32 break
33 }
34 time.Sleep(100 * time.Millisecond)
35 }
36
37 Expect(tid).ShouldNot(Equal(0))
38 Expect(err).ShouldNot(HaveOccurred())
39 proc, err := os.FindProcess(int(pid))
40 Expect(err).ShouldNot(HaveOccurred())
41 Expect(proc).ShouldNot(BeNil())
42 err = stopProxy(true)
43 Expect(err).ShouldNot(HaveOccurred())
44 })
45
46 It("proxies over a windows pipe", func() {
47 err := startProxy()
48 Expect(err).ShouldNot(HaveOccurred())
49 defer func() {
50 Expect(stopProxy(false)).ShouldNot(HaveOccurred())
51 }()
52 httpClient := &http.Client{
53 Transport: &http.Transport{
54 DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
55 return winio.DialPipe(`\\.\pipe\fake_docker_engine`, &timeout)
56 },
57 },
58 }
59
60 Eventually(func(g Gomega) {
61 resp, err := httpClient.Get("http://host/ping")
62 g.Expect(err).ShouldNot(HaveOccurred())
63 defer resp.Body.Close()
64
65 g.Expect(resp.StatusCode).To(Equal(http.StatusOK))
66 g.Expect(resp.ContentLength).To(Equal(int64(4)))
67
68 reply := make([]byte, resp.ContentLength)
69 _, err = io.ReadAtLeast(resp.Body, reply, len(reply))
70
71 g.Expect(err).ShouldNot(HaveOccurred())
72 g.Expect(string(reply)).To(Equal("pong"))
73
74 }).Should(Succeed())
75 })
76
77 It("windows event logs were created", func() {
78 cmd := exec.Command("powershell", "-Command", "&{Get-WinEvent -ProviderName \".NET Runtime\" -MaxEvents 10 | Where-Object -Property Message -Match \"test:\"}")
79 reader, err := cmd.StdoutPipe()
80 Expect(err).ShouldNot(HaveOccurred())
81 err = cmd.Start()
82 Expect(err).ShouldNot(HaveOccurred())
83 output, err := io.ReadAll(reader)
84 Expect(err).ShouldNot(HaveOccurred())
85 err = cmd.Wait()
86 Expect(err).ShouldNot(HaveOccurred())
87 Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
88 Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
89 })
90})