@@ -469,6 +469,49 @@ skipUnlessSqlite('opencode provider - session parsing', () => {
469469 expect ( calls ) . toHaveLength ( 0 )
470470 } )
471471
472+ it ( 'keeps zero-usage assistant messages when router responses contain text' , async ( ) => {
473+ const dbPath = createTestDb ( tmpDir )
474+ withTestDb ( dbPath , ( db ) => {
475+ insertSession ( db , 'sess-1' )
476+ insertMessage ( db , 'msg-u1' , 'sess-1' , 1700000000000 , { role : 'user' } )
477+ insertPart ( db , 'part-u1' , 'msg-u1' , 'sess-1' , { type : 'text' , text : 'use the configured router' } )
478+ insertMessage ( db , 'msg-a1' , 'sess-1' , 1700000001000 , {
479+ role : 'assistant' , modelID : 'edenai/router-model' , cost : 0 ,
480+ tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
481+ } )
482+ insertPart ( db , 'part-a1' , 'msg-a1' , 'sess-1' , { type : 'text' , text : 'router response text' } )
483+ } )
484+
485+ const calls = await collectCalls ( createOpenCodeProvider ( tmpDir ) , dbPath , 'sess-1' )
486+ expect ( calls ) . toHaveLength ( 1 )
487+ expect ( calls [ 0 ] ! . model ) . toBe ( 'edenai/router-model' )
488+ expect ( calls [ 0 ] ! . inputTokens ) . toBe ( 0 )
489+ expect ( calls [ 0 ] ! . outputTokens ) . toBe ( 0 )
490+ expect ( calls [ 0 ] ! . costUSD ) . toBe ( 0 )
491+ expect ( calls [ 0 ] ! . userMessage ) . toBe ( 'use the configured router' )
492+ } )
493+
494+ it ( 'keeps zero-usage assistant messages when router responses contain tool calls' , async ( ) => {
495+ const dbPath = createTestDb ( tmpDir )
496+ withTestDb ( dbPath , ( db ) => {
497+ insertSession ( db , 'sess-1' )
498+ insertMessage ( db , 'msg-a1' , 'sess-1' , 1700000001000 , {
499+ role : 'assistant' , modelID : 'edenai/router-model' , cost : 0 ,
500+ tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
501+ } )
502+ insertPart ( db , 'part-a1' , 'msg-a1' , 'sess-1' , {
503+ type : 'tool' , tool : 'bash' ,
504+ state : { status : 'completed' , input : { command : 'npm test' } } ,
505+ } )
506+ } )
507+
508+ const calls = await collectCalls ( createOpenCodeProvider ( tmpDir ) , dbPath , 'sess-1' )
509+ expect ( calls ) . toHaveLength ( 1 )
510+ expect ( calls [ 0 ] ! . tools ) . toEqual ( [ 'Bash' ] )
511+ expect ( calls [ 0 ] ! . bashCommands ) . toEqual ( [ 'npm' ] )
512+ expect ( calls [ 0 ] ! . costUSD ) . toBe ( 0 )
513+ } )
514+
472515 it ( 'deduplicates messages across parses' , async ( ) => {
473516 const dbPath = createTestDb ( tmpDir )
474517 withTestDb ( dbPath , ( db ) => {
0 commit comments