fix: require default discovery for metadata reuse

This commit is contained in:
Shakker
2026-05-07 06:35:36 +01:00
parent 917ccde7bf
commit a7cc9e8a56
8 changed files with 181 additions and 19 deletions

View File

@@ -182,15 +182,17 @@ function applyPluginAutoEnableForActivation(params: {
workspaceDir: params.workspaceDir,
allowWorkspaceScopedSnapshot: true,
});
const currentManifestRegistry =
currentSnapshot?.manifestRegistry ??
(normalizePluginsConfig(params.config.plugins).loadPaths.length === 0
const defaultDiscoverySnapshot =
normalizePluginsConfig(params.config.plugins).loadPaths.length === 0
? getCurrentPluginMetadataSnapshot({
env: params.env,
workspaceDir: params.workspaceDir,
allowWorkspaceScopedSnapshot: true,
})?.manifestRegistry
: undefined);
requireDefaultDiscoveryContext: true,
})
: undefined;
const currentManifestRegistry =
currentSnapshot?.manifestRegistry ?? defaultDiscoverySnapshot?.manifestRegistry;
return applyPluginAutoEnable({
config: params.config,
env: params.env,

View File

@@ -113,6 +113,32 @@ describe("current plugin metadata snapshot", () => {
).toBeUndefined();
});
it("rejects configless default-discovery reuse for snapshots created with load paths", () => {
const config = { plugins: { allow: ["demo"], load: { paths: ["/plugins/one"] } } };
const snapshot = createSnapshot({ config });
setCurrentPluginMetadataSnapshot(snapshot, { config });
expect(
getCurrentPluginMetadataSnapshot({
allowWorkspaceScopedSnapshot: true,
requireDefaultDiscoveryContext: true,
}),
).toBeUndefined();
});
it("accepts configless default-discovery reuse for snapshots created without load paths", () => {
const config = { plugins: { allow: ["demo"] } };
const snapshot = createSnapshot({ config });
setCurrentPluginMetadataSnapshot(snapshot, { config });
expect(
getCurrentPluginMetadataSnapshot({
allowWorkspaceScopedSnapshot: true,
requireDefaultDiscoveryContext: true,
}),
).toBe(snapshot);
});
it("rejects a current snapshot when env-resolved plugin load paths change", () => {
const config = { plugins: { load: { paths: ["~/plugins"] } } };
const snapshot = createSnapshot({ config });

View File

@@ -70,6 +70,7 @@ export function getCurrentPluginMetadataSnapshot(
env?: NodeJS.ProcessEnv;
workspaceDir?: string;
allowWorkspaceScopedSnapshot?: boolean;
requireDefaultDiscoveryContext?: boolean;
} = {},
): PluginMetadataSnapshot | undefined {
const {
@@ -110,6 +111,25 @@ export function getCurrentPluginMetadataSnapshot(
return undefined;
}
}
if (params.requireDefaultDiscoveryContext === true) {
const defaultDiscoveryConfigFingerprint = resolvePluginMetadataControlPlaneFingerprint(
{},
{
env: params.env,
index: snapshot.index,
policyHash: snapshot.policyHash,
workspaceDir: requestedWorkspaceDir,
},
);
const compatibleFingerprints = new Set(compatibleConfigFingerprints ?? []);
const fingerprintMatches =
configFingerprint === defaultDiscoveryConfigFingerprint ||
snapshot.configFingerprint === defaultDiscoveryConfigFingerprint ||
compatibleFingerprints.has(defaultDiscoveryConfigFingerprint);
if (!fingerprintMatches) {
return undefined;
}
}
if (snapshot.workspaceDir !== undefined && requestedWorkspaceDir === undefined) {
return undefined;
}