@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it } from "vitest";
55import "./test-helpers/fast-coding-tools.js" ;
66import "./test-helpers/fast-openclaw-tools.js" ;
77import type { OpenClawConfig } from "../config/config.js" ;
8+ import { resolveChannelGroupToolsPolicy } from "../config/group-policy.js" ;
89import { setActivePluginRegistry } from "../plugins/runtime.js" ;
910import { createSessionConversationTestRegistry } from "../test-utils/session-conversation-registry.js" ;
1011import { 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" , ( ) => {
0 commit comments