fix(plugins): invalidate index on policy changes

This commit is contained in:
Vincent Koc
2026-04-25 01:20:16 -07:00
parent b001b8c947
commit 36219b0ffc
3 changed files with 62 additions and 0 deletions

View File

@@ -154,6 +154,30 @@ describe("installed plugin index persistence", () => {
},
});
await expect(
inspectPersistedInstalledPluginIndex({
stateDir,
candidates: [candidate],
config: {
plugins: {
entries: {
demo: {
enabled: false,
},
},
},
},
env,
}),
).resolves.toMatchObject({
state: "stale",
refreshReasons: ["policy-changed"],
persisted: current,
current: {
plugins: [expect.objectContaining({ pluginId: "demo", enabled: false })],
},
});
fs.writeFileSync(
path.join(pluginDir, "openclaw.plugin.json"),
JSON.stringify({

View File

@@ -466,6 +466,40 @@ describe("installed plugin index", () => {
]);
});
it("treats enablement changes as policy invalidation", () => {
const fixture = createRichPluginFixture();
const previous = loadInstalledPluginIndex({
candidates: [fixture.candidate],
config: {
plugins: {
entries: {
demo: {
enabled: true,
},
},
},
},
env: hermeticEnv(),
});
const current = loadInstalledPluginIndex({
candidates: [fixture.candidate],
config: {
plugins: {
entries: {
demo: {
enabled: false,
},
},
},
},
env: hermeticEnv(),
});
expect(diffInstalledPluginIndexInvalidationReasons(previous, current)).toEqual([
"policy-changed",
]);
});
it("marks disabled plugins without dropping their cold contributions", () => {
const fixture = createRichPluginFixture();

View File

@@ -29,6 +29,7 @@ export type InstalledPluginIndexRefreshReason =
| "stale-manifest"
| "stale-package"
| "source-changed"
| "policy-changed"
| "host-contract-changed"
| "compat-registry-changed"
| "manual";
@@ -613,6 +614,9 @@ export function diffInstalledPluginIndexInvalidationReasons(
) {
reasons.add("source-changed");
}
if (previousPlugin.enabled !== currentPlugin.enabled) {
reasons.add("policy-changed");
}
if (previousPlugin.manifestHash !== currentPlugin.manifestHash) {
reasons.add("stale-manifest");
}