@liang-hz/agent-in-chrome 0.55.2 → 0.55.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.
@@ -204,7 +204,9 @@ console.log("\n\x1b[1m旗标解析\x1b[0m");
204
204
 
205
205
  console.log("\n\x1b[1mlauncher 条目的形状:print-config 与 agents.mjs 是同一份\x1b[0m");
206
206
  {
207
- const trae = buildAgents({ serverPath: facts.serverPath, mcpLauncher: facts.mcp.launcher.command }).find((a) => a.id === "trae");
207
+ const launcherPath =
208
+ process.platform === "win32" ? facts.mcp.launcher.args[facts.mcp.launcher.args.length - 1] : facts.mcp.launcher.command;
209
+ const trae = buildAgents({ serverPath: facts.serverPath, mcpLauncher: launcherPath }).find((a) => a.id === "trae");
208
210
  const entry = JSON.parse(trae.preview.join("\n")).mcpServers["agent-in-chrome"];
209
211
  check(
210
212
  "print-config 的 mcp.launcher 和 agents.mjs 写给 GUI 客户端的条目一致",
@@ -285,7 +287,7 @@ console.log("\n\x1b[1m文档漂移:README / docs 里的 npx 子命令都得存
285
287
  console.log("\n\x1b[1mskill 与 command 的形状\x1b[0m");
286
288
  {
287
289
  const frontmatter = (text) => {
288
- const lines = text.split("\n");
290
+ const lines = text.replace(/\r\n/g, "\n").split("\n");
289
291
  if (lines[0].trim() !== "---") return null;
290
292
  const end = lines.indexOf("---", 1);
291
293
  if (end === -1) return null;
@@ -374,5 +376,38 @@ console.log("\n\x1b[1mregistered 字段真的在读文件\x1b[0m");
374
376
  fs.rmSync(tmp, { recursive: true, force: true });
375
377
  }
376
378
 
379
+ console.log("\n\x1b[1m运行时内容漂移:runtimeDrift 只认字节,不认 mtime\x1b[0m");
380
+ {
381
+ fs.mkdirSync(RUNTIME_DIR, { recursive: true });
382
+ const codeManifest = [
383
+ ["host.mjs", path.join(ROOT, "native-host", "host.mjs")],
384
+ ["server.mjs", path.join(ROOT, "mcp", "server.mjs")],
385
+ ["token.mjs", path.join(ROOT, "mcp", "token.mjs")],
386
+ ];
387
+ for (const [rel, src] of codeManifest) fs.copyFileSync(src, path.join(RUNTIME_DIR, rel));
388
+ check("逐字节一致 → 无漂移", install.runtimeDrift(codeManifest, RUNTIME_DIR).length === 0, JSON.stringify(install.runtimeDrift(codeManifest, RUNTIME_DIR)));
389
+
390
+ fs.appendFileSync(path.join(RUNTIME_DIR, "server.mjs"), "\n");
391
+ const drifted = install.runtimeDrift(codeManifest, RUNTIME_DIR);
392
+ check(
393
+ "改了内容 → differ,且只点名单上的那一个",
394
+ drifted.length === 1 && drifted[0].rel === "server.mjs" && drifted[0].why === "differ",
395
+ JSON.stringify(drifted)
396
+ );
397
+
398
+ fs.rmSync(path.join(RUNTIME_DIR, "token.mjs"));
399
+ const missing = install.runtimeDrift(codeManifest, RUNTIME_DIR);
400
+ check("缺文件 → missing", missing.some((d) => d.rel === "token.mjs" && d.why === "missing"), JSON.stringify(missing));
401
+
402
+ const withPhantom = [...codeManifest, ["ghost.mjs", path.join(RUNTIME_DIR, "definitely-not-here.mjs")]];
403
+ check(
404
+ "源文件读不到的条目直接跳过",
405
+ install.runtimeDrift(withPhantom, RUNTIME_DIR).every((d) => d.rel !== "ghost.mjs"),
406
+ JSON.stringify(install.runtimeDrift(withPhantom, RUNTIME_DIR))
407
+ );
408
+
409
+ fs.rmSync(RUNTIME_DIR, { recursive: true, force: true });
410
+ }
411
+
377
412
  console.log(`\n${failed ? "\x1b[31m" : "\x1b[32m"}${passed} 通过,${failed} 失败\x1b[0m\n`);
378
413
  process.exit(failed ? 1 : 0);
@@ -6,7 +6,7 @@ import fs from "node:fs";
6
6
  import os from "node:os";
7
7
  import path from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
- import { getToken, bridgeEndpoint } from "../mcp/token.mjs";
9
+ import { getToken, bridgeEndpoint, handshakeNonce, handshakeProof, timingSafeEqualStr } from "../mcp/token.mjs";
10
10
 
11
11
  const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
12
12
  const TMP = fs.mkdtempSync(path.join(os.tmpdir(), "agent-in-chrome-proto-"));
@@ -796,6 +796,107 @@ console.log("\n\x1b[1m11c. 更新版本的从连上来:老主让位,在飞
796
796
  P.p.kill();
797
797
  }
798
798
 
799
+ console.log("\n\x1b[1mN. host 启动竞态:扩展的 hello 不许抢跑成第一行\x1b[0m");
800
+ {
801
+ const dir = path.join(TMP, "hostgate");
802
+ fs.mkdirSync(dir, { recursive: true });
803
+ const sock = path.join(dir, "t.sock");
804
+ const token = getToken(dir);
805
+ const snonce = handshakeNonce();
806
+ const lines = [];
807
+ let host = null;
808
+ let injected = false;
809
+ const chromeFrame = (obj) => {
810
+ const b = Buffer.from(JSON.stringify(obj), "utf8");
811
+ const h = Buffer.alloc(4);
812
+ h.writeUInt32LE(b.length, 0);
813
+ return Buffer.concat([h, b]);
814
+ };
815
+ const fakeMaster = net.createServer((c) => {
816
+ c.setEncoding("utf8");
817
+ c.on("error", () => {});
818
+ let authed = false;
819
+ let buf = "";
820
+ c.on("data", (chunk) => {
821
+ buf += chunk;
822
+ let i;
823
+ while ((i = buf.indexOf("\n")) >= 0) {
824
+ const line = buf.slice(0, i).trim();
825
+ buf = buf.slice(i + 1);
826
+ if (!line) continue;
827
+ let m;
828
+ try {
829
+ m = JSON.parse(line);
830
+ } catch {
831
+ continue;
832
+ }
833
+ lines.push(m);
834
+ if (!authed) {
835
+ const roleOk = m.type === "hello" && (m.role === "host" || m.role === "peer");
836
+ const proofOk =
837
+ roleOk &&
838
+ typeof m.proof === "string" &&
839
+ timingSafeEqualStr(m.proof, handshakeProof(token, "client", snonce, m.nonce || ""));
840
+ if (!proofOk) {
841
+ c.write(
842
+ JSON.stringify({ type: "error", code: "unauthorized", message: "(假主)第一行必须是 hello(host/peer)+proof" }) + "\n",
843
+ () => c.destroy()
844
+ );
845
+ return;
846
+ }
847
+ authed = true;
848
+ c.write(JSON.stringify({ type: "welcome", proof: handshakeProof(token, "server", snonce, m.nonce) }) + "\n");
849
+ }
850
+ }
851
+ });
852
+ if (host && !injected) {
853
+ injected = true;
854
+ host.stdin.write(chromeFrame({ type: "hello", role: "extension", version: "9.9.9-gate", bootedAt: 42 }));
855
+ }
856
+ setTimeout(() => c.write(JSON.stringify({ type: "challenge", v: 1, nonce: snonce }) + "\n"), 200);
857
+ });
858
+ fakeMaster.listen(ep(sock));
859
+ await until(() => sockUp(sock));
860
+
861
+ const hostHome = path.join(TMP, "hostgate-home");
862
+ fs.mkdirSync(path.join(hostHome, ".agent-in-chrome"), { recursive: true });
863
+ const hostLog = path.join(hostHome, ".agent-in-chrome", "agent-in-chrome-host.log");
864
+ host = spawn(process.execPath, [path.join(ROOT, "native-host", "host.mjs")], {
865
+ env: { ...process.env, AGENT_IN_CHROME_SOCK: sock, HOME: hostHome, USERPROFILE: hostHome },
866
+ stdio: ["pipe", "pipe", "pipe"],
867
+ });
868
+
869
+ await until(() => lines.length >= 2, 6000);
870
+ await sleep(150);
871
+ check(
872
+ "host 的第一行永远是它自己的 hello(带 proof),不是扩展的帧",
873
+ lines[0]?.type === "hello" && lines[0]?.role === "host" && typeof lines[0]?.proof === "string",
874
+ JSON.stringify(lines[0])
875
+ );
876
+ check(
877
+ "扩展 hello 没有丢:握手走完按原顺序补发到了第二行",
878
+ lines[1]?.type === "hello" && lines[1]?.role === "extension" && lines[1]?.version === "9.9.9-gate",
879
+ JSON.stringify(lines[1])
880
+ );
881
+ await until(() => {
882
+ try {
883
+ return fs.readFileSync(hostLog, "utf8").includes("host 启动");
884
+ } catch {
885
+ return false;
886
+ }
887
+ }, 3000);
888
+ await sleep(1600);
889
+ let logText = "";
890
+ try {
891
+ logText = fs.readFileSync(hostLog, "utf8");
892
+ } catch {}
893
+ check("host 日志里没有「agent 拒绝了我们的令牌」", !logText.includes("agent 拒绝了我们的令牌"), logText.slice(0, 300));
894
+ check("host 一次就握上了(「已连上 agent」只出现一次)", (logText.match(/已连上 agent/g) || []).length === 1, logText.slice(0, 300));
895
+
896
+ host.kill();
897
+ fakeMaster.close();
898
+ }
899
+
799
900
  console.log(failed ? `\n\x1b[31m${passed} 通过, ${failed} 失败\x1b[0m` : `\n\x1b[32m${passed} 通过, ${failed} 失败\x1b[0m`);
800
901
  try {
801
902
  fs.rmSync(TMP, { recursive: true, force: true });
@@ -568,10 +568,13 @@ console.log("\n\x1b[1mP4-2b 桥接行为:握手窗口 / 代发记账 / 分块
568
568
  const box = sandbox("peerwin");
569
569
  getToken(box.dir);
570
570
  const EP = bridgeEndpoint(box.sock);
571
+ const EP_IS_PIPE = EP !== box.sock;
571
572
  const got = [];
572
573
  let firstConnAt = 0;
574
+ let closedSilent = 0;
573
575
  const owner = net.createServer((c) => {
574
576
  firstConnAt = Date.now();
577
+ let frames = 0;
575
578
  c.setEncoding("utf8");
576
579
  let b = "";
577
580
  c.on("data", (d) => {
@@ -581,11 +584,13 @@ console.log("\n\x1b[1mP4-2b 桥接行为:握手窗口 / 代发记账 / 分块
581
584
  const l = b.slice(0, i).trim();
582
585
  b = b.slice(i + 1);
583
586
  if (!l) continue;
587
+ frames++;
584
588
  try {
585
589
  got.push({ ...JSON.parse(l), at: Date.now() });
586
590
  } catch {}
587
591
  }
588
592
  });
593
+ c.on("close", () => { if (frames === 0) closedSilent++; });
589
594
  c.on("error", () => {});
590
595
  });
591
596
  await new Promise((r) => owner.listen(EP, r));
@@ -595,19 +600,33 @@ console.log("\n\x1b[1mP4-2b 桥接行为:握手窗口 / 代发记账 / 分块
595
600
  await waitFor(() => firstConnAt > 0, 5000);
596
601
  const callAt = Date.now();
597
602
  S.rpc("tools/call", { name: "browser_status", arguments: {} });
598
- await waitFor(() => got.some((m) => m.type === "hello"), 5000);
599
- await sleep(600);
600
-
601
- const iHello = got.findIndex((m) => m.type === "hello");
602
- const iCall = got.findIndex((m) => m.type === "call");
603
- if (callAt - firstConnAt > 700) {
604
- console.log(` \x1b[90m·\x1b[0m 工具调用没落在握手窗口内(晚了 ${callAt - firstConnAt}ms),跳过这条`);
605
- } else {
603
+ if (EP_IS_PIPE) {
604
+ await sleep(13000);
606
605
  check(
607
- "握手走完之前不许把 call 发给主(修复前:连上就发,主会当未认证连接断掉)",
608
- iHello >= 0 && (iCall < 0 || iCall > iHello),
606
+ "管道上对面不出题就一个字节都不发(令牌连明文都不许过线)",
607
+ got.length === 0,
609
608
  JSON.stringify(got.map((m) => m.type))
610
609
  );
610
+ check(
611
+ "到握手死线把这条没话的连接断掉(不许永久挂着)",
612
+ closedSilent >= 1,
613
+ `一条都没断(silent=${closedSilent})`
614
+ );
615
+ } else {
616
+ await waitFor(() => got.some((m) => m.type === "hello"), 5000);
617
+ await sleep(600);
618
+
619
+ const iHello = got.findIndex((m) => m.type === "hello");
620
+ const iCall = got.findIndex((m) => m.type === "call");
621
+ if (callAt - firstConnAt > 700) {
622
+ console.log(` \x1b[90m·\x1b[0m 工具调用没落在握手窗口内(晚了 ${callAt - firstConnAt}ms),跳过这条`);
623
+ } else {
624
+ check(
625
+ "握手走完之前不许把 call 发给主(修复前:连上就发,主会当未认证连接断掉)",
626
+ iHello >= 0 && (iCall < 0 || iCall > iHello),
627
+ JSON.stringify(got.map((m) => m.type))
628
+ );
629
+ }
611
630
  }
612
631
  S.kill();
613
632
  owner.close();
@@ -748,7 +767,7 @@ console.log("\n\x1b[1mP4-2c 工具管线:截图落盘 / 参数不过桥 / 探
748
767
  check("inline+outFile 同给时也真的落了盘(修复前 outFile 被静默忽略)", fs.existsSync(shot), shot);
749
768
  check(
750
769
  "落盘路径回给了调用方(否则「存哪了」没人答得上来)",
751
- JSON.stringify(r?.result?.content || []).includes(shot),
770
+ (r?.result?.content || []).some((c) => (c.text || "").includes(JSON.stringify(shot).slice(1, -1))),
752
771
  JSON.stringify(kinds)
753
772
  );
754
773
  const shotCall = host.calls().filter((c) => c.tool === "screenshot").pop();
@@ -912,7 +931,7 @@ console.log("\n\x1b[1mP4-3 native host 的缓冲上限\x1b[0m");
912
931
  box.clean();
913
932
  }
914
933
 
915
- console.log("\n\x1b[1mP4-4 Windows 上 CLI/headless 模式必须被拒\x1b[0m");
934
+ console.log("\n\x1b[1mP4-4 Windows 上 CLI/headless 模式可用(0.55.x 的拒绝闸已撤)\x1b[0m");
916
935
  {
917
936
  const box = sandbox("cli");
918
937
  const runAs = (platform, env) =>
@@ -938,11 +957,13 @@ console.log("\n\x1b[1mP4-4 Windows 上 CLI/headless 模式必须被拒\x1b[0m");
938
957
  });
939
958
 
940
959
  const win = await runAs("win32", { AGENT_IN_CHROME_LAUNCH: "1", AGENT_IN_CHROME_BIN: "C:\\nope\\chrome.exe" });
941
- check("win32 + LAUNCH=1 直接退出(旧代码会一路进到 CLI 模式)", win.code === 1, `exit=${win.code}`);
942
- check("说了为什么不支持", /不支持|拒绝启动/.test(win.err) && /chrome/i.test(win.err), oneline(win.err));
943
- check("说了插件模式不受影响", /插件模式/.test(win.err), oneline(win.err));
944
- check("给了去哪跟进", /README|browser-launch/.test(win.err), oneline(win.err));
945
- check("拒绝文案点明 AGENT_IN_CHROME_BIN 绕不过去", /AGENT_IN_CHROME_BIN.*绕不过去|绕过的只是/.test(win.err), oneline(win.err, 300));
960
+ check("win32 + LAUNCH=1 照常启动(不再拒绝)", win.code === null, `exit=${win.code} ${oneline(win.err, 200)}`);
961
+ check("拒绝文案不会再出现", !/拒绝启动|不支持 CLI\/headless/.test(win.err), oneline(win.err, 200));
962
+ check(
963
+ "起不了浏览器的原因报得出来(点名 BIN,进程不死)",
964
+ /自启浏览器失败/.test(win.err) && /AGENT_IN_CHROME_BIN|nope/.test(win.err),
965
+ oneline(win.err, 300)
966
+ );
946
967
 
947
968
  const mac = await runAs("darwin", { AGENT_IN_CHROME_LAUNCH: "1" });
948
969
  check("非 win32 不受影响(没有被这道闸拦下)", !/不支持 CLI\/headless/.test(mac.err), oneline(mac.err));
@@ -1286,6 +1286,7 @@ function makeChrome(state) {
1286
1286
  if (!state.noNativeChange) {
1287
1287
  for (const l of target._listeners) if (l.type === "change") l.fn({ type: "change" });
1288
1288
  }
1289
+ if (typeof state.afterSetFiles === "function") state.afterSetFiles(target, scope);
1289
1290
  }
1290
1291
  return cb({});
1291
1292
  }
@@ -10128,6 +10129,72 @@ const B_PATH = "/tmp/aic-upload/b.bin";
10128
10129
  check("如实报告 change 已由浏览器触发", r.changeFired === true && r.changeDispatchedManually === undefined, JSON.stringify(r));
10129
10130
  }
10130
10131
 
10132
+ {
10133
+ const page = uploadPage();
10134
+ const st = freshState({ page, fileSizes: { [A_PATH]: 123 } });
10135
+ const T = loadSw(st);
10136
+ await T.new_tab({ url: "https://example.com/form" }, "s1");
10137
+ const avatar = page.elements[0];
10138
+ let replaced = false;
10139
+ st.afterSetFiles = (target) => {
10140
+ if (target !== avatar) return;
10141
+ replaced = true;
10142
+ target.isConnected = false;
10143
+ for (const k of Object.keys(target._attrs)) delete target._attrs[k];
10144
+ };
10145
+
10146
+ let r;
10147
+ try {
10148
+ r = await T.upload_file({ selector: "#avatar", files: [A_PATH] }, "s1");
10149
+ } catch (e) {
10150
+ r = { __threw: String(e?.message || e) };
10151
+ }
10152
+ check("换节点:用例本身确实造出了替换(没走空)", replaced, String(replaced));
10153
+ if (r.__threw) {
10154
+ check("换节点:不再误报失败", false, `upload_file 抛了错:${r.__threw}`);
10155
+ } else {
10156
+ check("换节点:不再误报失败", r.count === 1 && r.uploaded?.[0]?.name === "一号.txt", JSON.stringify(r).slice(0, 200));
10157
+ check("换节点:如实带上本机路径", r.uploaded?.[0]?.path === A_PATH, JSON.stringify(r.uploaded));
10158
+ check("换节点:如实标注校验依据换成了 change 时刻的抓拍", r.elementReplaced === true, JSON.stringify(r));
10159
+ check("换节点:changeFired 仍如实为 true", r.changeFired === true, JSON.stringify(r));
10160
+ }
10161
+ }
10162
+
10163
+ {
10164
+ const page = uploadPage();
10165
+ const st = freshState({ page, fileSizes: { [A_PATH]: 0 } });
10166
+ const T = loadSw(st);
10167
+ await T.new_tab({ url: "https://example.com/form" }, "s1");
10168
+ const avatar = page.elements[0];
10169
+ st.afterSetFiles = (target) => {
10170
+ if (target !== avatar) return;
10171
+ target.isConnected = false;
10172
+ for (const k of Object.keys(target._attrs)) delete target._attrs[k];
10173
+ };
10174
+
10175
+ const t = await throws(
10176
+ () => T.upload_file({ selector: "#avatar", files: [A_PATH], expect: [{ name: "一号.txt", sizeBytes: 123 }] }, "s1"),
10177
+ /没被真正读进去/
10178
+ );
10179
+ check("换节点 + 字节数对不上:照样报错,没被退路盖过去", t.threw && t.match, t.msg);
10180
+ }
10181
+
10182
+ {
10183
+ const page = uploadPage();
10184
+ const st = freshState({ page, fileSizes: { [A_PATH]: 123 }, noNativeChange: true });
10185
+ const T = loadSw(st);
10186
+ await T.new_tab({ url: "https://example.com/form" }, "s1");
10187
+ const avatar = page.elements[0];
10188
+ st.afterSetFiles = (target) => {
10189
+ if (target !== avatar) return;
10190
+ target.isConnected = false;
10191
+ for (const k of Object.keys(target._attrs)) delete target._attrs[k];
10192
+ };
10193
+
10194
+ const t = await throws(() => T.upload_file({ selector: "#avatar", files: [A_PATH] }, "s1"), /从页面上消失了/);
10195
+ check("换节点但 change 没触发:仍然报错(没有证据不说成功)", t.threw && t.match, t.msg);
10196
+ }
10197
+
10131
10198
  {
10132
10199
  const st = freshState({ page: uploadPage(), fileSizes: { [A_PATH]: 123 } });
10133
10200
  const T = loadSw(st);
@@ -14383,23 +14450,41 @@ console.log("\n\x1b[1m冷启动路径:别冻事件循环、别重复 spawn、
14383
14450
 
14384
14451
  {
14385
14452
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "aic-ver-"));
14386
- const tally = path.join(tmp, "tally");
14387
- const bin = path.join(tmp, "fake-chrome");
14388
- fs.writeFileSync(bin, `#!/bin/sh\necho x >> ${tally}\necho "Google Chrome 151.0.7999.1"\n`);
14389
- fs.chmodSync(bin, 0o755);
14390
- const out = execFileSync(
14391
- process.execPath,
14392
- ["-e", `import(${JSON.stringify(BL)}).then((m) => { for (let i = 0; i < 5; i++) m.browserArgs({ headless: true, bin: ${JSON.stringify(bin)} }); console.log("done"); })`],
14393
- { encoding: "utf8", env: { ...process.env, HOME: tmp } }
14394
- );
14395
- const runs = fs.existsSync(tally) ? fs.readFileSync(tally, "utf8").trim().split("\n").length : 0;
14396
- check("5 次 browserArgs 只 spawn 一次 --version(原来是 5 次)", runs === 1, `spawn 了 ${runs} 次(${out.trim()})`);
14397
- const args = execFileSync(
14398
- process.execPath,
14399
- ["-e", `import(${JSON.stringify(BL)}).then((m) => console.log(m.browserArgs({ headless: true, bin: ${JSON.stringify(bin)} }).join("\\n")))`],
14400
- { encoding: "utf8", env: { ...process.env, HOME: tmp } }
14401
- );
14402
- check("缓存的版本号确实用上了(UA 里是 151)", /--user-agent=.*Chrome\/151\.0\.0\.0/.test(args), (args.match(/--user-agent=.*/) || [""])[0]);
14453
+ const homeEnv = process.platform === "win32" ? { HOME: tmp, USERPROFILE: tmp } : { HOME: tmp };
14454
+ if (process.platform === "win32") {
14455
+ const bin = path.join(tmp, "chrome.exe");
14456
+ fs.writeFileSync(bin, "");
14457
+ fs.mkdirSync(path.join(tmp, "151.0.7999.1"));
14458
+ fs.mkdirSync(path.join(tmp, "149.0.1111.2"));
14459
+ const args = execFileSync(
14460
+ process.execPath,
14461
+ ["-e", `import(${JSON.stringify(BL)}).then((m) => console.log(m.browserArgs({ headless: true, bin: ${JSON.stringify(bin)} }).join("\\n")))`],
14462
+ { encoding: "utf8", env: { ...process.env, ...homeEnv } }
14463
+ );
14464
+ check(
14465
+ "Windows 版本号从安装目录读(空 exe 也读得出,多版本目录挑最大)",
14466
+ /--user-agent=.*Chrome\/151\.0\.0\.0/.test(args),
14467
+ (args.match(/--user-agent=.*/) || ["(没有 --user-agent)"])[0]
14468
+ );
14469
+ } else {
14470
+ const tally = path.join(tmp, "tally");
14471
+ const bin = path.join(tmp, "fake-chrome");
14472
+ fs.writeFileSync(bin, `#!/bin/sh\necho x >> ${tally}\necho "Google Chrome 151.0.7999.1"\n`);
14473
+ fs.chmodSync(bin, 0o755);
14474
+ const out = execFileSync(
14475
+ process.execPath,
14476
+ ["-e", `import(${JSON.stringify(BL)}).then((m) => { for (let i = 0; i < 5; i++) m.browserArgs({ headless: true, bin: ${JSON.stringify(bin)} }); console.log("done"); })`],
14477
+ { encoding: "utf8", env: { ...process.env, ...homeEnv } }
14478
+ );
14479
+ const runs = fs.existsSync(tally) ? fs.readFileSync(tally, "utf8").trim().split("\n").length : 0;
14480
+ check("5 次 browserArgs 只 spawn 一次 --version(原来是 5 次)", runs === 1, `spawn 了 ${runs} 次(${out.trim()})`);
14481
+ const args = execFileSync(
14482
+ process.execPath,
14483
+ ["-e", `import(${JSON.stringify(BL)}).then((m) => console.log(m.browserArgs({ headless: true, bin: ${JSON.stringify(bin)} }).join("\\n")))`],
14484
+ { encoding: "utf8", env: { ...process.env, ...homeEnv } }
14485
+ );
14486
+ check("缓存的版本号确实用上了(UA 里是 151)", /--user-agent=.*Chrome\/151\.0\.0\.0/.test(args), (args.match(/--user-agent=.*/) || [""])[0]);
14487
+ }
14403
14488
  fs.rmSync(tmp, { recursive: true, force: true });
14404
14489
  }
14405
14490
 
@@ -14422,7 +14507,7 @@ console.log("\n\x1b[1m冷启动路径:别冻事件循环、别重复 spawn、
14422
14507
  process.stdout.write(String(n));
14423
14508
  });`.replace("MODPLACEHOLDER", mod),
14424
14509
  ],
14425
- { encoding: "utf8", env: { ...process.env, HOME: tmp }, stdio: ["ignore", "pipe", "ignore"] }
14510
+ { encoding: "utf8", env: { ...process.env, HOME: tmp, USERPROFILE: tmp }, stdio: ["ignore", "pipe", "ignore"] }
14426
14511
  ).trim()
14427
14512
  );
14428
14513
  const n = count(BL);