Skip to content

Commit 9491efe

Browse files
author
Peter Steinberger
committed
test(gateway): avoid async facade mock race
1 parent ffcca75 commit 9491efe

2 files changed

Lines changed: 70 additions & 58 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { vi } from "vitest";
2+
3+
export {
4+
listAgentIds,
5+
resolveAgentDir,
6+
resolveAgentWorkspaceDir,
7+
resolveSessionAgentId,
8+
} from "../../../agents/agent-scope.js";
9+
export { getRegisteredAgentHarness } from "../../../agents/harness/registry.js";
10+
export { resolveReplyToMode } from "../../../auto-reply/reply/reply-threading.js";
11+
export { resolveRuntimeConfigCacheKey } from "../../../config/config.js";
12+
export { deliveryContextFromSession } from "../../../utils/delivery-context.shared.js";
13+
export { loadSessionEntryReadOnly, resolveSessionModelRef } from "../../session-utils.js";
14+
15+
export const toolsEffectiveGlobalAgentRuntimeMocks = {
16+
resolveEffectiveToolInventory: vi.fn(
17+
(params: { agentId: string; modelProvider?: string; modelId?: string }) => ({
18+
agentId: params.agentId,
19+
profile: "coding",
20+
groups: [
21+
{
22+
id: "core",
23+
label: "Built-in tools",
24+
source: "core",
25+
tools: [
26+
{
27+
id: "exec",
28+
label: "Exec",
29+
description: "Run shell commands",
30+
source: "core",
31+
},
32+
],
33+
},
34+
],
35+
modelProvider: params.modelProvider,
36+
modelId: params.modelId,
37+
}),
38+
),
39+
resolveEffectiveToolInventoryRuntimeModelContext: vi.fn((_params?: unknown) => ({
40+
modelApi: "openai-responses",
41+
runtimeModel: {
42+
id: "work-model",
43+
name: "Work model",
44+
provider: "openai",
45+
api: "openai-responses",
46+
baseUrl: "https://api.openai.com/v1",
47+
},
48+
})),
49+
resolveEffectiveToolInventoryRuntimeModelContextAsync: vi.fn(async (params: unknown) =>
50+
toolsEffectiveGlobalAgentRuntimeMocks.resolveEffectiveToolInventoryRuntimeModelContext(params),
51+
),
52+
};
53+
54+
export const resolveEffectiveToolInventory =
55+
toolsEffectiveGlobalAgentRuntimeMocks.resolveEffectiveToolInventory;
56+
export const resolveEffectiveToolInventoryRuntimeModelContextAsync =
57+
toolsEffectiveGlobalAgentRuntimeMocks.resolveEffectiveToolInventoryRuntimeModelContextAsync;
58+
export const peekSessionMcpRuntime = vi.fn(() => undefined);
59+
export const resolveSessionMcpConfigSummary = vi.fn(() => ({
60+
fingerprint: "mcp:0",
61+
serverNames: [] as string[],
62+
}));
63+
export const buildBundleMcpToolsFromCatalog = vi.fn(() => []);
64+
export const applyFinalEffectiveToolPolicy = vi.fn(
65+
(params: { bundledTools: unknown[] }) => params.bundledTools,
66+
);
67+
export const getActivePluginRegistryVersion = vi.fn(() => 1);
68+
export const getActivePluginChannelRegistryVersion = vi.fn(() => 1);

‎src/gateway/server-methods/tools-effective.global-agent.integration.test.ts‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,10 @@ import { expectDefined } from "@openclaw/normalization-core";
44
import { beforeEach, describe, expect, it, vi } from "vitest";
55
import { installGatewayTestHooks, testState, writeSessionStore } from "../test-helpers.js";
66
import { getGatewayConfigModule, sessionStoreEntry } from "../test/server-sessions.test-helpers.js";
7+
import { toolsEffectiveGlobalAgentRuntimeMocks as inventoryMocks } from "./__mocks__/tools-effective.runtime.js";
78
import { testing, toolsEffectiveHandlers } from "./tools-effective.js";
89

9-
const inventoryMocks = vi.hoisted(() => ({
10-
resolveEffectiveToolInventory: vi.fn(
11-
(params: { agentId: string; modelProvider?: string; modelId?: string }) => ({
12-
agentId: params.agentId,
13-
profile: "coding",
14-
groups: [
15-
{
16-
id: "core",
17-
label: "Built-in tools",
18-
source: "core",
19-
tools: [
20-
{
21-
id: "exec",
22-
label: "Exec",
23-
description: "Run shell commands",
24-
source: "core",
25-
},
26-
],
27-
},
28-
],
29-
modelProvider: params.modelProvider,
30-
modelId: params.modelId,
31-
}),
32-
),
33-
resolveEffectiveToolInventoryRuntimeModelContext: vi.fn((_params?: unknown) => ({
34-
modelApi: "openai-responses",
35-
runtimeModel: {
36-
id: "work-model",
37-
name: "Work model",
38-
provider: "openai",
39-
api: "openai-responses",
40-
baseUrl: "https://api.openai.com/v1",
41-
},
42-
})),
43-
resolveEffectiveToolInventoryRuntimeModelContextAsync: vi.fn(async (params: unknown) =>
44-
inventoryMocks.resolveEffectiveToolInventoryRuntimeModelContext(params),
45-
),
46-
}));
47-
48-
vi.mock("./tools-effective.runtime.js", async (importOriginal) => {
49-
const actual = await importOriginal<typeof import("./tools-effective.runtime.js")>();
50-
return {
51-
...actual,
52-
resolveEffectiveToolInventory: inventoryMocks.resolveEffectiveToolInventory,
53-
resolveEffectiveToolInventoryRuntimeModelContext:
54-
inventoryMocks.resolveEffectiveToolInventoryRuntimeModelContext,
55-
resolveEffectiveToolInventoryRuntimeModelContextAsync:
56-
inventoryMocks.resolveEffectiveToolInventoryRuntimeModelContextAsync,
57-
peekSessionMcpRuntime: vi.fn(() => undefined),
58-
resolveSessionMcpConfigSummary: vi.fn(() => ({ fingerprint: "mcp:0", serverNames: [] })),
59-
buildBundleMcpToolsFromCatalog: vi.fn(() => []),
60-
applyFinalEffectiveToolPolicy: vi.fn(
61-
(params: { bundledTools: unknown[] }) => params.bundledTools,
62-
),
63-
getActivePluginRegistryVersion: vi.fn(() => 1),
64-
getActivePluginChannelRegistryVersion: vi.fn(() => 1),
65-
};
66-
});
10+
vi.mock("./tools-effective.runtime.js");
6711

6812
installGatewayTestHooks();
6913

0 commit comments

Comments
 (0)