@@ -583,12 +583,17 @@ func TestNormalizeRawReadsCPA7118UsageFields(t *testing.T) {
583583 }
584584 if ! event .Failed || event .FailStatusCode != 429 ||
585585 ! strings .Contains (event .FailBody , "rate limit exceeded" ) ||
586- ! strings .Contains (event .FailBody , "Retry-After" ) {
586+ strings .Contains (event .FailBody , "Retry-After" ) {
587587 t .Fatalf ("event failure = %#v" , event )
588588 }
589- if ! strings .Contains (event .FailSummary , "rate limit exceeded" ) || ! strings .Contains (event .FailSummary , "Retry-After" ) {
589+ if ! strings .Contains (event .FailSummary , "rate limit exceeded" ) || strings .Contains (event .FailSummary , "Retry-After" ) {
590590 t .Fatalf ("fail summary = %q" , event .FailSummary )
591591 }
592+ if event .ResponseMetadata == nil || event .ResponseMetadata .Errors == nil ||
593+ event .ResponseMetadata .Errors .RetryAfterSeconds == nil ||
594+ * event .ResponseMetadata .Errors .RetryAfterSeconds != 30 {
595+ t .Fatalf ("response metadata = %#v" , event .ResponseMetadata )
596+ }
592597 if event .LatencyMS == nil || * event .LatencyMS != 1500 {
593598 t .Fatalf ("latency = %#v" , event .LatencyMS )
594599 }
@@ -611,12 +616,51 @@ func TestNormalizeRawReadsCPA7118UsageFields(t *testing.T) {
611616 detail .Tokens .CacheCreationTokens != 1 || detail .FailStatusCode != 429 ||
612617 detail .Tokens .CachedTokens != 0 || detail .Tokens .CacheTokens != 0 ||
613618 ! strings .Contains (detail .FailSummary , "rate limit exceeded" ) ||
614- ! strings .Contains (detail .FailSummary , "Retry-After" ) || detail .TTFTMS == nil ||
619+ strings .Contains (detail .FailSummary , "Retry-After" ) || detail .ResponseMetadata == nil ||
620+ detail .ResponseMetadata .Errors == nil || detail .TTFTMS == nil ||
615621 * detail .TTFTMS != 450 {
616622 t .Fatalf ("detail = %#v" , detail )
617623 }
618624}
619625
626+ func TestNormalizeRawKeepsSuccessfulResponseHeadersOutOfFailureFields (t * testing.T ) {
627+ marker := strings .Repeat ("large-success-header-marker-" , 256 )
628+ payload , err := json .Marshal (map [string ]any {
629+ "timestamp" : "2026-04-25T00:00:00Z" ,
630+ "source" : "user@example.com" ,
631+ "tokens" : map [string ]any {
632+ "input_tokens" : 1 ,
633+ "total_tokens" : 1 ,
634+ },
635+ "failed" : false ,
636+ "provider" : "openai" ,
637+ "model" : "gpt-5.4" ,
638+ "endpoint" : "POST /v1/chat/completions" ,
639+ "response_headers" : map [string ]any {
640+ "Content-Type" : []any {"application/json" },
641+ "X-CPAMP-Unindexed-Diagnostic" : []any {marker },
642+ },
643+ })
644+ if err != nil {
645+ t .Fatalf ("marshal payload: %v" , err )
646+ }
647+
648+ event , err := NormalizeRaw (payload )
649+ if err != nil {
650+ t .Fatalf ("normalize successful response: %v" , err )
651+ }
652+ if event .Failed || event .FailBody != "" || event .FailSummary != "" {
653+ t .Fatalf ("successful failure fields = failed:%v body:%q summary:%q" , event .Failed , event .FailBody , event .FailSummary )
654+ }
655+ if event .ResponseMetadata == nil || event .ResponseMetadata .Response == nil ||
656+ event .ResponseMetadata .Response .ContentType != "application/json" || event .ResponseMetadataJSON == "" {
657+ t .Fatalf ("response metadata = %#v json=%q" , event .ResponseMetadata , event .ResponseMetadataJSON )
658+ }
659+ if ! strings .Contains (event .RawJSON , marker ) {
660+ t .Fatalf ("raw json did not preserve response headers" )
661+ }
662+ }
663+
620664func TestNormalizeRawReadsAnthropicCacheUsageFields (t * testing.T ) {
621665 payload := `{
622666 "timestamp": "2026-04-25T00:00:00Z",
0 commit comments