@@ -2,13 +2,19 @@ import { afterEach, describe, expect, it, vi } from "vitest";
22import {
33 testing ,
44 applySubagentWaitOutcome ,
5+ buildCompactAnnounceStatsLine ,
56 buildChildCompletionFindings ,
67 readSubagentOutput ,
78} from "./subagent-announce-output.js" ;
89
910type CallGateway = typeof import ( "../gateway/call.js" ) . callGateway ;
11+ type GetRuntimeConfig = typeof import ( "./subagent-announce.runtime.js" ) . getRuntimeConfig ;
12+ type ReadSessionEntry = typeof import ( "./subagent-announce.runtime.js" ) . readSessionEntry ;
1013type ReadSessionMessagesAsync =
1114 typeof import ( "./subagent-announce.runtime.js" ) . readSessionMessagesAsync ;
15+ type ResolveAgentIdFromSessionKey =
16+ typeof import ( "./subagent-announce.runtime.js" ) . resolveAgentIdFromSessionKey ;
17+ type ResolveStorePath = typeof import ( "./subagent-announce.runtime.js" ) . resolveStorePath ;
1218
1319function installOutputDeps ( params : {
1420 messages : Array < unknown > ;
@@ -53,6 +59,31 @@ function sessionsYieldTurn(message = "Waiting for subagent completion.") {
5359 ] ;
5460}
5561
62+ describe ( "buildCompactAnnounceStatsLine" , ( ) => {
63+ afterEach ( ( ) => {
64+ testing . setDepsForTest ( ) ;
65+ } ) ;
66+
67+ it ( "rolls one-decimal thousand token stats over to the million unit" , async ( ) => {
68+ testing . setDepsForTest ( {
69+ getRuntimeConfig : ( ( ) => ( { session : { store : "memory" } } ) ) as GetRuntimeConfig ,
70+ readSessionEntry : ( ( ) => ( {
71+ inputTokens : 999_999 ,
72+ outputTokens : 0 ,
73+ totalTokens : 999_999 ,
74+ } ) ) as ReadSessionEntry ,
75+ resolveAgentIdFromSessionKey : ( ( ) => "main" ) as ResolveAgentIdFromSessionKey ,
76+ resolveStorePath : ( ( ) => "/tmp/openclaw-session-store" ) as ResolveStorePath ,
77+ } ) ;
78+
79+ await expect (
80+ buildCompactAnnounceStatsLine ( {
81+ sessionKey : "agent:main:subagent:child" ,
82+ } ) ,
83+ ) . resolves . toBe ( "Stats: runtime n/a • tokens 1.0m (in 1.0m / out 0)" ) ;
84+ } ) ;
85+ } ) ;
86+
5687describe ( "readSubagentOutput" , ( ) => {
5788 afterEach ( ( ) => {
5889 testing . setDepsForTest ( ) ;
0 commit comments