Skip to content

Commit 569d489

Browse files
committed
fix: preserve install records during registry refresh
1 parent babbad8 commit 569d489

3 files changed

Lines changed: 102 additions & 3 deletions

File tree

‎src/plugins/installed-plugin-index-store.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,55 @@ describe("installed plugin index persistence", () => {
254254
plugins: [expect.objectContaining({ pluginId: "demo" })],
255255
});
256256
});
257+
258+
it("preserves existing install records when refreshing the manifest cache", async () => {
259+
const stateDir = makeTempDir();
260+
await writePersistedInstalledPluginIndex(
261+
createIndex({
262+
installRecords: {
263+
missing: {
264+
source: "npm",
265+
266+
installPath: path.join(stateDir, "plugins", "missing"),
267+
},
268+
},
269+
plugins: [],
270+
}),
271+
{ stateDir },
272+
);
273+
274+
const index = await refreshPersistedInstalledPluginIndex({
275+
reason: "manual",
276+
stateDir,
277+
candidates: [],
278+
env: {
279+
OPENCLAW_BUNDLED_PLUGINS_DIR: undefined,
280+
OPENCLAW_DISABLE_PLUGIN_DISCOVERY_CACHE: "1",
281+
OPENCLAW_DISABLE_PLUGIN_MANIFEST_CACHE: "1",
282+
OPENCLAW_VERSION: "2026.4.25",
283+
VITEST: "true",
284+
},
285+
});
286+
287+
expect(index).toMatchObject({
288+
installRecords: {
289+
missing: {
290+
source: "npm",
291+
292+
installPath: path.join(stateDir, "plugins", "missing"),
293+
},
294+
},
295+
plugins: [],
296+
});
297+
await expect(readPersistedInstalledPluginIndex({ stateDir })).resolves.toMatchObject({
298+
installRecords: {
299+
missing: {
300+
source: "npm",
301+
302+
installPath: path.join(stateDir, "plugins", "missing"),
303+
},
304+
},
305+
plugins: [],
306+
});
307+
});
257308
});

‎src/plugins/installed-plugin-index-store.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,25 @@ export async function inspectPersistedInstalledPluginIndex(
198198
export async function refreshPersistedInstalledPluginIndex(
199199
params: RefreshInstalledPluginIndexParams & InstalledPluginIndexStoreOptions,
200200
): Promise<InstalledPluginIndex> {
201-
const index = refreshInstalledPluginIndex(params);
201+
const persisted = params.installRecords ? null : await readPersistedInstalledPluginIndex(params);
202+
const index = refreshInstalledPluginIndex({
203+
...params,
204+
installRecords:
205+
params.installRecords ?? extractPluginInstallRecordsFromInstalledPluginIndex(persisted),
206+
});
202207
await writePersistedInstalledPluginIndex(index, params);
203208
return index;
204209
}
205210

206211
export function refreshPersistedInstalledPluginIndexSync(
207212
params: RefreshInstalledPluginIndexParams & InstalledPluginIndexStoreOptions,
208213
): InstalledPluginIndex {
209-
const index = refreshInstalledPluginIndex(params);
214+
const persisted = params.installRecords ? null : readPersistedInstalledPluginIndexSync(params);
215+
const index = refreshInstalledPluginIndex({
216+
...params,
217+
installRecords:
218+
params.installRecords ?? extractPluginInstallRecordsFromInstalledPluginIndex(persisted),
219+
});
210220
writePersistedInstalledPluginIndexSync(index, params);
211221
return index;
212222
}

‎src/plugins/plugin-registry.test.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import fs from "node:fs";
22
import path from "node:path";
33
import { afterEach, describe, expect, it } from "vitest";
44
import type { PluginCandidate } from "./discovery.js";
5-
import { writePersistedInstalledPluginIndex } from "./installed-plugin-index-store.js";
5+
import {
6+
readPersistedInstalledPluginIndex,
7+
writePersistedInstalledPluginIndex,
8+
} from "./installed-plugin-index-store.js";
69
import {
710
resolveInstalledPluginIndexPolicyHash,
811
type InstalledPluginIndex,
@@ -385,4 +388,39 @@ describe("plugin registry facade", () => {
385388
},
386389
});
387390
});
391+
392+
it("preserves install records when refreshing the persisted registry", async () => {
393+
const stateDir = makeTempDir();
394+
await writePersistedInstalledPluginIndex(
395+
createIndex("missing", {
396+
installRecords: {
397+
missing: {
398+
source: "npm",
399+
400+
installPath: path.join(stateDir, "plugins", "missing"),
401+
},
402+
},
403+
plugins: [],
404+
}),
405+
{ stateDir },
406+
);
407+
408+
await refreshPluginRegistry({
409+
reason: "manual",
410+
stateDir,
411+
candidates: [],
412+
env: hermeticEnv(),
413+
});
414+
415+
await expect(readPersistedInstalledPluginIndex({ stateDir })).resolves.toMatchObject({
416+
installRecords: {
417+
missing: {
418+
source: "npm",
419+
420+
installPath: path.join(stateDir, "plugins", "missing"),
421+
},
422+
},
423+
plugins: [],
424+
});
425+
});
388426
});

0 commit comments

Comments
 (0)