workflow-status.test.mjs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // 独立真实 renderer 验证状态、展开滚动与打开回调;不覆盖宿主侧栏路由。
  2. import assert from "node:assert/strict";
  3. import test from "node:test";
  4. import { chromium } from "playwright-core";
  5. test("Workflow status 查询状态与展开内容", 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-status.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 summary = page.locator(".group\\/tool-summary");
  27. await summary.waitFor();
  28. assert.match(await summary.innerText(), /Checking workflow status/);
  29. assert.equal(await summary.getAttribute("role"), null);
  30. await page.getByRole("button", { name: "running", exact: true }).click();
  31. assert.match(await summary.innerText(), /Workflow status\s*·\s*Status workflow\s*·\s*1\/3 steps/s);
  32. await summary.click();
  33. const body = page.getByTestId("workflow-status-body");
  34. await body.waitFor();
  35. assert.match(await body.innerText(), /1\/3 steps/);
  36. assert.doesNotMatch(await body.innerText(), /Actors|Usage|No logs/);
  37. assert.equal(await summary.getByRole("button", { name: /details/i }).count(), 0);
  38. await page.getByRole("button", { name: "completed", exact: true }).click();
  39. await body.getByRole("button", { name: "Copy code" }).waitFor();
  40. await page.waitForFunction(() => {
  41. const n = document.querySelector('[data-testid="workflow-status-body"] .max-h-80');
  42. return n && n.scrollHeight > n.clientHeight;
  43. });
  44. const copy = body.getByRole("button", { name: "Copy code" });
  45. const before = await copy.boundingBox();
  46. await body.locator(".max-h-80").evaluate((n) => {
  47. n.scrollTop = 100;
  48. });
  49. assert.equal((await copy.boundingBox()).y, before.y);
  50. await page.getByRole("button", { name: "run-failed", exact: true }).click();
  51. assert.match(await body.innerText(), /^RUN_ERROR: Actor failed/);
  52. await page.getByRole("button", { name: "query-failed", exact: true }).click();
  53. assert.equal(await body.innerText(), "Query denied");
  54. }
  55. } finally {
  56. await browser.close();
  57. }
  58. });