@@ -59,23 +59,40 @@ function cacheWith(entries: readonly [string, number, readonly UsageRecord[]][])
5959}
6060
6161describe ( "scan cache round trip" , ( ) => {
62- it ( "restores records unchanged" , ( ) => {
62+ it ( "restores cached history unchanged except for Claude local placeholders " , ( ) => {
6363 const original = cacheWith ( [
6464 [
6565 "/a.jsonl" ,
6666 100 ,
6767 [ record ( ) , record ( { dedupeKey : "msg_2:" , model : "claude-opus-5-5" , speed : "fast" } ) ] ,
6868 ] ,
69- [ "/b.jsonl" , 200 , [ record ( { sessionId : "session-b" , reportedCostUsd : 1.5 } ) ] ] ,
69+ [
70+ "/b.jsonl" ,
71+ 200 ,
72+ [
73+ record ( {
74+ sessionId : "session-b" ,
75+ reportedCostUsd : 1.5 ,
76+ totals : {
77+ uncachedInputTokens : 0 ,
78+ cachedInputTokens : 0 ,
79+ cacheCreationTokens : 0 ,
80+ outputTokens : 0 ,
81+ reasoningTokens : 0 ,
82+ } ,
83+ } ) ,
84+ ] ,
85+ ] ,
7086 ] ) ;
7187 original . set ( "/grok.jsonl" , {
7288 size : 40 ,
7389 mtimeMs : 300 ,
7490 provider : "grok" ,
7591 records : [
7692 record ( { provider : "grok" , model : "grok-4.5-build" , dedupeKey : "s:p:grok-4.5-build" } ) ,
93+ record ( { provider : "grok" , model : "<synthetic>" , dedupeKey : "s:p:<synthetic>" } ) ,
7794 ] ,
78- tailRecords : [ record ( { provider : "grok" , model : "grok-4.5-build " , dedupeKey : null } ) ] ,
95+ tailRecords : [ record ( { provider : "grok" , model : "<synthetic> " , dedupeKey : null } ) ] ,
7996 position : position ( { resumeOffset : 30 , guardLength : 30 , guardHash : 123 } ) ,
8097 } ) ;
8198 original . set ( "/codex.jsonl" , {
@@ -99,16 +116,26 @@ describe("scan cache round trip", () => {
99116 } ) ,
100117 } ) ;
101118
119+ original . set ( "/a.jsonl" , {
120+ ...original . get ( "/a.jsonl" ) ! ,
121+ tailRecords : [ record ( { dedupeKey : "msg_tail:" } ) ] ,
122+ } ) ;
123+ const claude = original . get ( "/a.jsonl" ) ! ;
124+ const cached = new Map ( original ) ;
125+ cached . set ( "/a.jsonl" , {
126+ ...claude ,
127+ records : [ ...claude . records , record ( { model : "<synthetic>" } ) ] ,
128+ tailRecords : [
129+ ...claude . tailRecords ,
130+ record ( { model : "<synthetic>" , dedupeKey : "msg_tail:" } ) ,
131+ ] ,
132+ } ) ;
102133 const restored = decodeScanCache (
103- JSON . parse ( JSON . stringify ( encodeScanCache ( original ) ) ) ,
134+ JSON . parse ( JSON . stringify ( encodeScanCache ( cached ) ) ) ,
104135 TEST_FORMAT_MAP ,
105136 ) ;
106137
107- expect ( restored . size ) . toBe ( 4 ) ;
108- expect ( restored . get ( "/a.jsonl" ) ) . toEqual ( original . get ( "/a.jsonl" ) ) ;
109- expect ( restored . get ( "/b.jsonl" ) ) . toEqual ( original . get ( "/b.jsonl" ) ) ;
110- expect ( restored . get ( "/grok.jsonl" ) ) . toEqual ( original . get ( "/grok.jsonl" ) ) ;
111- expect ( restored . get ( "/codex.jsonl" ) ) . toEqual ( original . get ( "/codex.jsonl" ) ) ;
138+ expect ( restored ) . toEqual ( original ) ;
112139 } ) ;
113140
114141 it ( "drops an entry whose persisted parse state is corrupt" , ( ) => {
@@ -157,16 +184,6 @@ describe("scan cache round trip", () => {
157184 expect ( decodeScanCache ( JSON . parse ( JSON . stringify ( previous ) ) , TEST_FORMAT_MAP ) . size ) . toBe ( 0 ) ;
158185 } ) ;
159186
160- it ( "drops Claude's locally generated messages from entries cached with them" , ( ) => {
161- const kept = record ( ) ;
162- const encoded = encodeScanCache (
163- cacheWith ( [ [ "/a.jsonl" , 100 , [ kept , record ( { model : "<synthetic>" , dedupeKey : "msg_2:" } ) ] ] ] ) ,
164- ) ;
165-
166- const restored = decodeScanCache ( JSON . parse ( JSON . stringify ( encoded ) ) , TEST_FORMAT_MAP ) ;
167- expect ( restored . get ( "/a.jsonl" ) ?. records ) . toEqual ( [ kept ] ) ;
168- } ) ;
169-
170187 it ( "rewrites only changed entries and still restores the whole cache" , ( ) => {
171188 const write = makeScanCacheWriter ( ) ;
172189 const cache = cacheWith ( [
0 commit comments