tool-summary-groups.test.mjs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. import assert from "node:assert/strict";
  2. import { before, after, test } from "node:test";
  3. import { mkdir } from "node:fs/promises";
  4. import { fileURLToPath } from "node:url";
  5. import { join } from "node:path";
  6. import { createServer } from "vite";
  7. import react from "@vitejs/plugin-react";
  8. import tailwindcss from "@tailwindcss/vite";
  9. import { chromium } from "playwright-core";
  10. const root = fileURLToPath(new URL("../../../../../../", import.meta.url));
  11. const entry = "/packages/ui/test/browser/manual-review/pending/tool-summary-spacing.fixture.tsx";
  12. let server, browser, origin;
  13. const artifacts = join(root, "packages/desktop/.e2e-artifacts/tool-summary-spacing-browser");
  14. before(async () => {
  15. await mkdir(artifacts, { recursive: true });
  16. server = await createServer({
  17. root,
  18. configFile: false,
  19. cacheDir: join(root, "node_modules/.vite-tool-summary-spacing"),
  20. plugins: [
  21. react(),
  22. tailwindcss(),
  23. {
  24. name: "permission-fixture",
  25. configureServer(vite) {
  26. vite.middlewares.use(async (req, res, next) => {
  27. if (!req.url?.startsWith("/fixture?")) return next();
  28. res.setHeader("Content-Type", "text/html");
  29. res.end(
  30. await vite.transformIndexHtml(
  31. req.url,
  32. `<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1" /></head><body><div id="root"></div><script type="module" src="${entry}"></script></body></html>`,
  33. ),
  34. );
  35. });
  36. },
  37. },
  38. ],
  39. resolve: { alias: { "@": `${root}packages/ui/src` } },
  40. optimizeDeps: { entries: [entry.slice(1)] },
  41. server: { host: "127.0.0.1", port: 0 },
  42. });
  43. await server.listen();
  44. origin = server.resolvedUrls.local[0];
  45. browser = await chromium.launch(
  46. process.env.CHROME_EXECUTABLE_PATH
  47. ? { executablePath: process.env.CHROME_EXECUTABLE_PATH }
  48. : { channel: "chrome" },
  49. );
  50. });
  51. after(async () => {
  52. await browser?.close();
  53. await server?.close();
  54. });
  55. // 检查实际 CSS 动画,避免只有类名却未产生扫光的假通过。
  56. async function assertShimmer(locator, expected) {
  57. const style = await locator.evaluate((element) => {
  58. const computed = getComputedStyle(element);
  59. return {
  60. name: computed.animationName,
  61. state: computed.animationPlayState,
  62. background: computed.backgroundImage,
  63. };
  64. });
  65. if (expected) {
  66. assert.match(style.name, /gradient-flow/);
  67. assert.equal(style.state, "running");
  68. assert.notEqual(style.background, "none");
  69. } else {
  70. assert.doesNotMatch(style.name, /gradient-flow/);
  71. }
  72. }
  73. for (const theme of ["light", "dark"]) {
  74. for (const locale of ["en-US", "zh-CN"]) {
  75. test(`XSG02 lifecycle ${theme}/${locale}`, async () => {
  76. const page = await browser.newPage({ viewport: { width: 1200, height: 900 } });
  77. page.setDefaultTimeout(15000);
  78. const errors = [];
  79. page.on("pageerror", (error) => errors.push(error.message));
  80. try {
  81. await page.goto(`${origin}fixture?share=1&theme=${theme}&locale=${locale}`);
  82. const group = page.locator("[data-consecutive-summary-group]").first();
  83. const trigger = group.locator("[data-summary-group-trigger]");
  84. await trigger.waitFor();
  85. assert.equal(await trigger.getAttribute("aria-expanded"), "false");
  86. assert.equal(await group.getAttribute("data-group-running"), "true");
  87. await page.getByRole("button", { name: "Tool done", exact: true }).click();
  88. const stats = group.locator("[data-summary-group-statistics]");
  89. await trigger.getByText("example.ts", { exact: true }).waitFor();
  90. await assertShimmer(trigger.locator(".tool-summary-kind-label"), true);
  91. assert.equal(await stats.count(), 0);
  92. assert.equal(await group.getAttribute("data-group-running"), "true");
  93. await trigger.click();
  94. await stats.waitFor();
  95. assert.match(await stats.getAttribute("class"), /animated-gradient-text/);
  96. const completedChildren = group.locator(
  97. '[data-conversation-work-items="group"] .tool-summary-kind-label',
  98. );
  99. for (const label of await completedChildren.all()) await assertShimmer(label, false);
  100. await page.getByRole("button", { name: "Next summary", exact: true }).click();
  101. assert.equal(await trigger.getAttribute("aria-expanded"), "true");
  102. await trigger.click();
  103. assert.equal(await stats.count(), 0);
  104. await page.getByRole("button", { name: "Tool done", exact: true }).click();
  105. assert.equal(await stats.count(), 0);
  106. assert.equal(await group.getAttribute("data-group-running"), "true");
  107. const thoughtLabel = trigger.locator("[data-reasoning-label] .font-normal").first();
  108. await thoughtLabel.waitFor();
  109. await assertShimmer(thoughtLabel, true);
  110. await page.getByRole("button", { name: "Text boundary", exact: true }).click();
  111. await page.waitForFunction(
  112. () =>
  113. document
  114. .querySelector("[data-consecutive-summary-group]")
  115. ?.getAttribute("data-group-running") === "false",
  116. );
  117. assert.doesNotMatch(await stats.getAttribute("class"), /animated-gradient-text/);
  118. await assertShimmer(stats, false);
  119. await trigger.click();
  120. await page.getByRole("button", { name: "Finish", exact: true }).click();
  121. assert.equal(await trigger.getAttribute("aria-expanded"), "true");
  122. // 正文闭合和任务结束是两条独立路径,不能让前者掩盖末尾组结算。
  123. await page.goto(`${origin}fixture?share=1&theme=${theme}&locale=${locale}`);
  124. await trigger.waitFor();
  125. assert.equal(await group.getAttribute("data-group-running"), "true");
  126. await page.getByRole("button", { name: "Finish", exact: true }).click();
  127. await page.waitForFunction(
  128. () =>
  129. document
  130. .querySelector("[data-consecutive-summary-group]")
  131. ?.getAttribute("data-group-running") === "false",
  132. );
  133. assert.doesNotMatch(await stats.getAttribute("class"), /animated-gradient-text/);
  134. await assertShimmer(stats, false);
  135. assert.deepEqual(errors, []);
  136. } finally {
  137. await page.close();
  138. }
  139. });
  140. test(`XSG02 change files ${theme}/${locale}`, async () => {
  141. const page = await browser.newPage({ viewport: { width: 1200, height: 900 } });
  142. try {
  143. await page.goto(`${origin}fixture?share=1&changes=1&theme=${theme}&locale=${locale}`);
  144. await page.getByRole("button", { name: "Finish", exact: true }).click();
  145. const files = page.locator("[data-change-summary-files]");
  146. await files.waitFor();
  147. assert.equal(await files.locator("[data-tool-file-name]").count(), 1);
  148. assert.match(await files.innerText(), /App.tsx/);
  149. const trigger = page.locator("[data-summary-group-trigger]").first();
  150. assert.equal(await trigger.getAttribute("aria-expanded"), "false");
  151. await files.locator("[data-tool-file-name]").first().hover();
  152. const tooltip = page.getByRole("tooltip");
  153. await tooltip.waitFor();
  154. assert.match(await tooltip.innerText(), /\/workspace\/src\/App.tsx/);
  155. for (let i = 0; i < 4; i++)
  156. await page.getByRole("button", { name: "Next summary", exact: true }).click();
  157. await page.getByRole("button", { name: "Finish", exact: true }).click();
  158. assert.equal(await files.locator("[data-tool-file-name]").count(), 5);
  159. await page.setViewportSize({ width: 390, height: 900 });
  160. await page.locator("[data-change-summary-overflow]").waitFor();
  161. await page.setViewportSize({ width: 1600, height: 900 });
  162. await page.waitForFunction(() => !document.querySelector("[data-change-summary-overflow]"));
  163. await trigger.click();
  164. await files.waitFor({ state: "hidden" });
  165. assert.equal(await trigger.getAttribute("aria-expanded"), "true");
  166. } finally {
  167. await page.close();
  168. }
  169. });
  170. }
  171. }
  172. for (const width of [390, 1200])
  173. for (const theme of ["light", "dark"]) {
  174. test(`group boundary spacing ${width}/${theme}`, async () => {
  175. const page = await browser.newPage({ viewport: { width, height: 900 } });
  176. try {
  177. await page.goto(`${origin}fixture?share=1&theme=${theme}&locale=en-US`);
  178. await page.locator("[data-summary-group-trigger]").first().waitFor();
  179. for (let i = 0; i < 11; i++)
  180. await page.getByRole("button", { name: "Next summary", exact: true }).click();
  181. await page.getByRole("button", { name: "Finish", exact: true }).click();
  182. const first = page.locator("[data-consecutive-summary-group]").first();
  183. const last = page.locator("[data-consecutive-summary-group]").last();
  184. const measure = async () => {
  185. const after = await first.evaluate((el) => {
  186. const next = el.nextElementSibling;
  187. return (
  188. next.querySelector(".summary-hover-text").getBoundingClientRect().top -
  189. el.getBoundingClientRect().bottom
  190. );
  191. });
  192. const before = await last.evaluate((el) => {
  193. const previous = el.previousElementSibling;
  194. return (
  195. el.querySelector("[data-summary-group-trigger]").getBoundingClientRect().top -
  196. previous.getBoundingClientRect().bottom
  197. );
  198. });
  199. assert.ok(Math.abs(after - 16) < 1, `group → agent: ${after}`);
  200. assert.ok(Math.abs(before - 16) < 1, `workflow → group: ${before}`);
  201. };
  202. const assertSingleLine = async () => {
  203. const metrics = await first.locator("[data-summary-group-statistics]").evaluate((el) => ({
  204. height: el.getBoundingClientRect().height,
  205. lineHeight: parseFloat(getComputedStyle(el).lineHeight),
  206. whiteSpace: getComputedStyle(el).whiteSpace,
  207. overflow: getComputedStyle(el).textOverflow,
  208. title: el.getAttribute("title"),
  209. }));
  210. assert.equal(metrics.whiteSpace, "nowrap");
  211. assert.equal(metrics.overflow, "ellipsis");
  212. assert.ok(metrics.height <= metrics.lineHeight + 1);
  213. assert.ok(metrics.title?.includes("Explored"));
  214. };
  215. await measure();
  216. await assertSingleLine();
  217. await first.locator("[data-summary-group-trigger]").click();
  218. // 等待共享折叠动画结束,仅用于测量,不参与产品逻辑。
  219. await page.waitForTimeout(500);
  220. await measure();
  221. await assertSingleLine();
  222. assert.equal(
  223. await first
  224. .locator("[data-conversation-work-items]")
  225. .evaluate((el) => getComputedStyle(el).rowGap),
  226. "8px",
  227. );
  228. const headerBox = await first.locator("[data-summary-group-trigger]").boundingBox();
  229. const contentBox = await first.locator("[data-summary-group-scroll]").boundingBox();
  230. assert.ok(Math.abs(contentBox.y - headerBox.y - headerBox.height - 8) < 1);
  231. const childList = first.locator('[data-conversation-work-items="group"]');
  232. const guide = await childList.evaluate((el) => {
  233. const style = getComputedStyle(el);
  234. return {
  235. border: getComputedStyle(el, "::before").borderLeftWidth,
  236. margin: style.marginLeft,
  237. padding: style.paddingLeft,
  238. };
  239. });
  240. assert.deepEqual(guide, { border: "1px", margin: "8px", padding: "16px" });
  241. const headerX = await first
  242. .locator("[data-summary-group-statistics]")
  243. .evaluate((el) => el.getBoundingClientRect().left);
  244. const textPositions = await childList
  245. .locator(".tool-summary-kind-label, [data-reasoning-label]")
  246. .evaluateAll((elements) => elements.map((el) => el.getBoundingClientRect().left));
  247. assert.ok(textPositions.length >= 2);
  248. for (const x of textPositions)
  249. assert.ok(Math.abs(x - headerX) < 0.1, `child text ${x}, header ${headerX}`);
  250. const childIcons = childList.locator("[data-summary-leading-icon]");
  251. assert.ok((await childIcons.count()) > 0);
  252. assert.ok(
  253. await childIcons.evaluateAll((elements) =>
  254. elements.every((el) => getComputedStyle(el).display === "none"),
  255. ),
  256. );
  257. assert.equal(await first.locator("[data-summary-group-icon]").isVisible(), true);
  258. await childList.locator('[data-testid="chat-reasoning-trigger"]').click();
  259. const thoughtBody = childList.locator("[data-reasoning-scroll-mask]");
  260. await thoughtBody.waitFor();
  261. // 截图与几何验收等待真实展开动画,避免只截到内容高度为零的首帧。
  262. await first.evaluate(async (el) => {
  263. await Promise.all(
  264. el
  265. .getAnimations({ subtree: true })
  266. .map((animation) => animation.finished.catch(() => {})),
  267. );
  268. });
  269. const thoughtLayout = await thoughtBody.evaluate((el) => {
  270. const style = getComputedStyle(el);
  271. return {
  272. border: style.borderLeftWidth,
  273. margin: style.marginLeft,
  274. padding: style.paddingLeft,
  275. x: el.getBoundingClientRect().left,
  276. };
  277. });
  278. assert.deepEqual(
  279. {
  280. border: thoughtLayout.border,
  281. margin: thoughtLayout.margin,
  282. padding: thoughtLayout.padding,
  283. },
  284. { border: "0px", margin: "0px", padding: "0px" },
  285. );
  286. assert.ok(Math.abs(thoughtLayout.x - headerX) < 0.1);
  287. assert.equal(
  288. await thoughtBody.evaluate((el) => getComputedStyle(el.parentElement).paddingTop),
  289. "4px",
  290. );
  291. await page.screenshot({ path: join(artifacts, `boundary-${width}-${theme}.png`) });
  292. } finally {
  293. await page.close();
  294. }
  295. });
  296. }
  297. for (const width of [390, 1200])
  298. for (const theme of ["light", "dark"]) {
  299. test(`outer summary spacing ${width}/${theme}`, async () => {
  300. const page = await browser.newPage({ viewport: { width, height: 1600 } });
  301. page.on("pageerror", (error) => console.error(error.message));
  302. page.setDefaultTimeout(5000);
  303. try {
  304. await page.goto(`${origin}fixture?theme=${theme}&locale=en-US`);
  305. await page.locator('[data-example="agent"] .summary-hover-text').waitFor();
  306. const pairs = [
  307. ["reasoning-hover", "reasoning-running-hover"],
  308. ["agent", "agent-pending"],
  309. ["agent-stopped", "todo-spacing"],
  310. ["todo-spacing", "cua-hover"],
  311. ["read", "write"],
  312. ];
  313. for (const [before, after] of pairs) {
  314. const previous = await page.locator(`[data-example="${before}"]`).boundingBox();
  315. const next = await page
  316. .locator(`[data-example="${after}"] .summary-hover-text`)
  317. .first()
  318. .boundingBox();
  319. assert.ok(
  320. Math.abs(next.y - previous.y - previous.height - 16) < 1,
  321. `${before} → ${after}: ${next.y - previous.y - previous.height}`,
  322. );
  323. }
  324. await page.screenshot({ path: join(artifacts, `outer-${width}-${theme}.png`) });
  325. } finally {
  326. await page.close();
  327. }
  328. });
  329. }
  330. for (const width of [390, 1200])
  331. for (const theme of ["light", "dark"]) {
  332. test(`group scrolling ${width}/${theme}`, async () => {
  333. const page = await browser.newPage({ viewport: { width, height: 900 } });
  334. try {
  335. await page.goto(`${origin}fixture?scroll=1&theme=${theme}`);
  336. const trigger = page.locator("[data-summary-group-trigger]");
  337. await trigger.click();
  338. const group = page.locator("[data-summary-group-scroll]");
  339. // 等待折叠区域展开后再测量和截图;运行态扫光是无限动画,不参与等待。
  340. await group.evaluate(async (el) => {
  341. const animations = el
  342. .closest("[data-consecutive-summary-group]")
  343. .getAnimations({ subtree: true });
  344. await Promise.all(
  345. animations
  346. .filter((animation) => animation.effect.getTiming().iterations !== Infinity)
  347. .map((animation) => animation.finished.catch(() => {})),
  348. );
  349. });
  350. const thinking = page.locator("[data-reasoning-scroll-mask]");
  351. // 独立思考保留自身导线与缩进,分组样式不能泄漏到外部。
  352. assert.deepEqual(
  353. await thinking.evaluate((el) => {
  354. const style = getComputedStyle(el);
  355. return [style.borderLeftWidth, style.marginLeft, style.paddingLeft];
  356. }),
  357. ["1px", "8px", "14px"],
  358. );
  359. assert.equal(
  360. await thinking.evaluate((el) => getComputedStyle(el.parentElement).paddingTop),
  361. "12px",
  362. );
  363. const atBottom = async (locator) => {
  364. await page.waitForFunction(
  365. (selector) => {
  366. const el = document.querySelector(selector);
  367. return el && Math.abs(el.scrollHeight - el.clientHeight - el.scrollTop) <= 2;
  368. },
  369. (await locator.getAttribute("data-summary-group-scroll")) !== null
  370. ? "[data-summary-group-scroll]"
  371. : "[data-reasoning-scroll-mask]",
  372. );
  373. };
  374. await atBottom(group);
  375. await atBottom(thinking);
  376. const geometry = await group.evaluate((el) => ({
  377. height: el.clientHeight,
  378. line: parseFloat(getComputedStyle(el).lineHeight),
  379. overflow: el.scrollHeight > el.clientHeight,
  380. }));
  381. assert.ok(geometry.overflow);
  382. assert.ok(Math.abs(geometry.height - (geometry.line * 16 + 120)) <= 1);
  383. assert.equal(await group.getAttribute("data-scroll-mask"), "top");
  384. await page.screenshot({ path: join(artifacts, `scroll-bottom-${width}-${theme}.png`) });
  385. await page.getByRole("button", { name: "Append", exact: true }).click();
  386. await atBottom(group);
  387. await atBottom(thinking);
  388. await page.getByRole("button", { name: "Grow", exact: true }).click();
  389. await atBottom(group);
  390. for (const locator of [group, thinking]) {
  391. await locator.evaluate((el) => {
  392. el.scrollTop = 30;
  393. el.dispatchEvent(new Event("scroll"));
  394. });
  395. }
  396. await page.getByRole("button", { name: "Append", exact: true }).click();
  397. await page.waitForTimeout(100);
  398. assert.equal(await group.evaluate((el) => el.scrollTop), 30);
  399. assert.equal(await thinking.evaluate((el) => el.scrollTop), 30);
  400. assert.equal(await group.getAttribute("data-scroll-mask"), "both");
  401. await page.screenshot({ path: join(artifacts, `scroll-middle-${width}-${theme}.png`) });
  402. await group.evaluate((el) => {
  403. el.scrollTop = 0;
  404. el.dispatchEvent(new Event("scroll"));
  405. });
  406. await page.waitForFunction(
  407. () =>
  408. document
  409. .querySelector("[data-summary-group-scroll]")
  410. ?.getAttribute("data-scroll-mask") === "bottom",
  411. );
  412. for (const locator of [group, thinking])
  413. await locator.evaluate((el) => {
  414. el.scrollTop = el.scrollHeight;
  415. el.dispatchEvent(new Event("scroll"));
  416. });
  417. await page.getByRole("button", { name: "Append", exact: true }).click();
  418. await atBottom(group);
  419. await atBottom(thinking);
  420. await trigger.click();
  421. await page.waitForTimeout(300);
  422. await trigger.click();
  423. await atBottom(group);
  424. await page.getByRole("button", { name: "Grow", exact: true }).click();
  425. await page.getByRole("button", { name: "Short", exact: true }).click();
  426. await page.waitForFunction(
  427. () =>
  428. document
  429. .querySelector("[data-summary-group-scroll]")
  430. ?.getAttribute("data-scroll-mask") === "none",
  431. );
  432. await page.screenshot({ path: join(artifacts, `scroll-${width}-${theme}.png`) });
  433. } finally {
  434. await page.close();
  435. }
  436. });
  437. }
  438. for (const theme of ["light", "dark"])
  439. for (const locale of ["en-US", "zh-CN"]) {
  440. test(`XSG02 session tools ${theme}/${locale}`, async () => {
  441. const page = await browser.newPage({ viewport: { width: 390, height: 900 } });
  442. const errors = [];
  443. page.on("pageerror", (error) => errors.push(error.message));
  444. try {
  445. await page.goto(`${origin}fixture?share=1&sessions=1&theme=${theme}&locale=${locale}`);
  446. const group = page.locator("[data-consecutive-summary-group]").first();
  447. const trigger = group.locator("[data-summary-group-trigger]");
  448. await trigger.waitFor();
  449. assert.equal(await trigger.getAttribute("aria-expanded"), "false");
  450. await trigger.click();
  451. await group
  452. .getByText(locale === "en-US" ? "Read session" : "读取会话", { exact: true })
  453. .click();
  454. await group.getByText("Session detail preserved", { exact: true }).waitFor();
  455. for (let i = 0; i < 4; i++)
  456. await page.getByRole("button", { name: "Next summary", exact: true }).click();
  457. assert.equal(await page.locator("[data-consecutive-summary-group]").count(), 1);
  458. assert.equal(await trigger.getAttribute("aria-expanded"), "true");
  459. const stats = group.locator("[data-summary-group-statistics]");
  460. assert.match(
  461. await stats.innerText(),
  462. locale === "en-US" ? /^Run 5 commands$/ : /^执行 5 命令$/,
  463. );
  464. assert.equal(
  465. await group
  466. .locator('[data-conversation-work-items="group"] [data-summary-leading-icon]:visible')
  467. .count(),
  468. 0,
  469. );
  470. await page.getByRole("button", { name: "Next summary", exact: true }).click();
  471. assert.equal(await group.getAttribute("data-group-running"), "false");
  472. assert.match(
  473. await stats.innerText(),
  474. locale === "en-US" ? /^Ran 5 commands$/ : /^已执行 5 命令$/,
  475. );
  476. for (let i = 0; i < 2; i++)
  477. await page.getByRole("button", { name: "Next summary", exact: true }).click();
  478. assert.equal(await page.locator("[data-consecutive-summary-group]").count(), 2);
  479. await page.getByRole("button", { name: "Finish", exact: true }).click();
  480. const sessionOnlyStats = page
  481. .locator("[data-consecutive-summary-group]")
  482. .nth(1)
  483. .locator("[data-summary-group-statistics]");
  484. assert.match(
  485. await sessionOnlyStats.innerText(),
  486. locale === "en-US" ? /^Ran 2 commands$/ : /^已执行 2 命令$/,
  487. );
  488. for (const width of [390, 1200]) {
  489. await page.setViewportSize({ width, height: 900 });
  490. assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
  491. await page.screenshot({
  492. path: join(artifacts, `session-group-${width}-${theme}-${locale}.png`),
  493. });
  494. }
  495. assert.deepEqual(errors, []);
  496. } finally {
  497. await page.close();
  498. }
  499. });
  500. }
  501. for (const width of [390, 1200])
  502. for (const theme of ["light", "dark"])
  503. for (const locale of ["en-US", "zh-CN"]) {
  504. test(`Bash description ${width}/${theme}/${locale}`, async () => {
  505. const page = await browser.newPage({
  506. viewport: { width, height: 900 },
  507. reducedMotion: "reduce",
  508. });
  509. page.setDefaultTimeout(15000);
  510. const errors = [];
  511. page.on("pageerror", (error) => errors.push(error.message));
  512. try {
  513. for (const description of ["present", "empty", "missing"]) {
  514. await page.goto(
  515. `${origin}fixture?share=1&bash=1&theme=${theme}&locale=${locale}&description=${description}`,
  516. );
  517. const expected =
  518. description === "present" ? "检查当前项目的构建结果" : "echo bash-summary-output";
  519. const solo = page.locator("[data-bash-standalone]");
  520. await solo.getByText(expected, { exact: true }).waitFor();
  521. if (description === "present") {
  522. await solo.getByText(expected, { exact: true }).click();
  523. await solo.getByTestId("execute-command").waitFor();
  524. await solo.getByText(expected, { exact: true }).waitFor({ state: "visible" });
  525. await solo.getByText(expected, { exact: true }).click();
  526. await solo.getByTestId("execute-command").waitFor({ state: "hidden" });
  527. await solo.getByText(expected, { exact: true }).waitFor({ state: "visible" });
  528. }
  529. const group = page.locator("[data-consecutive-summary-group]").first();
  530. const trigger = group.locator("[data-summary-group-trigger]");
  531. await trigger.getByText(expected, { exact: true }).waitFor();
  532. if (description === "present")
  533. assert.ok(!(await trigger.innerText()).includes("echo bash-summary-output"));
  534. await page.screenshot({
  535. animations: "disabled",
  536. path: join(artifacts, `bash-active-${width}-${theme}-${locale}-${description}.png`),
  537. });
  538. await trigger.click();
  539. const children = group.locator('[data-conversation-work-items="group"]');
  540. await children.getByText(expected, { exact: true }).click();
  541. await children.getByTestId("execute-command").waitFor();
  542. if (description === "present")
  543. await children.getByText(expected, { exact: true }).waitFor({ state: "visible" });
  544. assert.match(
  545. await children.getByTestId("execute-command").innerText(),
  546. /echo bash-summary-output/,
  547. );
  548. assert.equal(
  549. await children.getByTestId("bash-output-preview-full").innerText(),
  550. "bash-summary-output",
  551. );
  552. await page.screenshot({
  553. animations: "disabled",
  554. path: join(
  555. artifacts,
  556. `bash-description-${width}-${theme}-${locale}-${description}.png`,
  557. ),
  558. });
  559. await trigger.click();
  560. await page.getByRole("button", { name: "Tool done", exact: true }).click();
  561. await trigger.getByText(expected, { exact: true }).waitFor();
  562. await assertShimmer(trigger.locator(".tool-summary-kind-label"), true);
  563. await assertShimmer(solo.locator(".tool-summary-kind-label"), false);
  564. assert.equal(await group.locator("[data-summary-group-statistics]").count(), 0);
  565. assert.equal(await group.getAttribute("data-group-running"), "true");
  566. await page.screenshot({
  567. animations: "disabled",
  568. path: join(artifacts, `bash-idle-${width}-${theme}-${locale}-${description}.png`),
  569. });
  570. await page.getByRole("button", { name: "Finish", exact: true }).click();
  571. await group.locator("[data-summary-group-statistics]").waitFor();
  572. assert.ok(!(await trigger.innerText()).includes(expected));
  573. }
  574. assert.deepEqual(errors, []);
  575. } finally {
  576. await page.close();
  577. }
  578. });
  579. }
  580. for (const width of [390, 1200])
  581. for (const theme of ["light", "dark"]) {
  582. test(`group scroll chain ${width}/${theme}`, async () => {
  583. const page = await browser.newPage({ viewport: { width, height: 900 } });
  584. try {
  585. await page.goto(`${origin}fixture?scroll=1&chain=1&theme=${theme}`);
  586. await page.locator("[data-summary-group-trigger]").click();
  587. const group = page.locator("[data-summary-group-scroll]");
  588. const parent = page.locator("[data-scroll-parent]");
  589. await group.evaluate(async (el) => {
  590. await Promise.all(
  591. el
  592. .closest("[data-consecutive-summary-group]")
  593. .getAnimations({ subtree: true })
  594. .filter((a) => a.effect.getTiming().iterations !== Infinity)
  595. .map((a) => a.finished.catch(() => {})),
  596. );
  597. });
  598. const metrics = async () => ({
  599. inner: await group.evaluate((el) => el.scrollTop),
  600. outer: await parent.evaluate((el) => el.scrollTop),
  601. });
  602. // 原生滚轮验证滚动链;程序化赋值仅用于准备起点,不代替用户动作。
  603. const wheelOverGroup = async (delta) => {
  604. const box = await group.boundingBox();
  605. const outerBox = await parent.boundingBox();
  606. await page.mouse.move(
  607. box.x + box.width / 2,
  608. (Math.max(box.y, outerBox.y) +
  609. Math.min(box.y + box.height, outerBox.y + outerBox.height)) /
  610. 2,
  611. );
  612. await page.mouse.wheel(0, delta);
  613. await page.waitForTimeout(300);
  614. return metrics();
  615. };
  616. const resetParent = async () => {
  617. await parent.evaluate((el) => {
  618. el.scrollTop = 0;
  619. });
  620. };
  621. assert.ok(await parent.evaluate((el) => el.scrollHeight > el.clientHeight));
  622. assert.ok(await group.evaluate((el) => el.scrollHeight > el.clientHeight));
  623. const bottom = await metrics();
  624. const down = await wheelOverGroup(180);
  625. console.log(
  626. JSON.stringify({ width, theme, scenario: "bottom", before: bottom, after: down }),
  627. );
  628. assert.ok(down.outer > bottom.outer, "bottom edge must scroll parent downward");
  629. assert.equal(down.inner, bottom.inner);
  630. await group.evaluate((el) => {
  631. el.scrollTop = 0;
  632. });
  633. await parent.evaluate((el) => {
  634. el.scrollTop = 100;
  635. });
  636. const up = await wheelOverGroup(-60);
  637. assert.ok(up.outer < 100, "top edge must scroll parent upward");
  638. assert.equal(up.inner, 0);
  639. console.log(JSON.stringify({ width, theme, scenario: "top", after: up }));
  640. await resetParent();
  641. await group.evaluate((el) => {
  642. el.scrollTop = (el.scrollHeight - el.clientHeight) / 2;
  643. });
  644. const middle = await metrics();
  645. const innerDown = await wheelOverGroup(20);
  646. assert.ok(innerDown.inner > middle.inner, "available inner space consumes downward scroll");
  647. assert.equal(innerDown.outer, 0);
  648. const innerUp = await wheelOverGroup(-20);
  649. assert.ok(innerUp.inner < innerDown.inner, "available inner space consumes upward scroll");
  650. assert.equal(innerUp.outer, 0);
  651. await page.getByRole("button", { name: "Short", exact: true }).click();
  652. await page.waitForFunction(() => {
  653. const el = document.querySelector("[data-summary-group-scroll]");
  654. return el.scrollHeight === el.clientHeight && el.dataset.scrollMask === "none";
  655. });
  656. assert.ok((await wheelOverGroup(180)).outer > 0, "short group must let parent scroll");
  657. await resetParent();
  658. for (let i = 0; i < 8; i++)
  659. await page.getByRole("button", { name: "Append", exact: true }).click();
  660. await page.waitForFunction(() => {
  661. const el = document.querySelector("[data-summary-group-scroll]");
  662. return el.scrollHeight > el.clientHeight && el.dataset.scrollMask === "top";
  663. });
  664. assert.ok(
  665. (await wheelOverGroup(180)).outer > 0,
  666. "grown group still passes bottom edge scroll",
  667. );
  668. await resetParent();
  669. const trigger = page.locator("[data-summary-group-trigger]");
  670. await trigger.click();
  671. await group.waitFor({ state: "hidden" });
  672. await trigger.click();
  673. await page.waitForFunction(() => {
  674. const el = document.querySelector("[data-summary-group-scroll]");
  675. return (
  676. el &&
  677. el.clientHeight > 0 &&
  678. el.scrollHeight > el.clientHeight &&
  679. Math.abs(el.scrollHeight - el.clientHeight - el.scrollTop) <= 2
  680. );
  681. });
  682. assert.ok(
  683. (await wheelOverGroup(180)).outer > 0,
  684. "reopened group still passes bottom edge scroll",
  685. );
  686. await page.screenshot({ path: join(artifacts, `scroll-chain-${width}-${theme}.png`) });
  687. } finally {
  688. await page.close();
  689. }
  690. });
  691. }