






















@@ -3,7 +3,10 @@ import path from "node:path";
33import { afterEach, describe, expect, it } from "vitest";
44import type { PluginCandidate } from "./discovery.js";
55import { writePersistedInstalledPluginIndex } from "./installed-plugin-index-store.js";
6-import type { InstalledPluginIndex } from "./installed-plugin-index.js";
6+import {
7+resolveInstalledPluginIndexPolicyHash,
8+type InstalledPluginIndex,
9+} from "./installed-plugin-index.js";
710import {
811DISABLE_PERSISTED_PLUGIN_REGISTRY_ENV,
912createPluginRegistryIdNormalizer,
@@ -91,7 +94,10 @@ function createCandidate(rootDir: string): PluginCandidate {
9194};
9295}
939694-function createIndex(pluginId = "demo"): InstalledPluginIndex {
97+function createIndex(
98+pluginId = "demo",
99+overrides: Partial<InstalledPluginIndex> = {},
100+): InstalledPluginIndex {
95101return {
96102version: 1,
97103hostContractVersion: "2026.4.25",
@@ -127,6 +133,7 @@ function createIndex(pluginId = "demo"): InstalledPluginIndex {
127133},
128134],
129135diagnostics: [],
136+ ...overrides,
130137};
131138}
132139@@ -241,11 +248,18 @@ describe("plugin registry facade", () => {
241248const stateDir = makeTempDir();
242249const rootDir = makeTempDir();
243250const candidate = createCandidate(rootDir);
244-await writePersistedInstalledPluginIndex(createIndex("persisted"), { stateDir });
251+const config = {} as const;
252+await writePersistedInstalledPluginIndex(
253+createIndex("persisted", {
254+policyHash: resolveInstalledPluginIndexPolicyHash(config),
255+}),
256+{ stateDir },
257+);
245258246259const result = loadPluginRegistrySnapshotWithMetadata({
247260 stateDir,
248261candidates: [candidate],
262+ config,
249263env: hermeticEnv(),
250264});
251265@@ -256,6 +270,37 @@ describe("plugin registry facade", () => {
256270]);
257271});
258272273+it("falls back to the derived registry when persisted policy is stale", async () => {
274+const stateDir = makeTempDir();
275+const rootDir = makeTempDir();
276+const candidate = createCandidate(rootDir);
277+await writePersistedInstalledPluginIndex(
278+createIndex("persisted", {
279+policyHash: resolveInstalledPluginIndexPolicyHash({
280+plugins: { entries: { persisted: { enabled: true } } },
281+}),
282+}),
283+{ stateDir },
284+);
285+286+const result = loadPluginRegistrySnapshotWithMetadata({
287+ stateDir,
288+candidates: [candidate],
289+config: {
290+plugins: { entries: { demo: { enabled: true } } },
291+},
292+env: hermeticEnv(),
293+});
294+295+expect(result.source).toBe("derived");
296+expect(result.diagnostics).toEqual([
297+expect.objectContaining({ code: "persisted-registry-stale-policy" }),
298+]);
299+expect(listPluginRecords({ index: result.snapshot }).map((plugin) => plugin.pluginId)).toEqual([
300+"demo",
301+]);
302+});
303+259304it("falls back to the derived registry when the persisted registry is missing", () => {
260305const stateDir = makeTempDir();
261306const rootDir = makeTempDir();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。