Skip to content

Commit 51c7f54

Browse files
committed
fix: reject unscoped workspace plugin metadata
1 parent 4ceae82 commit 51c7f54

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/plugins/current-plugin-metadata-snapshot.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe("current plugin metadata snapshot", () => {
6767
expect(getCurrentPluginMetadataSnapshot({ config, workspaceDir: "/workspace/a" })).toBe(
6868
snapshot,
6969
);
70-
expect(getCurrentPluginMetadataSnapshot({ config })).toBe(snapshot);
70+
expect(getCurrentPluginMetadataSnapshot({ config })).toBeUndefined();
7171
expect(
7272
getCurrentPluginMetadataSnapshot({
7373
config: { plugins: { allow: ["other"] } },
@@ -79,6 +79,14 @@ describe("current plugin metadata snapshot", () => {
7979
).toBeUndefined();
8080
});
8181

82+
it("rejects a workspace-scoped snapshot when the caller does not provide workspace scope", () => {
83+
const config = { plugins: { allow: ["demo"] } };
84+
const snapshot = createSnapshot({ config, workspaceDir: "/workspace/a" });
85+
setCurrentPluginMetadataSnapshot(snapshot, { config });
86+
87+
expect(getCurrentPluginMetadataSnapshot({ config })).toBeUndefined();
88+
});
89+
8290
it("rejects a current snapshot when plugin load paths change", () => {
8391
const config = { plugins: { load: { paths: ["/plugins/one"] } } };
8492
const snapshot = createSnapshot({ config });

src/plugins/current-plugin-metadata-snapshot.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export function getCurrentPluginMetadataSnapshot(
6363
) {
6464
return undefined;
6565
}
66+
if (snapshot.workspaceDir !== undefined && params.workspaceDir === undefined) {
67+
return undefined;
68+
}
6669
if (
6770
params.workspaceDir !== undefined &&
6871
(snapshot.workspaceDir ?? "") !== (params.workspaceDir ?? "")

0 commit comments

Comments
 (0)