@@ -2,7 +2,10 @@ import fs from "node:fs";
22import os from "node:os" ;
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
5- import { createTranscriptEventReader } from "./doctor-session-sqlite-readers.js" ;
5+ import {
6+ countTranscriptEventsForPath ,
7+ createTranscriptEventReader ,
8+ } from "./doctor-session-sqlite-readers.js" ;
69
710describe ( "legacy transcript row classification" , ( ) => {
811 let directory : string ;
@@ -13,6 +16,36 @@ describe("legacy transcript row classification", () => {
1316 } ) ;
1417 afterEach ( ( ) => fs . rmSync ( directory , { recursive : true , force : true } ) ) ;
1518
19+ it . each ( [ 1 , 2 , 3 ] ) ( "preserves records when UTF-8 splits after byte %s" , ( splitAfter ) => {
20+ const header = '\uFEFF{"type":"session","version":3}\r\n \t\r\n' ;
21+ const prefix = '{"type":"plugin_state","payload":"' ;
22+ const padding = "x" . repeat ( 65_536 - Buffer . byteLength ( header + prefix ) - splitAfter ) ;
23+ const firstLine = `${ prefix } ${ padding } 🦞"}` ;
24+ const giant = { type : "plugin_state" , payload : "λ" . repeat ( 100_000 ) } ;
25+ const tail = { type : "plugin_state" , payload : "final unterminated row" } ;
26+ fs . writeFileSync (
27+ transcriptPath ,
28+ `${ header } ${ firstLine } \r\n\n${ JSON . stringify ( giant ) } \r\n${ JSON . stringify ( tail ) } ` ,
29+ ) ;
30+
31+ const events : unknown [ ] = [ ] ;
32+ const validate = createTranscriptEventReader (
33+ transcriptPath ,
34+ "target" ,
35+ ) ( ( event ) => events . push ( event ) ) ;
36+ validate ( ) ;
37+
38+ expect ( events [ 0 ] ) . toEqual ( {
39+ type : "session" ,
40+ version : 3 ,
41+ id : "target" ,
42+ timestamp : "" ,
43+ cwd : "" ,
44+ } ) ;
45+ expect ( events . slice ( 1 ) ) . toEqual ( [ JSON . parse ( firstLine ) , giant , tail ] ) ;
46+ expect ( countTranscriptEventsForPath ( transcriptPath ) ) . toEqual ( { status : "ok" , events : 4 } ) ;
47+ } ) ;
48+
1649 it . each ( [ 1 , 2 , 3 , 4 ] ) ( "preserves recognized and opaque rows from version %s" , ( version ) => {
1750 const unindexedHook = { type : "message" , message : { role : "custom" , content : "context" } } ;
1851 const opaqueRows = [
0 commit comments