11// Qqbot tests cover channel-api tool behavior.
2+
3+ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts" ;
24import { afterEach , describe , expect , it , vi } from "vitest" ;
35import { createStreamingResponse } from "../../../../test-support/streaming-error-response.js" ;
46
@@ -14,6 +16,10 @@ vi.mock("openclaw/plugin-sdk/ssrf-runtime", async (importOriginal) => {
1416
1517import { executeChannelApi } from "./channel-api.js" ;
1618
19+ function qqbotCfg ( qqbot : Record < string , unknown > ) : OpenClawConfig {
20+ return { channels : { qqbot } } as OpenClawConfig ;
21+ }
22+
1723function cancelTrackedResponse (
1824 text : string ,
1925 init : ResponseInit ,
@@ -79,6 +85,110 @@ describe("executeChannelApi", () => {
7985 } ) ;
8086 } ) ;
8187
88+ it ( "blocks guild listing when qqbot groups are scoped" , async ( ) => {
89+ const result = await executeChannelApi (
90+ { method : "GET" , path : "/users/@me/guilds" } ,
91+ {
92+ accessToken : "token-1" ,
93+ cfg : qqbotCfg ( { groups : { G1 : { } } } ) ,
94+ } ,
95+ ) ;
96+
97+ expect ( result . details ) . toEqual ( {
98+ error : "QQ channel API guild listing is unavailable while qqbot groups are scoped." ,
99+ path : "/users/@me/guilds" ,
100+ } ) ;
101+ expect ( fetchWithSsrFGuardMock ) . not . toHaveBeenCalled ( ) ;
102+ } ) ;
103+
104+ it ( "blocks guild paths when qqbot groups are scoped" , async ( ) => {
105+ const result = await executeChannelApi (
106+ { method : "GET" , path : "/guilds/G1/channels" } ,
107+ {
108+ accessToken : "token-1" ,
109+ cfg : qqbotCfg ( { groups : { G1 : { } } } ) ,
110+ } ,
111+ ) ;
112+
113+ expect ( result . details ) . toEqual ( {
114+ error : "QQ channel API guild paths are unavailable while qqbot groups are scoped." ,
115+ path : "/guilds/G1/channels" ,
116+ } ) ;
117+ expect ( fetchWithSsrFGuardMock ) . not . toHaveBeenCalled ( ) ;
118+ } ) ;
119+
120+ it ( "blocks channel paths when qqbot groups are scoped" , async ( ) => {
121+ const result = await executeChannelApi (
122+ { method : "GET" , path : "/channels/C1/threads" } ,
123+ {
124+ accessToken : "token-1" ,
125+ cfg : qqbotCfg ( { groups : { C1 : { } } } ) ,
126+ } ,
127+ ) ;
128+
129+ expect ( result . details ) . toEqual ( {
130+ error : "QQ channel API channel paths are unavailable while qqbot groups are scoped." ,
131+ path : "/channels/C1/threads" ,
132+ } ) ;
133+ expect ( fetchWithSsrFGuardMock ) . not . toHaveBeenCalled ( ) ;
134+ } ) ;
135+
136+ it ( "allows guild paths with wildcard qqbot groups" , async ( ) => {
137+ const release = vi . fn ( async ( ) => { } ) ;
138+ fetchWithSsrFGuardMock . mockResolvedValueOnce ( {
139+ response : new Response ( JSON . stringify ( { id : "channel-1" } ) , { status : 200 } ) ,
140+ release,
141+ } ) ;
142+
143+ const result = await executeChannelApi (
144+ { method : "GET" , path : "/guilds/G1/channels" } ,
145+ {
146+ accessToken : "token-1" ,
147+ cfg : qqbotCfg ( { groups : { "*" : { } } } ) ,
148+ } ,
149+ ) ;
150+
151+ expect ( result . details ) . toMatchObject ( {
152+ success : true ,
153+ status : 200 ,
154+ path : "/guilds/G1/channels" ,
155+ } ) ;
156+ expect ( fetchWithSsrFGuardMock ) . toHaveBeenCalledWith (
157+ expect . objectContaining ( {
158+ url : "https://api.sgroup.qq.com/guilds/G1/channels" ,
159+ } ) ,
160+ ) ;
161+ expect ( release ) . toHaveBeenCalledTimes ( 1 ) ;
162+ } ) ;
163+
164+ it ( "allows global guild listing with wildcard qqbot groups" , async ( ) => {
165+ const release = vi . fn ( async ( ) => { } ) ;
166+ fetchWithSsrFGuardMock . mockResolvedValueOnce ( {
167+ response : new Response ( JSON . stringify ( [ { id : "guild-1" } ] ) , { status : 200 } ) ,
168+ release,
169+ } ) ;
170+
171+ const result = await executeChannelApi (
172+ { method : "GET" , path : "/users/@me/guilds" } ,
173+ {
174+ accessToken : "token-1" ,
175+ cfg : qqbotCfg ( { groups : { "*" : { } } } ) ,
176+ } ,
177+ ) ;
178+
179+ expect ( result . details ) . toMatchObject ( {
180+ success : true ,
181+ status : 200 ,
182+ path : "/users/@me/guilds" ,
183+ } ) ;
184+ expect ( fetchWithSsrFGuardMock ) . toHaveBeenCalledWith (
185+ expect . objectContaining ( {
186+ url : "https://api.sgroup.qq.com/users/@me/guilds" ,
187+ } ) ,
188+ ) ;
189+ expect ( release ) . toHaveBeenCalledTimes ( 1 ) ;
190+ } ) ;
191+
82192 it ( "bounds error bodies without using response.text()" , async ( ) => {
83193 const release = vi . fn ( async ( ) => { } ) ;
84194 const tracked = cancelTrackedResponse ( `${ "channel api unavailable " . repeat ( 1024 ) } tail` , {
0 commit comments