@liang-hz/agent-in-chrome 0.55.0
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.
- package/.ext-id.txt +4 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/PRIVACY.md +86 -0
- package/README.en.md +419 -0
- package/README.md +406 -0
- package/bin/agent-in-chrome.mjs +97 -0
- package/commands/agent-in-chrome.md +18 -0
- package/commands/install-agent-in-chrome.md +22 -0
- package/docs/AGENTS.md +94 -0
- package/docs/CLI.md +297 -0
- package/docs/client-compat.json +23 -0
- package/extension/about-toc.js +25 -0
- package/extension/about.html +240 -0
- package/extension/about.js +44 -0
- package/extension/agent-window.html +100 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-24.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/icons/icon-64.png +0 -0
- package/extension/icons/icon-attention-128.png +0 -0
- package/extension/icons/icon-attention-16.png +0 -0
- package/extension/icons/icon-attention-24.png +0 -0
- package/extension/icons/icon-attention-32.png +0 -0
- package/extension/icons/icon-attention-48.png +0 -0
- package/extension/icons/icon-attention-64.png +0 -0
- package/extension/icons/icon-attention.svg +18 -0
- package/extension/icons/icon-failed-128.png +0 -0
- package/extension/icons/icon-failed-16.png +0 -0
- package/extension/icons/icon-failed-24.png +0 -0
- package/extension/icons/icon-failed-32.png +0 -0
- package/extension/icons/icon-failed-48.png +0 -0
- package/extension/icons/icon-failed-64.png +0 -0
- package/extension/icons/icon-failed.svg +18 -0
- package/extension/icons/icon-idle-128.png +0 -0
- package/extension/icons/icon-idle-16.png +0 -0
- package/extension/icons/icon-idle-24.png +0 -0
- package/extension/icons/icon-idle-32.png +0 -0
- package/extension/icons/icon-idle-48.png +0 -0
- package/extension/icons/icon-idle-64.png +0 -0
- package/extension/icons/icon-idle.svg +18 -0
- package/extension/icons/icon-mark.svg +10 -0
- package/extension/icons/icon-running-128.png +0 -0
- package/extension/icons/icon-running-16.png +0 -0
- package/extension/icons/icon-running-24.png +0 -0
- package/extension/icons/icon-running-32.png +0 -0
- package/extension/icons/icon-running-48.png +0 -0
- package/extension/icons/icon-running-64.png +0 -0
- package/extension/icons/icon-running.svg +18 -0
- package/extension/icons/icon.svg +18 -0
- package/extension/manifest.json +44 -0
- package/extension/popup-ui.js +38 -0
- package/extension/popup.html +350 -0
- package/extension/popup.js +741 -0
- package/extension/sw.js +11127 -0
- package/extension/update-check.js +66 -0
- package/extension/welcome.html +110 -0
- package/extension/welcome.js +18 -0
- package/mcp/agent-identity.mjs +1007 -0
- package/mcp/cdp/bridge.mjs +239 -0
- package/mcp/cdp/browser-launch.mjs +1127 -0
- package/mcp/cdp/chrome-shim.mjs +1124 -0
- package/mcp/cdp/client.mjs +443 -0
- package/mcp/cli-invocation.mjs +67 -0
- package/mcp/config.mjs +191 -0
- package/mcp/foreground-guard.mjs +295 -0
- package/mcp/proc-win.mjs +112 -0
- package/mcp/secret-shape.mjs +155 -0
- package/mcp/server.mjs +3437 -0
- package/mcp/session-id.mjs +281 -0
- package/mcp/token.mjs +260 -0
- package/mcp/tool-tiers.mjs +84 -0
- package/mcp/trace.mjs +528 -0
- package/mcp/update-cli.mjs +163 -0
- package/mcp/update-notice.mjs +194 -0
- package/native-host/host.mjs +356 -0
- package/native-host/mac-foreground/aic-fg.swift +114 -0
- package/native-host/mac-foreground/build.mjs +43 -0
- package/package.json +46 -0
- package/scripts/agents.mjs +921 -0
- package/scripts/borrow-login.mjs +935 -0
- package/scripts/cli-browser.mjs +148 -0
- package/scripts/e2e-sweep.mjs +192 -0
- package/scripts/e2e.mjs +3911 -0
- package/scripts/fixture-server.mjs +1419 -0
- package/scripts/guard-publish.mjs +175 -0
- package/scripts/install.mjs +1383 -0
- package/scripts/launcher-provenance.mjs +74 -0
- package/scripts/pack-crx.mjs +82 -0
- package/scripts/pick.mjs +114 -0
- package/scripts/test-agents.mjs +968 -0
- package/scripts/test-borrow.mjs +289 -0
- package/scripts/test-config.mjs +618 -0
- package/scripts/test-e2e-sweep.mjs +251 -0
- package/scripts/test-foreground-guard.mjs +383 -0
- package/scripts/test-identity.mjs +1141 -0
- package/scripts/test-install-skill.mjs +378 -0
- package/scripts/test-protocol.mjs +712 -0
- package/scripts/test-security.mjs +1360 -0
- package/scripts/test-sw.mjs +14526 -0
- package/scripts/test-update.mjs +301 -0
- package/skills/agent-in-chrome/SKILL.md +60 -0
- package/skills/agent-in-chrome/references/actions-and-waits.md +136 -0
- package/skills/agent-in-chrome/references/amap-dir-dropdown.md +66 -0
- package/skills/agent-in-chrome/references/geetest-click-captcha.md +55 -0
- package/skills/agent-in-chrome/references/network-debugging.md +20 -0
- package/skills/agent-in-chrome/references/reading-pages.md +30 -0
- package/skills/agent-in-chrome/references/recovery.md +25 -0
- package/skills/agent-in-chrome/references/tabs-and-sessions.md +34 -0
- package/skills/install-agent-in-chrome/SKILL.md +252 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { ownerPidOf, liveRegisteredSessions, pickStraySessions, runSweep } from "./e2e-sweep.mjs";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
let passed = 0;
|
|
11
|
+
let failed = 0;
|
|
12
|
+
const check = (name, cond, extra = "") => {
|
|
13
|
+
if (cond) {
|
|
14
|
+
console.log(` \x1b[32m✓\x1b[0m ${name}`);
|
|
15
|
+
passed++;
|
|
16
|
+
} else {
|
|
17
|
+
console.log(` \x1b[31m✗\x1b[0m ${name}${extra ? ` — ${extra}` : ""}`);
|
|
18
|
+
failed++;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const section = (s) => console.log(`\n\x1b[1m${s}\x1b[0m`);
|
|
22
|
+
|
|
23
|
+
const alive = (set) => (pid) => set.includes(pid);
|
|
24
|
+
const sess = (session, tabIds = [1]) => ({ session, tabIds, tabId: tabIds[0] ?? null, label: "x" });
|
|
25
|
+
const pick = (otherSessions, registry, live) =>
|
|
26
|
+
pickStraySessions({ otherSessions, registry, isAlive: alive(live) }).map((s) => s.session);
|
|
27
|
+
|
|
28
|
+
section("1. ownerPidOf:主人 pid 就写在 sid 尾巴上");
|
|
29
|
+
|
|
30
|
+
check("带跑次后缀的解得出", ownerPidOf("e2e-A-61578-msfi8af4") === 61578, String(ownerPidOf("e2e-A-61578-msfi8af4")));
|
|
31
|
+
check("名字里带横线的也解得出", ownerPidOf("e2e-cdp-shadow-1234-abc0") === 1234, String(ownerPidOf("e2e-cdp-shadow-1234-abc0")));
|
|
32
|
+
check("裸名解不出(旧版遗留)", ownerPidOf("e2e-A") === null);
|
|
33
|
+
check("裸名带横线也解不出", ownerPidOf("e2e-cdp-shadow") === null);
|
|
34
|
+
check("只认结尾,中间的数字段不算", ownerPidOf("e2e-h2-frames") === null, String(ownerPidOf("e2e-h2-frames")));
|
|
35
|
+
check("pid 为 0 不算", ownerPidOf("e2e-A-0-abc") === null);
|
|
36
|
+
check("空值不炸", ownerPidOf(null) === null && ownerPidOf(undefined) === null && ownerPidOf("") === null);
|
|
37
|
+
|
|
38
|
+
section("2. liveRegisteredSessions:只护主人还活着的行");
|
|
39
|
+
|
|
40
|
+
const reg = [
|
|
41
|
+
{ pid: 100, runId: "r1", sessions: ["e2e-A-100-x", "e2e-shot-100-x"] },
|
|
42
|
+
{ pid: 200, runId: "r2", sessions: ["e2e-A-200-y"] },
|
|
43
|
+
];
|
|
44
|
+
const protectedNow = liveRegisteredSessions(reg, alive([100]));
|
|
45
|
+
check("活着那行的会话都在", protectedNow.has("e2e-A-100-x") && protectedNow.has("e2e-shot-100-x"));
|
|
46
|
+
check("死了那行的不在(留给回收)", !protectedNow.has("e2e-A-200-y"));
|
|
47
|
+
check("表是坏的也不炸", liveRegisteredSessions(null, alive([100])).size === 0);
|
|
48
|
+
check("行缺字段也不炸", liveRegisteredSessions([{}, { pid: "x" }, { pid: 100 }], alive([100])).size === 0);
|
|
49
|
+
|
|
50
|
+
section("3. 该收的:主人已经没了");
|
|
51
|
+
|
|
52
|
+
check(
|
|
53
|
+
"旧版裸名残留——正是 2026-08-05 真机上那七个",
|
|
54
|
+
JSON.stringify(
|
|
55
|
+
pick(
|
|
56
|
+
[sess("e2e-A"), sess("e2e-frames"), sess("e2e-shot"), sess("e2e-verify"), sess("e2e-cursor"), sess("e2e-ergo"), sess("e2e-adopt")],
|
|
57
|
+
[],
|
|
58
|
+
[999]
|
|
59
|
+
)
|
|
60
|
+
) === JSON.stringify(["e2e-A", "e2e-frames", "e2e-shot", "e2e-verify", "e2e-cursor", "e2e-ergo", "e2e-adopt"])
|
|
61
|
+
);
|
|
62
|
+
check("带后缀但主人已退出的(登记表漏了它)", JSON.stringify(pick([sess("e2e-A-777-abc")], [], [999])) === JSON.stringify(["e2e-A-777-abc"]));
|
|
63
|
+
check(
|
|
64
|
+
"登记表里有这一行、但主人已死 → 照收(sweepDeadRuns 收不干净时接手)",
|
|
65
|
+
JSON.stringify(pick([sess("e2e-A-777-abc")], [{ pid: 777, runId: "r", sessions: ["e2e-A-777-abc"] }], [999])) ===
|
|
66
|
+
JSON.stringify(["e2e-A-777-abc"])
|
|
67
|
+
);
|
|
68
|
+
check("收的时候把标签页一起报出来,日志才有用", (() => {
|
|
69
|
+
const [s] = pickStraySessions({ otherSessions: [sess("e2e-A", [7, 8])], registry: [], isAlive: alive([]) });
|
|
70
|
+
return s.tabIds.join(",") === "7,8" && /裸名/.test(s.why);
|
|
71
|
+
})());
|
|
72
|
+
check("带后缀的 why 里写明是哪个 pid 没了", (() => {
|
|
73
|
+
const [s] = pickStraySessions({ otherSessions: [sess("e2e-A-777-abc")], registry: [], isAlive: alive([]) });
|
|
74
|
+
return /777/.test(s.why);
|
|
75
|
+
})());
|
|
76
|
+
|
|
77
|
+
section("4. 不该收的:误收的代价远大于漏收");
|
|
78
|
+
|
|
79
|
+
check("非 e2e- 前缀一概不看——用户自己的会话", JSON.stringify(pick([sess("s61578-msfi8af4"), sess("去哪儿酒店比价")], [], [])) === "[]");
|
|
80
|
+
check("前缀得从头匹配,不是 includes", JSON.stringify(pick([sess("mine-e2e-A")], [], [])) === "[]");
|
|
81
|
+
check("主人还活着的跑次不碰(并发跑的另一轮 e2e)", JSON.stringify(pick([sess("e2e-A-555-abc")], [], [555])) === "[]");
|
|
82
|
+
check(
|
|
83
|
+
"本轮自己的更不能碰——RUN_ID 开头就是本进程 pid",
|
|
84
|
+
JSON.stringify(pick([sess(`e2e-shot-${process.pid}-msfi8af4`)], [], [process.pid])) === "[]"
|
|
85
|
+
);
|
|
86
|
+
check(
|
|
87
|
+
"登记表护住的不碰,哪怕 sid 形状认不出主人",
|
|
88
|
+
JSON.stringify(pick([sess("e2e-手动起的名字")], [{ pid: 100, runId: "r", sessions: ["e2e-手动起的名字"] }], [100])) === "[]"
|
|
89
|
+
);
|
|
90
|
+
check("手上没有标签页的不值得起进程去收", JSON.stringify(pick([sess("e2e-A", [])], [], [])) === "[]");
|
|
91
|
+
check("otherSessions 是坏的也不炸", JSON.stringify(pick(null, [], [])) === "[]" && JSON.stringify(pick([null, {}, 1], [], [])) === "[]");
|
|
92
|
+
|
|
93
|
+
section("5. 混在一起:真机上就是这个样子");
|
|
94
|
+
|
|
95
|
+
check(
|
|
96
|
+
"只挑走游离的 e2e,用户会话和活着的跑次原样留下",
|
|
97
|
+
JSON.stringify(
|
|
98
|
+
pick(
|
|
99
|
+
[
|
|
100
|
+
sess("s57432-msemm674", [1]),
|
|
101
|
+
sess("e2e-A"),
|
|
102
|
+
sess("e2e-cursor"),
|
|
103
|
+
sess("e2e-A-555-abc"),
|
|
104
|
+
sess("e2e-hard-777-abc"),
|
|
105
|
+
sess("s84989-msesviuo", [2]),
|
|
106
|
+
],
|
|
107
|
+
[{ pid: 555, runId: "r", sessions: ["e2e-A-555-abc"] }],
|
|
108
|
+
[555]
|
|
109
|
+
)
|
|
110
|
+
) === JSON.stringify(["e2e-A", "e2e-cursor", "e2e-hard-777-abc"])
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
section("6. runSweep:真的去收,而且只收该收的");
|
|
114
|
+
|
|
115
|
+
function fakeClientFactory({ otherSessions, closedCount = 2, stuck = [], released = 0 }) {
|
|
116
|
+
const seen = [];
|
|
117
|
+
const factory = (sessionId) => {
|
|
118
|
+
const rec = { sessionId, calls: [] };
|
|
119
|
+
seen.push(rec);
|
|
120
|
+
return {
|
|
121
|
+
async init() {},
|
|
122
|
+
async call(tool, args) {
|
|
123
|
+
rec.calls.push({ tool, args });
|
|
124
|
+
if (tool === "browser_status") return { otherSessions };
|
|
125
|
+
if (tool === "browser_close_all") {
|
|
126
|
+
if (stuck.includes(sessionId)) throw new Error("attach 卡住了");
|
|
127
|
+
return { closedCount, releasedCount: released };
|
|
128
|
+
}
|
|
129
|
+
return {};
|
|
130
|
+
},
|
|
131
|
+
kill() { rec.killed = true; },
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
factory.seen = seen;
|
|
135
|
+
return factory;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const others = [
|
|
139
|
+
{ session: "s61578-msfi8af4", tabIds: [1, 2] },
|
|
140
|
+
{ session: "e2e-A", tabIds: [3] },
|
|
141
|
+
{ session: "e2e-hard-777-abc", tabIds: [4, 5] },
|
|
142
|
+
{ session: "e2e-live-555-abc", tabIds: [6] },
|
|
143
|
+
];
|
|
144
|
+
const liveIs = (pid) => pid === 555;
|
|
145
|
+
|
|
146
|
+
{
|
|
147
|
+
const f = fakeClientFactory({ otherSessions: others, closedCount: 1, released: 1 });
|
|
148
|
+
const lines = [];
|
|
149
|
+
const r = await runSweep({ makeClient: f, registry: [], isAlive: liveIs, log: (m) => lines.push(m) });
|
|
150
|
+
check("只解组没关的页也如实计数", r.released === 2, String(r.released));
|
|
151
|
+
check("汇总里点出来了,而不是含糊报成收干净", lines.some((l) => /只解了组、没有关/.test(l)), JSON.stringify(lines.slice(-2)));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
{
|
|
155
|
+
const f = fakeClientFactory({ otherSessions: others });
|
|
156
|
+
const lines = [];
|
|
157
|
+
const r = await runSweep({ makeClient: f, registry: [], isAlive: liveIs, log: (m) => lines.push(m) });
|
|
158
|
+
const closedFor = f.seen.filter((c) => c.calls.some((x) => x.tool === "browser_close_all")).map((c) => c.sessionId);
|
|
159
|
+
check("挑出来的正是那两个游离会话", JSON.stringify(r.stray.map((s) => s.session)) === JSON.stringify(["e2e-A", "e2e-hard-777-abc"]));
|
|
160
|
+
check("冒充的 sid 一个不多一个不少", JSON.stringify(closedFor) === JSON.stringify(["e2e-A", "e2e-hard-777-abc"]), JSON.stringify(closedFor));
|
|
161
|
+
check("用户的会话从头到尾没被冒充过", !f.seen.some((c) => c.sessionId === "s61578-msfi8af4"));
|
|
162
|
+
check("活着那轮的会话也没被碰", !closedFor.includes("e2e-live-555-abc"));
|
|
163
|
+
check(
|
|
164
|
+
"close_all 一律 scope:\"session\",绝不 \"all\"",
|
|
165
|
+
f.seen.every((c) => c.calls.every((x) => x.tool !== "browser_close_all" || x.args?.scope === "session"))
|
|
166
|
+
);
|
|
167
|
+
check("收掉的标签页数如实汇总", r.closed === 4, String(r.closed));
|
|
168
|
+
check("每个起过的 client 都被收掉(不留进程)", f.seen.every((c) => c.killed));
|
|
169
|
+
check("探路会话不带 e2e- 前缀(否则下次清扫会把自己当残留)", !f.seen[0].sessionId.startsWith("e2e-"));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
{
|
|
173
|
+
const f = fakeClientFactory({ otherSessions: others });
|
|
174
|
+
const r = await runSweep({ makeClient: f, registry: [], isAlive: liveIs, log: () => {}, dryRun: true });
|
|
175
|
+
check("--dry-run 报得出该收哪些", r.stray.length === 2);
|
|
176
|
+
check("--dry-run 一个 close_all 都没发", !f.seen.some((c) => c.calls.some((x) => x.tool === "browser_close_all")));
|
|
177
|
+
check("--dry-run 汇总的关闭数是 0", r.closed === 0);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
{
|
|
181
|
+
const f = fakeClientFactory({ otherSessions: others, stuck: ["e2e-A"] });
|
|
182
|
+
const lines = [];
|
|
183
|
+
const r = await runSweep({ makeClient: f, registry: [], isAlive: liveIs, log: (m) => lines.push(m) });
|
|
184
|
+
const closedFor = f.seen.filter((c) => c.calls.some((x) => x.tool === "browser_close_all")).map((c) => c.sessionId);
|
|
185
|
+
check("一个会话收不动,后面的照收", closedFor.includes("e2e-hard-777-abc") && r.closed === 2, String(r.closed));
|
|
186
|
+
check("收不动的那个在日志里说清了,而且没当成收干净了", lines.some((l) => /e2e-A.*没收成/.test(l)));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
{
|
|
190
|
+
const f = fakeClientFactory({ otherSessions: [{ session: "s1-x", tabIds: [1] }] });
|
|
191
|
+
const lines = [];
|
|
192
|
+
const r = await runSweep({ makeClient: f, registry: [], isAlive: liveIs, log: (m) => lines.push(m) });
|
|
193
|
+
check("没有残留时干脆地说一声就走", r.stray.length === 0 && r.closed === 0 && lines.some((l) => /干净/.test(l)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
{
|
|
197
|
+
const f = fakeClientFactory({ otherSessions: [{ session: "e2e-手动起的名字", tabIds: [9] }] });
|
|
198
|
+
await runSweep({
|
|
199
|
+
makeClient: f,
|
|
200
|
+
registry: [{ pid: 555, runId: "r", sessions: ["e2e-手动起的名字"] }],
|
|
201
|
+
isAlive: liveIs,
|
|
202
|
+
log: () => {},
|
|
203
|
+
});
|
|
204
|
+
check("登记表护住的不收", !f.seen.some((c) => c.sessionId === "e2e-手动起的名字"));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
section("7. CLI 入口:`node scripts/e2e-sweep.mjs` 真的能跑起来");
|
|
208
|
+
|
|
209
|
+
{
|
|
210
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
211
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "aic-sweep-cli-"));
|
|
212
|
+
const stub = path.join(tmp, "stub-server.mjs");
|
|
213
|
+
fs.writeFileSync(
|
|
214
|
+
stub,
|
|
215
|
+
`let buf = "";
|
|
216
|
+
process.stdin.setEncoding("utf8");
|
|
217
|
+
process.stdin.on("data", (c) => {
|
|
218
|
+
buf += c; let i;
|
|
219
|
+
while ((i = buf.indexOf("\\n")) >= 0) {
|
|
220
|
+
const line = buf.slice(0, i).trim(); buf = buf.slice(i + 1);
|
|
221
|
+
if (!line) continue;
|
|
222
|
+
const m = JSON.parse(line);
|
|
223
|
+
if (m.method === "initialize") {
|
|
224
|
+
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: m.id, result: { protocolVersion: "2025-06-18", capabilities: {}, serverInfo: { name: "stub", version: "0" } } }) + "\\n");
|
|
225
|
+
} else if (m.method === "tools/call") {
|
|
226
|
+
const body = m.params.name === "browser_status"
|
|
227
|
+
? { otherSessions: [{ session: "e2e-stray-424242-zz", tabIds: [11, 12] }, { session: "\\u7528\\u6237\\u7684\\u4f1a\\u8bdd", tabIds: [13] }] }
|
|
228
|
+
: { closedCount: 2 };
|
|
229
|
+
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: m.id, result: { content: [{ type: "text", text: JSON.stringify(body) }] } }) + "\\n");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
`
|
|
234
|
+
);
|
|
235
|
+
const launcher = path.join(tmp, "launcher.sh");
|
|
236
|
+
fs.writeFileSync(launcher, `#!/bin/sh\nexec ${process.execPath} ${stub} "$@"\n`);
|
|
237
|
+
fs.chmodSync(launcher, 0o755);
|
|
238
|
+
const env = { ...process.env, AGENT_IN_CHROME_E2E_LAUNCHER: launcher, AGENT_IN_CHROME_SOCK: path.join(tmp, "s.sock") };
|
|
239
|
+
const dry = spawnSync(process.execPath, [path.join(HERE, "e2e-sweep.mjs"), "--dry-run"], { encoding: "utf8", env, timeout: 30000 });
|
|
240
|
+
check("`--dry-run` 退出码 0", dry.status === 0, String(dry.status) + (dry.stderr || ""));
|
|
241
|
+
check("`--dry-run` 报出了那个游离会话", /e2e-stray-424242-zz/.test(dry.stdout || ""), dry.stdout);
|
|
242
|
+
check("`--dry-run` 明说一个都没收", /一个都没收/.test(dry.stdout || ""), dry.stdout);
|
|
243
|
+
const run = spawnSync(process.execPath, [path.join(HERE, "e2e-sweep.mjs")], { encoding: "utf8", env, timeout: 30000 });
|
|
244
|
+
check("不带参数时真的去收,退出码 0", run.status === 0, String(run.status) + (run.stderr || ""));
|
|
245
|
+
check("汇总里报了收掉的标签页数", /共收掉 2 个标签页/.test(run.stdout || ""), run.stdout);
|
|
246
|
+
check("用户的会话没出现在要收的名单里", !/用户的会话(/.test(run.stdout || ""), run.stdout);
|
|
247
|
+
try { fs.rmSync(tmp, { recursive: true, force: true }); } catch {}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
console.log(`\n${failed ? "\x1b[31m" : "\x1b[32m"}${passed} 通过,${failed} 失败\x1b[0m\n`);
|
|
251
|
+
process.exit(failed ? 1 : 0);
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn as realSpawn } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { createForegroundGuard, helperCandidates } from "../mcp/foreground-guard.mjs";
|
|
9
|
+
import { compareInstalledMcp, listMjs, provenanceReport, versionOf } from "./launcher-provenance.mjs";
|
|
10
|
+
|
|
11
|
+
const SELF = fileURLToPath(import.meta.url);
|
|
12
|
+
|
|
13
|
+
if (process.argv.includes("--fake-helper")) {
|
|
14
|
+
process.stdout.write(JSON.stringify({ t: "ready", ms: Date.now(), front: "com.fake.Editor" }) + "\n");
|
|
15
|
+
let armedUntil = 0;
|
|
16
|
+
let stealAt = 0;
|
|
17
|
+
let buf = "";
|
|
18
|
+
process.stdin.setEncoding("utf8");
|
|
19
|
+
process.stdin.on("data", (d) => {
|
|
20
|
+
buf += d;
|
|
21
|
+
let i;
|
|
22
|
+
while ((i = buf.indexOf("\n")) >= 0) {
|
|
23
|
+
const line = buf.slice(0, i).trim();
|
|
24
|
+
buf = buf.slice(i + 1);
|
|
25
|
+
const [cmd, arg] = line.split(" ");
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
if (cmd === "arm") {
|
|
28
|
+
armedUntil = now + Number(arg || 0);
|
|
29
|
+
stealAt = process.env.FAKE_STEAL === "0" ? 0 : now;
|
|
30
|
+
process.stdout.write(JSON.stringify({ t: "armed", ms: now, base: "com.fake.Editor" }) + "\n");
|
|
31
|
+
} else if (cmd === "confirm") {
|
|
32
|
+
if (now > armedUntil) process.stdout.write(JSON.stringify({ t: "skip", ms: now, why: "not-armed" }) + "\n");
|
|
33
|
+
else if (!stealAt) process.stdout.write(JSON.stringify({ t: "skip", ms: now, why: "no-steal" }) + "\n");
|
|
34
|
+
else if (now - stealAt > Number(process.env.FAKE_WINDOW_MS || 600))
|
|
35
|
+
process.stdout.write(JSON.stringify({ t: "skip", ms: now, why: "late" }) + "\n");
|
|
36
|
+
else
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
JSON.stringify({ t: "restore", ms: now, to: "com.fake.Editor", ok: true, exposureMs: now - stealAt }) + "\n"
|
|
39
|
+
);
|
|
40
|
+
} else if (cmd === "disarm") {
|
|
41
|
+
armedUntil = 0;
|
|
42
|
+
stealAt = 0;
|
|
43
|
+
process.stdout.write(JSON.stringify({ t: "disarmed", ms: now }) + "\n");
|
|
44
|
+
} else if (cmd === "quit") process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
process.stdin.on("end", () => process.exit(0));
|
|
48
|
+
setInterval(() => {}, 1 << 30);
|
|
49
|
+
} else {
|
|
50
|
+
queueMicrotask(() => main());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let pass = 0;
|
|
54
|
+
let fail = 0;
|
|
55
|
+
const failures = [];
|
|
56
|
+
function check(name, cond, extra = "") {
|
|
57
|
+
if (cond) {
|
|
58
|
+
console.log(` \x1b[32m✓\x1b[0m ${name}`);
|
|
59
|
+
pass++;
|
|
60
|
+
} else {
|
|
61
|
+
console.log(` \x1b[31m✗\x1b[0m ${name}${extra ? ` — ${String(extra).slice(0, 300)}` : ""}`);
|
|
62
|
+
failures.push(name);
|
|
63
|
+
fail++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const section = (s) => console.log(`\n\x1b[1m${s}\x1b[0m`);
|
|
67
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
68
|
+
|
|
69
|
+
async function until(fn, ms = 3000) {
|
|
70
|
+
const end = Date.now() + ms;
|
|
71
|
+
for (;;) {
|
|
72
|
+
const v = fn();
|
|
73
|
+
if (v) return v;
|
|
74
|
+
if (Date.now() > end) return null;
|
|
75
|
+
await sleep(15);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function helperGuard(extraEnv = {}) {
|
|
80
|
+
return createForegroundGuard({
|
|
81
|
+
platform: "darwin",
|
|
82
|
+
base: "/nonexistent",
|
|
83
|
+
exists: () => true,
|
|
84
|
+
spawn: (cmd, args, opts) =>
|
|
85
|
+
realSpawn(process.execPath, [SELF, "--fake-helper"], { ...opts, env: { ...process.env, ...extraEnv } }),
|
|
86
|
+
armTtlMs: 400,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function main() {
|
|
91
|
+
section("1. 平台与开关:非 macOS / 显式关掉 → 一个子进程都不起");
|
|
92
|
+
{
|
|
93
|
+
let spawned = 0;
|
|
94
|
+
const g = createForegroundGuard({
|
|
95
|
+
platform: "linux",
|
|
96
|
+
spawn: () => {
|
|
97
|
+
spawned++;
|
|
98
|
+
throw new Error("不该走到这儿");
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
check("非 macOS:arm() 返回 false", g.arm() === false);
|
|
102
|
+
check("非 macOS:confirm() 返回 false", g.confirm() === false);
|
|
103
|
+
check("非 macOS:一次 spawn 都没有", spawned === 0);
|
|
104
|
+
check("非 macOS:mode 停在 off", g.stats().mode === "off", JSON.stringify(g.stats()));
|
|
105
|
+
|
|
106
|
+
const g2 = createForegroundGuard({
|
|
107
|
+
platform: "darwin",
|
|
108
|
+
enabled: false,
|
|
109
|
+
spawn: () => {
|
|
110
|
+
spawned++;
|
|
111
|
+
throw new Error("不该走到这儿");
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
g2.arm();
|
|
115
|
+
g2.confirm();
|
|
116
|
+
check("AGENT_IN_CHROME_NO_FG_GUARD 关掉后同样零 spawn", spawned === 0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
section("2. 惰性:没 arm 过就不起 helper");
|
|
120
|
+
{
|
|
121
|
+
let spawned = 0;
|
|
122
|
+
const g = createForegroundGuard({
|
|
123
|
+
platform: "darwin",
|
|
124
|
+
exists: () => true,
|
|
125
|
+
spawn: (...a) => {
|
|
126
|
+
spawned++;
|
|
127
|
+
return realSpawn(process.execPath, [SELF, "--fake-helper"], { stdio: ["pipe", "pipe", "ignore"] });
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
check("建出来时还没有子进程", spawned === 0);
|
|
131
|
+
check("没武装过的 confirm 不作数、也不起进程", g.confirm() === false && spawned === 0);
|
|
132
|
+
g.arm();
|
|
133
|
+
check("第一次 arm 才起 helper", spawned === 1);
|
|
134
|
+
g.arm();
|
|
135
|
+
g.arm();
|
|
136
|
+
check("后续 arm 复用同一个 helper", spawned === 1);
|
|
137
|
+
g.stop();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
section("3. helper 路径:武装 + 确认 → 真的还前台");
|
|
141
|
+
{
|
|
142
|
+
const g = helperGuard();
|
|
143
|
+
g.arm();
|
|
144
|
+
check("armed 事件回来了", !!(await until(() => g.events().find((e) => e.t === "armed"))), JSON.stringify(g.events()));
|
|
145
|
+
g.confirm();
|
|
146
|
+
const ev = await until(() => g.events().find((e) => e.t === "restore"));
|
|
147
|
+
check("发出了 restore", !!ev, JSON.stringify(g.events()));
|
|
148
|
+
check("restore 报了还给谁", ev?.to === "com.fake.Editor", JSON.stringify(ev));
|
|
149
|
+
check("stats 记了一次 restore、零 skip", g.stats().restores === 1 && g.stats().skips === 0, JSON.stringify(g.stats()));
|
|
150
|
+
g.stop();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
section("4. 只武装不确认 → 不还(用户自己切过去的不许被拽走)");
|
|
154
|
+
{
|
|
155
|
+
const g = helperGuard();
|
|
156
|
+
g.arm();
|
|
157
|
+
await until(() => g.events().find((e) => e.t === "armed"));
|
|
158
|
+
await sleep(250);
|
|
159
|
+
check("没有任何 restore", !g.events().some((e) => e.t === "restore"), JSON.stringify(g.events()));
|
|
160
|
+
check("stats.restores 仍是 0", g.stats().restores === 0);
|
|
161
|
+
g.stop();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
section("5. 动作没开出新页(只武装、结果因不成立)→ 不还");
|
|
165
|
+
{
|
|
166
|
+
const g = helperGuard({ FAKE_STEAL: "0" });
|
|
167
|
+
g.arm();
|
|
168
|
+
await until(() => g.events().find((e) => e.t === "armed"));
|
|
169
|
+
g.confirm();
|
|
170
|
+
const sk = await until(() => g.events().find((e) => e.t === "skip"));
|
|
171
|
+
check("被判成 no-steal 并跳过", sk?.why === "no-steal", JSON.stringify(g.events()));
|
|
172
|
+
check("一次 restore 都没有", !g.events().some((e) => e.t === "restore"));
|
|
173
|
+
g.stop();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
section("6. 确认迟到 → 不还");
|
|
177
|
+
{
|
|
178
|
+
const g = helperGuard({ FAKE_WINDOW_MS: "50" });
|
|
179
|
+
g.arm();
|
|
180
|
+
await until(() => g.events().find((e) => e.t === "armed"));
|
|
181
|
+
await sleep(160);
|
|
182
|
+
g.confirm();
|
|
183
|
+
const sk = await until(() => g.events().find((e) => e.t === "skip"));
|
|
184
|
+
check("被判成 late 并跳过", sk?.why === "late", JSON.stringify(g.events()));
|
|
185
|
+
g.stop();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
section("7. 武装过期 → 不还");
|
|
189
|
+
{
|
|
190
|
+
const g = helperGuard();
|
|
191
|
+
g.arm();
|
|
192
|
+
await until(() => g.events().find((e) => e.t === "armed"));
|
|
193
|
+
await sleep(520);
|
|
194
|
+
g.confirm();
|
|
195
|
+
const sk = await until(() => g.events().find((e) => e.t === "skip"));
|
|
196
|
+
check("被判成 not-armed 并跳过", sk?.why === "not-armed", JSON.stringify(g.events()));
|
|
197
|
+
g.stop();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
section("8. disarm / stop:解除之后确认不算数,helper 收得掉");
|
|
201
|
+
{
|
|
202
|
+
const g = helperGuard();
|
|
203
|
+
g.arm();
|
|
204
|
+
await until(() => g.events().find((e) => e.t === "armed"));
|
|
205
|
+
g.disarm();
|
|
206
|
+
await until(() => g.events().find((e) => e.t === "disarmed"));
|
|
207
|
+
g.confirm();
|
|
208
|
+
const sk = await until(() => g.events().find((e) => e.t === "skip"));
|
|
209
|
+
check("disarm 之后的 confirm 被跳过", !!sk && sk.why === "not-armed", JSON.stringify(g.events()));
|
|
210
|
+
g.stop();
|
|
211
|
+
check("stop 之后 stats 还读得到(幂等,不抛)", typeof g.stats().arms === "number");
|
|
212
|
+
g.stop();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
section("9. helper 找不到 → 退到 open -b 兜底路径");
|
|
216
|
+
{
|
|
217
|
+
const calls = [];
|
|
218
|
+
const fake = (cmd, args) => {
|
|
219
|
+
calls.push({ cmd, args });
|
|
220
|
+
const n = calls.filter((c) => c.cmd === "/usr/bin/lsappinfo").length;
|
|
221
|
+
const bid = n <= 1 ? "com.fake.Editor" : "com.fake.Browser";
|
|
222
|
+
const body = `1) "x" ASN:0x0-1: (in front) \n bundleID="${bid}"\n`;
|
|
223
|
+
return realSpawn(process.execPath, ["-e", `process.stdout.write(${JSON.stringify(body)})`], {
|
|
224
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
const g = createForegroundGuard({
|
|
228
|
+
platform: "darwin",
|
|
229
|
+
exists: () => false,
|
|
230
|
+
spawn: fake,
|
|
231
|
+
armTtlMs: 3000,
|
|
232
|
+
});
|
|
233
|
+
g.arm();
|
|
234
|
+
check("mode 落到 fallback", g.stats().mode === "fallback", JSON.stringify(g.stats()));
|
|
235
|
+
await until(() => calls.some((c) => c.cmd === "/usr/bin/lsappinfo"));
|
|
236
|
+
await sleep(120);
|
|
237
|
+
g.confirm();
|
|
238
|
+
const open = await until(() => calls.find((c) => c.cmd === "/usr/bin/open"));
|
|
239
|
+
check("兜底路径真的调了 open -b", !!open, JSON.stringify(calls));
|
|
240
|
+
check("还给的是武装那一刻的 app", open?.args?.[1] === "com.fake.Editor", JSON.stringify(open));
|
|
241
|
+
check("记了一次 restore", g.stats().restores === 1, JSON.stringify(g.stats()));
|
|
242
|
+
g.stop();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
section("10. 兜底路径:前台压根没换人 → 不 open");
|
|
246
|
+
{
|
|
247
|
+
const calls = [];
|
|
248
|
+
const g = createForegroundGuard({
|
|
249
|
+
platform: "darwin",
|
|
250
|
+
exists: () => false,
|
|
251
|
+
spawn: (cmd, args) => {
|
|
252
|
+
calls.push({ cmd, args });
|
|
253
|
+
const body = `1) "x" ASN:0x0-1: (in front) \n bundleID="com.fake.Editor"\n`;
|
|
254
|
+
return realSpawn(process.execPath, ["-e", `process.stdout.write(${JSON.stringify(body)})`], {
|
|
255
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
armTtlMs: 3000,
|
|
259
|
+
});
|
|
260
|
+
g.arm();
|
|
261
|
+
await until(() => calls.some((c) => c.cmd === "/usr/bin/lsappinfo"));
|
|
262
|
+
await sleep(120);
|
|
263
|
+
g.confirm();
|
|
264
|
+
await sleep(300);
|
|
265
|
+
check("没有 open -b", !calls.some((c) => c.cmd === "/usr/bin/open"), JSON.stringify(calls));
|
|
266
|
+
check("被记成 no-steal", g.stats().lastSkip === "no-steal", JSON.stringify(g.stats()));
|
|
267
|
+
g.stop();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
section("11. 兜底路径:武装已过期 → 不 open");
|
|
271
|
+
{
|
|
272
|
+
const calls = [];
|
|
273
|
+
const g = createForegroundGuard({
|
|
274
|
+
platform: "darwin",
|
|
275
|
+
exists: () => false,
|
|
276
|
+
spawn: (cmd, args) => {
|
|
277
|
+
calls.push({ cmd, args });
|
|
278
|
+
const n = calls.filter((c) => c.cmd === "/usr/bin/lsappinfo").length;
|
|
279
|
+
const body = `1) "x" ASN:0x0-1: (in front) \n bundleID="${n <= 1 ? "com.fake.Editor" : "com.fake.Browser"}"\n`;
|
|
280
|
+
return realSpawn(process.execPath, ["-e", `process.stdout.write(${JSON.stringify(body)})`], {
|
|
281
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
armTtlMs: 100,
|
|
285
|
+
});
|
|
286
|
+
g.arm();
|
|
287
|
+
await until(() => calls.some((c) => c.cmd === "/usr/bin/lsappinfo"));
|
|
288
|
+
await sleep(200);
|
|
289
|
+
g.confirm();
|
|
290
|
+
await sleep(250);
|
|
291
|
+
check("过期之后不 open", !calls.some((c) => c.cmd === "/usr/bin/open"), JSON.stringify(calls));
|
|
292
|
+
g.stop();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
section("12. 并发两个守护各记各的,互不串");
|
|
296
|
+
{
|
|
297
|
+
const a = helperGuard();
|
|
298
|
+
const b = helperGuard({ FAKE_STEAL: "0" });
|
|
299
|
+
a.arm();
|
|
300
|
+
b.arm();
|
|
301
|
+
await until(() => a.events().find((e) => e.t === "armed") && b.events().find((e) => e.t === "armed"));
|
|
302
|
+
a.confirm();
|
|
303
|
+
b.confirm();
|
|
304
|
+
await until(() => a.events().find((e) => e.t === "restore"));
|
|
305
|
+
await until(() => b.events().find((e) => e.t === "skip"));
|
|
306
|
+
check("A 还了", a.stats().restores === 1 && a.stats().skips === 0, JSON.stringify(a.stats()));
|
|
307
|
+
check("B 没还", b.stats().restores === 0 && b.stats().skips === 1, JSON.stringify(b.stats()));
|
|
308
|
+
a.stop();
|
|
309
|
+
b.stop();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
section("13. helper 候选路径:装完那份和仓库那份都在名单里");
|
|
313
|
+
{
|
|
314
|
+
const c = helperCandidates("/opt/rt");
|
|
315
|
+
check("含运行时目录那份", c.includes(path.join("/opt/rt", "mac-foreground", "aic-fg")), JSON.stringify(c));
|
|
316
|
+
check(
|
|
317
|
+
"含仓库检出那份",
|
|
318
|
+
c.includes(path.join("/opt/rt", "..", "native-host", "mac-foreground", "aic-fg")),
|
|
319
|
+
JSON.stringify(c)
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
section("14. 真 helper(macOS 上编出来了才跑):ready 帧说得出话");
|
|
324
|
+
{
|
|
325
|
+
const repoBin = path.join(path.dirname(SELF), "..", "native-host", "mac-foreground", "aic-fg");
|
|
326
|
+
if (process.platform !== "darwin" || !fs.existsSync(repoBin)) {
|
|
327
|
+
console.log(` \x1b[90m·\x1b[0m 本机没有编好的 aic-fg(${process.platform}),这一节不适用——兜底路径已由第 9~11 节覆盖`);
|
|
328
|
+
} else {
|
|
329
|
+
const g = createForegroundGuard({ platform: "darwin", base: path.join(path.dirname(SELF), "..", "mcp") });
|
|
330
|
+
g.arm();
|
|
331
|
+
const ready = await until(() => g.events().find((e) => e.t === "ready"));
|
|
332
|
+
check("真 helper 起来了并报了 ready", !!ready, JSON.stringify(g.events()));
|
|
333
|
+
check("走的是 helper 模式", g.stats().mode === "helper", JSON.stringify(g.stats()));
|
|
334
|
+
const armed = await until(() => g.events().find((e) => e.t === "armed"));
|
|
335
|
+
check("真 helper 认 arm", !!armed, JSON.stringify(g.events()));
|
|
336
|
+
g.confirm();
|
|
337
|
+
const sk = await until(() => g.events().find((e) => e.t === "skip"));
|
|
338
|
+
check("没有被抢时真 helper 不动手", sk?.why === "no-steal", JSON.stringify(g.events()));
|
|
339
|
+
g.stop();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
section("15. e2e 启动器来源比对(scripts/launcher-provenance.mjs)");
|
|
344
|
+
{
|
|
345
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "aic-prov-"));
|
|
346
|
+
const ws = path.join(tmp, "mcp");
|
|
347
|
+
const rt = path.join(tmp, "rt");
|
|
348
|
+
fs.mkdirSync(path.join(ws, "cdp"), { recursive: true });
|
|
349
|
+
fs.mkdirSync(path.join(rt, "cdp"), { recursive: true });
|
|
350
|
+
fs.writeFileSync(path.join(ws, "server.mjs"), 'const VERSION = "9.9.9";\n');
|
|
351
|
+
fs.writeFileSync(path.join(ws, "cdp", "client.mjs"), "export const a = 1;\n");
|
|
352
|
+
fs.writeFileSync(path.join(rt, "server.mjs"), 'const VERSION = "9.9.9";\n');
|
|
353
|
+
fs.writeFileSync(path.join(rt, "cdp", "client.mjs"), "export const a = 1;\n");
|
|
354
|
+
|
|
355
|
+
check("列出的是相对路径且带子目录", JSON.stringify(listMjs(ws)) === '["cdp/client.mjs","server.mjs"]', JSON.stringify(listMjs(ws)));
|
|
356
|
+
check("一致时 ok", compareInstalledMcp(ws, rt).ok === true);
|
|
357
|
+
check("版本号读得出", versionOf(path.join(rt, "server.mjs")) === "9.9.9");
|
|
358
|
+
|
|
359
|
+
let r = provenanceReport({ launcher: "L", custom: false, workspaceMcpDir: ws, runtimeDir: rt });
|
|
360
|
+
check("一致时不致命", r.fatal === null, JSON.stringify(r));
|
|
361
|
+
check("首行报了来源路径与版本", r.line.includes(path.join(rt, "server.mjs")) && r.line.includes("9.9.9"), r.line);
|
|
362
|
+
|
|
363
|
+
fs.writeFileSync(path.join(ws, "cdp", "client.mjs"), "export const a = 2;\n");
|
|
364
|
+
r = provenanceReport({ launcher: "L", custom: false, workspaceMcpDir: ws, runtimeDir: rt });
|
|
365
|
+
check("内容不同 → 致命", !!r.fatal && r.fatal.includes("cdp/client.mjs(内容不同)"), JSON.stringify(r));
|
|
366
|
+
check("致命文案里写了怎么办", r.fatal.includes("scripts/install.mjs") && r.fatal.includes("AGENT_IN_CHROME_E2E_LAUNCHER"), r.fatal);
|
|
367
|
+
|
|
368
|
+
fs.writeFileSync(path.join(ws, "cdp", "client.mjs"), "export const a = 1;\n");
|
|
369
|
+
fs.writeFileSync(path.join(ws, "brand-new.mjs"), "export const b = 1;\n");
|
|
370
|
+
r = provenanceReport({ launcher: "L", custom: false, workspaceMcpDir: ws, runtimeDir: rt });
|
|
371
|
+
check("新模块没装过去 → 也致命", !!r.fatal && r.fatal.includes("brand-new.mjs(没装过去)"), JSON.stringify(r));
|
|
372
|
+
|
|
373
|
+
const rc = provenanceReport({ launcher: "/my/launcher", custom: true, workspaceMcpDir: ws, runtimeDir: rt });
|
|
374
|
+
check("自定义启动器不比对、不致命", rc.fatal === null && rc.line.includes("/my/launcher"), JSON.stringify(rc));
|
|
375
|
+
|
|
376
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
console.log(`\n${fail === 0 ? "\x1b[32m" : "\x1b[31m"}${pass} 通过, ${fail} 失败\x1b[0m`);
|
|
380
|
+
if (fail) console.log("失败项:\n - " + failures.join("\n - "));
|
|
381
|
+
console.log("");
|
|
382
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
383
|
+
}
|