fix: reject unscoped workspace plugin metadata

This commit is contained in:
Shakker
2026-04-27 17:34:44 +01:00
parent 4ceae8262f
commit 51c7f544f3
2 changed files with 12 additions and 1 deletions

View File

@@ -67,7 +67,7 @@ describe("current plugin metadata snapshot", () => {
expect(getCurrentPluginMetadataSnapshot({ config, workspaceDir: "/workspace/a" })).toBe(
snapshot,
);
expect(getCurrentPluginMetadataSnapshot({ config })).toBe(snapshot);
expect(getCurrentPluginMetadataSnapshot({ config })).toBeUndefined();
expect(
getCurrentPluginMetadataSnapshot({
config: { plugins: { allow: ["other"] } },
@@ -79,6 +79,14 @@ describe("current plugin metadata snapshot", () => {
).toBeUndefined();
});
it("rejects a workspace-scoped snapshot when the caller does not provide workspace scope", () => {
const config = { plugins: { allow: ["demo"] } };
const snapshot = createSnapshot({ config, workspaceDir: "/workspace/a" });
setCurrentPluginMetadataSnapshot(snapshot, { config });
expect(getCurrentPluginMetadataSnapshot({ config })).toBeUndefined();
});
it("rejects a current snapshot when plugin load paths change", () => {
const config = { plugins: { load: { paths: ["/plugins/one"] } } };
const snapshot = createSnapshot({ config });

View File

@@ -63,6 +63,9 @@ export function getCurrentPluginMetadataSnapshot(
) {
return undefined;
}
if (snapshot.workspaceDir !== undefined && params.workspaceDir === undefined) {
return undefined;
}
if (
params.workspaceDir !== undefined &&
(snapshot.workspaceDir ?? "") !== (params.workspaceDir ?? "")