femo-plugin 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/docs/ActiveRoadmaps/Func/345/201/234/346/255/242/350/257/255/344/271/211-/351/201/227/345/274/203/346/216/245/347/273/255-/346/226/275/345/267/245/346/270/205/345/215/225.md +91 -0
  2. package/docs/ActiveRoadmaps//345/217/214user/346/226/275/345/267/245/346/270/205/345/215/225.md +326 -0
  3. package/docs/Specs//346/212/225/345/275/261/344/270/255/345/277/203/350/241/214/345/215/217/350/256/256.md +616 -569
  4. package/femo2host/AGENTS.md +1 -1
  5. package/femo2host/femoGenConnector/engine-client.mjs +7 -2
  6. package/femo2host/femoGenConnector/file-dialogs.mjs +108 -2
  7. package/femo2host/femoToolcall/chronica.py +99 -19
  8. package/femo2host/femo_api.py +14 -1
  9. package/femo2host/host/actor-core.d.mts +25 -0
  10. package/femo2host/host/actor-core.mjs +72 -0
  11. package/femo2host/host/cast-core.d.mts +3 -0
  12. package/femo2host/host/cast-core.mjs +14 -0
  13. package/femo2host/host/daemon-client.mjs +59 -10
  14. package/femo2host/host/hub-render-core.d.mts +2 -0
  15. package/femo2host/host/hub-render-core.mjs +6 -2
  16. package/femo2host/host/run-state-core.d.mts +4 -0
  17. package/femo2host/host/run-state-core.mjs +4 -0
  18. package/femo2host/host/speech-core.mjs +11 -4
  19. package/femo2host/host/tools-core.d.mts +11 -0
  20. package/femo2host/host/tools-core.mjs +39 -0
  21. package/femo2host/mailbox.py +66 -20
  22. package/femo2host/projectionCenter/app.css +61 -0
  23. package/femo2host/projectionCenter/composer.mjs +69 -11
  24. package/femo2host/projectionCenter/identity.mjs +131 -0
  25. package/femo2host/projectionCenter/index.html +54 -1
  26. package/femo2host/projectionCenter/main.mjs +209 -33
  27. package/femo2host/projectionCenter/panels.mjs +108 -16
  28. package/femo2host/projectionCenter/render.mjs +813 -695
  29. package/femo2host/projectionCenter/state.mjs +30 -0
  30. package/femo2host/projectionCenter/util.mjs +28 -0
  31. package/femo2host/projection_hub.py +9917 -8422
  32. package/femo2host/python/femo_bridge.py +270 -32
  33. package/femo2host/python/femo_daemon.py +1528 -1209
  34. package/femo2host/python/mirror_window.py +237 -0
  35. package/femoBridges/ContextExample.py +113 -71
  36. package/femoCompiler/AGENTS.md +1 -0
  37. package/femoCompiler/FEMO_parser.py +2641 -2567
  38. package/femoCompiler/FEMO_runtime.py +201 -44
  39. package/femoCompiler/FEMO_scope_resolver.py +26 -12
  40. package/femoCompiler/block_collector.py +24 -27
  41. package/femoCompiler/db_utils.py +560 -503
  42. package/femoCompiler/femoAsync.py +466 -436
  43. package/femoCompiler/func_registry.py +74 -0
  44. package/femoCompiler/protocol.py +127 -127
  45. package/femoCompiler/save_dialog.py +497 -446
  46. package/femoExamples/AI/350/201/212/345/244/251/345/256/244/AI/350/201/212/345/244/251/345/256/244-/345/270/246agent/347/211/210.femo +229 -142
  47. package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +91 -2
  48. package/femoExamples/LuxFiat/luxfiat-loop.femo +0 -1
  49. package/femoExamples/LuxFiat/luxfiat-simple.femo +23 -24
  50. package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +221 -222
  51. package/femoExamples/discussion.femo +72 -72
  52. package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210-9/344/272/272/351/242/204/345/245/263/347/214/216.femo +1 -2
  53. package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +1 -2
  54. package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +1 -2
  55. package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +1 -1
  56. package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +1 -1
  57. package/femoGen/src/femoParser.jsx +14 -0
  58. package/hostAdapter/dshAdapter/host/femo-skill.ts +23 -10
  59. package/hostAdapter/dshAdapter/host/routes/projection-input.ts +3 -0
  60. package/hostAdapter/dshAdapter/lib/client.js +20 -2
  61. package/hostAdapter/dshAdapter/lib/client.js.map +2 -2
  62. package/hostAdapter/dshAdapter/lib/main.js +161 -18
  63. package/hostAdapter/dshAdapter/lib/main.js.map +3 -3
  64. package/hostAdapter/dshAdapter/package.json +1 -1
  65. package/hostAdapter/webAdapter/console/index.html +12 -4
  66. package/hostAdapter/webAdapter/extension/background.js +16 -5
  67. package/hostAdapter/webAdapter/extension/seat-agent-core.js +2 -1
  68. package/hostAdapter/webAdapter/extension/sidepanel/actors.mjs +101 -0
  69. package/hostAdapter/webAdapter/extension/sidepanel/main.mjs +81 -20
  70. package/hostAdapter/webAdapter/extension/sidepanel/reconnect.mjs +33 -0
  71. package/hostAdapter/webAdapter/extension/sidepanel/run-control.mjs +22 -11
  72. package/hostAdapter/webAdapter/extension/sidepanel/seats.mjs +6 -20
  73. package/hostAdapter/webAdapter/extension/sidepanel.html +30 -8
  74. package/hostAdapter/webAdapter/native/install-native-host.mjs +1 -0
  75. package/hostAdapter/webAdapter/native/register-core.mjs +69 -28
  76. package/hostAdapter/webAdapter/native/web-launcher.sh +37 -0
  77. package/hostAdapter/webAdapter/readme.md +51 -10
  78. package/hostAdapter/webAdapter/server/bridge.mjs +1 -1
  79. package/hostAdapter/webAdapter/server/runtime.mjs +51 -5
  80. package/hostAdapter/webAdapter/server/seats.mjs +11 -6
  81. package/hostAdapter/webAdapter/server/service.mjs +108 -15
  82. package/hostAdapter/webAdapter/shared/seats-core.mjs +31 -6
  83. package/hostAdapter/webAdapter/sites/chatglm.cn/inject.js +76 -4
  84. package/hostAdapter/webAdapter/sites/chatgpt.com/SITE.md +1 -0
  85. package/hostAdapter/webAdapter/sites/chatgpt.com/content.js +13 -4
  86. package/hostAdapter/webAdapter/sites/chatgpt.com/inject.js +40 -4
  87. package/hostAdapter/webAdapter/start-service.command +16 -0
  88. package/hostAdapter/webAdapter/tests/chatgpt-parser.test.mjs +37 -0
  89. package/hostAdapter/webAdapter/tests/runtime.test.mjs +42 -0
  90. package/hostAdapter/webAdapter/tests/seats-core.test.mjs +37 -1
  91. package/hostAdapter/webAdapter/tests/smoke-service.mjs +261 -232
  92. package/hostAdapter/zcodeAdapter/runtime/speech-collect.mjs +6 -0
  93. package/hostAdapter/zcodeAdapter/tests/unbound-actors.test.mjs +51 -0
  94. package/package.json +1 -1
  95. package//350/257/255/346/263/225/346/226/207/346/241/243.md +1222 -1202
