99 * in a 0600 file only, and no written artifact carrying it.
1010 */
1111
12- import { createHash } from 'node:crypto' ;
1312import { existsSync , readdirSync , readFileSync , rmSync , writeFileSync } from 'node:fs' ;
1413import { join , dirname , resolve } from 'node:path' ;
1514import { fileURLToPath } from 'node:url' ;
@@ -31,7 +30,12 @@ const COMMAND = `${process.execPath} ${FAKE}`;
3130
3231/** A key no other text in a run could hold by chance. */
3332const KEY = 'sk-scenario-e2e-key-9f27c1d4' ;
34- const sha = ( s : string ) => createHash ( 'sha256' ) . update ( s ) . digest ( 'hex' ) ;
33+ /** The stand-in's fingerprint of the key it read (FNV-1a, 32-bit, hex): enough to tell this run's keys apart without logging one. */
34+ const keyPrint = ( s : string ) => {
35+ let h = 0x811c9dc5 ;
36+ for ( let i = 0 ; i < s . length ; i ++ ) h = Math . imul ( h ^ s . charCodeAt ( i ) , 0x01000193 ) >>> 0 ;
37+ return h . toString ( 16 ) . padStart ( 8 , '0' ) ;
38+ } ;
3539
3640const author = ( prompt : string , cwd = tempDir ( 'ext-project' ) ) : AuthorTask => ( { card : 'c' , mode : 'scratch' , phase : 'build' , step : 'author' , cwd, prompt, tier : 'starter' } ) ;
3741const ask = ( prompt : string ) : AskTask => ( { card : 'c' , mode : 'scratch' , phase : 'run' , step : 'q1' , persona : 'sdr' , prompt, mcp : { url : 'http://127.0.0.1:9/api/v1/mcp' , apiKey : KEY } } ) ;
@@ -85,7 +89,7 @@ describe('the external driver contract — one process per call, JSON in on stdi
8589 const { input, argv, seen } = echoed ( turn ) ;
8690 expect ( input ) . toMatchObject ( { contract : EXTERNAL_DRIVER_CONTRACT , kind : 'ask' , step : { card : 'c' , mode : 'scratch' , phase : 'run' , step : 'q1' , persona : 'sdr' } , prompt : 'ECHO how many accounts?' , limits : { timeoutMs : 5 * 60_000 } } ) ;
8791 expect ( Object . keys ( input . mcp as object ) . sort ( ) ) . toEqual ( [ 'configFile' , 'url' ] ) ;
88- expect ( seen ) . toMatchObject ( { fileMode : '600' , urlMatches : true , runsInConfigDir : true , keySha : sha ( KEY ) , keyOnArgv : false , keyInEnv : false , keyOnStdin : false } ) ;
92+ expect ( seen ) . toMatchObject ( { fileMode : '600' , urlMatches : true , runsInConfigDir : true , keyPrint : keyPrint ( KEY ) , keyOnArgv : false , keyInEnv : false , keyOnStdin : false } ) ;
8993 expect ( argv . join ( ' ' ) ) . not . toContain ( KEY ) ;
9094 expect ( existsSync ( seen ! . configFile as string ) ) . toBe ( false ) ;
9195 expect ( existsSync ( dirname ( seen ! . configFile as string ) ) ) . toBe ( false ) ;
@@ -185,10 +189,11 @@ describe('the persona keys, end to end over the external driver — the record,
185189 const calls = readFileSync ( log , 'utf8' ) . trim ( ) . split ( '\n' ) . map ( ( l ) => JSON . parse ( l ) as { kind : string ; seen ?: Record < string , unknown > } ) ;
186190 const asks = calls . filter ( ( c ) => c . kind === 'ask' ) ;
187191 expect ( asks . length ) . toBeGreaterThan ( 5 ) ;
188- const keys = new Set ( [ `${ KEY } admin` , ...fx . scenario . card . run . personas . map ( ( p ) => `${ KEY } ${ p . id } ` ) ] . map ( sha ) ) ;
192+ const keys = new Set ( [ `${ KEY } admin` , ...fx . scenario . card . run . personas . map ( ( p ) => `${ KEY } ${ p . id } ` ) ] . map ( keyPrint ) ) ;
193+ expect ( keys . size ) . toBe ( fx . scenario . card . run . personas . length + 1 ) ;
189194 for ( const a of asks ) {
190195 expect ( a . seen ) . toMatchObject ( { fileMode : '600' , keyOnArgv : false , keyInEnv : false , keyOnStdin : false } ) ;
191- expect ( keys . has ( a . seen ! . keySha as string ) ) . toBe ( true ) ;
196+ expect ( keys . has ( a . seen ! . keyPrint as string ) ) . toBe ( true ) ;
192197 expect ( existsSync ( a . seen ! . configFile as string ) ) . toBe ( false ) ;
193198 }
194199
@@ -222,5 +227,12 @@ describe('the persona keys, end to end over the external driver — the record,
222227 const page = readFileSync ( join ( out , 'apps' , fx . scenario . card . id , 'README.md' ) , 'utf8' ) ;
223228 expect ( page ) . toContain ( '- Driver: external:fake-agent 1.2.3 (re-graded from a recording of that run)\n' ) ;
224229 expect ( page ) . not . toContain ( runs ) ;
225- } ) ;
230+ // The budget is measured, not vitest's 5 s default. The run starts the
231+ // stand-in once per turn, one after another: 45 starts (3 author calls,
232+ // 42 asks over scratch run, scratch iterate-run and template iterate-run).
233+ // Measured 2.2–2.5 s over 10 local runs at ~50 ms a start. On a Test Core
234+ // shard one start took 212 ms (the info case) and this case was cut off
235+ // at 5042 ms (merge-queue run 42414930416). 30 s is ~6x the slowest
236+ // observed.
237+ } , 30_000 ) ;
226238} ) ;
0 commit comments