跳到主要内容

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

浏览文件

proxy-chain-ui-smoke.mjs

135 行 · 9.9 KB历史下载
1// Runs the actual workbench with isolated API fixtures. Real core forwarding is
2// covered by proxy-chain-smoke.mjs; this script covers user input and recovery.
3import assert from 'node:assert/strict';
4import fs from 'node:fs/promises';
5import path from 'node:path';
6import { createWorkbench, chooseInline } from './workbench-fixture.mjs';
7
8const output = path.resolve(process.env.CAGE_CHAIN_QA_OUTPUT || 'ui/.oil-ui/proxy-chain-20261105/shots');
9await fs.mkdir(output, { recursive: true });
10const f = await createWorkbench();
11const { page, state, browser, errors } = f;
12const saved = {
13 sources: [
14 { id:'airport', name:'旅行订阅', nodes:[{id:'entry',name:'🇺🇸 USA Los Angeles 02',type:'anytls'}, {id:'extra',name:'Tokyo Transit',type:'trojan'}]},
15 { id:'home',name:'住宅代理',nodes:[{id:'exit',name:'LoopsForge · AI 住宅 IP · 节点001',type:'vless'}]},
16 ], selected:'entry',route:['entry'],active:true,running:true,core_available:true,port:17896,state_label:'待启动环境',route_error:'',
17};
18let failRoute = false, submissions = [];
19await page.route('**/api/proxy', r=>r.fulfill({json:saved}));
20await page.route('**/api/proxy/route', r=>{
21 const body=r.request().postDataJSON();
22 submissions.push(body);
23 const available=saved.sources.flatMap(s=>s.nodes.map(n=>n.id));
24 const valid=body.node_ids.length>0 && body.node_ids.every(id=>available.includes(id)) && new Set(body.node_ids).size===body.node_ids.length;
25 const error=failRoute ? '代理核心拒绝该配置;原配置已保留' : !valid ? '代理链节点无效' : '';
26 if (!error) { saved.route=[...body.node_ids];saved.selected=body.node_ids.at(-1); }
27 state.status.job={id:`route-${submissions.length}`,kind:'proxy',running:false,error,message:error?'':'节点已应用;启动 Cage 环境后完成联网检查'};
28 return r.fulfill({json:{id:state.status.job.id}});
29});
30const enter = async()=>{
31 await page.getByRole('button',{name:/^设置/}).click();
32 await page.getByRole('button',{name:'网络与代理',exact:true}).click();
33 await page.getByRole('heading',{name:'内置代理',exact:true}).waitFor();
34 await page.getByRole('combobox',{name:'最终出口',exact:true}).waitFor();
35};
36const idle = ()=>page.waitForFunction(()=>!document.querySelector('.proxy-progress'));
37try {
38 await page.getByRole('button',{name:'Cage 环境 网络检查',exact:true}).click();
39 await page.getByRole('button',{name:'出口规则',exact:true}).click();
40 await page.getByRole('heading',{name:'内置代理',exact:true}).waitFor();
41 await page.getByRole('region',{name:'IP 变化规则',exact:true}).waitFor();
42 await page.getByRole('button',{name:'链式代理',exact:true}).click();
43 assert.equal(await page.getByRole('button',{name:'应用代理',exact:true}).isDisabled(),true);
44 await chooseInline(page.getByRole('combobox',{name:'最终出口',exact:true}),'exit');
45 const exit = page.getByRole('combobox',{name:'最终出口',exact:true});
46 const via = page.getByRole('combobox',{name:'中转节点',exact:true});
47 const relativeExit = async () => (await exit.boundingBox()).y - (await page.locator(".proxy-route").boundingBox()).y;
48 const before=await relativeExit();
49 await via.click();
50 const after=await relativeExit();
51 assert.ok(Math.abs(after-before)<1,'floating dropdown must not move the following exit');
52 const list=await page.getByRole('listbox',{name:'中转节点选项'}).boundingBox();
53 const container=await page.locator('.proxy-route').boundingBox();
54 assert.ok(list.x>=container.x && list.x+list.width<=container.x+container.width,'dropdown escapes its container');
55 await page.screenshot({path:path.join(output,'inline-options.png')});
56 await via.press('Home'); await via.press('Enter');
57 assert.match(await via.innerText(), /Los Angeles/);
58 assert.equal(await via.getAttribute('aria-expanded'),'false');
59 assert.equal(await via.evaluate(el=>el===document.activeElement),true);
60 assert.ok(Math.abs((await relativeExit())-before)<2,'collapsed dropdown did not restore layout');
61 assert.equal(submissions.length,0,'editing a chain applied it early');
62 await page.getByText('代理修改待应用,请点击「应用代理」',{exact:true}).waitFor();
63 await page.getByRole('button',{name:'返回工作台',exact:true}).last().click();
64 await page.getByRole('dialog',{name:'放弃尚未保存的修改?',exact:true}).waitFor();
65 await page.getByRole('dialog').getByRole('button',{name:'取消',exact:true}).click();
66 assert.equal(await page.locator('.proxy-route-hop').count(),2);
67 await page.getByRole('button',{name:'通用',exact:true}).click();
68 await page.getByRole('dialog',{name:'放弃尚未应用的代理修改?',exact:true}).waitFor();
69 await page.getByRole('dialog').getByRole('button',{name:'取消',exact:true}).click();
70 assert.equal(await page.locator('.proxy-route-hop').count(),2);
71 assert.equal(await page.getByRole('button',{name:'选择节点 🇺🇸 USA Los Angeles 02',exact:true}).isDisabled(),true,'transit can also be selected as exit');
72 await page.getByLabel('加密 DNS',{exact:true}).fill('https://dns.google/dns-query');
73 await page.getByRole('button',{name:'保存设置',exact:true}).click();
74 await page.waitForFunction(()=>document.querySelector('.settings-footer button.primary')?.disabled===true);
75 assert.equal(await page.locator('.proxy-route-hop').count(),2,'saving other settings discarded the proxy draft');
76 assert.equal(submissions.length,0,'saving other settings implicitly applied the route');
77
78 await page.locator('.settings-content').evaluate(el=>el.scrollTop=0);
79 await page.screenshot({path:path.join(output,'chain-draft.png')});
80 await page.getByRole('button',{name:'应用代理',exact:true}).click(); await idle();
81 await page.getByText('当前配置已应用',{exact:true}).waitFor();
82 await page.getByRole('button',{name:'重新应用',exact:true}).waitFor();
83 assert.deepEqual(saved.route,['entry','exit']);
84 assert.deepEqual(submissions[0],{node_ids:['entry','exit'],port:17896});
85 await page.reload();await enter();
86 assert.match(await page.getByRole('combobox',{name:'中转节点',exact:true}).innerText(),/Los Angeles/);
87 assert.match(await page.getByRole('combobox',{name:'最终出口',exact:true}).innerText(),/LoopsForge/);
88 await page.getByRole('button',{name:'添加中转',exact:true}).click();
89 const extra=page.getByRole('combobox',{name:'中转节点 2',exact:true});
90 await extra.focus();await extra.press('ArrowDown');await extra.press('End');await extra.press('Enter');
91 assert.match(await extra.innerText(),/Tokyo/);
92 failRoute=true;
93 await page.getByRole('button',{name:'应用代理',exact:true}).click(); await idle();
94 await page.getByRole('alert').filter({hasText:'代理核心拒绝该配置'}).waitFor();
95 assert.deepEqual(saved.route,['entry','exit'],'failed route replaced persisted selection');
96 assert.match(await extra.innerText(),/Tokyo/,'failed save lost the draft');
97 await page.screenshot({path:path.join(output,'failed-apply.png')});
98 failRoute=false;
99 await page.getByRole('button',{name:'应用代理',exact:true}).click(); await idle();
100 await page.getByText('当前配置已应用',{exact:true}).waitFor();
101 assert.deepEqual(saved.route,['entry','extra','exit']);
102 await page.getByRole('button',{name:'移除中转节点 2',exact:true}).click();
103 await page.getByRole('button',{name:'撤销修改',exact:true}).click();
104 assert.equal(await page.locator('.proxy-route-hop').count(),3);
105 await page.getByRole('button',{name:'单节点',exact:true}).click();
106 assert.equal(await page.locator('.proxy-route-hop').count(),1);
107 await page.getByRole('button',{name:'应用代理',exact:true}).click(); await idle();
108 await page.getByText('当前配置已应用',{exact:true}).waitFor();
109 assert.deepEqual(saved.route,['exit']);
110 // A changed backend list cannot silently shorten a pending route.
111 saved.sources[0].nodes=saved.sources[0].nodes.filter(n=>n.id!=='extra');
112 await page.getByRole('button',{name:'链式代理',exact:true}).click();
113 await chooseInline(page.getByRole('combobox',{name:'中转节点',exact:true}),'entry');
114 await page.getByRole('button',{name:'应用代理',exact:true}).click(); await idle();
115 await page.getByText('当前配置已应用',{exact:true}).waitFor();
116 await page.locator('.settings-content').evaluate(el=>el.scrollTop=0);
117 await page.waitForFunction(()=>[...document.querySelectorAll('.proxy-route-hop')].every(el=>getComputedStyle(el).opacity==='1'));
118 await page.screenshot({path:path.join(output,'chain-applied.png')});
119 await page.locator('.proxy-route').screenshot({path:path.join(output,'chain-panel.png'),animations:'disabled'});
120 await page.setViewportSize({width:760,height:900});
121 await page.locator('.settings-content').evaluate(el=>el.scrollTop=0);
122 const bounds=await page.locator('.proxy-route').boundingBox();
123 assert.ok(bounds.x>=0 && bounds.x+bounds.width<=760,'route panel overflows the narrow viewport');
124 await page.waitForFunction(()=>innerHeight===900 && innerWidth===760);
125 assert.equal(await page.getByRole('heading',{name:'内置代理',exact:true}).count(),1);
126 assert.equal(await page.locator('.settings-page').count(),1);
127 await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));
128 await page.screenshot({path:path.join(output,'narrow.png'),animations:'disabled'});
129 await page.setViewportSize({width:1280,height:850});
130 await page.emulateMedia({colorScheme:'dark',reducedMotion:'reduce'});
131 await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));
132 await page.screenshot({path:path.join(output,'dark.png'),animations:'disabled'});
133 assert.deepEqual(errors,[]);
134 console.log(JSON.stringify({passed:true,submissions:submissions.length,checks:['network-check exit-rules entry','cross-source route draft','floating options keep layout fixed','keyboard selection and focus','explicit atomic apply','reload persistence','failed apply keeps draft','retry','multiple transit nodes','undo','leave and section-change confirmation','saving DNS preserves route draft','single-node mode','narrow viewport'],browserErrors:errors}));
135} finally {await browser.close();}