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

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