conversation-session-plugin-missing-package-workspace.test.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { readFile, writeFile, mkdir } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import {
  4. clearAppData,
  5. clickTestIdByDom,
  6. getE2EAppDataPaths,
  7. } from "../../../helpers/desktop-app.js";
  8. import {
  9. addLifecycleMarketplaceThroughUi,
  10. createPluginLifecycleFixture,
  11. getPluginOverview,
  12. installPluginThroughUi,
  13. openPluginCard,
  14. openPluginSettings,
  15. PLUGIN_LIFECYCLE_ID,
  16. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  17. PLUGIN_LIFECYCLE_MCP_TOOL_NAME,
  18. PLUGIN_LIFECYCLE_RUNTIME_MARKER,
  19. pluginStoragePath,
  20. waitForPluginCard,
  21. } from "../../../helpers/plugin-management-lifecycle.js";
  22. import {
  23. E2E_REPLY_TOKEN,
  24. getToolCallBlockByToolName,
  25. prepareConversationE2E,
  26. sendPrompt,
  27. startNewTask,
  28. waitForAssistantMessageContaining,
  29. waitForUpstreamRequestContaining,
  30. } from "../../../helpers/conversation-session.js";
  31. import {
  32. ensureToolCrossProductFullAccessMode,
  33. respondToToolCrossProductBlockers,
  34. } from "../../../helpers/conversation-session-tool-cross-product.js";
  35. import {
  36. captureArtifactAdvertisesToolName,
  37. findUpstreamRequestContaining,
  38. } from "../../../helpers/plugin-mcp-skill.js";
  39. describe("WPL-006 Workspace Plugin missing package E2E", () => {
  40. after(async () => {
  41. await browser.electron.restoreAllMocks();
  42. await clearAppData();
  43. });
  44. it("keeps the project declaration without auto-install, then runs after explicit install", async function () {
  45. this.timeout(300000);
  46. const { workspace } = getE2EAppDataPaths();
  47. const workspaceConfigPath = join(workspace, ".zcode", "config.json");
  48. await mkdir(join(workspace, ".zcode"), { recursive: true });
  49. await writeFile(
  50. workspaceConfigPath,
  51. `${JSON.stringify({ plugins: { enabledPlugins: { [PLUGIN_LIFECYCLE_ID]: true } } }, null, 2)}\n`,
  52. "utf8",
  53. );
  54. const fixture = await createPluginLifecycleFixture("1.0.0");
  55. const installedPluginsPath = pluginStoragePath("installed_plugins.json");
  56. expect(await readOptionalText(installedPluginsPath)).toBeNull();
  57. await openPluginSettings();
  58. await addLifecycleMarketplaceThroughUi(fixture);
  59. await clickTestIdByDom("plugin-store-segment-personal");
  60. await waitForPluginCard(PLUGIN_LIFECYCLE_ID);
  61. const beforeInstall = await getPluginOverview();
  62. expect(beforeInstall.availablePlugins).toEqual(
  63. expect.arrayContaining([
  64. expect.objectContaining({
  65. id: PLUGIN_LIFECYCLE_ID,
  66. installed: false,
  67. marketplace: PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  68. }),
  69. ]),
  70. );
  71. expect(beforeInstall.installedPlugins).not.toEqual(
  72. expect.arrayContaining([expect.objectContaining({ id: PLUGIN_LIFECYCLE_ID })]),
  73. );
  74. expect(await readOptionalText(installedPluginsPath)).toBeNull();
  75. await openPluginCard(PLUGIN_LIFECYCLE_ID);
  76. await installPluginThroughUi(PLUGIN_LIFECYCLE_ID);
  77. const afterInstall = await getPluginOverview();
  78. expect(afterInstall.installedPlugins).toEqual(
  79. expect.arrayContaining([
  80. expect.objectContaining({ id: PLUGIN_LIFECYCLE_ID, scope: "user" }),
  81. ]),
  82. );
  83. expect(await readFile(workspaceConfigPath, "utf8")).toContain(PLUGIN_LIFECYCLE_ID);
  84. expect(await readFile(installedPluginsPath, "utf8")).toContain(PLUGIN_LIFECYCLE_ID);
  85. await startNewTask();
  86. await assertLifecycleRuntimeAfterExplicitInstall();
  87. });
  88. });
  89. async function assertLifecycleRuntimeAfterExplicitInstall(): Promise<void> {
  90. await prepareConversationE2E();
  91. await ensureToolCrossProductFullAccessMode();
  92. await startNewTask();
  93. const marker = `${PLUGIN_LIFECYCLE_RUNTIME_MARKER}_1.0.0`;
  94. await sendPrompt(
  95. `${marker}: Call ${PLUGIN_LIFECYCLE_MCP_TOOL_NAME} exactly once, then reply with exactly ${E2E_REPLY_TOKEN}.`,
  96. );
  97. await waitForUpstreamRequestContaining(marker, 60000);
  98. const requestRecord = await findUpstreamRequestContaining(marker, 60000, {
  99. advertisedToolName: PLUGIN_LIFECYCLE_MCP_TOOL_NAME,
  100. });
  101. expect(requestRecord).not.toBeNull();
  102. if (!requestRecord) return;
  103. expect(captureArtifactAdvertisesToolName(requestRecord.requestJson, PLUGIN_LIFECYCLE_MCP_TOOL_NAME)).toBe(true);
  104. await browser.waitUntil(
  105. async () => {
  106. await respondToToolCrossProductBlockers();
  107. return Boolean((await getToolCallBlockByToolName(PLUGIN_LIFECYCLE_MCP_TOOL_NAME))?.exists);
  108. },
  109. { timeout: 60000, timeoutMsg: "Missing-package Plugin MCP call did not render" },
  110. );
  111. await waitForAssistantMessageContaining(E2E_REPLY_TOKEN);
  112. }
  113. async function readOptionalText(path: string): Promise<string | null> {
  114. try {
  115. return await readFile(path, "utf8");
  116. } catch (error) {
  117. if (
  118. error &&
  119. typeof error === "object" &&
  120. "code" in error &&
  121. (error as { code?: string }).code === "ENOENT"
  122. ) {
  123. return null;
  124. }
  125. throw error;
  126. }
  127. }