From d0d93d0fde204646687ac03813147e4298be3a9c Mon Sep 17 00:00:00 2001 From: Shakker Date: Sun, 26 Apr 2026 03:58:12 +0100 Subject: [PATCH] test: harden bundle index reconstruction --- .../manifest-registry-installed.test.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/plugins/manifest-registry-installed.test.ts b/src/plugins/manifest-registry-installed.test.ts index 353f850894f..3285ccd3384 100644 --- a/src/plugins/manifest-registry-installed.test.ts +++ b/src/plugins/manifest-registry-installed.test.ts @@ -1,6 +1,10 @@ import fs from "node:fs"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { + readPersistedInstalledPluginIndex, + writePersistedInstalledPluginIndex, +} from "./installed-plugin-index-store.js"; import type { InstalledPluginIndex } from "./installed-plugin-index.js"; import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js"; import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js"; @@ -137,4 +141,73 @@ describe("loadPluginManifestRegistryForInstalledIndex", () => { }), ]); }); + + it("round-trips bundle metadata through the persisted index before reconstruction", async () => { + const stateDir = makeTempDir(); + const rootDir = makeTempDir(); + fs.mkdirSync(path.join(rootDir, ".claude-plugin"), { recursive: true }); + fs.mkdirSync(path.join(rootDir, "commands"), { recursive: true }); + fs.writeFileSync( + path.join(rootDir, ".claude-plugin", "plugin.json"), + JSON.stringify({ + name: "Claude Bundle", + commands: "commands", + }), + "utf8", + ); + + const index = createIndex(rootDir); + await writePersistedInstalledPluginIndex( + { + ...index, + plugins: [ + { + ...index.plugins[0], + pluginId: "claude-bundle", + manifestPath: path.join(rootDir, ".claude-plugin", "plugin.json"), + source: rootDir, + format: "bundle", + bundleFormat: "claude", + setupSource: path.join(rootDir, "setup-api.js"), + }, + ], + }, + { stateDir }, + ); + + const persisted = await readPersistedInstalledPluginIndex({ stateDir }); + if (!persisted) { + throw new Error("expected persisted installed plugin index"); + } + expect(persisted?.plugins[0]).toMatchObject({ + pluginId: "claude-bundle", + source: rootDir, + format: "bundle", + bundleFormat: "claude", + setupSource: path.join(rootDir, "setup-api.js"), + rootDir, + }); + + const registry = loadPluginManifestRegistryForInstalledIndex({ + index: persisted, + env: { + OPENCLAW_DISABLE_PLUGIN_DISCOVERY_CACHE: "1", + OPENCLAW_DISABLE_PLUGIN_MANIFEST_CACHE: "1", + OPENCLAW_VERSION: "2026.4.25", + VITEST: "true", + }, + includeDisabled: true, + }); + + expect(registry.diagnostics).toEqual([]); + expect(registry.plugins).toEqual([ + expect.objectContaining({ + id: "claude-bundle", + format: "bundle", + bundleFormat: "claude", + rootDir, + skills: ["commands"], + }), + ]); + }); });