@@ -72,6 +72,19 @@ function createPrefixOnlyChannelPlugin(
7272 } ;
7373}
7474
75+ function createEnablementHostileChannelPlugin ( id : string ) : ChannelPlugin {
76+ const base = createPrefixOnlyChannelPlugin ( id , [ id ] ) ;
77+ return {
78+ ...base ,
79+ config : {
80+ ...base . config ,
81+ // Mirrors twitch/discord: an unlisted or credential-suppressed account
82+ // resolves to a not-enabled account, which must NOT read as operator intent.
83+ isEnabled : ( ) => false ,
84+ } ,
85+ } ;
86+ }
87+
7588function setCronValidationTestRegistry ( ) : void {
7689 setActivePluginRegistry (
7790 createTestRegistry ( [
@@ -85,6 +98,11 @@ function setCronValidationTestRegistry(): void {
8598 plugin : createPrefixOnlyChannelPlugin ( "slack" , [ "slack" ] ) ,
8699 source : "test:slack" ,
87100 } ,
101+ {
102+ pluginId : "twitch" ,
103+ plugin : createEnablementHostileChannelPlugin ( "twitch" ) ,
104+ source : "test:twitch" ,
105+ } ,
88106 {
89107 pluginId : "msteams" ,
90108 plugin : createPrefixOnlyChannelPlugin ( "msteams" , [ "msteams" , "teams" ] , [ "teams" ] ) ,
@@ -346,6 +364,20 @@ function telegramSlackConfig(params: { includeMainSession?: boolean } = {}): Ope
346364 } as OpenClawConfig ;
347365}
348366
367+ function telegramDisabledAccountConfig ( ) : OpenClawConfig {
368+ return {
369+ channels : {
370+ telegram : {
371+ accounts : {
372+ primary : { botToken : "telegram-token-primary" } ,
373+ retired : { botToken : "telegram-token-retired" , enabled : false } ,
374+ } ,
375+ } ,
376+ } ,
377+ plugins : pluginEntries ( "telegram" ) ,
378+ } as OpenClawConfig ;
379+ }
380+
349381function msteamsConfig ( ) : OpenClawConfig {
350382 return {
351383 channels : {
@@ -2134,6 +2166,247 @@ describe("cron method validation", () => {
21342166 expectResponseError ( respond , { messageIncludes : "delivery.channel is not configured" } ) ;
21352167 } ) ;
21362168
2169+ it ( "rejects an announce accountId whose account is explicitly disabled" , async ( ) => {
2170+ setRuntimeConfig ( telegramDisabledAccountConfig ( ) ) ;
2171+
2172+ const { context, respond } = await invokeCronAdd (
2173+ agentTurnCronParams ( {
2174+ name : "disabled delivery account" ,
2175+ delivery : {
2176+ mode : "announce" ,
2177+ channel : "telegram" ,
2178+ to : "telegram:123456" ,
2179+ accountId : "retired" ,
2180+ } ,
2181+ } ) ,
2182+ ) ;
2183+
2184+ expect ( context . cron . add ) . not . toHaveBeenCalled ( ) ;
2185+ expectResponseError ( respond , {
2186+ code : "INVALID_REQUEST" ,
2187+ messageIncludes : "delivery.accountId" ,
2188+ } ) ;
2189+ } ) ;
2190+
2191+ it ( "accepts an announce accountId whose account is enabled" , async ( ) => {
2192+ setRuntimeConfig ( telegramDisabledAccountConfig ( ) ) ;
2193+
2194+ const { context, respond } = await invokeCronAdd (
2195+ agentTurnCronParams ( {
2196+ name : "enabled delivery account" ,
2197+ delivery : {
2198+ mode : "announce" ,
2199+ channel : "telegram" ,
2200+ to : "telegram:123456" ,
2201+ accountId : "primary" ,
2202+ } ,
2203+ } ) ,
2204+ ) ;
2205+
2206+ expect ( context . cron . add ) . toHaveBeenCalled ( ) ;
2207+ expectCronSuccess ( respond ) ;
2208+ } ) ;
2209+
2210+ it ( "accepts an unlisted accountId so binding-derived ids keep working" , async ( ) => {
2211+ // Cron delivery ids are not always operator-typed: delivery-context.ts copies
2212+ // the current context account into inferred jobs, and a channel may resolve an
2213+ // unlisted binding id against its sole token. Only disabled accounts are rejected.
2214+ setRuntimeConfig ( telegramConfig ( ) ) ;
2215+
2216+ const { context, respond } = await invokeCronAdd (
2217+ agentTurnCronParams ( {
2218+ name : "binding-derived delivery account" ,
2219+ delivery : {
2220+ mode : "announce" ,
2221+ channel : "telegram" ,
2222+ to : "telegram:123456" ,
2223+ accountId : "bot:12345" ,
2224+ } ,
2225+ } ) ,
2226+ ) ;
2227+
2228+ expect ( context . cron . add ) . toHaveBeenCalled ( ) ;
2229+ expectCronSuccess ( respond ) ;
2230+ } ) ;
2231+
2232+ it ( "accepts an unlisted accountId on a channel whose isEnabled reports it disabled" , async ( ) => {
2233+ // twitch/discord resolve an unlisted or credential-suppressed account to a
2234+ // not-enabled account. That is not the operator disabling a route, so cron
2235+ // creation must not be blocked by it - only a config-declared enabled:false is.
2236+ setRuntimeConfig ( {
2237+ channels : { twitch : { accounts : { main : { accessToken : "t" } } } } ,
2238+ plugins : pluginEntries ( "twitch" ) ,
2239+ } as OpenClawConfig ) ;
2240+
2241+ const { respond } = await invokeCronAdd (
2242+ agentTurnCronParams ( {
2243+ name : "enablement-hostile channel account" ,
2244+ delivery : {
2245+ mode : "announce" ,
2246+ channel : "twitch" ,
2247+ to : "twitch:room" ,
2248+ accountId : "unlisted-account" ,
2249+ } ,
2250+ } ) ,
2251+ ) ;
2252+
2253+ const call = respond . mock . calls . at ( 0 ) ;
2254+ // The channel itself may be judged unconfigured in this fixture; what must not
2255+ // happen is a rejection naming delivery.accountId.
2256+ expect ( String ( call ?. [ 2 ] ? ( call [ 2 ] as { message ?: unknown } ) . message : "" ) ) . not . toContain (
2257+ "delivery.accountId" ,
2258+ ) ;
2259+ } ) ;
2260+
2261+ it ( "accepts a named account when only the top-level channel config is disabled" , async ( ) => {
2262+ // A top-level `channels.<id>.enabled: false` is not uniformly channel-wide:
2263+ // twitch resolves named accounts from `accounts` alone, so a disabled root
2264+ // block must not make every account on that channel unschedulable.
2265+ setRuntimeConfig ( {
2266+ channels : {
2267+ twitch : { enabled : false , accounts : { main : { accessToken : "t" } } } ,
2268+ } ,
2269+ plugins : pluginEntries ( "twitch" ) ,
2270+ } as OpenClawConfig ) ;
2271+
2272+ const { respond } = await invokeCronAdd (
2273+ agentTurnCronParams ( {
2274+ name : "named account under disabled root" ,
2275+ delivery : {
2276+ mode : "announce" ,
2277+ channel : "twitch" ,
2278+ to : "twitch:room" ,
2279+ accountId : "main" ,
2280+ } ,
2281+ } ) ,
2282+ ) ;
2283+
2284+ const call = respond . mock . calls . at ( 0 ) ;
2285+ expect ( String ( call ?. [ 2 ] ? ( call [ 2 ] as { message ?: unknown } ) . message : "" ) ) . not . toContain (
2286+ "delivery.accountId" ,
2287+ ) ;
2288+ } ) ;
2289+
2290+ it ( "rejects a disabled account whose config key is not canonical" , async ( ) => {
2291+ // Channels resolve account keys canonically: matrix treats `"Team Ops"` as
2292+ // `team-ops`. A disabled entry stored under the display form must still match.
2293+ setRuntimeConfig ( {
2294+ channels : {
2295+ telegram : {
2296+ accounts : {
2297+ primary : { botToken : "telegram-token-primary" } ,
2298+ "Team Ops" : { botToken : "telegram-token-team" , enabled : false } ,
2299+ } ,
2300+ } ,
2301+ } ,
2302+ plugins : pluginEntries ( "telegram" ) ,
2303+ } as OpenClawConfig ) ;
2304+
2305+ const { context, respond } = await invokeCronAdd (
2306+ agentTurnCronParams ( {
2307+ name : "noncanonical disabled account key" ,
2308+ delivery : {
2309+ mode : "announce" ,
2310+ channel : "telegram" ,
2311+ to : "telegram:123456" ,
2312+ accountId : "team-ops" ,
2313+ } ,
2314+ } ) ,
2315+ ) ;
2316+
2317+ expect ( context . cron . add ) . not . toHaveBeenCalled ( ) ;
2318+ expectResponseError ( respond , {
2319+ code : "INVALID_REQUEST" ,
2320+ messageIncludes : "delivery.accountId" ,
2321+ } ) ;
2322+ } ) ;
2323+
2324+ it ( "rejects a disabled account reached through a channel alias" , async ( ) => {
2325+ // Aliases are valid delivery channels (msteams answers to `teams`) while the
2326+ // config lives under the canonical id, so the alias must resolve before lookup.
2327+ setRuntimeConfig ( {
2328+ channels : {
2329+ msteams : {
2330+ accounts : {
2331+ work : { botToken : "teams-token-work" , enabled : false } ,
2332+ } ,
2333+ } ,
2334+ } ,
2335+ plugins : pluginEntries ( "msteams" ) ,
2336+ } as OpenClawConfig ) ;
2337+
2338+ const { context, respond } = await invokeCronAdd (
2339+ agentTurnCronParams ( {
2340+ name : "disabled account via alias" ,
2341+ delivery : {
2342+ mode : "announce" ,
2343+ channel : "teams" ,
2344+ to : "msteams:conversation" ,
2345+ accountId : "work" ,
2346+ } ,
2347+ } ) ,
2348+ ) ;
2349+
2350+ expect ( context . cron . add ) . not . toHaveBeenCalled ( ) ;
2351+ expectResponseError ( respond , {
2352+ code : "INVALID_REQUEST" ,
2353+ messageIncludes : "delivery.accountId" ,
2354+ } ) ;
2355+ } ) ;
2356+
2357+ it ( "accepts announce delivery that omits accountId" , async ( ) => {
2358+ setRuntimeConfig ( telegramConfig ( ) ) ;
2359+
2360+ const { context, respond } = await invokeCronAdd (
2361+ agentTurnCronParams ( {
2362+ name : "no delivery account" ,
2363+ delivery : { mode : "announce" , channel : "telegram" , to : "telegram:123456" } ,
2364+ } ) ,
2365+ ) ;
2366+
2367+ expect ( context . cron . add ) . toHaveBeenCalled ( ) ;
2368+ expectCronSuccess ( respond ) ;
2369+ } ) ;
2370+
2371+ it ( "rejects a delivery patch that introduces a disabled accountId" , async ( ) => {
2372+ setRuntimeConfig ( telegramDisabledAccountConfig ( ) ) ;
2373+
2374+ const { context, respond } = await invokeCronUpdate (
2375+ { id : "cron-1" , patch : { delivery : { accountId : "retired" } } } ,
2376+ createCronJob ( {
2377+ delivery : { mode : "announce" , channel : "telegram" , to : "telegram:123456" } ,
2378+ } ) ,
2379+ ) ;
2380+
2381+ expect ( context . cron . update ) . not . toHaveBeenCalled ( ) ;
2382+ expectResponseError ( respond , {
2383+ code : "INVALID_REQUEST" ,
2384+ messageIncludes : "delivery.accountId" ,
2385+ } ) ;
2386+ } ) ;
2387+
2388+ it ( "keeps a non-routing patch unblocked by a legacy-invalid stored accountId" , async ( ) => {
2389+ // Account validation runs only behind the delivery-patch gate, so edits that do
2390+ // not touch routing must not be rejected because of an id stored before this
2391+ // validation existed.
2392+ setRuntimeConfig ( telegramDisabledAccountConfig ( ) ) ;
2393+
2394+ const { context, respond } = await invokeCronUpdate (
2395+ { id : "cron-1" , patch : { enabled : false } } ,
2396+ createCronJob ( {
2397+ delivery : {
2398+ mode : "announce" ,
2399+ channel : "telegram" ,
2400+ to : "telegram:123456" ,
2401+ accountId : "retired" ,
2402+ } ,
2403+ } ) ,
2404+ ) ;
2405+
2406+ expect ( context . cron . update ) . toHaveBeenCalled ( ) ;
2407+ expectCronSuccess ( respond ) ;
2408+ } ) ;
2409+
21372410 it ( "accepts provider-prefixed announce target without delivery.channel when multiple channels are configured" , async ( ) => {
21382411 setRuntimeConfig ( telegramSlackConfig ( { includeMainSession : true } ) ) ;
21392412
0 commit comments