77import os from "node:os" ;
88import path from "node:path" ;
99import { beforeEach , describe , expect , it , vi } from "vitest" ;
10+ import { SUBAGENT_ENDED_REASON_KILLED } from "../../agents/subagent-lifecycle-events.js" ;
1011import { subagentRuns } from "../../agents/subagent-registry-memory.js" ;
1112import {
1213 countPendingDescendantRunsFromRuns ,
@@ -26,6 +27,7 @@ import type { ReplyPayload } from "../types.js";
2627import { buildSubagentsStatusLine } from "./commands-status-subagents.js" ;
2728import { extractMessageText } from "./commands-subagents-text.js" ;
2829import { handleSubagentsInfoAction } from "./commands-subagents/action-info.js" ;
30+ import { handleSubagentsListAction } from "./commands-subagents/action-list.js" ;
2931import { handleSubagentsLogAction } from "./commands-subagents/action-log.js" ;
3032import { resolveFocusTargetSession } from "./commands-subagents/shared.js" ;
3133import {
@@ -233,6 +235,62 @@ describe("subagents info", () => {
233235 expect ( text ) . toContain ( "Task summary: Completed the requested task" ) ;
234236 } ) ;
235237
238+ it . each ( [
239+ {
240+ name : "a killed run despite its provider error" ,
241+ endedReason : SUBAGENT_ENDED_REASON_KILLED ,
242+ outcome : { status : "error" , error : "agent run aborted" } as const ,
243+ expectedStatus : "killed" ,
244+ } ,
245+ {
246+ name : "a killed run despite its earlier successful result" ,
247+ endedReason : SUBAGENT_ENDED_REASON_KILLED ,
248+ outcome : { status : "ok" } as const ,
249+ expectedStatus : "killed" ,
250+ } ,
251+ {
252+ name : "a failed run" ,
253+ outcome : { status : "error" , error : "provider rejected the request" } as const ,
254+ expectedStatus : "failed" ,
255+ } ,
256+ {
257+ name : "a timed-out run" ,
258+ outcome : { status : "timeout" } as const ,
259+ expectedStatus : "timeout" ,
260+ } ,
261+ ] ) (
262+ "keeps /subagents info and list aligned for $name" ,
263+ ( { endedReason, outcome, expectedStatus } ) => {
264+ const now = Date . now ( ) ;
265+ const run = {
266+ runId : `commands-subagents-status-${ expectedStatus } ` ,
267+ childSessionKey : `agent:main:subagent:commands-status-${ expectedStatus } ` ,
268+ requesterSessionKey : "agent:main:main" ,
269+ requesterDisplayKey : "main" ,
270+ task : "report the actual child outcome" ,
271+ cleanup : "keep" ,
272+ createdAt : now - 2_000 ,
273+ startedAt : now - 2_000 ,
274+ endedAt : now - 1_000 ,
275+ ...( endedReason ? { endedReason } : { } ) ,
276+ outcome,
277+ } satisfies SubagentRunRecord ;
278+ addSubagentRunForTests ( run ) ;
279+ const context = buildInfoContext ( {
280+ cfg : buildCommandTestConfig ( ) ,
281+ runs : [ run ] ,
282+ restTokens : [ "1" ] ,
283+ } ) ;
284+
285+ expect ( requireReplyText ( handleSubagentsInfoAction ( context ) . reply ) ) . toContain (
286+ `Status: ${ expectedStatus } ` ,
287+ ) ;
288+ expect ( requireReplyText ( handleSubagentsListAction ( context ) . reply ) ) . toContain (
289+ ` ${ expectedStatus } ` ,
290+ ) ;
291+ } ,
292+ ) ;
293+
236294 it ( "omits Date-invalid subagent timestamps" , ( ) => {
237295 const runId = "commands-subagents-info-invalid-date-run" ;
238296 const childSessionKey = "agent:main:subagent:commands-info-invalid-date" ;
0 commit comments