@@ -3,6 +3,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
33import type { ChannelPlugin } from "../channels/plugins/types.js" ;
44import type { CliDeps } from "../cli/deps.js" ;
55import { migratePersistedImplicitMainRoster } from "../config/legacy.roster.js" ;
6+ import type { MessageActionResult } from "../infra/outbound/message-action-contracts.js" ;
67import type { RuntimeEnv } from "../runtime.js" ;
78import { captureEnv } from "../test-utils/env.js" ;
89
@@ -97,15 +98,18 @@ vi.mock("../cli/command-secret-targets.js", () => ({
9798} ) ) ;
9899
99100const runMessageActionMock = vi . hoisted ( ( ) =>
100- vi . fn ( async ( { action, params } : RunMessageActionParams ) => ( {
101- kind : action === "poll" ? "poll" : "send" ,
102- channel : typeof params . channel === "string" ? params . channel : "telegram" ,
103- action : action === "poll" ? "poll" : "send" ,
104- to : typeof params . target === "string" ? params . target : "123456" ,
105- handledBy : "plugin" ,
106- payload : { ok : true } ,
107- dryRun : false ,
108- } ) ) ,
101+ vi . fn ( async ( { action, params } : RunMessageActionParams ) : Promise < MessageActionResult > => {
102+ const base = {
103+ channel : typeof params . channel === "string" ? params . channel : "telegram" ,
104+ to : typeof params . target === "string" ? params . target : "123456" ,
105+ handledBy : "plugin" as const ,
106+ payload : { ok : true } ,
107+ dryRun : false ,
108+ } ;
109+ return action === "poll"
110+ ? { ...base , kind : "poll" , action : "poll" }
111+ : { ...base , kind : "send" , action : "send" } ;
112+ } ) ,
109113) ;
110114
111115vi . mock ( "../infra/outbound/message-action-runner.js" , ( ) => ( {
@@ -253,6 +257,34 @@ async function runMessageCommand(opts: Record<string, unknown> = {}) {
253257}
254258
255259describe ( "messageCommand" , ( ) => {
260+ it ( "includes aggregate broadcast failure and every target row in JSON output" , async ( ) => {
261+ const results : Extract < MessageActionResult , { kind : "broadcast" } > [ "payload" ] [ "results" ] = [
262+ { channel : "telegram" , to : "123" , ok : true } ,
263+ { channel : "telegram" , to : "456" , ok : false , error : "provider rejected the message" } ,
264+ ] ;
265+ runMessageActionMock . mockResolvedValueOnce ( {
266+ kind : "broadcast" ,
267+ channel : "telegram" ,
268+ action : "broadcast" ,
269+ handledBy : "core" ,
270+ payload : { results } ,
271+ dryRun : false ,
272+ } ) ;
273+
274+ await runMessageCommand ( {
275+ action : "broadcast" ,
276+ target : undefined ,
277+ targets : [ "123" , "456" ] ,
278+ } ) ;
279+
280+ const output = JSON . parse ( String ( vi . mocked ( runtime . log ) . mock . calls [ 0 ] ?. [ 0 ] ) ) as {
281+ ok ?: boolean ;
282+ payload ?: { results ?: unknown [ ] } ;
283+ } ;
284+ expect ( output . ok ) . toBe ( false ) ;
285+ expect ( output . payload ?. results ) . toEqual ( results ) ;
286+ } ) ;
287+
256288 it ( "rejects a malformed explicit account before resolving secrets" , async ( ) => {
257289 await expect ( runMessageCommand ( { accountId : "!!!" } ) ) . rejects . toThrow ( "Invalid account ID" ) ;
258290
0 commit comments