mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:50:43 +00:00
perf: reuse metadata for bundle settings
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
normalizePluginsConfigWithResolver,
|
||||
resolveEffectivePluginActivationState,
|
||||
} from "../plugins/config-policy.js";
|
||||
import { getCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js";
|
||||
import {
|
||||
isPluginMetadataSnapshotCompatible,
|
||||
loadPluginMetadataSnapshot,
|
||||
@@ -84,11 +85,21 @@ export function loadEnabledBundlePiSettingsSnapshot(params: {
|
||||
workspaceDir,
|
||||
})
|
||||
? providedSnapshot
|
||||
: loadPluginMetadataSnapshot({
|
||||
: (getCurrentPluginMetadataSnapshot({
|
||||
config,
|
||||
env,
|
||||
workspaceDir,
|
||||
}) ??
|
||||
getCurrentPluginMetadataSnapshot({
|
||||
env,
|
||||
workspaceDir,
|
||||
allowWorkspaceScopedSnapshot: true,
|
||||
}) ??
|
||||
loadPluginMetadataSnapshot({
|
||||
workspaceDir,
|
||||
config,
|
||||
env,
|
||||
});
|
||||
}));
|
||||
const registry = metadataSnapshot.manifestRegistry;
|
||||
if (registry.plugins.length === 0) {
|
||||
return {};
|
||||
|
||||
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createTrackedTempDirs } from "../test-utils/tracked-temp-dirs.js";
|
||||
|
||||
const pluginMetadataSnapshotMocks = vi.hoisted(() => ({
|
||||
getCurrentPluginMetadataSnapshot: vi.fn(),
|
||||
isPluginMetadataSnapshotCompatible: vi.fn(),
|
||||
loadPluginMetadataSnapshot: vi.fn(),
|
||||
}));
|
||||
@@ -84,6 +85,10 @@ vi.mock("../plugins/plugin-registry.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../plugins/current-plugin-metadata-snapshot.js", () => ({
|
||||
getCurrentPluginMetadataSnapshot: pluginMetadataSnapshotMocks.getCurrentPluginMetadataSnapshot,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/plugin-metadata-snapshot.js", async () => {
|
||||
const fs = await import("node:fs");
|
||||
const path = await import("node:path");
|
||||
@@ -172,6 +177,8 @@ const tempDirs = createTrackedTempDirs();
|
||||
|
||||
afterEach(async () => {
|
||||
await tempDirs.cleanup();
|
||||
pluginMetadataSnapshotMocks.getCurrentPluginMetadataSnapshot.mockReset();
|
||||
pluginMetadataSnapshotMocks.getCurrentPluginMetadataSnapshot.mockReturnValue(undefined);
|
||||
pluginMetadataSnapshotMocks.isPluginMetadataSnapshotCompatible.mockClear();
|
||||
pluginMetadataSnapshotMocks.loadPluginMetadataSnapshot.mockClear();
|
||||
});
|
||||
@@ -275,6 +282,49 @@ describe("loadEnabledBundlePiSettingsSnapshot", () => {
|
||||
expect(pluginMetadataSnapshotMocks.loadPluginMetadataSnapshot).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("reuses the current plugin metadata snapshot for bundle settings", async () => {
|
||||
const workspaceDir = await tempDirs.make("openclaw-workspace-");
|
||||
const pluginRoot = await createWorkspaceBundle({ workspaceDir });
|
||||
const resolvedPluginRoot = await fs.realpath(pluginRoot);
|
||||
await fs.writeFile(
|
||||
path.join(pluginRoot, "settings.json"),
|
||||
JSON.stringify({ hideThinkingBlock: true }),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
pluginMetadataSnapshotMocks.getCurrentPluginMetadataSnapshot.mockReturnValueOnce({
|
||||
manifestRegistry: {
|
||||
diagnostics: [],
|
||||
plugins: [
|
||||
{
|
||||
id: "claude-bundle",
|
||||
origin: "workspace",
|
||||
format: "bundle",
|
||||
bundleFormat: "claude",
|
||||
settingsFiles: ["settings.json"],
|
||||
rootDir: resolvedPluginRoot,
|
||||
},
|
||||
],
|
||||
},
|
||||
normalizePluginId: (id: string) => id.trim(),
|
||||
});
|
||||
pluginMetadataSnapshotMocks.loadPluginMetadataSnapshot.mockClear();
|
||||
|
||||
const snapshot = loadEnabledBundlePiSettingsSnapshot({
|
||||
cwd: workspaceDir,
|
||||
cfg: {
|
||||
plugins: {
|
||||
entries: {
|
||||
"claude-bundle": { enabled: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(snapshot.hideThinkingBlock).toBe(true);
|
||||
expect(pluginMetadataSnapshotMocks.loadPluginMetadataSnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("loads sanitized settings and MCP defaults from enabled bundle plugins", async () => {
|
||||
const workspaceDir = await tempDirs.make("openclaw-workspace-");
|
||||
const pluginRoot = await createWorkspaceBundle({ workspaceDir });
|
||||
|
||||
Reference in New Issue
Block a user