@@ -2,6 +2,7 @@ import { describe, it, expect, afterAll, beforeEach, vi } from 'vitest'
22import { mkdtempSync , rmSync , mkdirSync , writeFileSync , utimesSync } from 'fs'
33import { tmpdir } from 'os'
44import { join } from 'path'
5+ import * as fsUtils from '../src/fs-utils.js'
56
67vi . mock ( 'os' , async ( ) => {
78 const actual = await vi . importActual < typeof import ( 'os' ) > ( 'os' )
@@ -313,6 +314,40 @@ describe('scanJsonlFile', () => {
313314 expect ( result . calls ) . toEqual ( [ ] )
314315 } )
315316
317+ it ( 'uses readSessionLines (streaming) rather than readSessionFile (full-string load)' , async ( ) => {
318+ const readSessionLinesSpy = vi . spyOn ( fsUtils , 'readSessionLines' )
319+ const readSessionFileSpy = vi . spyOn ( fsUtils , 'readSessionFile' )
320+ const root = makeFixtureRoot ( )
321+ const filePath = join ( root , 'session.jsonl' )
322+ const now = new Date ( ) . toISOString ( )
323+ writeFile ( filePath , JSON . stringify ( {
324+ type : 'assistant' , timestamp : now ,
325+ message : { content : [ { type : 'tool_use' , name : 'Bash' , input : { } } ] } ,
326+ } ) )
327+ await scanJsonlFile ( filePath , 'p1' , undefined )
328+ expect ( readSessionLinesSpy ) . toHaveBeenCalledWith ( filePath )
329+ expect ( readSessionFileSpy ) . not . toHaveBeenCalled ( )
330+ readSessionLinesSpy . mockRestore ( )
331+ readSessionFileSpy . mockRestore ( )
332+ } )
333+
334+ it ( 'processes all entries in a large multi-line file without truncation' , async ( ) => {
335+ const root = makeFixtureRoot ( )
336+ const filePath = join ( root , 'session.jsonl' )
337+ const now = new Date ( ) . toISOString ( )
338+ const ENTRY_COUNT = 500
339+ const lines = Array . from ( { length : ENTRY_COUNT } , ( _ , i ) =>
340+ JSON . stringify ( {
341+ type : 'assistant' ,
342+ timestamp : now ,
343+ message : { content : [ { type : 'tool_use' , name : 'Read' , input : { file_path : `/file-${ i } .ts` } } ] } ,
344+ } ) ,
345+ )
346+ writeFile ( filePath , lines . join ( '\n' ) )
347+ const result = await scanJsonlFile ( filePath , 'p1' , undefined )
348+ expect ( result . calls ) . toHaveLength ( ENTRY_COUNT )
349+ } )
350+
316351 it ( 'respects date-range filter for assistant entries' , async ( ) => {
317352 const root = makeFixtureRoot ( )
318353 const filePath = join ( root , 'session.jsonl' )
0 commit comments