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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. import { copyFile, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { clearAppData, DEFAULT_WORKSPACE } from "../helpers/desktop-app.js";
  4. import { resolveE2ERuntimePath } from "../helpers/e2e-runtime-paths.js";
  5. import { ensureToolCrossProductFullAccessMode } from "../helpers/conversation-session-tool-cross-product.js";
  6. import { countUpstreamRequests } from "../helpers/conversation-session-network.js";
  7. import {
  8. getV4PaneSnapshot,
  9. getV4ConfigProjection,
  10. openV4ComposerRunningBackgroundWorks,
  11. prepareV4ConversationE2E,
  12. selectV4TaskById,
  13. sendV4Prompt,
  14. switchV4Mode,
  15. waitForV4AssistantMessageContaining,
  16. setV4ElectronWindowSize,
  17. } from "../helpers/v4-conversation.js";
  18. import { startDraftFromProject } from "../helpers/project-sidebar.js";
  19. const ROOT = resolveE2ERuntimePath("background-bash-output", "中文 空格");
  20. const names: string[] = [];
  21. const outputFiles = new Set<string>();
  22. const details = () =>
  23. $('[role="tabpanel"][data-state="active"] [data-testid="background-bash-details"]');
  24. const body = () =>
  25. $('[role="tabpanel"][data-state="active"] [data-testid="background-bash-output"]');
  26. async function release(name: string, phase: number) {
  27. await writeFile(join(ROOT, `${name}.${phase}.release`), "go");
  28. }
  29. async function text() {
  30. return body().getText();
  31. }
  32. async function contains(value: string) {
  33. await browser.waitUntil(async () => (await text()).includes(value), {
  34. timeout: 15000,
  35. timeoutMsg: `后台详情缺少 ${value}`,
  36. });
  37. }
  38. async function openRow() {
  39. await openV4ComposerRunningBackgroundWorks(30000);
  40. const row = await $('[data-testid="background-bash-open"]');
  41. await row.waitForClickable();
  42. await row.click();
  43. await details().waitForDisplayed();
  44. }
  45. async function launch(name: string) {
  46. names.push(name);
  47. // 合并适配:全局新任务落到独立聊天目录,Bash fixture 必须从 ZCodeProject 发起。
  48. await startDraftFromProject(DEFAULT_WORKSPACE);
  49. // 项目新草稿恢复 build;显式选择 yolo,避免把模式切换动画中的旧文案当成已选中。
  50. await switchV4Mode("yolo");
  51. await browser.waitUntil(async () => (await getV4ConfigProjection()).mode === "yolo", {
  52. timeout: 15000,
  53. timeoutMsg: "项目草稿未应用 yolo 模式",
  54. });
  55. await sendV4Prompt(`E2E_BGV_${name}: Run the exact background Bash fixture.`);
  56. await waitForV4AssistantMessageContaining(`E2E_BGV_${name}_DONE`, 60000);
  57. const sessionId = (await getV4PaneSnapshot()).sessionId!;
  58. await openRow();
  59. // 文件入口使用运行时返回的 canonical 路径;临时输出根不再固定在 HOME 下。
  60. const file = $('[role="tabpanel"][data-state="active"] [data-testid="background-bash-file"]');
  61. await file.waitForDisplayed();
  62. const outputPath = await file.getAttribute("title");
  63. if (!outputPath) throw new Error("后台详情没有返回实际输出文件路径");
  64. outputFiles.add(outputPath);
  65. await contains(`${name}_STDERR_中文`);
  66. return { sessionId, outputPath };
  67. }
  68. async function terminal() {
  69. await browser.waitUntil(async () => (await details().getAttribute("data-status")) !== "running", {
  70. timeout: 15000,
  71. });
  72. }
  73. async function expectStatusBarAlignment() {
  74. const gaps = await browser.execute(() => {
  75. const pane = document.querySelector('[role="tabpanel"][data-state="active"]')!;
  76. const bar = pane.querySelector('[data-testid="background-bash-statusbar"]')!;
  77. const file = pane.querySelector('[data-testid="background-bash-file"]')!;
  78. const running = pane.querySelector('[data-testid="background-bash-running"]');
  79. const style = getComputedStyle(bar);
  80. return {
  81. right:
  82. bar.getBoundingClientRect().right -
  83. Number.parseFloat(style.paddingRight) -
  84. file.getBoundingClientRect().right,
  85. left: running
  86. ? running.getBoundingClientRect().left -
  87. bar.getBoundingClientRect().left -
  88. Number.parseFloat(style.paddingLeft)
  89. : 0,
  90. sameColor: !running || getComputedStyle(file).color === getComputedStyle(running).color,
  91. };
  92. });
  93. expect(Math.abs(gaps.right)).toBeLessThanOrEqual(1);
  94. expect(Math.abs(gaps.left)).toBeLessThanOrEqual(1);
  95. expect(gaps.sameColor).toBe(true);
  96. }
  97. async function alive(name: string) {
  98. const pid = Number(await readFile(join(ROOT, `${name}.pid`), "utf8"));
  99. try {
  100. process.kill(pid, 0);
  101. return true;
  102. } catch {
  103. return false;
  104. }
  105. }
  106. async function readAgentLogs() {
  107. const logDir = process.env.ZCODE_LOG_DIR!;
  108. const files = (await readdir(logDir)).filter((file) => file.endsWith(".jsonl"));
  109. return (await Promise.all(files.map((file) => readFile(join(logDir, file), "utf8")))).join("\n");
  110. }
  111. describe("后台 Bash 实时输出详情", () => {
  112. before(async function () {
  113. this.timeout(120000);
  114. await rm(ROOT, { recursive: true, force: true });
  115. await mkdir(ROOT, { recursive: true });
  116. await copyFile(
  117. new URL(
  118. "../fixtures/fs/conversation-session/background-bash-output/writer.cjs",
  119. import.meta.url,
  120. ),
  121. join(ROOT, "writer.cjs"),
  122. );
  123. await prepareV4ConversationE2E();
  124. await switchV4Mode("yolo");
  125. await browser.waitUntil(async () => (await getV4ConfigProjection()).mode === "yolo", {
  126. timeout: 15000,
  127. timeoutMsg: "项目草稿未应用 yolo 模式",
  128. });
  129. // 宿主显示器会截断 1000px 高窗口;800px 仍覆盖原有输出滚动和标签页断言。
  130. await setV4ElectronWindowSize(1440, 800);
  131. });
  132. afterEach(async () => {
  133. // 所有 barrier 均由用例拥有;断言失败也释放 producer,避免遗留后台任务。
  134. for (const name of names.splice(0)) {
  135. for (let phase = 1; phase <= 3; phase++) await release(name, phase);
  136. await browser.waitUntil(async () => !(await alive(name)), { timeout: 15000 });
  137. }
  138. });
  139. after(async () => {
  140. for (const file of outputFiles) await rm(file, { force: true });
  141. await browser.electron.restoreAllMocks();
  142. await clearAppData();
  143. });
  144. for (const [caseId, name] of [
  145. ["BGV01", "EXPLICIT"],
  146. ["BGV02", "AUTO"],
  147. ]) {
  148. it(`${caseId}: 退出前两次更新、两流中文无换行、8 KiB 淘汰与复用标签页 (${name})`, async function () {
  149. this.timeout(120000);
  150. const { outputPath } = await launch(name!);
  151. expect(await details().$('button[data-testid="background-bash-stop"]').isExisting()).toBe(
  152. false,
  153. );
  154. expect(await details().$("header").isExisting()).toBe(false);
  155. expect(await details().$('[data-testid="background-bash-running"]').isDisplayed()).toBe(true);
  156. await expectStatusBarAlignment();
  157. const requests = await countUpstreamRequests({ includes: [`E2E_BGV_${name}`] });
  158. const id = await details().getAttribute("data-work-id");
  159. await openRow();
  160. expect(await $$(`[data-testid="background-bash-details"][data-work-id="${id}"]`).length).toBe(
  161. 1,
  162. );
  163. await release(name!, 1);
  164. await contains(`${name}_SECOND_中文`);
  165. expect(await text()).not.toContain(`${name}_FIRST`);
  166. expect(Buffer.byteLength(await text())).toBeLessThanOrEqual(8192);
  167. expect(await details().$('[data-testid="background-bash-truncated"]').isExisting()).toBe(
  168. false,
  169. );
  170. expect(
  171. await browser.execute(() => {
  172. const pane = document.querySelector('[role="tabpanel"][data-state="active"]');
  173. const running = pane?.querySelector('[data-testid="background-bash-running"]');
  174. const output = pane?.querySelector('[data-testid="background-bash-scroll"]');
  175. return Boolean(
  176. running &&
  177. output &&
  178. running.getBoundingClientRect().bottom <= output.getBoundingClientRect().top + 1,
  179. );
  180. }),
  181. ).toBe(true);
  182. await expectStatusBarAlignment();
  183. expect((await stat(outputPath)).size).toBeGreaterThan(8192);
  184. await release(name!, 2);
  185. await contains(`${name}_THIRD_no_newline`);
  186. if (name === "EXPLICIT")
  187. await browser.saveScreenshot(
  188. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "background-bash-live.png"),
  189. );
  190. expect(await alive(name!)).toBe(true);
  191. expect(await details().getAttribute("data-status")).toBe("running");
  192. expect(await countUpstreamRequests({ includes: [`E2E_BGV_${name}`] })).toBe(requests);
  193. await release(name!, 3);
  194. await terminal();
  195. await contains(`${name}_FINAL`);
  196. expect(await details().getAttribute("data-status")).toBe("completed");
  197. expect(await details().$('[data-testid="background-bash-running"]').isExisting()).toBe(false);
  198. await expectStatusBarAlignment();
  199. if (name === "EXPLICIT") {
  200. const logDir = process.env.ZCODE_E2E_RUNTIME_LOG_DIR;
  201. expect(logDir).toBeTruthy();
  202. const files = (await readdir(logDir!)).filter((file) => file.endsWith(".log"));
  203. const logs = (
  204. await Promise.all(files.map((file) => readFile(join(logDir!, file), "utf8")))
  205. ).join("\n");
  206. // 成功日志曾随每秒轮询持续落盘;先确认真实 RPC 日志存在,再验证该查询被 debug 门控。
  207. expect(logs).toContain("[rpc:call]");
  208. expect(logs).not.toContain("[rpc:call] zcode-agent.backgroundBashOutputV4 OK");
  209. }
  210. });
  211. }
  212. it("BGV03: 向上滚动冻结、后台结束保留阅读位置、回到最新显示最终窗口", async function () {
  213. this.timeout(120000);
  214. await launch("PAUSE");
  215. const firstWindow = await text();
  216. const hiddenDetails = await details();
  217. await $('[role="tabpanel"][data-state="active"] [data-testid="background-bash-file"]').click();
  218. await browser.waitUntil(async () => !(await hiddenDetails.isDisplayed()), { timeout: 5000 });
  219. // 等已发出的旧查询结束,再制造新内容;隐藏 tab 不能读取这次变化。
  220. await browser.pause(1200);
  221. await release("PAUSE", 1);
  222. await browser.pause(1500);
  223. expect(await hiddenDetails.$('[data-testid="background-bash-output"]').getHTML()).toContain(
  224. "PAUSE_FIRST",
  225. );
  226. expect(await hiddenDetails.$('[data-testid="background-bash-output"]').getHTML()).not.toContain(
  227. "PAUSE_SECOND",
  228. );
  229. expect(firstWindow).toContain("PAUSE_FIRST");
  230. await openRow();
  231. await contains("PAUSE_SECOND");
  232. const viewport = await $(
  233. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-scroll"]',
  234. );
  235. await browser.waitUntil(
  236. async () => (await viewport.getAttribute("data-scroll-mask")) === "top",
  237. {
  238. timeout: 5000,
  239. timeoutMsg: "后台 Bash 吸底后没有顶部渐隐",
  240. },
  241. );
  242. expect((await viewport.getCSSProperty("mask-image")).value).toContain("linear-gradient");
  243. // 手动滚到底部必须恢复跟随;此前只有按钮调用 resume,实际到底后箭头仍常驻。
  244. await browser.execute(() => {
  245. const el = document.querySelector<HTMLElement>(
  246. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-scroll"]',
  247. )!;
  248. el.scrollTop = 0;
  249. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  250. });
  251. await details().$('[data-testid="background-bash-resume"]').waitForDisplayed();
  252. await browser.execute(() => {
  253. const el = document.querySelector<HTMLElement>(
  254. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-scroll"]',
  255. )!;
  256. el.scrollTop = el.scrollHeight;
  257. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  258. });
  259. const bottomState = await browser.execute(() => {
  260. const pane = document.querySelector(
  261. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-details"]',
  262. )!;
  263. const el = pane.querySelector('[data-testid="background-bash-scroll"]')!;
  264. return {
  265. following: pane.getAttribute("data-following"),
  266. bottomGap: el.scrollHeight - el.clientHeight - el.scrollTop,
  267. };
  268. });
  269. expect(bottomState.bottomGap).toBeLessThanOrEqual(8);
  270. await browser.waitUntil(
  271. async () => (await details().getAttribute("data-following")) === "true",
  272. {
  273. timeout: 5000,
  274. timeoutMsg: `手动到底后未恢复跟随: ${JSON.stringify(bottomState)}`,
  275. },
  276. );
  277. expect(await details().$('[data-testid="background-bash-resume"]').isExisting()).toBe(false);
  278. await release("PAUSE", 2);
  279. await contains("PAUSE_THIRD_no_newline");
  280. expect(await details().getAttribute("data-following")).toBe("true");
  281. await browser.execute(() => {
  282. const el = document.querySelector<HTMLElement>(
  283. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-scroll"]',
  284. )!;
  285. el.scrollTop = (el.scrollHeight - el.clientHeight) / 2;
  286. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  287. });
  288. await browser.waitUntil(
  289. async () => (await viewport.getAttribute("data-scroll-mask")) === "both",
  290. {
  291. timeout: 5000,
  292. timeoutMsg: "后台 Bash 中间位置没有上下渐隐",
  293. },
  294. );
  295. await browser.execute(() => {
  296. const el = document.querySelector<HTMLElement>(
  297. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-scroll"]',
  298. )!;
  299. el.scrollTop = 0;
  300. el.dispatchEvent(new Event("scroll", { bubbles: true }));
  301. });
  302. await $(
  303. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-resume"]',
  304. ).waitForDisplayed();
  305. const resume = await $(
  306. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-resume"]',
  307. );
  308. expect(await resume.getText()).toBe("");
  309. expect(await resume.getAttribute("aria-label")).toMatch(/Scroll to bottom|滚动到底部/i);
  310. expect(
  311. await browser.execute(() => {
  312. const pane = document.querySelector('[role="tabpanel"][data-state="active"]')!;
  313. const button = pane.querySelector<HTMLElement>('[data-testid="background-bash-resume"]')!;
  314. const output = pane.querySelector<HTMLElement>('[data-testid="background-bash-scroll"]')!;
  315. const bar = pane.querySelector('[data-testid="background-bash-statusbar"]');
  316. const rect = button.getBoundingClientRect();
  317. const viewport = output.getBoundingClientRect();
  318. const style = getComputedStyle(button);
  319. return (
  320. !output.contains(button) &&
  321. !bar?.contains(button) &&
  322. style.position === "absolute" &&
  323. Math.abs(rect.width - rect.height) < 1 &&
  324. Number.parseFloat(style.borderRadius) >= rect.width / 2 &&
  325. Math.abs(rect.left + rect.width / 2 - viewport.left - viewport.width / 2) < 1 &&
  326. rect.bottom < viewport.bottom &&
  327. rect.bottom > viewport.bottom - 24 &&
  328. getComputedStyle(button.parentElement!).maskImage === "none"
  329. );
  330. }),
  331. ).toBe(true);
  332. await browser.saveScreenshot(
  333. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "background-bash-paused.png"),
  334. );
  335. expect(await viewport.getAttribute("data-scroll-mask")).toBe("bottom");
  336. const frozen = await text();
  337. await release("PAUSE", 3);
  338. await terminal();
  339. expect(await text()).toBe(frozen);
  340. await $(
  341. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-resume"]',
  342. ).click();
  343. await contains("PAUSE_FINAL");
  344. await browser.waitUntil(
  345. async () => (await viewport.getAttribute("data-scroll-mask")) === "top",
  346. {
  347. timeout: 5000,
  348. timeoutMsg: "后台 Bash 恢复吸底后渐隐未更新",
  349. },
  350. );
  351. });
  352. it("BGV04: 切换会话隔离标签页,返回立即读取仍在运行的原任务", async function () {
  353. this.timeout(120000);
  354. const first = await launch("SCOPE_A");
  355. const second = await launch("SCOPE_B");
  356. expect(first.sessionId).not.toBe(second.sessionId);
  357. expect(await text()).not.toContain("SCOPE_A");
  358. await release("SCOPE_A", 1);
  359. await selectV4TaskById(first.sessionId);
  360. await openRow();
  361. await contains("SCOPE_A_SECOND");
  362. expect(await text()).not.toContain("SCOPE_B");
  363. expect(await alive("SCOPE_A")).toBe(true);
  364. expect(await alive("SCOPE_B")).toBe(true);
  365. });
  366. it("BGV04: 子会话冷恢复后仍能读取原后台 Bash,完成后保留最终输出", async function () {
  367. this.timeout(360000);
  368. names.push("CHILD");
  369. // 合并适配:全局新任务落到独立聊天目录,Bash fixture 必须从 ZCodeProject 发起。
  370. await startDraftFromProject(DEFAULT_WORKSPACE);
  371. await switchV4Mode("yolo");
  372. await browser.waitUntil(async () => (await getV4ConfigProjection()).mode === "yolo", {
  373. timeout: 15000,
  374. timeoutMsg: "项目草稿未应用 yolo 模式",
  375. });
  376. await sendV4Prompt("E2E_BGV_PARENT: Launch the exact background child fixture.");
  377. await waitForV4AssistantMessageContaining("E2E_BGV_PARENT_DONE", 60000);
  378. const rootSessionId = (await getV4PaneSnapshot()).sessionId;
  379. await openV4ComposerRunningBackgroundWorks(30000);
  380. const entry = await $('[data-running-subagent-session-trigger="true"]');
  381. await entry.waitForClickable({ timeout: 15000 });
  382. const childSessionId = await entry.getAttribute("data-child-session-id");
  383. expect(childSessionId).toBeTruthy();
  384. await entry.click();
  385. const openChildOutput = () =>
  386. browser.waitUntil(
  387. async () =>
  388. browser.execute(() => {
  389. const pane = document.querySelector('[role="tabpanel"][data-state="active"]');
  390. const button = pane?.querySelector<HTMLButtonElement>(
  391. '[data-testid="background-bash-open"]',
  392. );
  393. if (button) {
  394. button.click();
  395. return true;
  396. }
  397. const expand = pane?.querySelector<HTMLButtonElement>(
  398. '[data-status-section-trigger="terminal"]',
  399. );
  400. if (expand?.getAttribute("aria-expanded") === "false") expand.click();
  401. return false;
  402. }),
  403. { timeout: 15000, timeoutMsg: "子会话没有显示后台 Bash 入口" },
  404. );
  405. await openChildOutput();
  406. await details().waitForDisplayed();
  407. await contains("CHILD_STDERR_中文");
  408. const workId = await details().getAttribute("data-work-id");
  409. const outputTabId = await $(
  410. '[data-side-pane-tab-id^="bash-output:"][data-state="active"]',
  411. ).getAttribute("data-side-pane-tab-id");
  412. expect(workId).toBeTruthy();
  413. expect(await details().getAttribute("data-status")).toBe("running");
  414. // 旧任务由祖先 adapter 持有;必须实际释放 child publisher,再经普通订阅创建新 record。
  415. // 保留输出 tab,但关闭 child conversation 的订阅,让现有 120s grace / 60s tick 自然淘汰。
  416. await browser.execute((sessionId) => {
  417. document
  418. .querySelector<HTMLButtonElement>(
  419. `[data-side-pane-tab-id^="subagent-session:"][data-side-pane-tab-id$=":${sessionId}"] button`,
  420. )!
  421. .click();
  422. }, childSessionId);
  423. const releasedMessage = `release detached live child publisher session=${childSessionId}`;
  424. await browser.waitUntil(async () => (await readAgentLogs()).includes(releasedMessage), {
  425. timeout: 260000,
  426. interval: 1000,
  427. timeoutMsg: "子会话 publisher 未实际释放",
  428. });
  429. expect(await alive("CHILD")).toBe(true);
  430. await browser.saveScreenshot(
  431. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "background-bash-child-released.png"),
  432. );
  433. // Agent 摘要在已折叠的执行历史中;先展开历史,再从真实摘要入口重新订阅 child。
  434. const history = await $(
  435. `[data-session-id="${rootSessionId}"] [data-testid^="chat-assistant-history-trigger-"]`,
  436. );
  437. if ((await history.getAttribute("aria-expanded")) === "false") await history.click();
  438. const childSummary = await $(`[data-testid="v4-subagent-open-side-pane-${childSessionId}"]`);
  439. await childSummary.scrollIntoView();
  440. await childSummary.waitForClickable();
  441. await childSummary.click();
  442. const resumedMessage = `cold resume flight cleared session=${childSessionId}`;
  443. await browser.waitUntil(async () => (await readAgentLogs()).includes(resumedMessage), {
  444. timeout: 15000,
  445. timeoutMsg: "重新打开子会话未完成冷恢复",
  446. });
  447. // 冷恢复不新增历史后台任务目录;回到之前保留的输出 tab,验证它仍能查询原任务。
  448. await $(`[data-side-pane-tab-id="${outputTabId}"]`).click();
  449. await details().waitForDisplayed();
  450. expect(await details().getAttribute("data-work-id")).toBe(workId);
  451. const requests = await countUpstreamRequests({ includes: ["E2E_BGV_CHILD_WORK:"] });
  452. await release("CHILD", 1);
  453. await contains("CHILD_SECOND");
  454. await release("CHILD", 2);
  455. await contains("CHILD_THIRD_no_newline");
  456. expect(await alive("CHILD")).toBe(true);
  457. expect(await countUpstreamRequests({ includes: ["E2E_BGV_CHILD_WORK:"] })).toBe(requests);
  458. await writeFile(
  459. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "background-bash-cold-resume.json"),
  460. JSON.stringify(
  461. {
  462. childSessionId,
  463. rootSessionId,
  464. workId,
  465. releasedMessage,
  466. resumedMessage,
  467. requests,
  468. output: await text(),
  469. },
  470. null,
  471. 2,
  472. ),
  473. );
  474. await release("CHILD", 3);
  475. await terminal();
  476. await contains("CHILD_FINAL");
  477. expect(await details().getAttribute("data-status")).toBe("completed");
  478. expect((await getV4PaneSnapshot()).sessionId).toBe(rootSessionId);
  479. });
  480. it("BGV05: 文件删除明确报错、保留上一份输出,失败与关闭详情不停止进程", async function () {
  481. this.timeout(120000);
  482. const { outputPath } = await launch("ERROR");
  483. const previous = await text();
  484. await rm(outputPath);
  485. const error = await $(
  486. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-details"] [role="alert"]',
  487. );
  488. await error.waitForDisplayed({ timeout: 15000 });
  489. expect(await error.getText()).toMatch(/无法读取|Could not read/);
  490. expect(await text()).toBe(previous);
  491. expect(await alive("ERROR")).toBe(true);
  492. await $('[data-side-pane-tab-id^="bash-output:"][data-state="active"] button').click();
  493. expect(await alive("ERROR")).toBe(true);
  494. });
  495. it("BGV06: 原后台条目 Stop 后详情保留终态输出,详情本身没有停止按钮", async function () {
  496. this.timeout(120000);
  497. await launch("STOP");
  498. await openV4ComposerRunningBackgroundWorks(30000);
  499. const id = await details().getAttribute("data-work-id");
  500. await $(`[data-testid="v4-background-work-cancel-${id}"]`).click();
  501. await terminal();
  502. expect(await details().getAttribute("data-status")).toBe("cancelled");
  503. await browser.waitUntil(async () => !(await alive("STOP")), { timeout: 15000 });
  504. await contains("STOP_STDERR_中文");
  505. await $(
  506. '[role="tabpanel"][data-state="active"] [data-testid="background-bash-file"]',
  507. ).waitForDisplayed();
  508. });
  509. });