conversation-session-bash-direct-output.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. import {
  2. copyFile,
  3. mkdir,
  4. open,
  5. readFile,
  6. readdir,
  7. rm,
  8. stat,
  9. statfs,
  10. writeFile,
  11. } from "node:fs/promises";
  12. import { join } from "node:path";
  13. import { clearAppData, getE2EAppDataPaths } from "../helpers/desktop-app.js";
  14. import { resolveE2ERuntimePath } from "../helpers/e2e-runtime-paths.js";
  15. import { ensureToolCrossProductFullAccessMode } from "../helpers/conversation-session-tool-cross-product.js";
  16. import {
  17. getLatestUpstreamToolResultByToolCallId,
  18. countUpstreamRequests,
  19. } from "../helpers/conversation-session-network.js";
  20. import {
  21. listToolCallBlocks,
  22. waitForToolCallBlockByToolCallId,
  23. } from "../helpers/conversation-session-tool.js";
  24. import {
  25. clickV4Stop,
  26. getV4PaneSnapshot,
  27. prepareV4ConversationE2E,
  28. sendV4Prompt,
  29. selectV4TaskById,
  30. startNewV4Draft,
  31. waitForV4AssistantMessageContaining,
  32. waitForV4ConversationState,
  33. } from "../helpers/v4-conversation.js";
  34. const ROOT = resolveE2ERuntimePath("bash-direct-output", "中文 空格");
  35. const LIMIT = 5 * 1024 ** 3;
  36. const RELEASES = [
  37. "A.release",
  38. "B.release",
  39. "B.finish",
  40. "query.grow",
  41. "query.release",
  42. "foreground.release",
  43. "foreground.finish",
  44. "background.release",
  45. "background.finish",
  46. "read-failure.release",
  47. "realtime.1.release",
  48. "realtime.2.release",
  49. "realtime.3.release",
  50. "realtime.4.release",
  51. "realtime.5.release",
  52. ];
  53. const outputs = new Set<string>();
  54. async function release(name: string) {
  55. await writeFile(join(ROOT, name), "release");
  56. }
  57. async function waitFile(name: string) {
  58. await browser.waitUntil(async () => (await stat(join(ROOT, name)).catch(() => null)) !== null, {
  59. timeout: 90000,
  60. timeoutMsg: `producer 没有到达 ${name}`,
  61. });
  62. }
  63. async function idle() {
  64. await waitForV4ConversationState((s) => s.state === "idle", "BDO 会话没有回到 idle", 30000);
  65. }
  66. async function prompt(marker: string, newTask = true) {
  67. if (newTask) {
  68. await startNewV4Draft();
  69. // 新草稿恢复 build 后必须重新固定权限前置,避免 producer 尚未执行就等待 barrier。
  70. await ensureToolCrossProductFullAccessMode();
  71. }
  72. await sendV4Prompt(`${marker}: Execute the exact Bash output regression fixture.`);
  73. }
  74. async function done(marker: string) {
  75. await waitForV4AssistantMessageContaining(`${marker}_DONE`, 90000);
  76. await idle();
  77. }
  78. async function result(id: string) {
  79. const value = await getLatestUpstreamToolResultByToolCallId(id);
  80. expect(value).not.toBeNull();
  81. return value!;
  82. }
  83. async function outputPath(id: string) {
  84. const sessionId = (await getV4PaneSnapshot()).sessionId;
  85. expect(sessionId).not.toBe("draft");
  86. const path = join(
  87. getE2EAppDataPaths().storageRoot,
  88. "cli",
  89. "exec",
  90. sessionId!,
  91. `${id}-stdout.log`,
  92. );
  93. outputs.add(path);
  94. return path;
  95. }
  96. async function snippet(path: string, tail = false) {
  97. const handle = await open(path, "r");
  98. try {
  99. const size = (await handle.stat()).size;
  100. const buffer = Buffer.alloc(Math.min(size, 128));
  101. await handle.read(buffer, 0, buffer.length, tail ? size - buffer.length : 0);
  102. return buffer.toString();
  103. } finally {
  104. await handle.close();
  105. }
  106. }
  107. async function setExpanded(id: string, expanded: boolean) {
  108. await waitForToolCallBlockByToolCallId(id);
  109. const trigger = await $(`[data-testid="tool-summary-trigger-${id}"]`);
  110. if ((await trigger.getAttribute("aria-expanded")) !== String(expanded)) await trigger.click();
  111. }
  112. async function assertOutputHidden(id: string) {
  113. await browser.waitUntil(
  114. async () =>
  115. browser.execute((toolId) => {
  116. const block = document.querySelector(`[data-testid="chat-tool-call-block-${toolId}"]`);
  117. return (
  118. Boolean(block) &&
  119. !block!.querySelector(
  120. '[data-testid^="bash-output-preview-"], [data-testid="bash-result-output"], [data-testid="bash-output-notice"], [data-testid="bash-output-file"]',
  121. )
  122. );
  123. }, id),
  124. { timeout: 5000, timeoutMsg: `收起后的 Bash 仍渲染输出:${id}` },
  125. );
  126. }
  127. describe("Bash 直接文件输出补充 E2E", () => {
  128. before(async function () {
  129. this.timeout(120000);
  130. await mkdir(ROOT, { recursive: true });
  131. await copyFile(
  132. new URL("../fixtures/fs/conversation-session/bash-direct-output/writer.cjs", import.meta.url),
  133. join(ROOT, "writer.cjs"),
  134. );
  135. await prepareV4ConversationE2E();
  136. await ensureToolCrossProductFullAccessMode();
  137. });
  138. beforeEach(async () => {
  139. for (const name of await readdir(ROOT)) if (name.endsWith(".pid")) await rm(join(ROOT, name));
  140. for (const name of [
  141. ...RELEASES,
  142. "query.ready",
  143. "query.grown",
  144. "foreground.ready",
  145. "background.ready",
  146. "read-failure.ready",
  147. "realtime.1.ready",
  148. "realtime.2.ready",
  149. "realtime.3.ready",
  150. "realtime.4.ready",
  151. "realtime.5.ready",
  152. ]) {
  153. await rm(join(ROOT, name), { force: true });
  154. }
  155. });
  156. afterEach(async () => {
  157. // 失败同样释放本 case 的子进程,避免下一条测试或 coverage teardown 被遗留任务影响。
  158. await Promise.all(RELEASES.map(release));
  159. if ((await getV4PaneSnapshot()).canStop) await clickV4Stop();
  160. const pids = await Promise.all(
  161. (await readdir(ROOT))
  162. .filter((name) => name.endsWith(".pid"))
  163. .map(async (name) => Number(await readFile(join(ROOT, name), "utf8"))),
  164. );
  165. await browser.waitUntil(
  166. async () =>
  167. pids.every((pid) => {
  168. try {
  169. process.kill(pid, 0);
  170. return false;
  171. } catch {
  172. return true;
  173. }
  174. }),
  175. { timeout: 10000, timeoutMsg: "本条 Bash producer 没有清理完成" },
  176. );
  177. for (const path of outputs) await rm(path, { force: true, recursive: true });
  178. outputs.clear();
  179. });
  180. after(async () => {
  181. await browser.electron.restoreAllMocks();
  182. await clearAppData();
  183. });
  184. it("BDO01: 中文空格路径、两流无换行与非零空输出保持正确结果", async function () {
  185. this.timeout(120000);
  186. await prompt("E2E_BDO_SMALL");
  187. await done("E2E_BDO_SMALL");
  188. expect((await result("toolu_bdo_small")).content).toBe("BDO_中文_STDOUT|中文_STDERR");
  189. expect((await result("toolu_bdo_empty_error")).content).toContain("Exit code 7");
  190. expect(await stat(await outputPath("toolu_bdo_small")).catch(() => null)).toBeNull();
  191. });
  192. it("BDO02: 超过 64 MiB 的前台输出保留完整文件,详情只展示正文", async function () {
  193. this.timeout(120000);
  194. await prompt("E2E_BDO_LARGE");
  195. await done("E2E_BDO_LARGE");
  196. const path = await outputPath("toolu_bdo_large");
  197. expect((await stat(path)).size).toBe(
  198. 65 * 1024 ** 2 + Buffer.byteLength("BDO_HEAD\n\nBDO_TAIL\n"),
  199. );
  200. expect(await snippet(path)).toContain("BDO_HEAD");
  201. expect(await snippet(path, true)).toContain("BDO_TAIL");
  202. expect((await result("toolu_bdo_large")).content).toContain(path);
  203. await setExpanded("toolu_bdo_large", false);
  204. await assertOutputHidden("toolu_bdo_large");
  205. await setExpanded("toolu_bdo_large", true);
  206. const body = await $('[data-testid="bash-result-output"]');
  207. await body.waitForDisplayed();
  208. await browser.waitUntil(async () => (await body.getText()).includes("BDO_HEAD"), {
  209. timeout: 10000,
  210. timeoutMsg: "展开后的 Bash 头部摘要没有显示",
  211. });
  212. expect(await body.getText()).toContain("BDO_HEAD");
  213. expect(await body.getText()).not.toContain("BDO_TAIL");
  214. expect(Buffer.byteLength(await body.getText())).toBe(30000);
  215. expect(await $('[data-testid="bash-output-notice"]').isExisting()).toBe(false);
  216. expect(await $('[data-testid="bash-output-file"]').isExisting()).toBe(false);
  217. await setExpanded("toolu_bdo_large", false);
  218. await assertOutputHidden("toolu_bdo_large");
  219. });
  220. it("BDO03: 并发前台 Bash 共享进度期间一个退出不影响另一个", async function () {
  221. this.timeout(120000);
  222. const previews = () =>
  223. browser.execute(() =>
  224. Array.from(document.querySelectorAll('[data-testid="bash-output-preview-full"]')).map(
  225. (el) => el.textContent ?? "",
  226. ),
  227. );
  228. const waitPreview = (text: string) =>
  229. browser.waitUntil(async () => (await previews()).some((s) => s.includes(text)), {
  230. timeout: 30000,
  231. timeoutMsg: `Bash 没有更新进度:${text}`,
  232. });
  233. // 同一批 mutating Bash 会串行执行;两个独立会话才能形成真实并发。
  234. await prompt("E2E_BDO_PROGRESS_A");
  235. await setExpanded("toolu_bdo_progress_a", true);
  236. await waitPreview("A-STAGE1");
  237. const fullPreview = await $('[data-testid="bash-output-preview-full"]');
  238. await fullPreview.waitForDisplayed();
  239. // 展开动画期间元素已有尺寸但可见文本仍可能为空;等待实际预览再检查行数和字节数。
  240. await browser.waitUntil(async () => (await fullPreview.getText()).includes("A-STAGE1"), {
  241. timeout: 10000,
  242. timeoutMsg: "展开后的 Bash 进度预览没有显示",
  243. });
  244. const fullText = await fullPreview.getText();
  245. expect(fullText).toContain("A-STAGE1");
  246. expect(fullText.split("\n").length).toBeGreaterThan(5);
  247. expect(fullText.split("\n").length).toBeLessThanOrEqual(100);
  248. expect(Buffer.byteLength(fullText)).toBeLessThanOrEqual(4096);
  249. await setExpanded("toolu_bdo_progress_a", false);
  250. await assertOutputHidden("toolu_bdo_progress_a");
  251. const sessionA = (await getV4PaneSnapshot()).sessionId!;
  252. await outputPath("toolu_bdo_progress_a");
  253. await prompt("E2E_BDO_PROGRESS_B");
  254. await setExpanded("toolu_bdo_progress_b", true);
  255. await waitPreview("B-STAGE1");
  256. const sessionB = (await getV4PaneSnapshot()).sessionId!;
  257. await outputPath("toolu_bdo_progress_b");
  258. for (const text of await previews()) expect(text.length).toBeLessThanOrEqual(4096);
  259. await selectV4TaskById(sessionA);
  260. // 切回会话后明确展开,再检查进度;不隐含验证卡片展开状态的恢复。
  261. await setExpanded("toolu_bdo_progress_a", true);
  262. await waitPreview("A-STAGE1");
  263. await release("A.release");
  264. await done("E2E_BDO_PROGRESS_A");
  265. await selectV4TaskById(sessionB);
  266. await setExpanded("toolu_bdo_progress_b", true);
  267. await release("B.release");
  268. await browser.waitUntil(async () => (await previews()).some((s) => s.includes("B-STAGE2")), {
  269. timeout: 10000,
  270. timeoutMsg: "第一个 Bash 完成后另一个 Bash 的进度停止更新",
  271. });
  272. await release("B.finish");
  273. await done("E2E_BDO_PROGRESS_B");
  274. expect(await previews()).toEqual([]);
  275. });
  276. it("BDO07: 展开时实时刷新,收起不渲染输出,再展开显示最新内容", async function () {
  277. this.timeout(60000);
  278. const id = "toolu_bdo_realtime";
  279. const marker = "E2E_BDO_REALTIME";
  280. const artifactDir = process.env.ZCODE_E2E_ARTIFACT_DIR;
  281. if (!artifactDir) throw new Error("E2E artifact directory is required for refresh timings");
  282. const observations: {
  283. stage: number;
  284. fileVisibleMs: number;
  285. previewVisibleMs: number;
  286. height: number;
  287. lineHeight: number;
  288. bottomGap: number;
  289. }[] = [];
  290. await prompt(marker);
  291. await waitFile("realtime.1.ready");
  292. const path = await outputPath(id);
  293. const pid = Number(await readFile(join(ROOT, "realtime.pid"), "utf8"));
  294. await setExpanded(id, true);
  295. let expectedOutput = "";
  296. let frozenOutput = "";
  297. const scrollMetrics = () =>
  298. browser.execute(() => {
  299. const el = document.querySelector<HTMLElement>('[data-testid="bash-output-scroll"]')!;
  300. return {
  301. height: el.clientHeight,
  302. lineHeight: Number.parseFloat(getComputedStyle(el.querySelector("pre")!).lineHeight),
  303. bottomGap: el.scrollHeight - el.scrollTop - el.clientHeight,
  304. };
  305. });
  306. for (const stage of [1, 2, 3, 4, 5]) {
  307. if (stage > 1) await waitFile(`realtime.${stage}.ready`);
  308. const writtenAt = Number(await readFile(join(ROOT, `realtime.${stage}.ready`), "utf8"));
  309. const fragment = `实时-${stage}-stdout|实时-${stage}-stderr`;
  310. expectedOutput += (stage > 1 ? `line-${stage} abcdefghijklmnop\n`.repeat(80) : "") + fragment;
  311. // ready 由 producer 在两流写入后创建;release 前直接读原文件,不能用最终结果冒充实时输出。
  312. expect(await readFile(path, "utf8")).toBe(expectedOutput);
  313. const fileVisibleMs = Date.now() - writtenAt;
  314. if (stage === 3) {
  315. // 收起期间跨过一次 1 秒进度轮询;新输出仍不能重新渲染正文。
  316. await browser.pause(1200);
  317. await assertOutputHidden(id);
  318. await setExpanded(id, true);
  319. }
  320. const preview = await $('[data-testid="bash-output-preview-full"]');
  321. if (stage === 4) {
  322. // 用户上滚后即使 CLI 已发布新一段,正在阅读的有界窗口也不能被替换。
  323. await browser.pause(1500);
  324. expect(await preview.getText()).toBe(frozenOutput);
  325. await browser.execute(() => {
  326. const el = document.querySelector<HTMLElement>('[data-testid="bash-output-scroll"]')!;
  327. el.scrollTop = el.scrollHeight;
  328. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  329. });
  330. }
  331. await browser.waitUntil(
  332. async () => (await preview.isExisting()) && (await preview.getText()).includes(fragment),
  333. {
  334. timeout: stage === 1 ? 8000 : 5000,
  335. timeoutMsg: `第 ${stage} 段 Bash 输出未在退出前刷新`,
  336. },
  337. );
  338. const previewVisibleMs = Date.now() - writtenAt;
  339. expect(previewVisibleMs).toBeLessThanOrEqual(stage === 1 ? 8000 : 5000);
  340. expect(process.kill(pid, 0)).toBe(true);
  341. expect((await listToolCallBlocks()).find((block) => block.toolCallId === id)?.status).toBe(
  342. "in_progress",
  343. );
  344. expect(await getLatestUpstreamToolResultByToolCallId(id)).toBeNull();
  345. const metrics = await scrollMetrics();
  346. observations.push({ stage, fileVisibleMs, previewVisibleMs, ...metrics });
  347. console.log("BASH_REALTIME_VIEWPORT", JSON.stringify(observations.at(-1)));
  348. await writeFile(
  349. join(artifactDir, "bash-realtime-refresh.json"),
  350. JSON.stringify(observations, null, 2),
  351. );
  352. expect(metrics.lineHeight).toBeGreaterThan(0);
  353. expect(metrics.height).toBe(metrics.lineHeight * (stage === 1 ? 1 : 5));
  354. expect(metrics.bottomGap).toBeLessThanOrEqual(1);
  355. const scrollViewport = await $('[data-testid="bash-output-scroll"]');
  356. await browser.waitUntil(
  357. async () =>
  358. (await scrollViewport.getAttribute("data-scroll-mask")) ===
  359. (stage === 1 ? "none" : "top"),
  360. { timeout: 5000, timeoutMsg: "Bash 吸底后渐隐方向不正确" },
  361. );
  362. expect(
  363. await scrollViewport.getCSSProperty("mask-image").then((value) => value.value === "none"),
  364. ).toBe(stage === 1);
  365. expect(await $('[data-testid="bash-output-resume"]').isExisting()).toBe(false);
  366. if (stage === 2) {
  367. await setExpanded(id, false);
  368. await assertOutputHidden(id);
  369. }
  370. if (stage === 3 || stage === 5) {
  371. frozenOutput = await preview.getText();
  372. await browser.execute(() => {
  373. const el = document.querySelector<HTMLElement>('[data-testid="bash-output-scroll"]')!;
  374. el.scrollTop = (el.scrollHeight - el.clientHeight) / 2;
  375. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  376. });
  377. await browser.waitUntil(
  378. async () => (await scrollViewport.getAttribute("data-scroll-mask")) === "both",
  379. {
  380. timeout: 5000,
  381. timeoutMsg: "Bash 中间位置没有上下渐隐",
  382. },
  383. );
  384. await browser.execute(() => {
  385. const el = document.querySelector<HTMLElement>('[data-testid="bash-output-scroll"]')!;
  386. el.scrollTop = 0;
  387. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  388. });
  389. await browser.waitUntil(
  390. async () =>
  391. (await $('[data-testid="bash-output-scroll"]').getAttribute("data-following")) ===
  392. "false",
  393. { timeout: 5000, timeoutMsg: "用户上滚后没有暂停跟随" },
  394. );
  395. expect(await $('[data-testid="bash-output-resume"]').isExisting()).toBe(false);
  396. expect(await scrollViewport.getAttribute("data-scroll-mask")).toBe("bottom");
  397. }
  398. await release(`realtime.${stage}.release`);
  399. }
  400. await done(marker);
  401. // assistant 收尾会把工具移入可折叠历史;重新定位展开,不把父级卸载当成输出视口丢失。
  402. await setExpanded(id, false);
  403. await assertOutputHidden(id);
  404. await setExpanded(id, true);
  405. // 详情有展开动画;等待真实可见文本,不能把动画首帧的空 getText 当成丢输出。
  406. const finalOutput = await $('[data-testid="bash-result-output"]');
  407. await browser.waitUntil(async () => (await finalOutput.getText()) === expectedOutput, {
  408. timeout: 10000,
  409. timeoutMsg: "重新展开后没有显示最终 Bash 输出",
  410. });
  411. const finalMetrics = await scrollMetrics();
  412. expect(finalMetrics.height).toBe(finalMetrics.lineHeight * 5);
  413. expect(await $('[data-testid="bash-output-resume"]').isExisting()).toBe(false);
  414. expect((await result(id)).content).toBe(expectedOutput);
  415. expect((await waitForToolCallBlockByToolCallId(id)).status).toBe("completed");
  416. expect(await $('[data-testid="bash-output-preview-short"]').isExisting()).toBe(false);
  417. expect(await $('[data-testid="bash-output-preview-full"]').isExisting()).toBe(false);
  418. await setExpanded(id, false);
  419. await assertOutputHidden(id);
  420. expect(
  421. await countUpstreamRequests({ includes: [marker], excludes: ["Generate a concise title"] }),
  422. ).toBe(2);
  423. });
  424. it("BDO04: TaskOutput 运行时重复头读、完成后尾读", async function () {
  425. this.timeout(120000);
  426. await prompt("E2E_BDO_QUERY");
  427. await done("E2E_BDO_QUERY");
  428. await waitFile("query.ready");
  429. const path = await outputPath("toolu_bdo_query");
  430. await prompt("E2E_BDO_QUERY_FIRST", false);
  431. await done("E2E_BDO_QUERY_FIRST");
  432. const first = (await result("toolu_bdo_query_first")).content;
  433. expect(first).toContain("BDO_QUERY_HEAD");
  434. expect(first).not.toContain("BDO_QUERY_FIRST_TAIL");
  435. await release("query.grow");
  436. await waitFile("query.grown");
  437. await prompt("E2E_BDO_QUERY_SECOND", false);
  438. await done("E2E_BDO_QUERY_SECOND");
  439. const second = (await result("toolu_bdo_query_second")).content;
  440. const firstOutput = first.match(/<output>([\s\S]*?)<\/output>/)?.[1];
  441. expect(firstOutput).toBeDefined();
  442. expect(second.match(/<output>([\s\S]*?)<\/output>/)?.[1]).toBe(firstOutput);
  443. expect(second).not.toContain("BDO_QUERY_SECOND_TAIL");
  444. await release("query.release");
  445. await waitForV4AssistantMessageContaining("E2E_BDO_QUERY_NOTIFIED", 30000);
  446. await prompt("E2E_BDO_QUERY_FINAL", false);
  447. await done("E2E_BDO_QUERY_FINAL");
  448. const final = (await result("toolu_bdo_query_final")).content;
  449. expect(final).toContain("BDO_QUERY_FINAL_TAIL");
  450. expect(final).not.toContain("BDO_QUERY_HEAD");
  451. expect((await stat(path)).size).toBeGreaterThan(600000);
  452. });
  453. for (const mode of ["foreground", "background"] as const) {
  454. it(`BDO05: ${mode} 真实 5 GiB 边界与 5 秒 watchdog`, async function () {
  455. this.timeout(150000);
  456. const disk = await statfs(ROOT, { bigint: true });
  457. if (disk.bavail * disk.bsize < BigInt(12 * 1024 ** 3))
  458. throw new Error("5 GiB 实写需要至少 12 GiB 可用空间,未执行不能算通过");
  459. const marker = `E2E_BDO_LIMIT_${mode.toUpperCase()}`;
  460. await prompt(marker);
  461. await waitFile(`${mode}.ready`);
  462. const path = await outputPath(`toolu_bdo_limit_${mode}`);
  463. expect((await stat(path)).size).toBe(LIMIT);
  464. // 跨过完整检查周期后,等于阈值的命令必须仍存活。
  465. await browser.pause(5500);
  466. const pid = Number(await readFile(join(ROOT, `${mode}.pid`), "utf8"));
  467. expect(() => process.kill(pid, 0)).not.toThrow();
  468. await release(`${mode}.release`);
  469. await waitFile(`${mode}.exceeded`);
  470. await waitForV4AssistantMessageContaining(`${marker}_KILLED`, 20000);
  471. await idle();
  472. if (mode === "foreground") {
  473. const output = await result("toolu_bdo_limit_foreground");
  474. expect(output.isError).toBe(true);
  475. // 取消结果超过模型预算时沿用 artifact 包装,诊断在完整结果中而非 2 KiB 预览里。
  476. const persisted = output.content.match(/Full output saved to: ([^\n]+)/)?.[1];
  477. const full = persisted ? await readFile(persisted, "utf8") : output.content;
  478. expect(full).toContain("Command killed: output file exceeded 5GB");
  479. expect(await stat(path).catch(() => null)).toBeNull();
  480. } else {
  481. expect((await stat(path)).size).toBe(LIMIT + 1);
  482. expect(
  483. await countUpstreamRequests({
  484. includes: [marker, "<task-notification>", "<status>killed</status>"],
  485. }),
  486. ).toBe(1);
  487. }
  488. await browser.waitUntil(
  489. async () => {
  490. try {
  491. process.kill(pid, 0);
  492. return false;
  493. } catch {
  494. return true;
  495. }
  496. },
  497. { timeout: 10000, timeoutMsg: "超限 producer 没有退出" },
  498. );
  499. });
  500. }
  501. it("BDO06: 真实输出读取/打开失败有诊断,后续 Bash 仍能执行", async function () {
  502. this.timeout(120000);
  503. await prompt("E2E_BDO_READ_FAILURE");
  504. await waitFile("read-failure.ready");
  505. const path = await outputPath("toolu_bdo_read_failure");
  506. await rm(path);
  507. await release("read-failure.release");
  508. await done("E2E_BDO_READ_FAILURE");
  509. expect((await result("toolu_bdo_read_failure")).content).toContain("bash output unavailable");
  510. const blocked = await outputPath("toolu_bdo_open_failure");
  511. await mkdir(blocked, { recursive: true });
  512. await prompt("E2E_BDO_OPEN_FAILURE", false);
  513. await done("E2E_BDO_OPEN_FAILURE");
  514. // 启动失败没有进程退出码;验证实际错误诊断,不套用命令非零退出的 is_error 契约。
  515. expect((await result("toolu_bdo_open_failure")).content).toContain("EISDIR");
  516. expect((await stat(blocked)).isDirectory()).toBe(true);
  517. await prompt("E2E_BDO_RECOVERY", false);
  518. await done("E2E_BDO_RECOVERY");
  519. expect((await result("toolu_bdo_recovery")).content).toBe("BDO_中文_STDOUT|中文_STDERR");
  520. });
  521. });