@@ -11,6 +11,8 @@ import type { UsageRecord } from "@t3tools/provider-core/server/usage";
1111import { TEST_FORMAT_MAP } from "./usageTestFormats.ts" ;
1212import { initialCodexScanState , parseCodexLine } from "../provider/Drivers/codexUsage.ts" ;
1313
14+ const parse = ( parts : Iterable < string > ) => JSON . parse ( [ ...parts ] . join ( "" ) ) ;
15+
1416function record ( overrides : Partial < UsageRecord > = { } ) : UsageRecord {
1517 return {
1618 provider : "claude" ,
@@ -152,10 +154,7 @@ describe("scan cache round trip", () => {
152154 record ( { model : "<synthetic>" , dedupeKey : "msg_tail:" } ) ,
153155 ] ,
154156 } ) ;
155- const restored = decodeScanCache (
156- JSON . parse ( makeScanCacheWriter ( ) ( cached , { } ) ) ,
157- TEST_FORMAT_MAP ,
158- ) ;
157+ const restored = decodeScanCache ( parse ( makeScanCacheWriter ( ) ( cached , { } ) ) , TEST_FORMAT_MAP ) ;
159158
160159 expect ( restored . size ) . toBe ( 4 ) ;
161160 expect ( restored ) . toEqual ( original ) ;
@@ -196,7 +195,7 @@ describe("scan cache round trip", () => {
196195 malformedRecords : 0 ,
197196 } ;
198197 original . set ( "/clean-codex.jsonl" , cleanCodex ) ;
199- const encoded = JSON . parse ( makeScanCacheWriter ( ) ( original , { } ) ) ;
198+ const encoded = parse ( makeScanCacheWriter ( ) ( original , { } ) ) ;
200199 const entry = encoded . files [ "/gone.jsonl" ] ! ;
201200 const legacy = {
202201 ...encoded ,
@@ -251,7 +250,7 @@ describe("scan cache round trip", () => {
251250
252251 it ( "re-parses a Claude transcript cached before advisor usage was counted" , ( ) => {
253252 const original = cacheWith ( [ [ "/claude.jsonl" , 100 , [ record ( ) ] ] ] ) ;
254- const v9 = { ...JSON . parse ( makeScanCacheWriter ( ) ( original , { } ) ) , version : 9 } ;
253+ const v9 = { ...parse ( makeScanCacheWriter ( ) ( original , { } ) ) , version : 9 } ;
255254
256255 const restored = decodeScanCache ( JSON . parse ( JSON . stringify ( v9 ) ) , TEST_FORMAT_MAP ) ;
257256 expect ( restored . get ( "/claude.jsonl" ) ) . toEqual ( {
@@ -269,15 +268,15 @@ describe("scan cache round trip", () => {
269268 ] ) ;
270269 cache . set ( "/b.jsonl" , { ...cache . get ( "/b.jsonl" ) ! , malformedRecords : 2 } ) ;
271270 const sources = { "claude\u0000/projects" : { dir : "/projects" , volumeId : "1:2" } } ;
272- expect ( decodeScanCache ( JSON . parse ( write ( cache , { sources } ) ) , TEST_FORMAT_MAP ) ) . toEqual ( cache ) ;
271+ expect ( decodeScanCache ( parse ( write ( cache , { sources } ) ) , TEST_FORMAT_MAP ) ) . toEqual ( cache ) ;
273272
274273 cache . set ( "/b.jsonl" , {
275274 ...cache . get ( "/b.jsonl" ) ! ,
276275 size : 30 ,
277276 malformedRecords : 4 ,
278277 records : [ record ( { sessionId : "session-c" , model : "claude-opus-5-5" , dedupeKey : "msg_3:" } ) ] ,
279278 } ) ;
280- const document = JSON . parse ( write ( cache , { sources } ) ) ;
279+ const document = parse ( write ( cache , { sources } ) ) ;
281280 expect ( decodeScanCache ( document , TEST_FORMAT_MAP ) ) . toEqual ( cache ) ;
282281 expect ( document . sources ) . toEqual ( sources ) ;
283282 } ) ;
@@ -291,9 +290,7 @@ describe("scan cache round trip", () => {
291290 } ) ;
292291
293292 it ( "skips malformed file entries but keeps good ones" , ( ) => {
294- const encoded = JSON . parse (
295- makeScanCacheWriter ( ) ( cacheWith ( [ [ "/good.jsonl" , 100 , [ record ( ) ] ] ] ) , { } ) ,
296- ) ;
293+ const encoded = parse ( makeScanCacheWriter ( ) ( cacheWith ( [ [ "/good.jsonl" , 100 , [ record ( ) ] ] ] ) , { } ) ) ;
297294 const withJunk = {
298295 ...encoded ,
299296 files : { ...encoded . files , "/bad.jsonl" : { s : "nope" , m : 1 , p : "claude" , r : [ ] } } ,
@@ -304,7 +301,7 @@ describe("scan cache round trip", () => {
304301 } ) ;
305302
306303 it ( "drops the whole entry when any row is corrupt, forcing a cold re-parse" , ( ) => {
307- const encoded = JSON . parse (
304+ const encoded = parse (
308305 makeScanCacheWriter ( ) (
309306 cacheWith ( [ [ "/a.jsonl" , 100 , [ record ( ) , record ( { dedupeKey : "msg_2:" } ) ] ] ] ) ,
310307 { } ,
0 commit comments