@@ -12,6 +12,7 @@ const {
1212 readDedupedTokenUsage,
1313 getSummaryTitle,
1414 buildStepSummarySection,
15+ renderTokenTableAsPlainText,
1516 TOKEN_USAGE_AUDIT_PATH ,
1617 TOKEN_USAGE_PATH ,
1718 TOKEN_USAGE_PATHS ,
@@ -194,6 +195,9 @@ describe("parse_token_usage", () => {
194195 expect ( mockCore . summary . addRaw ) . toHaveBeenCalledWith ( expect . stringContaining ( "| Alias |" ) , true ) ;
195196 expect ( mockCore . summary . write ) . toHaveBeenCalled ( ) ;
196197 expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "Token usage summary appended" ) ) ;
198+ // Token table should also be rendered to core.info
199+ expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "Token Usage" ) ) ;
200+ expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "Alias" ) ) ;
197201 } ) ;
198202
199203 test ( "uses custom summary title when configured" , async ( ) => {
@@ -536,5 +540,30 @@ describe("parse_token_usage", () => {
536540 expect ( section ) . toContain ( "<details>" ) ;
537541 expect ( section ) . toContain ( "<summary>Per-request AI credits and token totals</summary>" ) ;
538542 } ) ;
543+
544+ test ( "renderTokenTableAsPlainText strips table separator lines and pipes" , ( ) => {
545+ const markdown = [ "| # | Alias | Input | Output |" , "|--:|-------|------:|-------:|" , "| 1 | sonnet46 | 100 | 200 |" , "| **Total** | | **100** | **200** |" , "" , "Legend: `Alias` is the model shorthand." , "" ] . join ( "\n" ) ;
546+
547+ const result = renderTokenTableAsPlainText ( "Token Usage" , markdown ) ;
548+
549+ expect ( result ) . toContain ( "Token Usage" ) ;
550+ // separator line is removed
551+ expect ( result ) . not . toMatch ( / \| - - / ) ;
552+ // leading/trailing pipes are stripped
553+ expect ( result ) . not . toMatch ( / ^ \| / m) ;
554+ expect ( result ) . not . toMatch ( / \| $ / m) ;
555+ // bold markers are removed
556+ expect ( result ) . not . toContain ( "**" ) ;
557+ // data is preserved
558+ expect ( result ) . toContain ( "sonnet46" ) ;
559+ expect ( result ) . toContain ( "100" ) ;
560+ expect ( result ) . toContain ( "200" ) ;
561+ expect ( result ) . toContain ( "Legend:" ) ;
562+ } ) ;
563+
564+ test ( "renderTokenTableAsPlainText prefixes output with title" , ( ) => {
565+ const result = renderTokenTableAsPlainText ( "My Token Usage" , "| A |\n|---|\n| 1 |" ) ;
566+ expect ( result . startsWith ( "My Token Usage" ) ) . toBe ( true ) ;
567+ } ) ;
539568 } ) ;
540569} ) ;
0 commit comments