@@ -12,6 +12,8 @@ import {
1212 addFinalRequestLog ,
1313 applyResponseLogMetadata ,
1414 beginRequestAttempt ,
15+ inspectResponseLogJson ,
16+ inspectResponseLogSsePayloadParsed ,
1517 recordAdapterTier ,
1618 type RequestLogContext ,
1719 type RequestLogEntry ,
@@ -245,6 +247,54 @@ describe("FastWire logging and persistence", () => {
245247 expect ( logged ?. tierOutcome ) . toEqual ( logged ?. attempts ?. [ 0 ] ?. tierOutcome ) ;
246248 } ) ;
247249
250+ test . each ( [
251+ {
252+ label : "JSON" ,
253+ inspect : ( logCtx : RequestLogContext ) => inspectResponseLogJson ( logCtx , "not-json" ) ,
254+ } ,
255+ {
256+ label : "SSE" ,
257+ inspect : ( logCtx : RequestLogContext ) => {
258+ inspectResponseLogSsePayloadParsed ( logCtx , "not-json" , undefined ) ;
259+ } ,
260+ } ,
261+ ] ) ( "$label inspection marks an unparseable response outcome unknown" , ( { inspect } ) => {
262+ const tracker = createAdapterTierMetadata (
263+ observation ( ) ,
264+ { kind : "set" , value : "priority" } ,
265+ "service-tier" ,
266+ "priority" ,
267+ ) ! ;
268+ const attempt = beginRequestAttempt ( 1 , "openai" , "gpt-5.6-sol" , "openai-responses" ) ;
269+ const logCtx : RequestLogContext = {
270+ model : "gpt-5.6-sol" ,
271+ provider : "openai" ,
272+ activeAttempt : attempt ,
273+ activeAttemptStartedAt : Date . now ( ) ,
274+ attempts : [ attempt ] ,
275+ } ;
276+ recordAdapterTier ( logCtx , {
277+ url : "https://example.test/v1/responses" ,
278+ method : "POST" ,
279+ headers : { } ,
280+ body : "{}" ,
281+ tierLog : tracker ,
282+ } satisfies AdapterRequest ) ;
283+ expect ( attempt . tierOutcome ) . toMatchObject ( {
284+ canonical : "priority" ,
285+ fastOutcome : "applied" ,
286+ confirmation : "assumed" ,
287+ } ) ;
288+
289+ inspect ( logCtx ) ;
290+
291+ expect ( attempt . tierOutcome ) . toMatchObject ( {
292+ fastOutcome : "unknown" ,
293+ confirmation : "unknown" ,
294+ } ) ;
295+ expect ( attempt . tierOutcome ) . not . toHaveProperty ( "canonical" ) ;
296+ } ) ;
297+
248298 test ( "old attempts remain valid and new outcomes survive normalization" , ( ) => {
249299 const oldAttempt = {
250300 ordinal : 1 ,
@@ -287,10 +337,12 @@ describe("FastWire logging and persistence", () => {
287337 } ) ;
288338
289339 test ( "callerServiceTier is trimmed, control-filtered, redacted, and capped" , ( ) => {
290- const secret = "sk-proj-abcdefghijklmnopqrstuvwxyz0123456789" ;
291- const sanitized = sanitizeLogMetadataString ( ` \u0000authorization: Bearer ${ secret } \n${ "x" . repeat ( 80 ) } ` ) ;
340+ const secret = [ "sk" , "proj" , "abcdefghijklmnopqrstuvwxyz0123456789" ] . join ( "-" ) ;
341+ const sanitized = sanitizeLogMetadataString (
342+ ` \u0000authorization: Bearer ${ secret } \n\u0085\u2028\u2029${ "x" . repeat ( 80 ) } ` ,
343+ ) ;
292344 expect ( sanitized ) . not . toContain ( secret ) ;
293- expect ( sanitized ) . not . toMatch ( / [ \u0000 - \u001f \u007f ] / ) ;
345+ expect ( sanitized ) . not . toMatch ( / [ \u0000 - \u001f \u007f - \u009f \u2028 \u2029 ] / ) ;
294346 expect ( sanitized ?. length ) . toBeLessThanOrEqual ( 64 ) ;
295347
296348 const normalized = normalizeUsageEntryForTest ( {
@@ -318,6 +370,31 @@ describe("FastWire per-attempt cost", () => {
318370 } ] ;
319371 const usage = { inputTokens : 200_000 , outputTokens : 20_000 } ;
320372
373+ test ( "an unknown unclassified outcome prices from the serialized caller tier" , ( ) => {
374+ const outcome = {
375+ wireKind : "service-tier" as const ,
376+ wireValue : "priority" ,
377+ fastOutcome : "unknown" as const ,
378+ confirmation : "unknown" as const ,
379+ } ;
380+ expect ( serviceTierContextFromOutcome ( outcome ) ) . toEqual ( {
381+ requestedServiceTier : "priority" ,
382+ } ) ;
383+
384+ const estimate = estimateComboCost ( [
385+ {
386+ ordinal : 1 ,
387+ provider : "openai" ,
388+ model : "gpt-5.6-sol" ,
389+ usageStatus : "reported" ,
390+ usage,
391+ tierOutcome : outcome ,
392+ } ,
393+ ] , overlays , { requestedServiceTier : "priority" } ) ! ;
394+ expect ( estimate . priorityMultiplier ) . toBe ( 2 ) ;
395+ expect ( estimate . cost . total ) . toBeCloseTo ( 3.2 , 9 ) ;
396+ } ) ;
397+
321398 test ( "combo prices each attempt from its own outcome before the top-level tier" , ( ) => {
322399 const attempts = [
323400 {
0 commit comments