conversation-session-developer-tools.test.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { TID_SIDE_PANE_TOGGLE, TID_V4_COMPOSER_INPUT } from "@zcode/shared/test-ids";
  2. import { clearAppData, switchToNewestWindow } from "#e2e/helpers/desktop-app";
  3. import {
  4. prepareV4ConversationE2E,
  5. sendV4Prompt,
  6. waitForV4AssistantMessageContaining,
  7. waitForV4ConversationState,
  8. } from "#e2e/helpers/v4-conversation";
  9. describe("DBG01 开发者工具请求诊断", () => {
  10. after(async () => {
  11. await browser.electron.restoreAllMocks();
  12. await clearAppData();
  13. });
  14. it("完成请求后打开面板,恢复 token、网络及首 token 后的 TPS", async function () {
  15. this.timeout(120_000);
  16. // 隔离用户目录首次启动会进入引导页,先退出再进入真实任务。
  17. await browser.waitUntil(
  18. async () => {
  19. await switchToNewestWindow();
  20. return (
  21. (await $('[data-testid="onboarding-page"]').isDisplayed()) ||
  22. (await $(`[data-testid="${TID_V4_COMPOSER_INPUT}"]`).isDisplayed())
  23. );
  24. },
  25. { timeout: 30_000, timeoutMsg: "首次引导或 Composer 没有出现" },
  26. );
  27. if (await $('[data-testid="onboarding-page"]').isDisplayed()) await browser.keys("Escape");
  28. await prepareV4ConversationE2E();
  29. await sendV4Prompt("E2E_DEVELOPER_TOOLS: Reply with exactly upstream-e2e-ok.");
  30. await waitForV4AssistantMessageContaining("upstream-e2e-ok");
  31. await waitForV4ConversationState((state) => state.state === "idle", "主请求尚未结束");
  32. await browser.execute(() => {
  33. localStorage.setItem("zcode:developer-tools:enabled", "1");
  34. window.dispatchEvent(new Event("focus"));
  35. });
  36. const launcher = await $('[data-side-pane-open-tab-item="developer-tools"]');
  37. const add = await $("[data-side-pane-add-tab-trigger]");
  38. if (!(await launcher.isDisplayed()) && !(await add.isDisplayed())) {
  39. await $(`[data-testid="${TID_SIDE_PANE_TOGGLE}"]`).click();
  40. }
  41. await browser.waitUntil(
  42. async () => (await launcher.isDisplayed()) || (await add.isDisplayed()),
  43. { timeout: 15_000, timeoutMsg: "右侧面板入口未出现" },
  44. );
  45. if (await launcher.isDisplayed()) {
  46. await launcher.click();
  47. } else {
  48. await add.waitForClickable({ timeout: 15_000 });
  49. await add.click();
  50. const item = await $(
  51. '[data-state="active"] [data-side-pane-open-tab-item="developer-tools"]',
  52. );
  53. await item.waitForClickable({ timeout: 10_000 });
  54. await item.click();
  55. }
  56. await browser.waitUntil(
  57. async () => {
  58. const cell = await $('[data-testid="token-debug-tps"]');
  59. return (await cell.isExisting()) && Number(await cell.getText()) > 0;
  60. },
  61. { timeout: 30_000, timeoutMsg: "请求诊断未到达面板" },
  62. );
  63. const tps = Number(await $('[data-testid="token-debug-tps"]').getText());
  64. // replay 首输出在 2s,结束在 5s,output=120;留给 SDK/调度少量时间误差。
  65. expect(tps).toBeGreaterThan(35);
  66. expect(tps).toBeLessThan(45);
  67. const panel = await $('[data-testid="developer-tools-pane"]');
  68. expect(await panel.getText()).toContain("120");
  69. expect(await panel.$$("summary")).not.toHaveLength(0);
  70. expect(await panel.$('[role="alert"]').isExisting()).toBe(false);
  71. });
  72. });