conversation-session-sidebar-activity-refresh.test.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { readFile, readdir, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { TID_TASK_ITEM, testId } from "@zcode/shared/test-ids";
  4. import {
  5. clickV4Stop,
  6. getV4PaneSnapshot,
  7. prepareV4ConversationE2E,
  8. sendV4Prompt,
  9. waitForV4Pane,
  10. waitForV4TimelineContaining,
  11. } from "#e2e/helpers/v4-conversation";
  12. async function readQueryCounts() {
  13. const directory = await browser.electron.execute(() => process.env.ZCODE_E2E_RUNTIME_LOG_DIR!);
  14. const logs = await Promise.all(
  15. (await readdir(directory))
  16. .filter((name) => name.endsWith(".log"))
  17. .map((name) => readFile(join(directory, name), "utf8")),
  18. );
  19. const text = logs.join("\n");
  20. const count = (method: string) => text.split(`[rpc:call] ${method} OK (`).length - 1;
  21. return { list: count("window-controller.listTaskList"), tree: count("project.readTree") };
  22. }
  23. describe("TSL40:完整桌面连续输出不重复读取侧栏目录", () => {
  24. it("活动窗口零重查,Stop 与真实改名仍同步", async function () {
  25. this.timeout(120_000);
  26. await prepareV4ConversationE2E();
  27. await sendV4Prompt("E2E_SLOW_STREAM E2E_SIDEBAR_ACTIVITY_REFRESH");
  28. await waitForV4TimelineContaining("ACTIVITY_02", 45_000);
  29. const taskId = (await getV4PaneSnapshot()).sessionId;
  30. expect(taskId && taskId !== "draft").toBeTruthy();
  31. const selector = `[data-testid="${testId(TID_TASK_ITEM, taskId!)}"]`;
  32. await $(selector).waitForDisplayed();
  33. // 已看到实际输出和持久行后才计数;测试不依赖可选的自动标题 sidecar。
  34. expect(await $(selector).getText()).toContain("E2E_SIDEBAR_ACTIVITY_REFRESH");
  35. const before = await readQueryCounts();
  36. expect(before.list).toBeGreaterThan(0);
  37. expect(before.tree).toBeGreaterThan(0);
  38. await waitForV4TimelineContaining("ACTIVITY_29", 30_000);
  39. const after = await readQueryCounts();
  40. await writeFile(
  41. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "sidebar-query-counts.json"),
  42. JSON.stringify({ before, after }),
  43. );
  44. expect(after).toEqual(before);
  45. await clickV4Stop();
  46. await waitForV4Pane((pane) => !pane.canStop, "Stop 未完成", 30_000);
  47. await browser.waitUntil(async () => !(await $(selector).$("svg.animate-spin").isExisting()));
  48. await $(selector).click({ button: "right" });
  49. const rename = $(
  50. '//*[@role="menuitem" and (normalize-space(.)="重命名任务" or normalize-space(.)="Rename task")]',
  51. );
  52. await rename.waitForDisplayed();
  53. await rename.click();
  54. const input = $('[role="dialog"] input');
  55. await input.waitForDisplayed();
  56. await input.setValue("E2E_ACTIVITY_RENAMED");
  57. await input.addValue("\uE007");
  58. await browser.waitUntil(async () =>
  59. (await $(selector).getText()).includes("E2E_ACTIVITY_RENAMED"),
  60. );
  61. await browser.saveScreenshot(
  62. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "sidebar-activity-renamed.png"),
  63. );
  64. });
  65. });