workflow-digest-gate.test.mjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // 独立真实 renderer 验证 run 联接与主轮结束门控;不覆盖服务层事件传输。
  2. import assert from "node:assert/strict";
  3. import test from "node:test";
  4. import { chromium } from "playwright-core";
  5. test("有 run 时立即显示下方卡片,不等主代理回复结束", 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-gate.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.locator('[data-workflow-run-digest="true"]');
  27. await page.getByRole("button", { name: "Join run" }).waitFor();
  28. assert.equal(await card.count(), 0);
  29. await page.getByRole("button", { name: "Join run" }).click();
  30. await card.waitFor();
  31. assert.equal(await card.count(), 1);
  32. await page.getByRole("button", { name: "Finish reply" }).click();
  33. assert.equal(await card.count(), 1);
  34. }
  35. } finally {
  36. await browser.close();
  37. }
  38. });