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