diff --git a/src/plugins/plugin-registry.test.ts b/src/plugins/plugin-registry.test.ts index 3020411627d..6dda1b905a4 100644 --- a/src/plugins/plugin-registry.test.ts +++ b/src/plugins/plugin-registry.test.ts @@ -309,6 +309,13 @@ describe("plugin registry facade", () => { policyHash: resolveInstalledPluginIndexPolicyHash({ plugins: { entries: { persisted: { enabled: true } } }, }), + installRecords: { + persisted: { + source: "npm", + spec: "persisted-plugin@1.0.0", + installPath: path.join(stateDir, "plugins", "persisted"), + }, + }, }), { stateDir }, ); @@ -329,6 +336,12 @@ describe("plugin registry facade", () => { expect(listPluginRecords({ index: result.snapshot }).map((plugin) => plugin.pluginId)).toEqual([ "demo", ]); + expect(result.snapshot.installRecords).toMatchObject({ + persisted: { + source: "npm", + spec: "persisted-plugin@1.0.0", + }, + }); }); it("falls back to the derived registry when the persisted registry is missing", () => { diff --git a/src/plugins/plugin-registry.ts b/src/plugins/plugin-registry.ts index 207a3e35d96..f674212ae93 100644 --- a/src/plugins/plugin-registry.ts +++ b/src/plugins/plugin-registry.ts @@ -326,12 +326,13 @@ export function loadPluginRegistrySnapshotWithMetadata( const disabledByCaller = params.preferPersisted === false; const disabledByEnv = hasEnvFlag(env, DISABLE_PERSISTED_PLUGIN_REGISTRY_ENV); const persistedReadsEnabled = !disabledByCaller && !disabledByEnv; + let persistedIndex: InstalledPluginIndex | null = null; if (persistedReadsEnabled) { - const persisted = readPersistedInstalledPluginIndexSync(params); - if (persisted) { + persistedIndex = readPersistedInstalledPluginIndexSync(params); + if (persistedIndex) { if ( params.config && - persisted.policyHash !== resolveInstalledPluginIndexPolicyHash(params.config) + persistedIndex.policyHash !== resolveInstalledPluginIndexPolicyHash(params.config) ) { diagnostics.push({ level: "warn", @@ -341,7 +342,7 @@ export function loadPluginRegistrySnapshotWithMetadata( }); } else { return { - snapshot: persisted, + snapshot: persistedIndex, source: "persisted", diagnostics, }; @@ -368,9 +369,7 @@ export function loadPluginRegistrySnapshotWithMetadata( ...params, installRecords: params.installRecords ?? - extractPluginInstallRecordsFromInstalledPluginIndex( - persistedReadsEnabled ? readPersistedInstalledPluginIndexSync(params) : null, - ), + extractPluginInstallRecordsFromInstalledPluginIndex(persistedIndex), }), source: "derived", diagnostics,