Skip to content

Commit 8103101

Browse files
authored
test(agents): consolidate OpenClaw tool suites (#117870)
* test(agents): consolidate OpenClaw tool suites * test(agents): align session status fixture types * test(agents): satisfy media fixture lint
1 parent 134dcac commit 8103101

20 files changed

Lines changed: 1188 additions & 1783 deletions

‎src/agents/openclaw-tools.browser-plugin.integration.test.ts‎

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import { resetConfigRuntimeState, setRuntimeConfigSnapshot } from "../config/con
77
import { activateSecretsRuntimeSnapshot, clearSecretsRuntimeSnapshot } from "../secrets/runtime.js";
88
import { getRuntimeAuthProfileStoreCredentialsRevision } from "./auth-profiles/runtime-snapshots.js";
99
import { resolveOpenClawPluginToolsForOptions } from "./openclaw-plugin-tools.js";
10+
import { createOpenClawTools } from "./openclaw-tools.js";
1011

1112
const hoisted = vi.hoisted(() => ({
1213
resolvePluginTools: vi.fn(),
1314
}));
1415
const TEST_AGENT_DIR = path.join(os.tmpdir(), "openclaw-plugin-tool-auth-test");
16+
const observedGatewayCallerIdentities: unknown[] = [];
1517

16-
vi.mock("../plugins/tools.js", () => ({
18+
vi.mock("../plugins/tools.js", async (importOriginal) => ({
19+
...(await importOriginal<typeof import("../plugins/tools.js")>()),
1720
resolvePluginTools: (...args: unknown[]) => hoisted.resolvePluginTools(...args),
1821
}));
1922

@@ -476,3 +479,87 @@ describe("createOpenClawTools browser plugin integration", () => {
476479
expect(getRuntimeConfig?.()?.plugins?.entries?.["memory-core"]?.enabled).toBe(false);
477480
});
478481
});
482+
483+
function requirePluginTool(name: string, overrides?: Parameters<typeof createOpenClawTools>[0]) {
484+
hoisted.resolvePluginTools.mockReturnValue([
485+
{
486+
name,
487+
label: "Synthetic direct cron plugin",
488+
description: "Calls Gateway cron directly like plugin-owned reminder tools.",
489+
parameters: { type: "object", properties: {} },
490+
execute: async () => {
491+
const { getGatewayToolCallerIdentity } = await import("./tools/gateway-caller-context.js");
492+
observedGatewayCallerIdentities.push(getGatewayToolCallerIdentity());
493+
return { content: [{ type: "text", text: "ok" }] };
494+
},
495+
},
496+
]);
497+
const tool = createOpenClawTools({
498+
agentSessionKey: "agent:main:discord:channel:123",
499+
disableMessageTool: true,
500+
pluginToolAllowlist: [name],
501+
requesterAgentIdOverride: "main",
502+
wrapBeforeToolCallHook: false,
503+
...overrides,
504+
}).find((candidate) => candidate.name === name);
505+
if (!tool?.execute) {
506+
throw new Error(`Expected executable tool ${name}`);
507+
}
508+
return tool;
509+
}
510+
511+
describe("createOpenClawTools Gateway caller identity", () => {
512+
afterEach(() => {
513+
observedGatewayCallerIdentities.length = 0;
514+
});
515+
516+
it("wraps plugin tools so direct cron Gateway calls inherit the agent identity", async () => {
517+
const tool = requirePluginTool("synthetic_direct_cron_plugin");
518+
await tool.execute("tool-call-1", {});
519+
520+
expect(observedGatewayCallerIdentities).toEqual([
521+
{ agentId: "main", sessionKey: "agent:main:discord:channel:123" },
522+
]);
523+
});
524+
525+
it("carries trusted turn-source routing with the agent identity", async () => {
526+
const tool = requirePluginTool("synthetic_direct_cron_plugin", {
527+
agentChannel: "discord",
528+
agentTo: "channel:123",
529+
agentAccountId: "work",
530+
agentThreadId: "thread-7",
531+
});
532+
await tool.execute("tool-call-2", {});
533+
534+
expect(observedGatewayCallerIdentities).toEqual([
535+
{
536+
agentId: "main",
537+
sessionKey: "agent:main:discord:channel:123",
538+
turnSourceChannel: "discord",
539+
turnSourceTo: "channel:123",
540+
turnSourceAccountId: "work",
541+
turnSourceThreadId: "thread-7",
542+
},
543+
]);
544+
});
545+
546+
it("uses scheduled creator account authority without changing live delivery routing", async () => {
547+
const tool = requirePluginTool("synthetic_direct_cron_plugin", {
548+
agentChannel: "discord",
549+
agentTo: "channel:123",
550+
agentAccountId: "delivery-account",
551+
gatewayCallerAccountId: "creator-account",
552+
});
553+
await tool.execute("tool-call-scheduled", {});
554+
555+
expect(observedGatewayCallerIdentities).toEqual([
556+
{
557+
agentId: "main",
558+
sessionKey: "agent:main:discord:channel:123",
559+
turnSourceChannel: "discord",
560+
turnSourceTo: "channel:123",
561+
turnSourceAccountId: "creator-account",
562+
},
563+
]);
564+
});
565+
});

‎src/agents/openclaw-tools.client-caps.test.ts‎

Lines changed: 0 additions & 117 deletions
This file was deleted.

‎src/agents/openclaw-tools.computer.test.ts‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎src/agents/openclaw-tools.gateway-caller-identity.test.ts‎

Lines changed: 0 additions & 100 deletions
This file was deleted.

‎src/agents/openclaw-tools.generation.test-support.ts‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎src/agents/openclaw-tools.image-generation.test.ts‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)