@@ -15,63 +15,6 @@ import { extractLastJson, extractCommandOutput } from '../fixtures/stdout-helper
1515// The API proxy sidecar is at this fixed IP on the awf-net network
1616const API_PROXY_IP = '172.30.0.30' ;
1717
18- /**
19- * Extract the last JSON object from stdout.
20- *
21- * When --build-local is used, Docker build output is mixed into stdout before
22- * the actual command output. This helper finds the last complete top-level
23- * JSON object in the output so that JSON.parse works reliably.
24- */
25- function extractLastJson ( stdout : string ) : unknown {
26- // Find the last '{' that starts a top-level JSON object
27- let depth = 0 ;
28- let jsonEnd = - 1 ;
29- let jsonStart = - 1 ;
30-
31- // Scan backwards from end to find the last complete JSON object
32- for ( let i = stdout . length - 1 ; i >= 0 ; i -- ) {
33- const ch = stdout [ i ] ;
34- if ( ch === '}' ) {
35- if ( depth === 0 ) jsonEnd = i ;
36- depth ++ ;
37- } else if ( ch === '{' ) {
38- depth -- ;
39- if ( depth === 0 ) {
40- jsonStart = i ;
41- break ;
42- }
43- }
44- }
45-
46- if ( jsonStart === - 1 || jsonEnd === - 1 ) {
47- throw new Error ( `No JSON object found in stdout (length=${ stdout . length } ): ${ stdout . slice ( - 200 ) } ` ) ;
48- }
49-
50- return JSON . parse ( stdout . slice ( jsonStart , jsonEnd + 1 ) ) ;
51- }
52-
53- /**
54- * Extract the HTTP response section from stdout when curl -i is used.
55- *
56- * Docker build output appears before the HTTP response. This finds the last
57- * HTTP response block (starting with "HTTP/") in stdout.
58- */
59- function extractHttpResponse ( stdout : string ) : string {
60- // Find the last occurrence of an HTTP status line
61- const httpPattern = / H T T P \/ [ \d . ] + \d + / g;
62- let lastMatch : RegExpExecArray | null = null ;
63- let match : RegExpExecArray | null ;
64- while ( ( match = httpPattern . exec ( stdout ) ) !== null ) {
65- lastMatch = match ;
66- }
67-
68- if ( lastMatch ) {
69- return stdout . slice ( lastMatch . index ) ;
70- }
71-
72- // Fallback: return the whole stdout
73- return stdout ;
74- }
7518
7619describe ( 'API Proxy Observability' , ( ) => {
7720 let runner : AwfRunner ;
0 commit comments