@@ -441,7 +441,7 @@ test("full chain clean -> summarize -> classify verifies with schema using parti
441441
442442 async function runVerb ( base , verb , content ) {
443443 const controller = new AbortController ( ) ;
444- const timeout = setTimeout ( ( ) => controller . abort ( ) , 10000 ) ;
444+ const timeout = setTimeout ( ( ) => controller . abort ( ) , 5000 ) ;
445445
446446 try {
447447 const res = await fetch ( `${ base } /${ verb } /v1.1.0` , {
@@ -460,58 +460,99 @@ test("full chain clean -> summarize -> classify verifies with schema using parti
460460 throw new Error ( `HTTP ${ res . status } : ${ text } ` ) ;
461461 }
462462
463- const json = JSON . parse ( text ) ;
464- return json ;
465-
463+ return JSON . parse ( text ) ;
466464 } catch ( err ) {
467- const cause = err ?. cause ?. code || err ?. cause || err . message ;
468- throw new Error ( `runVerb(${ verb } ) failed: ${ cause } ` ) ;
465+ const message = err ?. name === "AbortError" ? "AbortError" : err ?. message || String ( err ) ;
466+ throw new Error ( `runVerb(${ verb } ) failed: ${ message } ` ) ;
469467 } finally {
470468 clearTimeout ( timeout ) ;
471469 }
472470 }
473471
474- try {
475- const source = "Hello world. This is a test document. It contains multiple sentences." ;
476- let finalReceipt ;
472+ async function verifyReceiptWithTimeout ( receipt ) {
473+ const controller = new AbortController ( ) ;
474+ const timeout = setTimeout ( ( ) => controller . abort ( ) , 5000 ) ;
477475
478476 try {
479- const clean = await runVerb ( srv . base , "clean" , source ) ;
477+ const res = await fetch ( `${ srv . base } /verify?schema=1` , {
478+ method : "POST" ,
479+ headers : { "content-type" : "application/json" } ,
480+ body : JSON . stringify ( receipt ) ,
481+ signal : controller . signal ,
482+ } ) ;
483+ const text = await res . text ( ) ;
484+ let json ;
485+
486+ try {
487+ json = JSON . parse ( text ) ;
488+ } catch {
489+ json = null ;
490+ }
480491
481- assert . ok ( clean ?. receipt ?. result ?. cleaned_content , "clean step missing cleaned_content" ) ;
482- const cleanText = clean . receipt . result . cleaned_content ;
492+ if ( ! res . ok && res . status !== 202 ) {
493+ throw new Error ( `HTTP ${ res . status } : ${ text } ` ) ;
494+ }
483495
484- const summarize = await runVerb ( srv . base , "summarize" , cleanText ) ;
496+ return { res, text, json } ;
497+ } catch ( err ) {
498+ const message = err ?. name === "AbortError" ? "AbortError" : err ?. message || String ( err ) ;
499+ throw new Error ( `verify failed: ${ message } ` ) ;
500+ } finally {
501+ clearTimeout ( timeout ) ;
502+ }
503+ }
485504
486- assert . ok ( summarize ?. receipt ?. result ?. summary , "summarize step missing summary" ) ;
487- const summary = summarize . receipt . result . summary ;
505+ try {
506+ const source = "Hello world. This is a test document. It contains multiple sentences." ;
488507
489- const classify = await runVerb ( srv . base , "classify" , summary ) ;
508+ console . log ( "[chain] before clean request" ) ;
509+ const clean = await runVerb ( srv . base , "clean" , source ) ;
510+ console . log ( "[chain] after clean response" ) ;
511+ assert . ok ( clean ?. receipt ?. result ?. cleaned_content , "clean step missing cleaned_content" ) ;
512+ const cleanText = clean . receipt . result . cleaned_content ;
490513
491- assert . ok ( classify ?. receipt , "classify step missing receipt" ) ;
492- finalReceipt = classify . receipt ;
514+ console . log ( "[chain] before summarize request" ) ;
515+ const summarize = await runVerb ( srv . base , "summarize" , cleanText ) ;
516+ console . log ( "[chain] after summarize response" ) ;
517+ assert . ok ( summarize ?. receipt ?. result ?. summary , "summarize step missing summary" ) ;
518+ const summary = summarize . receipt . result . summary ;
493519
494- } catch ( err ) {
495- console . error ( "CHAIN FAILURE DEBUG:" ) ;
496- console . error ( err ) ;
497- throw err ;
498- }
520+ console . log ( "[chain] before classify request" ) ;
521+ const classify = await runVerb ( srv . base , "classify" , summary ) ;
522+ console . log ( "[chain] after classify response" ) ;
523+ assert . ok ( classify ?. receipt , "classify step missing receipt" ) ;
524+ const finalReceipt = classify . receipt ;
499525
500526 assert . equal ( finalReceipt . x402 . entry , "x402://classifyagent.eth/classify/v1.1.0" ) ;
501527
502- const verifyRes = await fetch ( `${ srv . base } /verify?schema=1` , {
503- method : "POST" ,
504- headers : { "content-type" : "application/json" } ,
505- body : JSON . stringify ( finalReceipt ) ,
506- } ) ;
507- const verifyJson = await verifyRes . json ( ) ;
528+ console . log ( "[chain] before verify request" ) ;
529+ let verifyAttempt = await verifyReceiptWithTimeout ( finalReceipt ) ;
530+ console . log ( "[chain] after verify response" , verifyAttempt . res . status , verifyAttempt . json ?? verifyAttempt . text ) ;
531+
532+ if (
533+ verifyAttempt . res . status === 202
534+ && verifyAttempt . json ?. reason === "validator_not_warmed_yet"
535+ ) {
536+ console . log ( "[chain] verify warmup 202 response" , verifyAttempt . json ) ;
537+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1200 ) ) ;
538+ console . log ( "[chain] before verify request retry" ) ;
539+ verifyAttempt = await verifyReceiptWithTimeout ( finalReceipt ) ;
540+ console . log ( "[chain] after verify response retry" , verifyAttempt . res . status , verifyAttempt . json ?? verifyAttempt . text ) ;
541+ }
508542
509- console . log ( "VERIFY RESULT:" , verifyJson ) ;
543+ const verifyRes = verifyAttempt . res ;
544+ const verifyJson = verifyAttempt . json ;
510545
546+ assert . ok ( verifyJson , "verify returned non-JSON response" ) ;
511547 assert . equal ( verifyRes . status , 200 ) ;
512548 assert . equal ( verifyJson . checks . signature_valid , true ) ;
513549 assert . equal ( verifyJson . checks . hash_matches , true ) ;
514550 assert . equal ( verifyJson . checks . schema_valid , true ) ;
551+ } catch ( err ) {
552+ console . error ( "CHAIN FAILURE DEBUG:" ) ;
553+ console . error ( err ) ;
554+ console . error ( "SERVER STDERR:" , srv . stderr ( ) ) ;
555+ throw err ;
515556 } finally {
516557 await stop ( srv . proc ) ;
517558 }
0 commit comments