From 1d49b8cdaa4a9c57d44a42505984aa7104fa6953 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 25 Apr 2026 12:42:16 -0700 Subject: [PATCH] fix(plugins): honor registry migration disable in doctor --- src/commands/doctor-plugin-registry.test.ts | 27 +++++++++++++++++++++ src/commands/doctor-plugin-registry.ts | 24 ++++++++---------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/commands/doctor-plugin-registry.test.ts b/src/commands/doctor-plugin-registry.test.ts index 3dc4022c913..8a96ea45fae 100644 --- a/src/commands/doctor-plugin-registry.test.ts +++ b/src/commands/doctor-plugin-registry.test.ts @@ -11,6 +11,7 @@ import type { InstalledPluginIndex } from "../plugins/installed-plugin-index.js" import { cleanupTrackedTempDirs, makeTrackedTempDir } from "../plugins/test-helpers/fs-fixtures.js"; import { note } from "../terminal/note.js"; import { maybeRepairPluginRegistryState } from "./doctor-plugin-registry.js"; +import { DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV } from "./doctor/shared/plugin-registry-migration.js"; vi.mock("../terminal/note.js", () => ({ note: vi.fn(), @@ -146,4 +147,30 @@ describe("maybeRepairPluginRegistryState", () => { ], }); }); + + it("does not mutate legacy install records when registry migration is disabled", async () => { + const stateDir = makeTempDir(); + + const nextConfig = await maybeRepairPluginRegistryState({ + stateDir, + env: hermeticEnv({ + [DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV]: "1", + }), + config: { + plugins: { + installs: { + demo: { + source: "npm", + resolvedName: "@vendor/demo", + }, + }, + }, + }, + prompter: { shouldRepair: true }, + }); + + expect(nextConfig.plugins?.installs?.demo?.resolvedName).toBe("@vendor/demo"); + await expect(readPersistedPluginInstallLedger({ stateDir })).resolves.toBeNull(); + expect(vi.mocked(note).mock.calls.join("\n")).toContain(DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV); + }); }); diff --git a/src/commands/doctor-plugin-registry.ts b/src/commands/doctor-plugin-registry.ts index 628427619b1..a917f67b144 100644 --- a/src/commands/doctor-plugin-registry.ts +++ b/src/commands/doctor-plugin-registry.ts @@ -28,7 +28,6 @@ type PluginRegistryDoctorRepairParams = Omit | undefined): number { @@ -54,7 +53,6 @@ async function maybeMigrateLegacyInstallLedger( return { config: params.config, migrated: false, - recordCount: 0, }; } @@ -70,7 +68,6 @@ async function maybeMigrateLegacyInstallLedger( return { config: params.config, migrated: false, - recordCount: legacyCount, }; } @@ -88,22 +85,13 @@ async function maybeMigrateLegacyInstallLedger( return { config: nextConfig, migrated: true, - recordCount: legacyCount, }; } export async function maybeRepairPluginRegistryState( params: PluginRegistryDoctorRepairParams, ): Promise { - let nextConfig = params.config; - const ledgerMigration = await maybeMigrateLegacyInstallLedger(params); - nextConfig = ledgerMigration.config; - - const migrationParams = { - ...params, - config: nextConfig, - }; - const preflight = preflightPluginRegistryInstallMigration(migrationParams); + const preflight = preflightPluginRegistryInstallMigration(params); for (const warning of preflight.deprecationWarnings) { note(warning, "Plugin registry"); } @@ -112,9 +100,17 @@ export async function maybeRepairPluginRegistryState( `${DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV} is set; skipping plugin registry repair.`, "Plugin registry", ); - return nextConfig; + return params.config; } + let nextConfig = params.config; + const ledgerMigration = await maybeMigrateLegacyInstallLedger(params); + nextConfig = ledgerMigration.config; + + const migrationParams = { + ...params, + config: nextConfig, + }; if (!params.prompter.shouldRepair) { if (preflight.action === "migrate") { note(