workspace-agent-warmup-lifecycle.test.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { dirname } from "node:path";
  2. import { DEFAULT_WORKSPACE, clearAppData, waitForWorkspaceApp } from "#e2e/helpers/desktop-app";
  3. import {
  4. PASSIVE_AGENT_STARTUP_SCENARIO,
  5. getPassiveAgentStartupWorkspacePaths,
  6. } from "#e2e/helpers/passive-agent-startup-fixture";
  7. import {
  8. isMainRendererUrl,
  9. isResourceManagerUrl,
  10. openResourceManager,
  11. switchToElectronRendererTarget,
  12. waitForResourceManagerReady,
  13. } from "#e2e/helpers/resource-manager";
  14. import {
  15. assertStableAgentSelection,
  16. openWorkspaceDraftFromSidebar,
  17. pickWorkspacePaths,
  18. waitForActiveWorkspacePath,
  19. waitForRestoredProjects,
  20. } from "#e2e/helpers/workspace-agent-warmup";
  21. describe("workspace Agent 预热生命周期", () => {
  22. after(async () => {
  23. await browser.electron.restoreAllMocks();
  24. await clearAppData();
  25. });
  26. it("TSL31: renderer reload 复用原 Agent PID,显式打开其他 workspace 后只增加 1 个", async function () {
  27. this.timeout(120_000);
  28. const workspacePaths = getPassiveAgentStartupWorkspacePaths(
  29. dirname(DEFAULT_WORKSPACE),
  30. PASSIVE_AGENT_STARTUP_SCENARIO.workspaceCount,
  31. );
  32. const activeWorkspacePath = workspacePaths[PASSIVE_AGENT_STARTUP_SCENARIO.activeWorkspaceIndex];
  33. const explicitWorkspacePath =
  34. workspacePaths[PASSIVE_AGENT_STARTUP_SCENARIO.explicitWorkspaceIndex];
  35. if (!activeWorkspacePath || !explicitWorkspacePath) {
  36. throw new Error("启动 fixture 缺少 active 或显式打开 workspace");
  37. }
  38. const startupWarmupWorkspacePaths = pickWorkspacePaths(
  39. workspacePaths,
  40. PASSIVE_AGENT_STARTUP_SCENARIO.expectedWarmupWorkspaceIndexes,
  41. );
  42. await waitForWorkspaceApp(activeWorkspacePath, 30_000);
  43. await waitForActiveWorkspacePath(activeWorkspacePath);
  44. await waitForRestoredProjects(workspacePaths);
  45. await openResourceManager();
  46. await switchToElectronRendererTarget(isResourceManagerUrl);
  47. await waitForResourceManagerReady();
  48. const beforeReload = await assertStableAgentSelection(
  49. workspacePaths,
  50. startupWarmupWorkspacePaths,
  51. );
  52. await switchToElectronRendererTarget(isMainRendererUrl);
  53. // renderer reload 应只给存活 Host 重新挂 MessagePort,不能重跑 InitLocal 或复制 Agent。
  54. await browser.execute(() => window.location.reload());
  55. await waitForActiveWorkspacePath(activeWorkspacePath);
  56. await waitForRestoredProjects(workspacePaths);
  57. await switchToElectronRendererTarget(isResourceManagerUrl);
  58. await waitForResourceManagerReady();
  59. const afterReload = await assertStableAgentSelection(
  60. workspacePaths,
  61. startupWarmupWorkspacePaths,
  62. );
  63. expect(afterReload).toEqual(beforeReload);
  64. await switchToElectronRendererTarget(isMainRendererUrl);
  65. await openWorkspaceDraftFromSidebar(explicitWorkspacePath);
  66. const expectedAfterExplicitOpen = [...startupWarmupWorkspacePaths, explicitWorkspacePath];
  67. await switchToElectronRendererTarget(isResourceManagerUrl);
  68. await assertStableAgentSelection(workspacePaths, expectedAfterExplicitOpen);
  69. });
  70. });