mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:20:43 +00:00
test: cover bundled MCP runtime cleanup gates
This commit is contained in:
@@ -162,6 +162,25 @@ describe("session MCP runtime", () => {
|
||||
expect(activeLeases).toBe(0);
|
||||
});
|
||||
|
||||
it("releases a runtime lease when catalog materialization fails", async () => {
|
||||
let activeLeases = 0;
|
||||
const runtime = {
|
||||
...makeRuntime([{ toolName: "bundle_probe", description: "Bundle MCP probe" }]),
|
||||
acquireLease: () => {
|
||||
activeLeases += 1;
|
||||
return () => {
|
||||
activeLeases -= 1;
|
||||
};
|
||||
},
|
||||
getCatalog: async () => {
|
||||
throw new Error("catalog failed");
|
||||
},
|
||||
};
|
||||
|
||||
await expect(materializeBundleMcpToolsForRun({ runtime })).rejects.toThrow("catalog failed");
|
||||
expect(activeLeases).toBe(0);
|
||||
});
|
||||
|
||||
it("reuses repeated materialization and recreates after explicit disposal", async () => {
|
||||
const created: SessionMcpRuntime[] = [];
|
||||
const disposed: string[] = [];
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
resolveAttemptFsWorkspaceOnly,
|
||||
resolveEmbeddedAgentStreamFn,
|
||||
resolveUnknownToolGuardThreshold,
|
||||
shouldCreateBundleMcpRuntimeForAttempt,
|
||||
resolvePromptBuildHookResult,
|
||||
resolvePromptModeForSession,
|
||||
shouldStripBootstrapFromEmbeddedContext,
|
||||
@@ -72,6 +73,34 @@ describe("applyEmbeddedAttemptToolsAllow", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldCreateBundleMcpRuntimeForAttempt", () => {
|
||||
it("skips bundle MCP when tools are disabled or unavailable", () => {
|
||||
expect(shouldCreateBundleMcpRuntimeForAttempt({ toolsEnabled: false })).toBe(false);
|
||||
expect(shouldCreateBundleMcpRuntimeForAttempt({ toolsEnabled: true, disableTools: true })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("creates bundle MCP only when the allowlist can reach bundle MCP tool names", () => {
|
||||
expect(shouldCreateBundleMcpRuntimeForAttempt({ toolsEnabled: true })).toBe(true);
|
||||
expect(shouldCreateBundleMcpRuntimeForAttempt({ toolsEnabled: true, toolsAllow: [] })).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
shouldCreateBundleMcpRuntimeForAttempt({
|
||||
toolsEnabled: true,
|
||||
toolsAllow: ["memory_search", "memory_get"],
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldCreateBundleMcpRuntimeForAttempt({
|
||||
toolsEnabled: true,
|
||||
toolsAllow: ["strict__strict_probe"],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolvePromptBuildHookResult", () => {
|
||||
function createLegacyOnlyHookRunner() {
|
||||
return {
|
||||
|
||||
@@ -466,7 +466,7 @@ export function applyEmbeddedAttemptToolsAllow<T extends { name: string }>(
|
||||
return tools.filter((tool) => allowSet.has(tool.name));
|
||||
}
|
||||
|
||||
function shouldCreateBundleMcpRuntimeForAttempt(params: {
|
||||
export function shouldCreateBundleMcpRuntimeForAttempt(params: {
|
||||
toolsEnabled: boolean;
|
||||
disableTools?: boolean;
|
||||
toolsAllow?: string[];
|
||||
|
||||
Reference in New Issue
Block a user