@@ -495,25 +495,33 @@ const CHECKER_MUTATIONS: Partial<Record<FixtureMode, (source: string) => string>
495495 ) ,
496496 "trusted-formula-mismatch" : ( source ) => source . replace ( FORMULA_DIGEST , "0" . repeat ( 64 ) ) ,
497497} ;
498+ const prependTrustedPin = ( source : string , name : string , pin : string ) : string => {
499+ const declarationStart = source . indexOf ( `const ${ name } ` ) ;
500+ const assignment = source . indexOf ( "=" , declarationStart ) ;
501+ const arrayStart = source . indexOf ( "[" , assignment ) ;
502+ assert . notEqual ( declarationStart , - 1 , `${ name } declaration must exist` ) ;
503+ assert . notEqual ( assignment , - 1 , `${ name } assignment must exist` ) ;
504+ assert . notEqual ( arrayStart , - 1 , `${ name } array must exist` ) ;
505+ return `${ source . slice ( 0 , arrayStart + 1 ) } \n${ pin } ${ source . slice ( arrayStart + 1 ) } ` ;
506+ } ;
507+
498508const trustAlternateRelease = ( source : string ) : string => {
499509 const digests = SYNTHETIC_SANDBOX_BUILD_DIGESTS ;
500- const sandbox = source . replace (
501- "const TRUSTED_SANDBOX_BUILD_PINS: readonly TrustedSandboxBuildPin[] = [\n" ,
502- `const TRUSTED_SANDBOX_BUILD_PINS: readonly TrustedSandboxBuildPin[] = [
503- { required: false, sha256: "${ digests [ 0 ] } ", version: "9.9.9" },
504- { required: false, sha256: "${ digests [ 1 ] } ", version: "9.9.9" },
505- ` ,
510+ const sandbox = prependTrustedPin (
511+ source ,
512+ "TRUSTED_SANDBOX_BUILD_PINS" ,
513+ ` { required: false, sha256: "${ digests [ 0 ] } ", version: "9.9.9" },
514+ { required: false, sha256: "${ digests [ 1 ] } ", version: "9.9.9" },` ,
506515 ) ;
507- return sandbox . replace (
508- "const TRUSTED_SUPERVISOR_MANIFEST_PINS: readonly TrustedSupervisorManifestPin[] = [\n" ,
509- `const TRUSTED_SUPERVISOR_MANIFEST_PINS: readonly TrustedSupervisorManifestPin[] = [
510- {
516+ return prependTrustedPin (
517+ sandbox ,
518+ " TRUSTED_SUPERVISOR_MANIFEST_PINS" ,
519+ ` {
511520 image: OPENSHELL_SUPERVISOR_IMAGE,
512521 manifestDigest: "${ SYNTHETIC_SUPERVISOR_MANIFEST_DIGEST } ",
513522 required: false,
514523 version: "9.9.9",
515- },
516- ` ,
524+ },` ,
517525 ) ;
518526} ;
519527const PARSER_MUTATIONS : Partial < Record < FixtureMode , ( source : string ) => string > > = {
@@ -524,10 +532,22 @@ const tempDirs: string[] = [];
524532
525533function trustedPinArray ( name : string ) : string {
526534 const start = TRUSTED_PARSER_TEMPLATE . indexOf ( `const ${ name } ` ) ;
527- const end = TRUSTED_PARSER_TEMPLATE . indexOf ( "\n];" , start ) ;
535+ const assignment = TRUSTED_PARSER_TEMPLATE . indexOf ( "=" , start ) ;
536+ const arrayStart = TRUSTED_PARSER_TEMPLATE . indexOf ( "[" , assignment ) ;
528537 expect ( start , `${ name } start` ) . not . toBe ( - 1 ) ;
529- expect ( end , `${ name } end` ) . not . toBe ( - 1 ) ;
530- return TRUSTED_PARSER_TEMPLATE . slice ( start , end ) ;
538+ expect ( assignment , `${ name } assignment` ) . not . toBe ( - 1 ) ;
539+ expect ( arrayStart , `${ name } array start` ) . not . toBe ( - 1 ) ;
540+
541+ let depth = 0 ;
542+ for ( let index = arrayStart ; index < TRUSTED_PARSER_TEMPLATE . length ; index += 1 ) {
543+ const character = TRUSTED_PARSER_TEMPLATE [ index ] ;
544+ if ( character === "[" ) depth += 1 ;
545+ if ( character !== "]" ) continue ;
546+ depth -= 1 ;
547+ if ( depth === 0 ) return TRUSTED_PARSER_TEMPLATE . slice ( arrayStart + 1 , index ) ;
548+ }
549+
550+ expect . fail ( `${ name } array end` ) ;
531551}
532552
533553function trustedSandboxBuildDigests ( version : string ) : readonly [ string , string ] | undefined {
0 commit comments