Skip to content

Commit 37e667c

Browse files
committed
test: keep tool-policy tests below coding tool construction
1 parent 492e98a commit 37e667c

4 files changed

Lines changed: 64 additions & 80 deletions

File tree

src/agents/pi-tools-agent-config.test.ts

Lines changed: 39 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it } from "vitest";
55
import "./test-helpers/fast-coding-tools.js";
66
import "./test-helpers/fast-openclaw-tools.js";
77
import type { OpenClawConfig } from "../config/config.js";
8+
import { resolveChannelGroupToolsPolicy } from "../config/group-policy.js";
89
import { setActivePluginRegistry } from "../plugins/runtime.js";
910
import { createSessionConversationTestRegistry } from "../test-utils/session-conversation-registry.js";
1011
import { createOpenClawCodingTools } from "./pi-tools.js";
@@ -382,7 +383,7 @@ describe("Agent-specific tool filtering", () => {
382383
});
383384
});
384385

385-
it("should apply group tool policy overrides (group-specific beats wildcard)", () => {
386+
it("should resolve group tool policy overrides (group-specific beats wildcard)", () => {
386387
const cfg: OpenClawConfig = {
387388
channels: {
388389
whatsapp: {
@@ -398,27 +399,13 @@ describe("Agent-specific tool filtering", () => {
398399
},
399400
};
400401

401-
const trustedTools = createOpenClawCodingTools({
402-
config: cfg,
403-
sessionKey: "agent:main:whatsapp:group:trusted",
404-
messageProvider: "whatsapp",
405-
workspaceDir: "/tmp/test-group-trusted",
406-
agentDir: "/tmp/agent-group",
407-
});
408-
const trustedNames = trustedTools.map((t) => t.name);
409-
expect(trustedNames).toContain("read");
410-
expect(trustedNames).toContain("exec");
402+
expect(
403+
resolveChannelGroupToolsPolicy({ cfg, channel: "whatsapp", groupId: "trusted" }),
404+
).toEqual({ allow: ["read", "exec"] });
411405

412-
const defaultTools = createOpenClawCodingTools({
413-
config: cfg,
414-
sessionKey: "agent:main:whatsapp:group:unknown",
415-
messageProvider: "whatsapp",
416-
workspaceDir: "/tmp/test-group-default",
417-
agentDir: "/tmp/agent-group",
418-
});
419-
const defaultNames = defaultTools.map((t) => t.name);
420-
expect(defaultNames).toContain("read");
421-
expect(defaultNames).not.toContain("exec");
406+
expect(
407+
resolveChannelGroupToolsPolicy({ cfg, channel: "whatsapp", groupId: "unknown" }),
408+
).toEqual({ allow: ["read"] });
422409
});
423410

424411
it("should apply per-sender tool policies for group tools", () => {
@@ -437,27 +424,23 @@ describe("Agent-specific tool filtering", () => {
437424
},
438425
};
439426

440-
const aliceTools = createOpenClawCodingTools({
441-
config: cfg,
442-
sessionKey: "agent:main:whatsapp:group:family",
443-
senderId: "alice",
444-
workspaceDir: "/tmp/test-group-sender",
445-
agentDir: "/tmp/agent-group-sender",
446-
});
447-
const aliceNames = aliceTools.map((t) => t.name);
448-
expect(aliceNames).toContain("read");
449-
expect(aliceNames).toContain("exec");
450-
451-
const bobTools = createOpenClawCodingTools({
452-
config: cfg,
453-
sessionKey: "agent:main:whatsapp:group:family",
454-
senderId: "bob",
455-
workspaceDir: "/tmp/test-group-sender-bob",
456-
agentDir: "/tmp/agent-group-sender",
457-
});
458-
const bobNames = bobTools.map((t) => t.name);
459-
expect(bobNames).toContain("read");
460-
expect(bobNames).not.toContain("exec");
427+
expect(
428+
resolveChannelGroupToolsPolicy({
429+
cfg,
430+
channel: "whatsapp",
431+
groupId: "family",
432+
senderId: "alice",
433+
}),
434+
).toEqual({ allow: ["read", "exec"] });
435+
436+
expect(
437+
resolveChannelGroupToolsPolicy({
438+
cfg,
439+
channel: "whatsapp",
440+
groupId: "family",
441+
senderId: "bob",
442+
}),
443+
).toEqual({ allow: ["read"] });
461444
});
462445

463446
it("should not let default sender policy override group tools", () => {
@@ -478,16 +461,14 @@ describe("Agent-specific tool filtering", () => {
478461
},
479462
};
480463

481-
const adminTools = createOpenClawCodingTools({
482-
config: cfg,
483-
sessionKey: "agent:main:whatsapp:group:locked",
484-
senderId: "admin",
485-
workspaceDir: "/tmp/test-group-default-override",
486-
agentDir: "/tmp/agent-group-default-override",
487-
});
488-
const adminNames = adminTools.map((t) => t.name);
489-
expect(adminNames).toContain("read");
490-
expect(adminNames).not.toContain("exec");
464+
expect(
465+
resolveChannelGroupToolsPolicy({
466+
cfg,
467+
channel: "whatsapp",
468+
groupId: "locked",
469+
senderId: "admin",
470+
}),
471+
).toEqual({ allow: ["read"] });
491472
});
492473

493474
it("should resolve telegram group tool policy for topic session keys", () => {
@@ -503,16 +484,9 @@ describe("Agent-specific tool filtering", () => {
503484
},
504485
};
505486

506-
const tools = createOpenClawCodingTools({
507-
config: cfg,
508-
sessionKey: "agent:main:telegram:group:123:topic:456",
509-
messageProvider: "telegram",
510-
workspaceDir: "/tmp/test-telegram-topic",
511-
agentDir: "/tmp/agent-telegram",
487+
expect(resolveChannelGroupToolsPolicy({ cfg, channel: "telegram", groupId: "123" })).toEqual({
488+
allow: ["read"],
512489
});
513-
const names = tools.map((t) => t.name);
514-
expect(names).toContain("read");
515-
expect(names).not.toContain("exec");
516490
});
517491

518492
it("should resolve feishu group tool policy for sender-scoped session keys", () => {
@@ -540,7 +514,7 @@ describe("Agent-specific tool filtering", () => {
540514
expect(names).not.toContain("exec");
541515
});
542516

543-
it("should inherit group tool policy for subagents from spawnedBy session keys", () => {
517+
it("should resolve inherited group tool policy for subagent parent groups", () => {
544518
const cfg: OpenClawConfig = {
545519
channels: {
546520
whatsapp: {
@@ -553,16 +527,9 @@ describe("Agent-specific tool filtering", () => {
553527
},
554528
};
555529

556-
const tools = createOpenClawCodingTools({
557-
config: cfg,
558-
sessionKey: "agent:main:subagent:test",
559-
spawnedBy: "agent:main:whatsapp:group:trusted",
560-
workspaceDir: "/tmp/test-subagent-group",
561-
agentDir: "/tmp/agent-subagent",
562-
});
563-
const names = tools.map((t) => t.name);
564-
expect(names).toContain("read");
565-
expect(names).not.toContain("exec");
530+
expect(
531+
resolveChannelGroupToolsPolicy({ cfg, channel: "whatsapp", groupId: "trusted" }),
532+
).toEqual({ allow: ["read"] });
566533
});
567534

568535
it("should apply global tool policy before agent-specific policy", () => {

src/agents/tools/music-generate-background.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ const musicGenerationTaskLifecycle = createMediaGenerationTaskLifecycle({
1919
completionLabel: "music",
2020
});
2121

22-
export const createMusicGenerationTaskRun = musicGenerationTaskLifecycle.createTaskRun;
22+
export const createMusicGenerationTaskRun = (
23+
...params: Parameters<typeof musicGenerationTaskLifecycle.createTaskRun>
24+
) => musicGenerationTaskLifecycle.createTaskRun(...params);
2325

24-
export const recordMusicGenerationTaskProgress = musicGenerationTaskLifecycle.recordTaskProgress;
26+
export const recordMusicGenerationTaskProgress = (
27+
...params: Parameters<typeof musicGenerationTaskLifecycle.recordTaskProgress>
28+
) => musicGenerationTaskLifecycle.recordTaskProgress(...params);
2529

26-
export const completeMusicGenerationTaskRun = musicGenerationTaskLifecycle.completeTaskRun;
30+
export const completeMusicGenerationTaskRun = (
31+
...params: Parameters<typeof musicGenerationTaskLifecycle.completeTaskRun>
32+
) => musicGenerationTaskLifecycle.completeTaskRun(...params);
2733

28-
export const failMusicGenerationTaskRun = musicGenerationTaskLifecycle.failTaskRun;
34+
export const failMusicGenerationTaskRun = (
35+
...params: Parameters<typeof musicGenerationTaskLifecycle.failTaskRun>
36+
) => musicGenerationTaskLifecycle.failTaskRun(...params);
2937

3038
export async function wakeMusicGenerationTaskCompletion(params: {
3139
config?: OpenClawConfig;

src/agents/tools/video-generate-background.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ const videoGenerationTaskLifecycle = createMediaGenerationTaskLifecycle({
1919
completionLabel: "video",
2020
});
2121

22-
export const createVideoGenerationTaskRun = videoGenerationTaskLifecycle.createTaskRun;
22+
export const createVideoGenerationTaskRun = (
23+
...params: Parameters<typeof videoGenerationTaskLifecycle.createTaskRun>
24+
) => videoGenerationTaskLifecycle.createTaskRun(...params);
2325

24-
export const recordVideoGenerationTaskProgress = videoGenerationTaskLifecycle.recordTaskProgress;
26+
export const recordVideoGenerationTaskProgress = (
27+
...params: Parameters<typeof videoGenerationTaskLifecycle.recordTaskProgress>
28+
) => videoGenerationTaskLifecycle.recordTaskProgress(...params);
2529

26-
export const completeVideoGenerationTaskRun = videoGenerationTaskLifecycle.completeTaskRun;
30+
export const completeVideoGenerationTaskRun = (
31+
...params: Parameters<typeof videoGenerationTaskLifecycle.completeTaskRun>
32+
) => videoGenerationTaskLifecycle.completeTaskRun(...params);
2733

28-
export const failVideoGenerationTaskRun = videoGenerationTaskLifecycle.failTaskRun;
34+
export const failVideoGenerationTaskRun = (
35+
...params: Parameters<typeof videoGenerationTaskLifecycle.failTaskRun>
36+
) => videoGenerationTaskLifecycle.failTaskRun(...params);
2937

3038
export async function wakeVideoGenerationTaskCompletion(params: {
3139
config?: OpenClawConfig;

src/plugin-sdk/provider-web-search-config-contract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export {
1616
setProviderWebSearchPluginConfigValue,
1717
setTopLevelCredentialValue,
1818
} from "../agents/tools/web-search-provider-config.js";
19+
export { createWebSearchProviderContractFields } from "./provider-web-search-contract.js";
1920
export type {
2021
WebSearchCredentialResolutionSource,
2122
WebSearchProviderSetupContext,

0 commit comments

Comments
 (0)