@@ -960,3 +960,45 @@ test('runtime: model_id 落账——交卷信封带 web:<站点名>;席位无
960
960
  assert.ok(speech2, '无 site 席位照常交卷');
961
961
  assert.equal(speech2.args.body.model_id, undefined, '无 site 不伪造 model_id(信封不带该栏)');
962
962
  });
963
+
964
+ // ── 续跑代际(2026-10-11 j2731 实案锁)────────────────────────────────
965
+ test('runtime: 按停中止不落「已交卷」账——续跑重发的同号拍照常派工', async () => {
966
+ // 实案:用户按停 → abortAll 把在飞回合记成「已交卷」→ 续跑后引擎重建
967
+ // Runtime、拍号从 0 重计、重发同号请求 → 连吃「双来路迟到拍」dedup →
968
+ // 引擎在节点上永等。中止 ≠ 交卷:一个字节没交的回合不许进防重账。
969
+ const { rt, sent, bridge } = makeRuntime({ resolveSeat: async () => SEAT });
970
+ rt.seats.upsertTabs('connA', [SEAT]);
971
+ const brief = { job_id: 8, wait_key: 'j8:ai_[AI发言]_1', node_name: 'AI发言', actor_name: 'wolf-seer', actor_info: { soul: 'wolf-seer' }, blocks: { prompt: '发言' } };
972
+ const first = await rt.dispatchActorRequest(brief);
973
+ assert.equal(first.accepted, true);
974
+ // 用户按停:中止在飞回合(停下信号事件现场)
975
+ bridge.onEvent('flow_paused', { job_id: 8 });
976
+ assert.equal(rt.stats().inflight, 0, '按停即在飞清空');
977
+ // 续跑:拍号从 0 重计,同号请求重发——必须照常派工
978
+ const again = await rt.dispatchActorRequest(brief);
979
+ assert.equal(again.accepted, true, '中止不落账:同号重发不被误杀');
980
+ assert.equal(sent.length, 2);
981
+ });
982
+
983
+ test('runtime: flow_start 代际重置——清防重账+释放在飞,同代保护不动', async () => {
984
+ const { rt, sent, bridge } = makeRuntime({ resolveSeat: async () => SEAT });
985
+ rt.seats.upsertTabs('connA', [SEAT]);
986
+ const brief = { job_id: 9, wait_key: 'j9:ai_[AI发言]_1', node_name: 'AI发言', actor_name: 'wolf-seer', actor_info: { soul: 'wolf-seer' }, blocks: { prompt: '发言' } };
987
+ await rt.dispatchActorRequest(brief);
988
+ const deliveryId = sent[0].deliveryId;
989
+ // 正常交卷:本代该 id 落「已交卷」防重账
990
+ rt.onSeatReport({ type: 'sent', deliveryId, sessionId: SEAT.sessionId });
991
+ rt.onSeatReport({ type: 'reply', deliveryId, sessionId: SEAT.sessionId, text: '我说完了' });
992
+ await new Promise(r => setTimeout(r, 20));
993
+ // 同一代内重复 → 原保护照旧(第二来路迟到拍丢弃)
994
+ const sameGen = await rt.dispatchActorRequest(brief);
995
+ assert.equal(sameGen.accepted, false);
996
+ assert.equal(sameGen.reason, 'duplicate (already completed)');
997
+ // 续跑:flow_start 落地 → 跨代身份作废,同号新拍照常派工
998
+ bridge.onEvent('flow_start', { job_id: 9 });
999
+ const nextGen = await rt.dispatchActorRequest(brief);
1000
+ assert.equal(nextGen.accepted, true, 'flow_start 已清账:同号新拍可派工');
1001
+ // 别场的账不受牵连
1002
+ const otherJob = await rt.dispatchActorRequest({ ...brief, job_id: 10, wait_key: 'j10:ai_[AI发言]_1' });
1003
+ assert.equal(otherJob.accepted, true);
1004
+ });
@@ -9,7 +9,7 @@
9
9
  import { test } from 'node:test';
10
10
  import assert from 'node:assert/strict';
11
11
 
12
- import { seatState, offlineRollCall, attendanceRefusal } from '../shared/seats-core.mjs';
12
+ import { seatState, offlineRollCall, attendanceRefusal, actorBindRefusal, actorWarningNotice } from '../shared/seats-core.mjs';
13
13
 
