跳到主要内容

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

浏览文件

tailnet-client.test.mjs

31 行 · 2.6 KB历史下载
1import test from "node:test";
2import assert from "node:assert/strict";
3import { spawn } from "node:child_process";
4import { createTailnetClient } from "./tailnet-client.mjs";
5
6test("stdio requests are serialized, preserve component errors and reject wire commands", async () => {
7 const seen = [];
8 const fixture = `let text=''; process.stdin.on('data',chunk=>{text+=chunk;let end;while((end=text.indexOf('\\n'))>=0){const input=JSON.parse(text.slice(0,end));text=text.slice(end+1);setTimeout(()=>console.log(JSON.stringify(input.action==='add-key'?{error:'请粘贴有效 SSH 公钥'}:{installed:true,action:input.action})),10)}});`;
9 const client = createTailnetClient({ executable: process.execPath, start: (file,args,options) => { seen.push({file,args}); return spawn(process.execPath, ["-e", fixture], options); } });
10 try {
11 const values = await Promise.all([client.request({action:"status"}), client.request({action:"connect"}), client.request({action:"add-key",key:"invalid"})]);
12 assert.deepEqual(values.map(v=>v.action||v.tailnet_error), ["status","connect","请粘贴有效 SSH 公钥"]);
13 assert.equal(seen.length,1);
14 await assert.rejects(client.request({action:"shell",command:"whoami"}));
15 await assert.rejects(client.request({action:"add-key",key:"x".repeat(8193)}));
16 assert.equal((await client.request({action:"status"})).installed,true);
17 } finally {client.close();}
18});
19test("missing guest payload offers installation without spawning a host VPN", async()=>{
20 const client=createTailnetClient({executable:"/nonexistent-cage-tailnet",start:()=>{throw Error("must not spawn")}});
21 assert.equal((await client.request({action:"status"})).installed,false);
22});
23test("service destinations are validated and forwarded through the same private protocol", async () => {
24 const client = createTailnetClient({ executable: process.execPath, start: (_file,_args,options) => spawn(process.execPath, ["-e", `let text='';process.stdin.on('data',chunk=>{text+=chunk;let end;while((end=text.indexOf('\\n'))>=0){const input=JSON.parse(text.slice(0,end));text=text.slice(end+1);console.log(JSON.stringify(input))}});`], options) });
25 try {
26 const result = await client.request({action:"open-service",host:"100.88.2.4",port:8080,command:"ignored"});
27 assert.deepEqual(result,{action:"open-service",host:"100.88.2.4",port:8080});
28 for (const input of [{host:"100.88.2.4",port:0},{host:"100.88.2.4",port:65536},{host:"100.88.2.4",port:"80"},{host:"100.88.2.4\ncommand",port:80}]) await assert.rejects(client.request({action:"open-service",...input}));
29 assert.equal((await client.request({action:"status"})).action,"status");
30 } finally {client.close();}
31});