mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 09:50:46 +00:00
fix: require default discovery for metadata reuse
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user