@@ -4,6 +4,7 @@ import path from 'node:path';
44import { fileURLToPath } from 'node:url' ;
55import { gradeScenario , inferStuckAt , renderSummary } from './lib/grader.mjs' ;
66import { buildSessionSettings , resolveCloudRunId , suiteShouldFail } from './lib/suite.mjs' ;
7+ import { GnippetsE2EClient } from './lib/webbrain-client.mjs' ;
78
89const root = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
910const scenarios = JSON . parse ( await fs . readFile ( path . join ( root , 'catalog' , 'scenarios.json' ) , 'utf8' ) ) ;
@@ -29,6 +30,47 @@ assert.deepEqual(
2930 { enabled : true , key : 'captcha-key' } ,
3031) ;
3132
33+ const diagnosticSecret = 'diagnostic-secret-that-must-not-leak' ;
34+ let diagnosticRequest ;
35+ const diagnosticClient = new GnippetsE2EClient ( {
36+ baseUrl : 'https://gnippets.example' ,
37+ controlToken : diagnosticSecret ,
38+ fetchImpl : async ( url , options ) => {
39+ diagnosticRequest = { url, options } ;
40+ return {
41+ ok : false ,
42+ status : 403 ,
43+ headers : {
44+ get ( name ) {
45+ return {
46+ server : 'cloudflare' ,
47+ 'cf-ray' : 'fixture-ray-IST' ,
48+ 'cf-mitigated' : 'challenge' ,
49+ 'content-type' : 'text/html' ,
50+ } [ name . toLowerCase ( ) ] || null ;
51+ } ,
52+ } ,
53+ async text ( ) {
54+ return `<html><title>Attention Required</title><body>Bearer ${ diagnosticSecret } </body></html>` ;
55+ } ,
56+ } ;
57+ } ,
58+ } ) ;
59+ await assert . rejects (
60+ diagnosticClient . createRun ( 'fixture' ) ,
61+ ( error ) => {
62+ assert . equal ( error . status , 403 ) ;
63+ assert . equal ( error . body . server , 'cloudflare' ) ;
64+ assert . equal ( error . body . cf_mitigated , 'challenge' ) ;
65+ assert . match ( error . message , / f i x t u r e - r a y - I S T / ) ;
66+ assert . match ( error . message , / A t t e n t i o n R e q u i r e d / ) ;
67+ assert . doesNotMatch ( error . message , new RegExp ( diagnosticSecret ) ) ;
68+ return true ;
69+ } ,
70+ ) ;
71+ assert . equal ( diagnosticRequest . options . headers . accept , 'application/json' ) ;
72+ assert . match ( diagnosticRequest . options . headers [ 'user-agent' ] , / W e b B r a i n C l o u d E 2 E / ) ;
73+
3274const mountainScenario = scenarios . find ( ( scenario ) => scenario . id === 'wikipedia-table-extraction' ) ;
3375const invalidMountainHeights = gradeScenario ( {
3476 scenario : mountainScenario ,
0 commit comments