mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:20:42 +00:00
fix(plugins): honor registry migration disable in doctor
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,7 +28,6 @@ type PluginRegistryDoctorRepairParams = Omit<PluginRegistryInstallMigrationParam
|
||||
type LegacyInstallLedgerMigrationResult = {
|
||||
config: OpenClawConfig;
|
||||
migrated: boolean;
|
||||
recordCount: number;
|
||||
};
|
||||
|
||||
function countRecords(records: Record<string, unknown> | 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<OpenClawConfig> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user