14
14
  test('seatState 四态:忙 > 在线 > 休眠 > 网页未打开', () => {
15
15
  assert.deepEqual(seatState({ busy: true, online: true, present: true }), { key: 'run', label: '运行中' });
@@ -132,3 +132,39 @@ test('总文案:总起一行 + 序号行间空行,每个缺席灵魂一条
132
132
  assert.ok(items[0].startsWith('1. '), '首条带序号 1');
133
133
  assert.ok(items[1].startsWith('2. '), '次条带序号 2');
134
134
  });
135
+
136
+ // ── 演员绑定账对账(2026-10-10,用户拍板「以 femo 脚本为先」)────────────────
137
+ // 判据与灵魂不同:多绑(账里有、脚本没有)=error 拦运行;少绑=warning 不拦。
138
+
139
+ test('演员点名:多绑进缺席数组(拦),少绑只走 warning 不拦', () => {
140
+ const actorCheck = {
141
+ errors: ['绑定的演员 @幽灵 不在剧本演员表里——检查名字(演员名带 @,照剧本里写的那样)'],
142
+ warnings: ['演员 @2号 还没绑定——轮到它时按缺员处置'],
143
+ };
144
+ const out = offlineRollCall([], [], actorCheck);
145
+ assert.equal(out.length, 1, '只有多绑那一行进拦行');
146
+ assert.ok(out[0].includes('@幽灵'));
147
+ });
148
+
149
+ test('演员点名:actorCheck 缺省/空两桶=零影响(灵魂判据零回归)', () => {
150
+ assert.deepEqual(offlineRollCall([], [{ actor: 'AI1', soul: 'ai4', bound: 'web', online: true }]), []);
151
+ assert.deepEqual(offlineRollCall([], [], { errors: [], warnings: [] }), []);
152
+ assert.deepEqual(offlineRollCall([], [], undefined), []);
153
+ });
154
+
155
+ test('演员绑定前拦截:空名/不带 @ 都拦,带 @ 放行', () => {
156
+ assert.equal(actorBindRefusal(''), '先填演员名(带 @,如 @玩家1)');
157
+ assert.equal(actorBindRefusal(' '), '先填演员名(带 @,如 @玩家1)');
158
+ assert.ok(actorBindRefusal('玩家1')?.includes('带 @ 开头'));
159
+ assert.equal(actorBindRefusal('@玩家1'), null);
160
+ assert.equal(actorBindRefusal('@1号'), null);
161
+ });
162
+
163
+ test('演员少绑提醒总文案:空=空串;有序号行且自带「不拦运行」', () => {
164
+ assert.equal(actorWarningNotice([]), '');
165
+ assert.equal(actorWarningNotice(undefined), '');
166
+ const text = actorWarningNotice(['演员 @1号 还没绑定——轮到它时按缺员处置', '演员 @2号 还没绑定——轮到它时按缺员处置']);
167
+ assert.ok(text.startsWith('演员绑定提醒(不拦运行)'));
168
+ assert.ok(text.includes('1. 演员 @1号'));
169
+ assert.ok(text.includes('2. 演员 @2号'));
170
+ });
@@ -1,232 +1,261 @@
1
- #!/usr/bin/env node
2
- /**
3
- * smoke-service.mjs — 本地服务冒烟(手动运行,不拉真桥、不碰真浏览器)。
4
- *
5
- * 起 service.mjs(随机端口+一次性沙盒),打一遍扩展协议面与操作台协议面:
6
- * /health /console /seats /seats/bind /extension/register /extension/poll
7
- * /extension/report /seats/deliver /state /tools
8
- * 运行:node tests/smoke-service.mjs
9
- */
10
-
11
- import { mkdtempSync, readFileSync } from 'node:fs';
12
- import { tmpdir } from 'node:os';
13
- import { join } from 'node:path';
14
- import { spawn } from 'node:child_process';
15
- import { fileURLToPath } from 'node:url';
16
- import { dirname } from 'node:path';
17
-
18
- const ADAPTER_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
19
- process.env.FEMO_DATA_DIR = mkdtempSync(join(tmpdir(), 'femo-web-svc-smoke-'));
20
- process.env.FEMO_WEB_PORT = '18796';
21
-
22
- const child = spawn(process.execPath, [join(ADAPTER_ROOT, 'server', 'service.mjs')], {
23
- env: process.env,
24
- stdio: ['ignore', 'pipe', 'pipe'],
25
- });
26
- child.stdout.on('data', c => process.stdout.write(`[svc] ${c}`));
27
- child.stderr.on('data', c => process.stdout.write(`[svc:err] ${c}`));
28
-
29
- const BASE = 'http://127.0.0.1:18796';
30
- const sleep = ms => new Promise(r => setTimeout(r, ms));
31
-
32
- async function waitHealthy() {
33
- for (let i = 0; i < 30; i++) {
34
- try {
35
- const r = await fetch(`${BASE}/health`);
36
- if (r.ok) return r.json();
37
- } catch { /* 还没起 */ }
38
- await sleep(300);
39
- }
40
- throw new Error('service did not become healthy in 9s');
41
- }
42
-
43
- async function post(path, body) {
44
- const r = await fetch(`${BASE}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
45
- return { status: r.status, json: await r.json() };
46
- }
47
-
48
- let ok = true;
49
- try {
50
- const health = await waitHealthy();
51
- console.log('health =>', JSON.stringify(health).slice(0, 140));
52
- assertEq(health.host, 'web', 'host 自称');
53
-
54
- const seats0 = await (await fetch(`${BASE}/seats`)).json();
55
- assertEq(seats0.seats.length, 0, '初始无席位');
56
-
57
- // 会话引用形态(`<域名>:<id>`,见 sites.mjs)——多站在役后的正字 id
58
- const REF = 'chat.deepseek.com:12345678-abcd';
59
- const reg = await post('/extension/register', { connId: 'conn-test', tabs: [{ tabId: 11, sessionId: REF, site: 'chat.deepseek.com', title: '冒烟会话', busy: false }] });
60
- assertEq(reg.json.ok, true, '注册成功');
61
- assertEq(reg.status, 200);
62
-
63
- const seats1 = await (await fetch(`${BASE}/seats`)).json();
64
- assertEq(seats1.seats.length, 1, '注册后一席');
65
- assertEq(seats1.seats[0].online, true);
66
- assertEq(seats1.seats[0].present, true, '在场=页开着');
67
- assertEq(seats1.seats[0].siteLabel, 'DeepSeek', '视图派生来源显示名');
68
- assertEq(seats1.seats[0].sidShort, '12345678', '视图派生短 id(剥来源前缀)');
69
-
70
- // 冻结页登记(2026-10-01 按需唤醒):online:false 的页照样在场(present:true);
71
- // 页关了(下轮没报到)才出账;恢复上报后席位复活(后面的绑定/下发要用它)。
72
- await post('/extension/register', { connId: 'conn-test', tabs: [{ tabId: 11, sessionId: REF, site: 'chat.deepseek.com', title: '冒烟会话', busy: false, online: false }] });
73
- const seatsFrozen = await (await fetch(`${BASE}/seats`)).json();
74
- assertEq(seatsFrozen.seats[0].present, true, '冻结页照样在场');
75
- assertEq(seatsFrozen.seats[0].online, false, '冻结页不在线');
76
- await post('/extension/register', { connId: 'conn-test', tabs: [] });
77
- const seatsGone = await (await fetch(`${BASE}/seats`)).json();
78
- assertEq(seatsGone.seats[0].present, false, '页关了=出账');
79
- assertEq(seatsGone.seats[0].online, false);
80
- await post('/extension/register', { connId: 'conn-test', tabs: [{ tabId: 11, sessionId: REF, site: 'chat.deepseek.com', title: '冒烟会话', busy: false, online: true }] });
81
-
82
- // 绑定要过 hub cast 账 + 角色库核查——先等桥/hub 就绪(投影中心地址解析出来即算)
83
- let projPort = 0;
84
- for (let i = 0; i < 40 && !projPort; i++) {
85
- const st = await fetch(`${BASE}/state`).then(r => r.json()).catch(() => undefined);
86
- projPort = st?.projection?.port ?? 0;
87
- if (!projPort) await sleep(300);
88
- }
89
- assertOk(projPort > 0, 'hub 就绪(投影中心地址已解析)');
90
-
91
- const soulsR = await post('/tools/femo_soul', { action: 'list' });
92
- const soulId = soulsR.json?.result?.souls?.map(s => s.soul_id).find(id => id && id !== 'human');
93
- assertOk(Boolean(soulId), `角色库可读(取 ${soulId} 冒烟;human 不可绑)`);
94
-
95
- const bind = await post('/seats/bind', { sessionId: REF, soul: soulId });
96
- assertEq(bind.json.ok, true, '绑定灵魂(hub cast 正身账 + 本地席位)');
97
- assertEq(bind.json.hub, true, '绑定写进 hub 正身账');
98
-
99
- const miss = await post('/seats/bind', { sessionId: 'nope', soul: soulId });
100
- assertEq(miss.status, 404, '无此席位 404');
101
-
102
- const rebind = await post('/seats/bind', { sessionId: REF, soul: soulId });
103
- assertEq(rebind.json.ok, true, '同魂同椅重复绑定幂等');
104
-
105
- // 长轮询:挂一个 poll,然后 deliver 应立刻送出
106
- const pollP = fetch(`${BASE}/extension/poll?conn=conn-test&timeout=3000`).then(r => r.json());
107
- await sleep(300);
108
- const dv = await post('/seats/deliver', { sessionId: REF, text: '冒烟测试一句话' });
109
- assertEq(dv.json.ok, true, '手工发消息受理');
110
- const pollR = await pollP;
111
- assertEq(pollR.frames.length, 1, 'poll 拿到下发帧');
112
- assertEq(pollR.frames[0].type, 'deliver');
113
-
114
- // 上行报告:busy/reply(reply 是 manual 帧 → runtime 无此 deliveryId,handled=false 也算通)
115
- const rep = await post('/extension/report', { type: 'busy', sessionId: REF, busy: true });
116
- assertEq(rep.json.handled, true, 'busy 上行受理');
117
-
118
- // ── 别家宿主绑定的灵魂:本场由 web 开、事件流全量送到 web,但信按设计留驿站等
119
- // 对方自取——web 一步都不许动(不派工、不弹提醒横条)。2026-10-06 用户实报:
120
- // 贴顶横条写「ai7 绑定的网页没能自动唤醒(Cannot access 'sid' before
121
- // initialization)」——service.resolveSeat 的外宿主闸引用未初始化的 sid 撞
122
- // TDZ,真正的「绑在别家」被 ReferenceError 顶掉,于是被当成唤醒失败 park 了。
123
- // 本段是这条链的端到端锁(真服务 + 真 hub 选角账 + 真驿站上门口):外宿主判定
124
- // 要抛得出来(服务日志见 skip 行),且一个提醒帧都不许发给扩展(全页面贴顶横条
125
- // 的真身就是消息通道里的提醒帧)。
126
- const hubCast = await fetch(`http://127.0.0.1:${projPort}/cast`, {
127
- method: 'POST', headers: { 'content-type': 'application/json' },
128
- body: JSON.stringify({ job_id: 2716, soul: 'ai7', sid: 'sess-zcode-1', host: 'zcode' }),
129
- }).then(r => r.json());
130
- assertEq(hubCast.ok, true, 'hub 选角账写入外宿主绑定(job 2716 / ai7 → zcode)');
131
- const logFile = join(process.env.FEMO_DATA_DIR, 'service.log');
132
- const logMark = readFileSync(logFile, 'utf8').length;
133
- const foreignPush = await post('/femo-plugin/mailbox-push', {
134
- letters: [{ kind: 'context', job_id: 2716, ref: 'wk-foreign' }],
135
- brief: {
136
- job_id: 2716, wait_key: 'wk-foreign', node_name: '[AI发言]', actor_name: '@Zcode(AI-7)',
137
- source: '', actor_info: { soul: 'ai7' }, blocks: { prompt: '轮到你发言' },
138
- },
139
- });
140
- assertEq(foreignPush.status, 200, '外宿主料包信上门照旧收下(驿站回执)');
141
- await sleep(800); // 派工在路由返回之后异步跑
142
- const afterLog = readFileSync(logFile, 'utf8').slice(logMark);
143
- assertOk(afterLog.includes('绑定在别家宿主(zcode)'), '外宿主灵魂被认出来并静默跳过(日志留痕)');
144
- assertOk(!/Cannot access 'sid'/.test(afterLog) && !afterLog.includes('没能自动唤醒'),
145
- '没有任何「唤醒失败」降级——TDZ 天书与提醒横条都不许出现');
146
- const pollAfter = await fetch(`${BASE}/extension/poll?conn=conn-test&timeout=300`).then(r => r.json()).catch(() => ({ frames: [] }));
147
- assertEq((pollAfter.frames ?? []).filter(f => f.type === 'remind').length, 0, '提醒横条一帧都没发(别家会话没响应不是本宿主的事)');
148
-
149
- const st = await (await fetch(`${BASE}/state`)).json();
150
- assertEq(st.host, 'web');
151
- assertOk(Array.isArray(st.runlog), 'state 带 runlog');
152
-
153
- const tools = await (await fetch(`${BASE}/tools`)).json();
154
- assertOk(Array.isArray(tools.tools) && tools.tools.length >= 6, `FEMO 运行控制工具 ${tools.tools?.length ?? 0} 个在册`);
155
-
156
- const consoleHtml = await (await fetch(`${BASE}/console`)).text();
157
- assertOk(consoleHtml.includes('操作台'), 'console 页可取');
158
-
159
- // 本地服务卡(2026-09-30 定名并收编侧栏快捷卡三钮):标题与三钮接线要在页面上。
160
- assertOk(consoleHtml.includes('本地服务') && consoleHtml.includes('id="svcAddr"'), '/console 有「本地服务」卡');
161
- assertOk(consoleHtml.includes('id="restartService"') && consoleHtml.includes('id="stopService"') && consoleHtml.includes('id="mirrorToggle"'),
162
- '/console 本地服务卡收编重启/关闭/镜窗三钮');
163
-
164
- // 共享判断层(侧栏/操作台单份磁盘文件):操作台侧经本路由取到。
165
- const sharedDom = await (await fetch(`${BASE}/console/shared/dom.mjs`)).text();
166
- assertOk(sharedDom.includes('export function escapeHtml'), '/console/shared/ 伺候判断层模块');
167
-
168
- // 画布(流程画布,server/canvas.mjs):页面两段播种脚本齐全(主题/后端 +
169
- // 自动挂载);自动挂载面在冒烟里没挂载过任何东西,应 ok:false 不给文本。
170
- const canvasHtml = await (await fetch(`${BASE}/canvas`)).text();
171
- assertOk(canvasHtml.includes('femo_backend_host'), '/canvas 注入主题与后端播种');
172
- assertOk(canvasHtml.includes("fetch('/canvas/mounted')") && canvasHtml.includes('femo_canvas_mount_applied'),
173
- '/canvas 注入自动挂载播种段');
174
- const mountedFace = await (await fetch(`${BASE}/canvas/mounted`)).json();
175
- assertEq(mountedFace.ok, false, '/canvas/mounted 未挂载时 ok:false');
176
-
177
- // femoGen 自有文件面(2026-09-30):path 槽 → 按名存(三态)→ 清单出现 →
178
- // 打开回读(槽跟随)→ 目录浮层面(新建/浏览/围栏)→ 移除。系统对话框
179
- // (pick-* 两个)要弹真窗口,不进冒烟,覆盖面在单测围栏 + 人工验收。
180
- const path0 = await (await fetch(`${BASE}/api/canvas/path`)).json();
181
- assertOk(path0.ok && (path0.path === null || typeof path0.path === 'string'), '/api/canvas/path 可读');
182
- const save1 = await post('/api/save-script', { dir: '', name: '冒烟剧本', femo: 'flow x=1' });
183
- assertEq(save1.json.ok, true, '/api/save-script 按名存盘');
184
- assertEq(save1.json.changed, true, '首存=真写');
185
- const save2 = await post('/api/save-script', { dir: '', name: '冒烟剧本', femo: 'flow x=1' });
186
- assertEq(save2.json.changed, false, '同内容再存=未改动不重写');
187
- const list1 = await post('/api/femo-files', {});
188
- assertOk(Array.isArray(list1.json.files) && list1.json.files.some(f => f.path === save1.json.path),
189
- '存盘后 /api/femo-files 清单出现该文件');
190
- const open1 = await post('/api/femo-files/open', { path: save1.json.path });
191
- assertEq(open1.json.content, 'flow x=1', '/api/femo-files/open 回读正文');
192
- const path1 = await (await fetch(`${BASE}/api/canvas/path`)).json();
193
- assertEq(path1.path, save1.json.path, 'path 槽跟随打开动作');
194
- const mk = await post('/api/projects/mkdir', { dir: '', name: '冒烟目录' });
195
- assertEq(mk.json.ok, true, '/api/projects/mkdir 新建文件夹');
196
- const br = await post('/api/projects/browser', { dir: '冒烟目录' });
197
- assertEq(br.json.ok, true, '/api/projects/browser 围栏内浏览');
198
- assertOk(br.json.dirs.length === 0 && br.json.files.length === 0, '新目录为空清单');
199
- const deny = await post('/api/projects/browser', { dir: '..' });
200
- assertEq(deny.status, 400, '围栏拒绝 .. 越界');
201
- const forget1 = await post('/api/femo-files/forget', { path: save1.json.path });
202
- assertEq(forget1.json.removed, true, '/api/femo-files/forget 移除');
203
-
204
- console.log('SMOKE OK');
205
- } catch (e) {
206
- ok = false;
207
- console.log('SMOKE FAIL:', String(e).slice(0, 500));
208
- } finally {
209
- child.kill();
210
- // 【2026-09-26 常驻化第 3 步】服务直连后会把常驻引擎代拉成脱离母进程的
211
- // 进程——按沙盒 hub.json 的 pid 收尸,不留野 daemon。
212
- await sleep(300);
213
- try {
214
- const { existsSync, readFileSync } = await import('node:fs');
215
- const hubJson = join(process.env.FEMO_DATA_DIR || '', 'femo', 'projection', 'hub.json');
216
- if (existsSync(hubJson)) {
217
- const pid = Number(JSON.parse(readFileSync(hubJson, 'utf8'))?.pid) || 0;
218
- if (pid > 0) { try { process.kill(pid); console.log('[cleanup] killed sandbox daemon pid', pid); } catch { /* 已死 */ } }
219
- }
220
- } catch { /* 无账 */ }
221
- await sleep(300);
222
- process.exitCode = ok ? 0 : 1;
223
- }
224
-
225
- function assertEq(actual, expected, label) {
226
- if (actual !== expected) throw new Error(`${label}: 期望 ${JSON.stringify(expected)},实际 ${JSON.stringify(actual)}`);
227
- console.log(` ok: ${label}`);
228
- }
229
- function assertOk(cond, label) {
230
- if (!cond) throw new Error(`${label}: 不成立`);
231
- console.log(` ok: ${label}`);
232
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * smoke-service.mjs — 本地服务冒烟(手动运行,不拉真桥、不碰真浏览器)。
4
+ *
5
+ * 起 service.mjs(随机端口+一次性沙盒),打一遍扩展协议面与操作台协议面:
6
+ * /health /console /seats /seats/bind /extension/register /extension/poll
7
+ * /extension/report /seats/deliver /state /tools
8
+ * 运行:node tests/smoke-service.mjs
9
+ */
10
+
11
+ import { mkdtempSync, readFileSync } from 'node:fs';
12
+ import { tmpdir } from 'node:os';
13
+ import { join } from 'node:path';
14
+ import { spawn } from 'node:child_process';
15
+ import { fileURLToPath } from 'node:url';
16
+ import { dirname } from 'node:path';
17
+
18
+ const ADAPTER_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
19
+ process.env.FEMO_DATA_DIR = mkdtempSync(join(tmpdir(), 'femo-web-svc-smoke-'));
20
+ process.env.FEMO_WEB_PORT = '18796';
21
+
22
+ const child = spawn(process.execPath, [join(ADAPTER_ROOT, 'server', 'service.mjs')], {
23
+ env: process.env,
24
+ stdio: ['ignore', 'pipe', 'pipe'],
25
+ });
26
+ child.stdout.on('data', c => process.stdout.write(`[svc] ${c}`));
27
+ child.stderr.on('data', c => process.stdout.write(`[svc:err] ${c}`));
28
+
29
+ const BASE = 'http://127.0.0.1:18796';
30
+ const sleep = ms => new Promise(r => setTimeout(r, ms));
31
+
32
+ async function waitHealthy() {
33
+ for (let i = 0; i < 30; i++) {
34
+ try {
35
+ const r = await fetch(`${BASE}/health`);
36
+ if (r.ok) return r.json();
37
+ } catch { /* 还没起 */ }
38
+ await sleep(300);
39
+ }
40
+ throw new Error('service did not become healthy in 9s');
41
+ }
42
+
43
+ async function post(path, body) {
44
+ const r = await fetch(`${BASE}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
45
+ return { status: r.status, json: await r.json() };
46
+ }
47
+
48
+ let ok = true;
49
+ try {
50
+ const health = await waitHealthy();
51
+ console.log('health =>', JSON.stringify(health).slice(0, 140));
52
+ assertEq(health.host, 'web', 'host 自称');
53
+
54
+ const seats0 = await (await fetch(`${BASE}/seats`)).json();
55
+ assertEq(seats0.seats.length, 0, '初始无席位');
56
+
57
+ // 会话引用形态(`<域名>:<id>`,见 sites.mjs)——多站在役后的正字 id
58
+ const REF = 'chat.deepseek.com:12345678-abcd';
59
+ const reg = await post('/extension/register', { connId: 'conn-test', tabs: [{ tabId: 11, sessionId: REF, site: 'chat.deepseek.com', title: '冒烟会话', busy: false }] });
60
+ assertEq(reg.json.ok, true, '注册成功');
61
+ assertEq(reg.status, 200);
62
+
63
+ const seats1 = await (await fetch(`${BASE}/seats`)).json();
64
+ assertEq(seats1.seats.length, 1, '注册后一席');
65
+ assertEq(seats1.seats[0].online, true);
66
+ assertEq(seats1.seats[0].present, true, '在场=页开着');
67
+ assertEq(seats1.seats[0].siteLabel, 'DeepSeek', '视图派生来源显示名');
68
+ assertEq(seats1.seats[0].sidShort, '12345678', '视图派生短 id(剥来源前缀)');
69
+
70
+ // 冻结页登记(2026-10-01 按需唤醒):online:false 的页照样在场(present:true);
71
+ // 页关了(下轮没报到)才出账;恢复上报后席位复活(后面的绑定/下发要用它)。
72
+ await post('/extension/register', { connId: 'conn-test', tabs: [{ tabId: 11, sessionId: REF, site: 'chat.deepseek.com', title: '冒烟会话', busy: false, online: false }] });
73
+ const seatsFrozen = await (await fetch(`${BASE}/seats`)).json();
74
+ assertEq(seatsFrozen.seats[0].present, true, '冻结页照样在场');
75
+ assertEq(seatsFrozen.seats[0].online, false, '冻结页不在线');
76
+ await post('/extension/register', { connId: 'conn-test', tabs: [] });
77
+ const seatsGone = await (await fetch(`${BASE}/seats`)).json();
78
+ assertEq(seatsGone.seats[0].present, false, '页关了=出账');
79
+ assertEq(seatsGone.seats[0].online, false);
80
+ await post('/extension/register', { connId: 'conn-test', tabs: [{ tabId: 11, sessionId: REF, site: 'chat.deepseek.com', title: '冒烟会话', busy: false, online: true }] });
81
+
82
+ // 绑定要过 hub cast 账 + 角色库核查——先等桥/hub 就绪(投影中心地址解析出来即算)
83
+ let projPort = 0;
84
+ for (let i = 0; i < 40 && !projPort; i++) {
85
+ const st = await fetch(`${BASE}/state`).then(r => r.json()).catch(() => undefined);
86
+ projPort = st?.projection?.port ?? 0;
87
+ if (!projPort) await sleep(300);
88
+ }
89
+ assertOk(projPort > 0, 'hub 就绪(投影中心地址已解析)');
90
+
91
+ const soulsR = await post('/tools/femo_soul', { action: 'list' });
92
+ const soulId = soulsR.json?.result?.souls?.map(s => s.soul_id).find(id => id && id !== 'human');
93
+ assertOk(Boolean(soulId), `角色库可读(取 ${soulId} 冒烟;human 不可绑)`);
94
+
95
+ const bind = await post('/seats/bind', { sessionId: REF, soul: soulId });
96
+ assertEq(bind.json.ok, true, '绑定灵魂(hub cast 正身账 + 本地席位)');
97
+ assertEq(bind.json.hub, true, '绑定写进 hub 正身账');
98
+
99
+ const miss = await post('/seats/bind', { sessionId: 'nope', soul: soulId });
100
+ assertEq(miss.status, 404, '无此席位 404');
101
+
102
+ const rebind = await post('/seats/bind', { sessionId: REF, soul: soulId });
103
+ assertEq(rebind.json.ok, true, '同魂同椅重复绑定幂等');
104
+
105
+ // 长轮询:挂一个 poll,然后 deliver 应立刻送出
106
+ const pollP = fetch(`${BASE}/extension/poll?conn=conn-test&timeout=3000`).then(r => r.json());
107
+ await sleep(300);
108
+ const dv = await post('/seats/deliver', { sessionId: REF, text: '冒烟测试一句话' });
109
+ assertEq(dv.json.ok, true, '手工发消息受理');
110
+ const pollR = await pollP;
111
+ assertEq(pollR.frames.length, 1, 'poll 拿到下发帧');
112
+ assertEq(pollR.frames[0].type, 'deliver');
113
+
114
+ // 上行报告:busy/reply(reply 是 manual 帧 → runtime 无此 deliveryId,handled=false 也算通)
115
+ const rep = await post('/extension/report', { type: 'busy', sessionId: REF, busy: true });
116
+ assertEq(rep.json.handled, true, 'busy 上行受理');
117
+
118
+
119
+ // ── 别家宿主绑定的灵魂:本场由 web 开、事件流全量送到 web,但信按设计留驿站等
120
+ // 对方自取——web 一步都不许动(不派工、不弹提醒横条)。2026-10-06 用户实报:
121
+ // 贴顶横条写「ai7 绑定的网页没能自动唤醒(Cannot access 'sid' before
122
+ // initialization)」——service.resolveSeat 的外宿主闸引用未初始化的 sid 撞
123
+ // TDZ,真正的「绑在别家」被 ReferenceError 顶掉,于是被当成唤醒失败 park 了。
124
+ // 本段是这条链的端到端锁(真服务 + 真 hub 选角账 + 真驿站上门口):外宿主判定
125
+ // 要抛得出来(服务日志见 skip 行),且一个提醒帧都不许发给扩展(全页面贴顶横条
126
+ // 的真身就是消息通道里的提醒帧)。
127
+ const hubCast = await fetch(`http://127.0.0.1:${projPort}/cast`, {
128
+ method: 'POST', headers: { 'content-type': 'application/json' },
129
+ body: JSON.stringify({ job_id: 2716, soul: 'ai7', sid: 'sess-zcode-1', host: 'zcode' }),
130
+ }).then(r => r.json());
131
+ assertEq(hubCast.ok, true, 'hub 选角账写入外宿主绑定(job 2716 / ai7 → zcode)');
132
+ const logFile = join(process.env.FEMO_DATA_DIR, 'service.log');
133
+ const logMark = readFileSync(logFile, 'utf8').length;
134
+ const foreignPush = await post('/femo-plugin/mailbox-push', {
135
+ letters: [{ kind: 'context', job_id: 2716, ref: 'wk-foreign' }],
136
+ brief: {
137
+ job_id: 2716, wait_key: 'wk-foreign', node_name: '[AI发言]', actor_name: '@Zcode(AI-7)',
138
+ source: '', actor_info: { soul: 'ai7' }, blocks: { prompt: '轮到你发言' },
139
+ },
140
+ });
141
+ assertEq(foreignPush.status, 200, '外宿主料包信上门照旧收下(驿站回执)');
142
+ await sleep(800); // 派工在路由返回之后异步跑
143
+ const afterLog = readFileSync(logFile, 'utf8').slice(logMark);
144
+ assertOk(afterLog.includes('绑定在别家宿主(zcode)'), '外宿主灵魂被认出来并静默跳过(日志留痕)');
145
+ assertOk(!/Cannot access 'sid'/.test(afterLog) && !afterLog.includes('没能自动唤醒'),
146
+ '没有任何「唤醒失败」降级——TDZ 天书与提醒横条都不许出现');
147
+ const pollAfter = await fetch(`${BASE}/extension/poll?conn=conn-test&timeout=300`).then(r => r.json()).catch(() => ({ frames: [] }));
148
+ assertEq((pollAfter.frames ?? []).filter(f => f.type === 'remind').length, 0, '提醒横条一帧都没发(别家会话没响应不是本宿主的事)');
149
+
150
+ const st = await (await fetch(`${BASE}/state`)).json();
151
+ assertEq(st.host, 'web');
152
+ assertOk(Array.isArray(st.runlog), 'state 带 runlog');
153
+
154
+ const tools = await (await fetch(`${BASE}/tools`)).json();
155
+ assertOk(Array.isArray(tools.tools) && tools.tools.length >= 6, `FEMO 运行控制工具 ${tools.tools?.length ?? 0} 个在册`);
156
+
157
+ const consoleHtml = await (await fetch(`${BASE}/console`)).text();
158
+ assertOk(consoleHtml.includes('操作台'), 'console 页可取');
159
+
160
+ // 本地服务卡(2026-09-30 定名并收编侧栏快捷卡三钮):标题与三钮接线要在页面上。
161
+ assertOk(consoleHtml.includes('本地服务') && consoleHtml.includes('id="svcAddr"'), '/console 有「本地服务」卡');
162
+ assertOk(consoleHtml.includes('id="restartService"') && consoleHtml.includes('id="stopService"') && consoleHtml.includes('id="mirrorToggle"'),
163
+ '/console 本地服务卡收编重启/关闭/镜窗三钮');
164
+
165
+ // 共享判断层(侧栏/操作台单份磁盘文件):操作台侧经本路由取到。
166
+ const sharedDom = await (await fetch(`${BASE}/console/shared/dom.mjs`)).text();
167
+ assertOk(sharedDom.includes('export function escapeHtml'), '/console/shared/ 伺候判断层模块');
168
+
169
+ // 画布(流程画布,server/canvas.mjs):页面两段播种脚本齐全(主题/后端 +
170
+ // 自动挂载);自动挂载面在冒烟里没挂载过任何东西,应 ok:false 不给文本。
171
+ const canvasHtml = await (await fetch(`${BASE}/canvas`)).text();
172
+ assertOk(canvasHtml.includes('femo_backend_host'), '/canvas 注入主题与后端播种');
173
+ assertOk(canvasHtml.includes("fetch('/canvas/mounted')") && canvasHtml.includes('femo_canvas_mount_applied'),
174
+ '/canvas 注入自动挂载播种段');
175
+ const mountedFace = await (await fetch(`${BASE}/canvas/mounted`)).json();
176
+ assertEq(mountedFace.ok, false, '/canvas/mounted 未挂载时 ok:false');
177
+
178
+ // femoGen 自有文件面(2026-09-30):path 槽 → 按名存(三态)→ 清单出现 →
179
+ // 打开回读(槽跟随)→ 目录浮层面(新建/浏览/围栏)→ 移除。系统对话框
180
+ // (pick-* 两个)要弹真窗口,不进冒烟,覆盖面在单测围栏 + 人工验收。
181
+ const path0 = await (await fetch(`${BASE}/api/canvas/path`)).json();
182
+ assertOk(path0.ok && (path0.path === null || typeof path0.path === 'string'), '/api/canvas/path 可读');
183
+ const save1 = await post('/api/save-script', { dir: '', name: '冒烟剧本', femo: 'flow x=1' });
184
+ assertEq(save1.json.ok, true, '/api/save-script 按名存盘');
185
+ assertEq(save1.json.changed, true, '首存=真写');
186
+ const save2 = await post('/api/save-script', { dir: '', name: '冒烟剧本', femo: 'flow x=1' });
187
+ assertEq(save2.json.changed, false, '同内容再存=未改动不重写');
188
+ const list1 = await post('/api/femo-files', {});
189
+ assertOk(Array.isArray(list1.json.files) && list1.json.files.some(f => f.path === save1.json.path),
190
+ '存盘后 /api/femo-files 清单出现该文件');
191
+ const open1 = await post('/api/femo-files/open', { path: save1.json.path });
192
+ assertEq(open1.json.content, 'flow x=1', '/api/femo-files/open 回读正文');
193
+ const path1 = await (await fetch(`${BASE}/api/canvas/path`)).json();
194
+ assertEq(path1.path, save1.json.path, 'path 槽跟随打开动作');
195
+ const mk = await post('/api/projects/mkdir', { dir: '', name: '冒烟目录' });
196
+ assertEq(mk.json.ok, true, '/api/projects/mkdir 新建文件夹');
197
+ const br = await post('/api/projects/browser', { dir: '冒烟目录' });
198
+ assertEq(br.json.ok, true, '/api/projects/browser 围栏内浏览');
199
+ assertOk(br.json.dirs.length === 0 && br.json.files.length === 0, '新目录为空清单');
200
+ const deny = await post('/api/projects/browser', { dir: '..' });
201
+ assertEq(deny.status, 400, '围栏拒绝 .. 越界');
202
+ const forget1 = await post('/api/femo-files/forget', { path: save1.json.path });
203
+ assertEq(forget1.json.removed, true, '/api/femo-files/forget 移除');
204
+
205
+ // ── 演员绑定链路(2026-10-10):正身=hub actor-preferences,键=@actor 全名;
206
+ // 校验口径与灵魂不同(用户拍板「以 femo 脚本为先」):绑了剧本里没有的
207
+ // 演员=报错拦下;少绑=warning 不拦(点名 actorCheck.warnings)。 ─────────
208
+ const actorScript = `meta:\n name: 演员冒烟\nactors:\n ai @AI1 = soul:${soulId}\n human @玩家1 =\nmainflow:\n - say @AI1: "hi"\n`;
209
+ const mountR = await post('/tools/femo_mount', { femo_text: actorScript });
210
+ assertEq(mountR.json.mounted, true, '挂载带演员表的冒烟剧本');
211
+ const noAt = await post('/seats/actor-bind', { sessionId: REF, actor: 'AI1' });
212
+ assertEq(noAt.status, 400, '不带 @ 的演员名当场拦(@ 是名字的一部分)');
213
+ const ghost = await post('/seats/actor-bind', { sessionId: REF, actor: '@幽灵' });
214
+ assertEq(ghost.status, 404, '绑剧本里没有的演员=报错拦下');
215
+ const abind = await post('/seats/actor-bind', { sessionId: REF, actor: '@AI1' });
216
+ assertEq(abind.json.ok, true, '绑演员 @AI1(hub 正身账)');
217
+ assertEq(abind.json.hub, true, '演员绑定写进 hub 正身账');
218
+ const seatsA = await (await fetch(`${BASE}/seats`)).json();
219
+ assertEq(seatsA.seats[0].actor, '@AI1', '席位展示镜像带演员(@ 全名照抄)');
220
+ const at1 = await post('/seats/attendance', {});
221
+ assertEq(at1.json.actorCheck.errors.length, 0, '点名:多绑为零');
222
+ assertOk(at1.json.actorCheck.warnings.some(w => w.includes('@玩家1')), '点名:少绑 @玩家1 出 warning');
223
+ const ahub = await fetch(`http://127.0.0.1:${projPort}/sessions/actor-preferences`).then(r => r.json());
224
+ assertEq(ahub.bindings['@AI1']?.type, 'ai', 'hub 账:type=ai(本宿主会话绑定)');
225
+ const aunbind = await post('/seats/actor-bind', { sessionId: REF, actor: '' });
226
+ assertEq(aunbind.json.ok, true, '解绑演员');
227
+ const seatsA2 = await (await fetch(`${BASE}/seats`)).json();
228
+ assertOk(!seatsA2.seats[0].actor, '解绑后展示镜像清空');
229
+
230
+
231
+
232
+
233
+ console.log('SMOKE OK');
234
+ } catch (e) {
235
+ ok = false;
236
+ console.log('SMOKE FAIL:', String(e).slice(0, 500));
237
+ } finally {
238
+ child.kill();
239
+ // 【2026-09-26 常驻化第 3 步】服务直连后会把常驻引擎代拉成脱离母进程的
240
+ // 进程——按沙盒 hub.json 的 pid 收尸,不留野 daemon。
241
+ await sleep(300);
242
+ try {
243
+ const { existsSync, readFileSync } = await import('node:fs');
244
+ const hubJson = join(process.env.FEMO_DATA_DIR || '', 'femo', 'projection', 'hub.json');
245
+ if (existsSync(hubJson)) {
246
+ const pid = Number(JSON.parse(readFileSync(hubJson, 'utf8'))?.pid) || 0;
247
+ if (pid > 0) { try { process.kill(pid); console.log('[cleanup] killed sandbox daemon pid', pid); } catch { /* 已死 */ } }
248
+ }
249
+ } catch { /* 无账 */ }
250
+ await sleep(300);
251
+ process.exitCode = ok ? 0 : 1;
252
+ }
253
+
254
+ function assertEq(actual, expected, label) {
255
+ if (actual !== expected) throw new Error(`${label}: 期望 ${JSON.stringify(expected)},实际 ${JSON.stringify(actual)}`);
256
+ console.log(` ok: ${label}`);
257
+ }
258
+ function assertOk(cond, label) {
259
+ if (!cond) throw new Error(`${label}: 不成立`);
260
+ console.log(` ok: ${label}`);
261
+ }