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

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