conversation-session-task-groups.test.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. import { writeFile } from "node:fs/promises";
  2. import { startProjectPointerDrag } from "#e2e/helpers/project-sidebar";
  3. import { join, basename } from "node:path";
  4. import { DatabaseSync } from "node:sqlite";
  5. import {
  6. loginWithApiKey,
  7. prepareV4ConversationE2E,
  8. sendV4Prompt,
  9. waitForV4AssistantMessageContaining,
  10. getV4PaneSnapshot,
  11. setV4ComposerText,
  12. waitForV4ComposerText,
  13. } from "#e2e/helpers/v4-conversation";
  14. import { installHandoffRpcProbe, callHandoffHost } from "#e2e/helpers/remote-project-handoff-probe";
  15. import { ServiceChannels, ZCODE_AGENT_PROVIDER } from "@zcode/shared";
  16. import { TID_TASK_ITEM, testId } from "@zcode/shared/test-ids";
  17. declare global {
  18. interface Window {
  19. __groupPlacementBarrier?: { held: number; release(): void; restore(): void };
  20. }
  21. }
  22. async function reloadGroupWorkspace() {
  23. await browser.refresh();
  24. const login = $('[data-testid="login-use-api-key-button"]');
  25. await browser.waitUntil(
  26. async () =>
  27. (await login.isDisplayed()) || (await $('[data-testid="sidebar-view-menu"]').isDisplayed()),
  28. { timeout: 45_000 },
  29. );
  30. if (await login.isDisplayed()) await loginWithApiKey();
  31. await $('[data-testid="sidebar-view-menu"]').waitForDisplayed({ timeout: 30_000 });
  32. }
  33. async function waitForGroupedLayout() {
  34. // 颜色菜单在 Portal 中退场;只等列表动画会让指针按在尚未卸载的菜单上。
  35. await $('[data-testid="task-group-color-gray"]').waitForExist({ reverse: true });
  36. await browser.waitUntil(() =>
  37. browser.execute(
  38. () =>
  39. !document
  40. .querySelector('[data-testid="task-grouped-view"]')
  41. ?.getAnimations({ subtree: true })
  42. .some(
  43. (animation) =>
  44. animation.playState === "running" &&
  45. animation.effect?.getComputedTiming().endTime !== Infinity,
  46. ),
  47. ),
  48. );
  49. }
  50. async function fillGroupTitle(value: string) {
  51. const input = $('[data-testid="task-group-title-input"]');
  52. await input.waitForDisplayed();
  53. await input.click();
  54. // WebDriver clear 会先 blur 并提交内联编辑;模拟真实用户全选输入。
  55. await browser.keys([process.platform === "darwin" ? "Meta" : "Control", "a"]);
  56. await input.addValue(value);
  57. }
  58. describe("任务分组独立视图", () => {
  59. afterEach(async function () {
  60. if (this.currentTest?.state === "failed") {
  61. const failureName = `task-groups-failure-${this.currentTest?.title.split(":")[0]?.replaceAll("/", "_")}`;
  62. await browser.saveScreenshot(join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `${failureName}.png`));
  63. const layout = await browser.execute(() => {
  64. const root = document.querySelector('[data-testid="task-grouped-view"]');
  65. const viewport = root?.closest("[data-scroll-mask]");
  66. const groups = [...document.querySelectorAll("[data-grouped-group-item-id]")].map(
  67. (group) => ({
  68. id: group.getAttribute("data-grouped-group-item-id"),
  69. collapsed: group.getAttribute("data-group-collapsed"),
  70. rect: group.getBoundingClientRect().toJSON(),
  71. header: group
  72. .querySelector("[data-grouped-group-header-id]")
  73. ?.getBoundingClientRect()
  74. .toJSON(),
  75. }),
  76. );
  77. return {
  78. root: root?.getBoundingClientRect().toJSON(),
  79. viewport: viewport?.getBoundingClientRect().toJSON(),
  80. scrollTop: viewport?.scrollTop,
  81. scrollHeight: viewport?.scrollHeight,
  82. groups,
  83. bodyCursor: document.body.style.cursor,
  84. sticky: document.querySelector("[data-grouped-sticky-header]")?.outerHTML,
  85. };
  86. });
  87. await writeFile(
  88. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `${failureName}.json`),
  89. JSON.stringify(layout, null, 2),
  90. );
  91. process.stderr.write(
  92. `GRP failure UI: ${await browser.execute(() => document.body.innerText.slice(0, 3500))}\n`,
  93. );
  94. }
  95. });
  96. before(async () => {
  97. await prepareV4ConversationE2E();
  98. await installHandoffRpcProbe();
  99. });
  100. it("GRP02:旧分组偏好迁移,新选择在重载后优先", async function () {
  101. this.timeout(60_000);
  102. await browser.execute(() => {
  103. localStorage.removeItem("zcode-project-sidebar-preferences");
  104. localStorage.setItem(
  105. "zcode-sidebar-task-preferences",
  106. JSON.stringify({ organizeBy: "grouped", sortBy: "updated" }),
  107. );
  108. });
  109. await reloadGroupWorkspace();
  110. await $('[data-testid="task-group-add"]').waitForDisplayed({ timeout: 30_000 });
  111. await $('[data-testid="sidebar-view-menu"]').click();
  112. expect(await $('[data-testid="sidebar-view-grouped"]').getAttribute("data-state")).toBe(
  113. "checked",
  114. );
  115. // 恢复必须沿用旧 Hash 入口;不是重新画一套分组控件。
  116. expect(await $('[data-testid="sidebar-view-grouped"] svg.lucide-hash').isExisting()).toBe(true);
  117. await $('[data-testid="sidebar-view-timeline"]').click();
  118. await reloadGroupWorkspace();
  119. await $('[data-testid="sidebar-view-menu"]').waitForClickable();
  120. await $('[data-testid="sidebar-view-menu"]').click();
  121. expect(await $('[data-testid="sidebar-view-timeline"]').getAttribute("data-state")).toBe(
  122. "checked",
  123. );
  124. await browser.keys("Escape");
  125. await $('[data-testid="sidebar-view-timeline"]').waitForExist({ reverse: true });
  126. await installHandoffRpcProbe();
  127. });
  128. it("GRP02/03/11:三视图、创建改色改名、重载与取消空组", async function () {
  129. this.timeout(90_000);
  130. await $('[data-testid="sidebar-view-menu"]').click();
  131. for (const view of ["projects", "grouped", "timeline"])
  132. await $(`[data-testid="sidebar-view-${view}"]`).waitForDisplayed();
  133. await $('[data-testid="sidebar-view-grouped"]').click();
  134. await $('[data-testid="task-group-add"]').waitForClickable();
  135. await $('[data-testid="task-group-add"]').click();
  136. const input = $('[data-testid="task-group-title-input"]');
  137. await input.waitForDisplayed();
  138. await fillGroupTitle("E2E_GROUP");
  139. await browser.keys("Enter");
  140. const row = $('[data-task-group-title="E2E_GROUP"]');
  141. await row.waitForDisplayed();
  142. await $('[data-testid="task-group-color-blue"]').click();
  143. const before = await callHandoffHost<{
  144. groups: Array<{ id: string; title: string; color: string }>;
  145. }>(ServiceChannels.TaskGroups, "read");
  146. const group = before.groups.find((group) => group.title === "E2E_GROUP");
  147. expect(group?.color).toBe("blue");
  148. await reloadGroupWorkspace();
  149. await row.waitForDisplayed();
  150. await installHandoffRpcProbe();
  151. await row.$('[data-testid="task-group-menu"]').click({ button: "right" });
  152. await $('[data-testid="task-group-rename"]').click();
  153. await fillGroupTitle("E2E_RENAMED");
  154. await browser.keys("Enter");
  155. const renamed = $('[data-task-group-title="E2E_RENAMED"]');
  156. await renamed.waitForDisplayed();
  157. // GRP11:旧版颜色圆标、标题折叠、可点击空态、草稿关闭,不能退回新画的拖拽把手。
  158. expect(await renamed.$("svg.lucide-hash").isExisting()).toBe(true);
  159. expect(await $$('[data-testid="task-group-drag-handle"]')).toHaveLength(0);
  160. await renamed.$("[data-grouped-group-header-id]").click();
  161. expect(await renamed.getAttribute("data-group-collapsed")).toBe("true");
  162. await renamed.$("[data-grouped-group-header-id]").click();
  163. await renamed.$("[data-grouped-empty-drop-zone-id]").click();
  164. const draft = renamed.$('[data-testid="grouped-draft-task"]');
  165. await draft.waitForDisplayed();
  166. await setV4ComposerText("PD12_GROUP_DRAFT_KEEP");
  167. await draft.moveTo();
  168. await draft.$("button").click();
  169. await draft.waitForExist({ reverse: true });
  170. await renamed.$("[data-grouped-empty-drop-zone-id]").waitForDisplayed();
  171. // 关闭分组行只撤销组织意图;刷新仍保留正文,不能从旧目录 key 复活分组行。
  172. await reloadGroupWorkspace();
  173. await installHandoffRpcProbe();
  174. await waitForV4ComposerText("PD12_GROUP_DRAFT_KEEP", "关闭分组草稿丢失正文");
  175. expect(await renamed.$('[data-testid="grouped-draft-task"]').isExisting()).toBe(false);
  176. await setV4ComposerText("");
  177. for (const [theme, locale] of [
  178. ["zai-light", "zh-CN"],
  179. ["zai-dark", "en-US"],
  180. ]) {
  181. await browser.execute(
  182. ([theme, locale]) => {
  183. const actions = (
  184. window as Window & {
  185. __testActions?: { setTheme(value: string): void; setLocale(value: string): void };
  186. }
  187. ).__testActions!;
  188. actions.setTheme(theme!);
  189. actions.setLocale(locale!);
  190. },
  191. [theme, locale],
  192. );
  193. await browser.waitUntil(() =>
  194. browser.execute(
  195. (value) => document.documentElement.classList.contains(`theme-${value}`),
  196. theme,
  197. ),
  198. );
  199. await browser.waitUntil(
  200. async () =>
  201. (await $('[data-testid="task-group-add"]').getAttribute("aria-label")) ===
  202. (locale === "zh-CN" ? "新建分组" : "New group"),
  203. );
  204. await browser.saveScreenshot(
  205. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, `task-groups-${theme}.png`),
  206. );
  207. }
  208. await renamed.$('[data-testid="task-group-menu"]').click({ button: "right" });
  209. await $('[data-testid="task-group-ungroup"]').click();
  210. await renamed.waitForExist({ reverse: true });
  211. const after = await callHandoffHost<{ groups: Array<{ id: string }> }>(
  212. ServiceChannels.TaskGroups,
  213. "read",
  214. );
  215. expect(after.groups.some((item) => item.id === group!.id)).toBe(false);
  216. });
  217. it("GRP04/05/06:组内首发、三视图菜单、置顶/归档和恢复保持成员", async function () {
  218. this.timeout(180_000);
  219. await $('[data-testid="task-group-add"]').click();
  220. await fillGroupTitle("E2E_GROUP_MEMBERS");
  221. await browser.keys("Enter");
  222. await browser.keys("Escape");
  223. const groupRow = $('[data-task-group-title="E2E_GROUP_MEMBERS"]');
  224. await groupRow.waitForDisplayed();
  225. const groupId = await groupRow.getAttribute("data-task-group-id");
  226. await groupRow.$('[data-testid="task-group-new-task"]').click();
  227. await sendV4Prompt("E2E_GROUP_TASK 请回复 E2E_GROUP_READY。");
  228. await waitForV4AssistantMessageContaining("E2E_GROUP_READY");
  229. await groupRow.$('[data-testid="grouped-draft-task"]').waitForExist({ reverse: true });
  230. const taskId = (await getV4PaneSnapshot()).sessionId!;
  231. const read = () =>
  232. callHandoffHost<{
  233. members: Array<{ groupId: string; taskId: string; workspaceKey: string }>;
  234. }>(ServiceChannels.TaskGroups, "read");
  235. await browser.waitUntil(async () =>
  236. (await read()).members.some((m) => m.taskId === taskId && m.groupId === groupId),
  237. );
  238. const tree = await callHandoffHost<{
  239. tasks: Array<{ taskId: string; workspacePath: string; projectId: string | null }>;
  240. }>(ServiceChannels.Project, "readTree");
  241. const task = tree.tasks.find((t) => t.taskId === taskId)!;
  242. expect(task.projectId).toBeNull();
  243. const target = { taskId, workspacePath: task.workspacePath };
  244. const selector = `[data-testid="${testId(TID_TASK_ITEM, taskId)}"]`;
  245. for (const view of ["projects", "timeline", "grouped"]) {
  246. await $('[data-testid="sidebar-view-menu"]').click();
  247. await $(`[data-testid="sidebar-view-${view}"]`).click();
  248. await $(selector).waitForDisplayed();
  249. await $(selector).click({ button: "right" });
  250. await $('[data-testid="task-group-move-menu"]').waitForDisplayed();
  251. await browser.keys("Escape");
  252. await $('[data-testid="task-group-move-menu"]').waitForExist({ reverse: true });
  253. }
  254. await callHandoffHost(ServiceChannels.ZCodeTask, "setTaskPinned", [
  255. { ...target, pinned: true },
  256. ]);
  257. await browser.execute(() => window.dispatchEvent(new Event("focus")));
  258. await $('[data-testid="project-pinned-tasks"]').$(selector).waitForDisplayed();
  259. expect(await $$(`[data-testid="task-grouped-view"] ${selector}`)).toHaveLength(0);
  260. await callHandoffHost(ServiceChannels.ZCodeTask, "setTaskPinned", [
  261. { ...target, pinned: false },
  262. ]);
  263. await callHandoffHost(ServiceChannels.ZCodeTask, "archiveTask", [target]);
  264. await browser.execute(() => window.dispatchEvent(new Event("focus")));
  265. await $(selector).waitForExist({ reverse: true });
  266. expect((await read()).members.some((m) => m.taskId === taskId && m.groupId === groupId)).toBe(
  267. true,
  268. );
  269. await callHandoffHost(ServiceChannels.ZCodeTask, "unarchiveTask", [target]);
  270. await browser.execute(() => window.dispatchEvent(new Event("focus")));
  271. await $(selector).waitForDisplayed();
  272. await $('[data-testid="task-group-add"]').click();
  273. await fillGroupTitle("E2E_DROP_TARGET");
  274. await browser.keys("Enter");
  275. await browser.keys("Escape");
  276. const dropTarget = $('[data-task-group-title="E2E_DROP_TARGET"]');
  277. await dropTarget.waitForDisplayed();
  278. const targetGroupId = await dropTarget.getAttribute("data-task-group-id");
  279. await waitForGroupedLayout();
  280. await startProjectPointerDrag(selector);
  281. const dropPoint = await browser.execute(() => {
  282. const rect = document
  283. .querySelector(
  284. '[data-task-group-title="E2E_DROP_TARGET"] [data-grouped-empty-drop-zone-id]',
  285. )!
  286. .getBoundingClientRect();
  287. return {
  288. x: Math.round(rect.left + rect.width / 2),
  289. y: Math.round(rect.top + rect.height / 2),
  290. };
  291. });
  292. await browser.performActions([
  293. {
  294. type: "pointer",
  295. id: "project-drag",
  296. parameters: { pointerType: "mouse" },
  297. actions: [{ type: "pointerMove", ...dropPoint, duration: 200 }],
  298. },
  299. ]);
  300. await browser.waitUntil(async () => await dropTarget.$(selector).isExisting());
  301. await browser.performActions([
  302. {
  303. type: "pointer",
  304. id: "project-drag",
  305. parameters: { pointerType: "mouse" },
  306. actions: [{ type: "pointerUp", button: 0 }],
  307. },
  308. ]);
  309. await browser.releaseActions();
  310. await browser.waitUntil(async () =>
  311. (await read()).members.some((m) => m.taskId === taskId && m.groupId === targetGroupId),
  312. );
  313. await waitForGroupedLayout();
  314. await $(selector).click({ button: "right" });
  315. await $('[data-testid="task-group-move-menu"]').waitForDisplayed();
  316. await $('[data-testid="task-group-move-menu"]').moveTo();
  317. await $('[data-testid="task-group-remove"]').waitForDisplayed();
  318. await $('[data-testid="task-group-remove"]').click();
  319. await browser.waitUntil(async () => !(await read()).members.some((m) => m.taskId === taskId));
  320. expect(
  321. (
  322. await callHandoffHost<{
  323. tasks: Array<{ taskId: string; workspacePath: string; projectId: string | null }>;
  324. }>(ServiceChannels.Project, "readTree")
  325. ).tasks.find((t) => t.taskId === taskId),
  326. ).toMatchObject({ taskId, workspacePath: task.workspacePath, projectId: task.projectId });
  327. });
  328. it("GRP06/CR-01:组织登记挂起时取消首发仍可刷新目录,释放后只入组一次", async function () {
  329. this.timeout(90_000);
  330. await $('[data-testid="sidebar-view-menu"]').click();
  331. await $('[data-testid="sidebar-view-grouped"]').click();
  332. await $('[data-testid="task-group-add"]').click();
  333. await fillGroupTitle("E2E_GROUP_PENDING");
  334. await browser.keys("Enter");
  335. await browser.keys("Escape");
  336. const row = $('[data-task-group-title="E2E_GROUP_PENDING"]');
  337. await row.waitForDisplayed();
  338. const groupId = await row.getAttribute("data-task-group-id");
  339. if (!groupId) throw new Error("CR-01: group identity unavailable");
  340. const readTree = () =>
  341. callHandoffHost<{ tasks: Array<{ taskId: string }> }>(ServiceChannels.Project, "readTree");
  342. const before = new Set((await readTree()).tasks.map((task) => task.taskId));
  343. // 挂住真实 UI 的 placement RPC,普通目录、分组读取和无 placement 登记继续通行。
  344. // 只控制故障边界,不替换创建 ACK、权威目录或分组服务。
  345. await browser.execute((groupId) => {
  346. const original = MessagePort.prototype.postMessage;
  347. const held: Array<{ port: MessagePort; args: unknown[] }> = [];
  348. const probe = {
  349. held: 0,
  350. release() {
  351. for (const { port, args } of held.splice(0)) Reflect.apply(original, port, args);
  352. },
  353. restore() {
  354. this.release();
  355. MessagePort.prototype.postMessage = original;
  356. delete window.__groupPlacementBarrier;
  357. },
  358. };
  359. MessagePort.prototype.postMessage = function (message: unknown, options?: unknown) {
  360. const text = message instanceof Uint8Array ? new TextDecoder().decode(message) : "";
  361. const args = options === undefined ? [message] : [message, options];
  362. if (
  363. text.includes("task-groups") &&
  364. text.includes("admit") &&
  365. text.includes("placement") &&
  366. text.includes(groupId)
  367. ) {
  368. held.push({ port: this, args });
  369. probe.held++;
  370. return;
  371. }
  372. Reflect.apply(original, this, args);
  373. };
  374. window.__groupPlacementBarrier = probe;
  375. }, groupId);
  376. try {
  377. await row.$('[data-testid="task-group-new-task"]').click();
  378. await sendV4Prompt("E2E_GROUP_PENDING 请回复 E2E_GROUP_PENDING_READY。");
  379. await browser.waitUntil(() =>
  380. browser.execute(() => window.__groupPlacementBarrier?.held === 1),
  381. );
  382. const created = (await readTree()).tasks.filter((task) => !before.has(task.taskId));
  383. expect(created).toHaveLength(1);
  384. const taskId = created[0]!.taskId;
  385. // 在组织请求未返回时离开首发 pane;新的目录事实必须仍可进入共享列表。
  386. await row.$('[data-testid="task-group-new-task"]').click();
  387. await callHandoffHost(ServiceChannels.Project, "saveProject", [
  388. { name: "E2E_CR01_REFRESH", roots: [] },
  389. ]);
  390. await $('[data-testid="sidebar-view-menu"]').click();
  391. await $('[data-testid="sidebar-view-projects"]').click();
  392. await $('[data-project-name="E2E_CR01_REFRESH"]').waitForDisplayed({ timeout: 10_000 });
  393. expect((await getV4PaneSnapshot()).sessionId).toBe("draft");
  394. expect(await browser.execute(() => window.__groupPlacementBarrier?.held)).toBe(1);
  395. await browser.execute(() => window.__groupPlacementBarrier?.release());
  396. await browser.waitUntil(async () => {
  397. const groups = await callHandoffHost<{
  398. members: Array<{ taskId: string; groupId: string }>;
  399. }>(ServiceChannels.TaskGroups, "read");
  400. return (
  401. groups.members.filter((member) => member.taskId === taskId && member.groupId === groupId)
  402. .length === 1
  403. );
  404. });
  405. expect((await getV4PaneSnapshot()).sessionId).toBe("draft");
  406. expect((await readTree()).tasks.filter((task) => !before.has(task.taskId))).toHaveLength(1);
  407. process.stderr.write(
  408. "CR-01: held placement, navigation cancellation, directory refresh and late group admission passed\n",
  409. );
  410. } finally {
  411. await browser.execute(() => window.__groupPlacementBarrier?.restore());
  412. }
  413. });
  414. it("GRP11:整组拖拽取消恢复展开,释放只调整顶层顺序", async function () {
  415. this.timeout(45_000);
  416. await $('[data-testid="sidebar-view-menu"]').click();
  417. await $('[data-testid="sidebar-view-grouped"]').click();
  418. await installHandoffRpcProbe();
  419. const first = await callHandoffHost<{ id: string }>(ServiceChannels.TaskGroups, "save", [
  420. { title: "E2E_ORDER_A" },
  421. ]);
  422. const second = await callHandoffHost<{ id: string }>(ServiceChannels.TaskGroups, "save", [
  423. { title: "E2E_ORDER_B" },
  424. ]);
  425. const readOrder = async () =>
  426. (await callHandoffHost<{ order: unknown[] }>(ServiceChannels.TaskGroups, "read")).order;
  427. const original = await readOrder();
  428. const source = `[data-grouped-group-header-id="${first.id}"]`;
  429. const target = `[data-grouped-group-header-id="${second.id}"]`;
  430. await $(source).waitForDisplayed();
  431. const start = async () => {
  432. await waitForGroupedLayout();
  433. const point = await browser.execute((selector) => {
  434. const rect = document.querySelector(selector)!.getBoundingClientRect();
  435. return { x: Math.round(rect.left + 80), y: Math.round(rect.top + rect.height / 2) };
  436. }, source);
  437. await browser.performActions([
  438. {
  439. type: "pointer",
  440. id: "group-drag",
  441. parameters: { pointerType: "mouse" },
  442. actions: [
  443. { type: "pointerMove", ...point, duration: 0 },
  444. { type: "pointerDown", button: 0 },
  445. { type: "pointerMove", x: point.x, y: point.y + 8, duration: 0 },
  446. ],
  447. },
  448. ]);
  449. await browser.waitUntil(
  450. async () => (await $(source).getAttribute("aria-pressed")) === "true",
  451. );
  452. const over = await browser.execute((selector) => {
  453. const rect = document.querySelector(selector)!.getBoundingClientRect();
  454. return { x: Math.round(rect.left + 80), y: Math.round(rect.top + rect.height / 2) };
  455. }, target);
  456. await browser.performActions([
  457. {
  458. type: "pointer",
  459. id: "group-drag",
  460. parameters: { pointerType: "mouse" },
  461. actions: [{ type: "pointerMove", ...over, duration: 250 }],
  462. },
  463. ]);
  464. expect(await $(source).getAttribute("aria-expanded")).toBe("false");
  465. };
  466. await start();
  467. await browser.keys("Escape");
  468. await browser.releaseActions();
  469. await browser.waitUntil(async () => (await $(source).getAttribute("aria-expanded")) === "true");
  470. expect(await readOrder()).toEqual(original);
  471. await start();
  472. await browser.performActions([
  473. {
  474. type: "pointer",
  475. id: "group-drag",
  476. parameters: { pointerType: "mouse" },
  477. actions: [{ type: "pointerUp", button: 0 }],
  478. },
  479. ]);
  480. await browser.releaseActions();
  481. await browser.waitUntil(
  482. async () => JSON.stringify(await readOrder()) !== JSON.stringify(original),
  483. );
  484. expect(await $(source).getAttribute("aria-expanded")).toBe("true");
  485. });
  486. it("GRP10:千行分组虚拟滚动、吸顶和折叠重载", async function () {
  487. this.timeout(90_000);
  488. await installHandoffRpcProbe();
  489. const group = await callHandoffHost<{ id: string }>(ServiceChannels.TaskGroups, "save", [
  490. { title: "E2E_LARGE_GROUP" },
  491. ]);
  492. const tree = await callHandoffHost<{ tasks: Array<{ workspacePath: string }> }>(
  493. ServiceChannels.Project,
  494. "readTree",
  495. );
  496. const cwd = tree.tasks[0]?.workspacePath;
  497. const home = process.env.ZCODE_E2E_HOME_DIR;
  498. // 批量 runner 的 runId 可以自定义;仍只允许写入隔离 E2E HOME。
  499. if (!home || !basename(home).startsWith(".e2e-home-") || !cwd)
  500. throw new Error("隔离 HOME 和真实任务目录 required");
  501. const db = new DatabaseSync(join(home, ".zcode/v2/tasks-index.sqlite"));
  502. try {
  503. db.exec("BEGIN IMMEDIATE");
  504. const task = db.prepare(
  505. `INSERT INTO tasks(workspace_key,workspace_path,task_id,title,created_at,updated_at,host_id,root_path,cli_title,cli_title_source,cli_created_at,cli_updated_at,cli_last_outcome,cli_deleted,handoff_pending,provider) VALUES(?,?,?,?,?,?,'local',?,?,'custom',?,?,'completed',0,8,?)`,
  506. );
  507. const member = db.prepare(
  508. `INSERT INTO task_group_members(group_id,workspace_key,workspace_path,task_id,sort_order,added_at,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?)`,
  509. );
  510. const now = Date.now();
  511. for (let i = 0; i < 1000; i++) {
  512. const id = `E2E_LARGE_${i}`;
  513. // 项目树现在只展示当前执行后端;列表夹具必须声明与真实任务一致的 provider。
  514. task.run(
  515. cwd,
  516. cwd,
  517. id,
  518. id,
  519. now + i,
  520. now + i,
  521. cwd,
  522. id,
  523. now + i,
  524. now + i,
  525. ZCODE_AGENT_PROVIDER,
  526. );
  527. member.run(group.id, cwd, cwd, id, i, now, now, now);
  528. }
  529. db.exec("COMMIT");
  530. } finally {
  531. db.close();
  532. }
  533. await reloadGroupWorkspace();
  534. await $('[data-testid="sidebar-view-menu"]').click();
  535. await $('[data-testid="sidebar-view-grouped"]').click();
  536. await $('[data-task-group-title="E2E_LARGE_GROUP"]').waitForDisplayed();
  537. await browser.waitUntil(() =>
  538. browser.execute(
  539. () =>
  540. document.querySelectorAll('[data-testid="task-grouped-view"] [data-task-item-key]')
  541. .length > 5,
  542. ),
  543. );
  544. const scroll = async (bottom: boolean) =>
  545. browser.execute((bottom) => {
  546. const list = document.querySelector('[data-testid="task-grouped-view"]')!;
  547. const viewport = list.closest("[data-scroll-mask]")!;
  548. viewport.scrollTop = bottom ? viewport.scrollHeight : 0;
  549. viewport.dispatchEvent(new Event("scroll"));
  550. }, bottom);
  551. await scroll(true);
  552. await $(`[data-testid="${testId(TID_TASK_ITEM, "E2E_LARGE_999")}"]`).waitForDisplayed();
  553. expect(
  554. (await $('[data-testid="task-grouped-view"]').$$("[data-task-item-key]")).length,
  555. ).toBeLessThan(80);
  556. // 大组后还有其他组;滚动到底并不代表仍在大组内,必须核对该组中段的吸顶身份。
  557. await browser.execute(() => {
  558. const group = document.querySelector('[data-task-group-title="E2E_LARGE_GROUP"]')!;
  559. const viewport = group.closest("[data-scroll-mask]")!;
  560. viewport.scrollTop +=
  561. group.getBoundingClientRect().top - viewport.getBoundingClientRect().top + 1000;
  562. });
  563. await $(`[data-grouped-sticky-header="${group.id}"]`).waitForDisplayed();
  564. const geometry = await browser.execute(() => {
  565. const header = document.querySelector("[data-grouped-sticky-header]")!;
  566. const viewport = document
  567. .querySelector('[data-testid="task-grouped-view"]')!
  568. .closest("[data-scroll-mask]")!;
  569. return {
  570. header: header.getBoundingClientRect().top,
  571. top: viewport.getBoundingClientRect().top,
  572. };
  573. });
  574. expect(Math.abs(geometry.header - geometry.top)).toBeLessThan(40);
  575. await browser.saveScreenshot(
  576. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "task-groups-long-list.png"),
  577. );
  578. await scroll(false);
  579. const header = $('[data-task-group-title="E2E_LARGE_GROUP"]');
  580. await header.$("[data-grouped-group-header-id]").click();
  581. await $(`[data-testid="${testId(TID_TASK_ITEM, "E2E_LARGE_0")}"]`).waitForExist({
  582. reverse: true,
  583. });
  584. await reloadGroupWorkspace();
  585. expect(await header.$("[data-grouped-group-header-id]").getAttribute("aria-expanded")).toBe(
  586. "false",
  587. );
  588. await header.$("[data-grouped-group-header-id]").click();
  589. await $(`[data-testid="${testId(TID_TASK_ITEM, "E2E_LARGE_0")}"]`).waitForDisplayed();
  590. });
  591. });