diff --git a/src/services/zoo-migration/ZooMigration.ts b/src/services/zoo-migration/ZooMigration.ts index fe18ab7b63..13b23f4321 100644 --- a/src/services/zoo-migration/ZooMigration.ts +++ b/src/services/zoo-migration/ZooMigration.ts @@ -202,10 +202,13 @@ export async function showZooMigrationNotice( export async function installOrShowZooExtension(): Promise { try { await vscode.commands.executeCommand("workbench.extensions.installExtension", ZOO_EXTENSION_ID) - } catch { - await vscode.commands.executeCommand("workbench.extensions.search", ZOO_EXTENSION_ID) - await vscode.window.showInformationMessage(t("common:zooMigration.installUnavailable")) - } + if (vscode.extensions.getExtension(ZOO_EXTENSION_ID)) { + return + } + } catch {} + + await vscode.commands.executeCommand("workbench.extensions.search", ZOO_EXTENSION_ID) + await vscode.window.showInformationMessage(t("common:zooMigration.installUnavailable")) } export async function promptAndCreateZooMigrationHandoff(options: { diff --git a/src/services/zoo-migration/__tests__/ZooMigration.spec.ts b/src/services/zoo-migration/__tests__/ZooMigration.spec.ts index ac5f0e19e4..f81cf84dcf 100644 --- a/src/services/zoo-migration/__tests__/ZooMigration.spec.ts +++ b/src/services/zoo-migration/__tests__/ZooMigration.spec.ts @@ -207,6 +207,7 @@ describe("installOrShowZooExtension", () => { it("installs the published Zoo Code marketplace extension", async () => { const executeCommand = vi.spyOn(vscode.commands, "executeCommand").mockResolvedValue(undefined) + vi.spyOn(vscode.extensions, "getExtension").mockReturnValue({} as any) await installOrShowZooExtension() @@ -214,6 +215,7 @@ describe("installOrShowZooExtension", () => { "workbench.extensions.installExtension", "ZooCodeOrganization.zoo-code", ) + expect(executeCommand).toHaveBeenCalledTimes(1) }) it("falls back to extension search when the configured gallery cannot install Zoo Code yet", async () => { @@ -233,6 +235,23 @@ describe("installOrShowZooExtension", () => { expect(executeCommand).toHaveBeenNthCalledWith(2, "workbench.extensions.search", "ZooCodeOrganization.zoo-code") expect(showInformationMessage).toHaveBeenCalled() }) + + it("falls back to extension search when install resolves without installing Zoo Code", async () => { + const executeCommand = vi.spyOn(vscode.commands, "executeCommand").mockResolvedValue(undefined) + vi.spyOn(vscode.extensions, "getExtension").mockReturnValue(undefined) + const showInformationMessage = vi.spyOn(vscode.window, "showInformationMessage").mockResolvedValue(undefined) + + await installOrShowZooExtension() + + expect(executeCommand).toHaveBeenNthCalledWith( + 1, + "workbench.extensions.installExtension", + "ZooCodeOrganization.zoo-code", + ) + expect(vscode.extensions.getExtension).toHaveBeenCalledWith("ZooCodeOrganization.zoo-code") + expect(executeCommand).toHaveBeenNthCalledWith(2, "workbench.extensions.search", "ZooCodeOrganization.zoo-code") + expect(showInformationMessage).toHaveBeenCalled() + }) }) function makeContext(globalStoragePath: string): vscode.ExtensionContext {