workflow-digest-fixed.test.mjs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // 独立真实 renderer 验证 hover/focus;不依赖当前会话,不覆盖宿主侧栏路由。
  2. import assert from "node:assert/strict";
  3. import test from "node:test";
  4. import { chromium } from "playwright-core";
  5. test("运行卡无箭头仍可收起,保留统计和侧栏入口", async () => {
  6. const browser = await chromium.launch({ channel: "chrome", headless: true });
  7. try {
  8. const page = await browser.newPage();
  9. page.on("pageerror", (error) => {
  10. process.stderr.write(String(error));
  11. });
  12. const targets = await (await fetch("http://localhost:9229/json/list")).json();
  13. const origin = new URL(targets.find((t) => t.type === "page").url).origin;
  14. await page.route("**/__workflow_hover", (route) =>
  15. route.fulfill({
  16. contentType: "text/html",
  17. body: `<div id="root"></div><script type="module">
  18. import RefreshRuntime from '/@react-refresh'; RefreshRuntime.injectIntoGlobalHook(window); window.$RefreshReg$=()=>{}; window.$RefreshSig$=()=>type=>type; window.__vite_plugin_react_preamble_installed__=true;
  19. await import('/@fs${process.cwd()}/packages/ui/test/fixtures/workflow-digest-fixed.fixture.tsx');
  20. </script>`,
  21. }),
  22. );
  23. for (const width of [1200, 390]) {
  24. await page.setViewportSize({ width, height: 800 });
  25. await page.goto(`${origin}/__workflow_hover`);
  26. const card = page.getByTestId("workflow-run-digest-fixed");
  27. await card.waitFor();
  28. const rail = card.getByTestId("workflow-timeline-rail").first();
  29. const railStyle = await rail.evaluate((node) => ({
  30. width: getComputedStyle(node).borderTopWidth,
  31. gradient: getComputedStyle(node, "::after").backgroundImage,
  32. animation: getComputedStyle(node, "::after").animationName,
  33. }));
  34. assert.equal(railStyle.width, "2px");
  35. assert.equal(
  36. await rail.evaluate((node) => getComputedStyle(node).borderTopColor),
  37. "rgba(0, 0, 0, 0)",
  38. );
  39. const stubWidths = await card
  40. .locator("[data-ledge-ink]")
  41. .evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).borderTopWidth));
  42. assert.ok(stubWidths.every((width) => width === "1px"));
  43. assert.match(await rail.getAttribute("class"), /rounded-full/);
  44. assert.equal(
  45. await rail.evaluate((node) => getComputedStyle(node, "::after").borderRadius),
  46. await rail.evaluate((node) => getComputedStyle(node).borderRadius),
  47. );
  48. assert.match(railStyle.gradient, /^repeating-linear-gradient/);
  49. assert.equal(railStyle.animation, "wf-rail-slide");
  50. await page.emulateMedia({ reducedMotion: "reduce" });
  51. assert.equal(
  52. await rail.evaluate((node) => getComputedStyle(node, "::after").animationName),
  53. "none",
  54. );
  55. await page.emulateMedia({ reducedMotion: "no-preference" });
  56. const spine = page.getByTestId("workflow-run-spine-rail");
  57. assert.equal(await spine.evaluate((node) => getComputedStyle(node).width), "2px");
  58. assert.equal(
  59. await spine.evaluate((node) => getComputedStyle(node).backgroundColor),
  60. "rgba(0, 0, 0, 0)",
  61. );
  62. const resume = page.getByTestId("workflow-digest-resume");
  63. assert.equal(await resume.evaluate((node) => getComputedStyle(node).height), "28px");
  64. await resume.click();
  65. assert.equal(await page.locator("body").getAttribute("data-resumed"), "true");
  66. assert.doesNotMatch(
  67. await card.getByTestId("workflow-card-name").getAttribute("class"),
  68. /font-mono/,
  69. );
  70. // 瓦片脸(round 19):内联 SVG,没有图片要等;身份是机身色相 --wf-face-body。
  71. const cluster = page.getByTestId("workflow-run-phase-cluster");
  72. assert.equal(await cluster.locator(".rounded-full").count(), 0);
  73. const avatarHues = await card
  74. .locator("svg[data-subagent-avatar]")
  75. .evaluateAll((nodes) => nodes.map((n) => n.style.getPropertyValue("--wf-face-body")));
  76. assert.equal(new Set(avatarHues).size, avatarHues.length);
  77. assert.ok(avatarHues.every((hue) => hue !== ""));
  78. assert.deepEqual(
  79. await cluster
  80. .locator("svg[data-subagent-avatar]")
  81. .evaluateAll((nodes) => nodes.map((n) => n.style.getPropertyValue("--wf-face-body"))),
  82. avatarHues,
  83. );
  84. const boxes = await cluster.locator("img, svg").evaluateAll((nodes) =>
  85. nodes.map((n) => {
  86. const r = n.getBoundingClientRect();
  87. return { left: r.left, right: r.right };
  88. }),
  89. );
  90. assert.ok(boxes.length > 1 && boxes[1].left >= boxes[0].right);
  91. assert.equal(
  92. await card
  93. .locator('[data-testid="workflow-agent-pill"] > svg[data-subagent-avatar]')
  94. .count(),
  95. 2,
  96. );
  97. assert.equal(await card.locator(".wf-pill-avatar").count(), 0);
  98. assert.match(
  99. await card.getByTestId("workflow-timeline-fraction").first().getAttribute("class"),
  100. /text-ui-sm/,
  101. );
  102. const completed = card.locator(
  103. '[data-testid="workflow-pill-status"]:has(svg.lucide-circle-check)',
  104. );
  105. assert.equal(await completed.count(), 1);
  106. assert.equal(
  107. await completed.evaluate((node) => getComputedStyle(node).color),
  108. await card
  109. .locator('[data-testid="workflow-pill-status"]:has(svg.animate-spin)')
  110. .first()
  111. .evaluate((node) => getComputedStyle(node).color),
  112. );
  113. const loading = card.locator('[data-testid="workflow-pill-status"]:has(svg.animate-spin)');
  114. assert.equal(await loading.count(), 1);
  115. assert.match(await loading.getAttribute("class"), /text-foreground-subtle/);
  116. assert.doesNotMatch(await loading.getAttribute("class"), /text-warning/);
  117. assert.equal(await card.getByTestId("workflow-card-toggle").count(), 0);
  118. assert.equal(await card.getByTestId("workflow-digest-status").count(), 0);
  119. assert.equal(
  120. await card.getByTestId("workflow-card-detail").innerText(),
  121. "1 agent working · 1/2 steps",
  122. );
  123. assert.match(
  124. await card.getByTestId("workflow-card-detail").getAttribute("class"),
  125. /text-ui-base/,
  126. );
  127. assert.doesNotMatch(
  128. await card.getByTestId("workflow-card-detail").getAttribute("class"),
  129. /font-mono/,
  130. );
  131. assert.equal(await card.getByTestId("workflow-agent-pill").count(), 2);
  132. await card.click({ position: { x: 5, y: 5 } });
  133. assert.equal(await card.getByTestId("workflow-agent-pill").count(), 0);
  134. await card.focus();
  135. await card.press("Enter");
  136. assert.equal(await card.getByTestId("workflow-agent-pill").count(), 2);
  137. const pill = card.getByTestId("workflow-agent-pill").first();
  138. await pill.hover();
  139. await page.waitForFunction(() => {
  140. const pill = document.querySelector('[data-testid="workflow-agent-pill"]');
  141. return pill && getComputedStyle(pill).boxShadow === "none";
  142. });
  143. assert.match(await pill.getAttribute("class"), /rounded-full/);
  144. await pill.click();
  145. assert.equal(await page.locator("body").getAttribute("data-agent-opened"), "true");
  146. await card.getByTestId("workflow-card-open-details").click();
  147. assert.equal(await page.locator("body").getAttribute("data-open"), "true");
  148. }
  149. } finally {
  150. await browser.close();
  151. }
  152. });