@@ -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,41 @@ assert.deepEqual(
2930 { enabled : true , key : 'captcha-key' } ,
3031) ;
3132
33+ const diagnosticSecret = 'diagnostic-secret-that-must-not-leak' ;
34+ const diagnosticClient = new GnippetsE2EClient ( {
35+ baseUrl : 'https://gnippets.example' ,
36+ controlToken : diagnosticSecret ,
37+ fetchImpl : async ( ) => ( {
38+ ok : false ,
39+ status : 403 ,
40+ headers : {
41+ get ( name ) {
42+ return {
43+ server : 'cloudflare' ,
44+ 'cf-ray' : 'fixture-ray-IST' ,
45+ 'cf-mitigated' : 'challenge' ,
46+ 'content-type' : 'text/html' ,
47+ } [ name . toLowerCase ( ) ] || null ;
48+ } ,
49+ } ,
50+ async text ( ) {
51+ return `<html><title>Attention Required</title><body>Bearer ${ diagnosticSecret } </body></html>` ;
52+ } ,
53+ } ) ,
54+ } ) ;
55+ await assert . rejects (
56+ diagnosticClient . createRun ( 'fixture' ) ,
57+ ( error ) => {
58+ assert . equal ( error . status , 403 ) ;
59+ assert . equal ( error . body . server , 'cloudflare' ) ;
60+ assert . equal ( error . body . cf_mitigated , 'challenge' ) ;
61+ assert . match ( error . message , / f i x t u r e - r a y - I S T / ) ;
62+ assert . match ( error . message , / A t t e n t i o n R e q u i r e d / ) ;
63+ assert . doesNotMatch ( error . message , new RegExp ( diagnosticSecret ) ) ;
64+ return true ;
65+ } ,
66+ ) ;
67+
3268const mountainScenario = scenarios . find ( ( scenario ) => scenario . id === 'wikipedia-table-extraction' ) ;
3369const invalidMountainHeights = gradeScenario ( {
3470 scenario : mountainScenario ,
0 commit comments