@@ -258,6 +258,39 @@ describe("request log metadata", () => {
258258 expect ( captured2 [ 0 ] ) . not . toHaveProperty ( "firstOutputMs" ) ;
259259 } ) ;
260260
261+ test ( "persists the shadow helper source marker to usage.jsonl" , ( ) => {
262+ const home = mkdtempSync ( join ( tmpdir ( ) , "ocx-shadow-usage-" ) ) ;
263+ const previousHome = process . env . OPENCODEX_HOME ;
264+ const rawSecret = `sk-proj-${ "x" . repeat ( 96 ) } ` ;
265+ const unsafeMarker = `gpt-5.6-luna\r\nBearer ${ rawSecret } \u0007 ${ "tail" . repeat ( 32 ) } ` ;
266+ process . env . OPENCODEX_HOME = home ;
267+ try {
268+ clearRequestLogsForTests ( ) ;
269+ resetUsageReadCacheForTests ( ) ;
270+ addFinalRequestLog ( "ocx-shadow-marker" , 1 , {
271+ model : "grok-4.5" ,
272+ provider : "xai" ,
273+ requestedModel : "gpt-5.6-luna" ,
274+ shadowCallRewrittenFrom : unsafeMarker ,
275+ } , 200 ) ;
276+
277+ const [ persisted ] = readUsageEntries ( ) ;
278+ const persistedMarker = persisted ?. shadowCallRewrittenFrom ;
279+ const inMemoryMarker = getRequestLogEntries ( ) [ 0 ] ?. shadowCallRewrittenFrom ;
280+ expect ( persistedMarker ) . toBe ( inMemoryMarker ) ;
281+ expect ( persistedMarker ) . toBeDefined ( ) ;
282+ expect ( persistedMarker ! . length ) . toBeLessThanOrEqual ( 64 ) ;
283+ expect ( persistedMarker ) . not . toContain ( rawSecret ) ;
284+ expect ( persistedMarker ) . not . toMatch ( / [ \u0000 - \u001f \u007f - \u009f \u2028 \u2029 ] / ) ;
285+ } finally {
286+ clearRequestLogsForTests ( ) ;
287+ if ( previousHome === undefined ) delete process . env . OPENCODEX_HOME ;
288+ else process . env . OPENCODEX_HOME = previousHome ;
289+ resetUsageReadCacheForTests ( ) ;
290+ rmSync ( home , { recursive : true , force : true } ) ;
291+ }
292+ } ) ;
293+
261294 test ( "records ordered attempts with sealed identity, fresh estimates, and deduplicated recoveries" , ( ) => {
262295 const a = beginRequestAttempt ( 1 , "provisional-a" , "model-a" , "openai-chat" ) ;
263296 noteAttemptSend ( a , 100 ) ;
@@ -1312,6 +1345,7 @@ describe("request log restart hydrate", () => {
13121345 provider : "chatgpt-pabcdef" ,
13131346 model : "gpt-5.6-sol" ,
13141347 requestedModel : "gpt-5.6-sol" ,
1348+ shadowCallRewrittenFrom : "gpt-5.6-luna" ,
13151349 requestedEffort : "high" ,
13161350 effectiveEffort : "high" ,
13171351 reasoningWireField : "reasoning_effort" ,
@@ -1334,6 +1368,7 @@ describe("request log restart hydrate", () => {
13341368 provider : "chatgpt-pabcdef" ,
13351369 model : "gpt-5.6-sol" ,
13361370 requestedModel : "gpt-5.6-sol" ,
1371+ shadowCallRewrittenFrom : "gpt-5.6-luna" ,
13371372 requestedEffort : "high" ,
13381373 effectiveEffort : "high" ,
13391374 reasoningWireField : "reasoning_effort" ,
@@ -1381,6 +1416,7 @@ describe("request log restart hydrate", () => {
13811416 terminalStatus : "failed" ,
13821417 closeReason : "terminal" ,
13831418 upstreamError : "Provider unreachable" ,
1419+ shadowCallRewrittenFrom : "gpt-5.6-luna" ,
13841420 } ,
13851421 ] ;
13861422
@@ -1392,6 +1428,7 @@ describe("request log restart hydrate", () => {
13921428 errorCode : "upstream_server_error" ,
13931429 upstreamError : "Provider unreachable" ,
13941430 requestedEffort : "xhigh" ,
1431+ shadowCallRewrittenFrom : "gpt-5.6-luna" ,
13951432 } ) ;
13961433
13971434 // Idempotent: a second start in the same process must not duplicate.
0 commit comments