@@ -114,19 +114,51 @@ async function activeCases() {
114114 const end = source . indexOf ( 'function requestGateExternalIdPrefix(' , start ) ;
115115 assert ( start >= 0 && end > start ) ;
116116 const classify = new AsyncFunction ( 'fixture' , `
117- const owner='hemsoft-dev',repo='fixture',pullNumber=42,currentHead='${ head } ',context={runId:99};
117+ const owner='hemsoft-dev',repo='fixture',pullNumber=42,currentHead='${ head } ',currentBase='${ base } ',context={runId:99};
118+ const baseMarker='<!-- sfl-codex-review:head=${ head } ;base=${ base } ;';
119+ ${ block ( 'REQUEST ELIGIBILITY' ) . split ( 'const requestOrder =' ) [ 0 ] }
120+ ${ block ( 'REVIEW CONTEXT PROVENANCE' ) }
118121 const requesterAllowed=async login=>fixture.allowed.includes(login);
119- const github={rest:{actions:{listWorkflowRuns:'runs'},repos:{listCommitStatusesForRef:'statuses'}},
120- paginate:async(method,args)=>method==='runs'?(args.status==='queued'?fixture.runs:[]):fixture.statuses};
122+ const github={rest:{actions:{listWorkflowRuns:'runs'},repos:{listCommitStatusesForRef:'statuses'},checks:{listForRef:'checks'},
123+ issues:{getComment:async({comment_id})=>{
124+ if(fixture.error)throw fixture.error;
125+ if(fixture.comment===null)throw Object.assign(new Error('deleted'),{status:404});
126+ return {data:fixture.comment || {id:comment_id,body:fixture.exact,html_url:'https://github.com/hemsoft-dev/fixture/pull/42#issuecomment-'+comment_id,user:{login:'admin'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:01Z'}};
127+ }}},
128+ paginate:async(method,args)=>method==='runs'?(args.status==='queued'?fixture.runs:[]):method==='checks'?(fixture.checks || [{app:{id:15368},external_id:fixture.token,output:{text:JSON.stringify({schema:1,pull_number:42,action:'opened',base_sha:currentBase})}}]):fixture.statuses};
121129 ${ unindent ( source . slice ( start , end ) ) }
122130 ${ block ( 'ACTIVE INVALIDATIONS' ) }
123- return (await activeInvalidationRuns()).map(run=>run.id);` ) ;
131+ const results=[];
132+ for(const step of fixture.steps || [{}]){
133+ Object.assign(fixture,step);
134+ results.push((await activeInvalidationRuns()).map(run=>run.id));
135+ }
136+ return fixture.steps ? results : results[0];` ) ;
124137 const run = ( actor , id = 101 , markerIntent = false ) => ( { id :1 , event :'issue_comment' , status :'queued' , actor :{ login :actor } , display_title :titleForComment ( id , markerIntent ? exact : 'ordinary comment' ) } ) ;
125138 const registration = ( creator = 'author' , url = commentURL ) => ( { context :'SFL Codex Review Request Registry' , creator :{ login :creator } , target_url :url } ) ;
126139 const cases = [
127140 [ 'ordinary administrator comment' , [ run ( 'admin' ) ] , [ ] , [ 'admin' ] , [ ] ] ,
128141 [ 'writer request before registry visibility' , [ run ( 'admin' , 101 , true ) ] , [ ] , [ 'admin' ] , [ 1 ] ] ,
129142 [ 'reader marker before registry visibility' , [ run ( 'reader' , 101 , true ) ] , [ ] , [ ] , [ ] ] ,
143+ ...[
144+ [ 'quoted marker' , `An earlier request said:\n${ exact } ` ] ,
145+ [ 'trailing prose' , `${ exact } \nordinary follow-up` ] ,
146+ [ 'old head' , exact . replace ( head , 'c' . repeat ( 40 ) ) ] ,
147+ [ 'old base' , exact . replace ( base , 'c' . repeat ( 40 ) ) ] ,
148+ [ 'arbitrary context' , exact . replace ( token , 'foo' ) ] ,
149+ [ 'empty context' , exact . replace ( token , '' ) ] ,
150+ [ 'padded context' , exact . replace ( token , ' ' + token ) ] ,
151+ ] . map ( ( [ name , body ] ) => [ name , [ { ...run ( 'admin' , 101 , true ) , display_title :titleForComment ( 101 , body ) } ] , [ ] , [ 'admin' ] , [ ] ,
152+ { id :101 , body, html_url :commentURL , user :{ login :'admin' } , created_at :'2026-10-08T00:00:01Z' , updated_at :'2026-10-08T00:00:01Z' } ] ) ,
153+ [ 'deleted registry-free marker' , [ run ( 'admin' , 101 , true ) ] , [ ] , [ 'admin' ] , [ ] , null ] ,
154+ [ 'deleted revoked registered request' , [ run ( 'author' , 101 , true ) ] , [ registration ( ) ] , [ ] , [ 1 ] , null ] ,
155+ [ 'edited registry-free marker' , [ run ( 'admin' , 101 , true ) ] , [ ] , [ 'admin' ] , [ ] ,
156+ { id :101 , body :exact , html_url :commentURL , user :{ login :'admin' } , created_at :'2026-10-08T00:00:01Z' , updated_at :'2026-10-08T00:00:02Z' } ] ,
157+ [ 'different comment target' , [ run ( 'admin' , 101 , true ) ] , [ ] , [ 'admin' ] , [ ] ,
158+ { id :101 , body :exact , html_url :commentURL . replace ( '/42#' , '/43#' ) , user :{ login :'admin' } , created_at :'2026-10-08T00:00:01Z' , updated_at :'2026-10-08T00:00:01Z' } ] ,
159+ [ 'different author before registry' , [ run ( 'admin' , 101 , true ) ] , [ ] , [ 'admin' ] , [ ] ,
160+ { id :101 , body :exact , html_url :commentURL , user :{ login :'other' } , created_at :'2026-10-08T00:00:01Z' , updated_at :'2026-10-08T00:00:01Z' } ] ,
161+
130162 [ 'registered administrator request' , [ run ( 'admin' ) ] , [ registration ( 'admin' ) ] , [ 'admin' ] , [ 1 ] ] ,
131163 [ 'revoked registered author' , [ run ( 'author' ) ] , [ registration ( ) ] , [ ] , [ 1 ] ] ,
132164 [ 'unprivileged other actor' , [ run ( 'reader' ) ] , [ registration ( ) ] , [ ] , [ ] ] ,
@@ -142,9 +174,32 @@ async function activeCases() {
142174 [ 'completed comment run' , [ { ...run ( 'admin' ) , status :'completed' } ] , [ registration ( 'admin' ) ] , [ 'admin' ] , [ ] ] ,
143175 [ 'legacy writer run' , [ { ...run ( 'admin' ) , display_title :'SFL Codex review request #42' } ] , [ ] , [ 'admin' ] , [ 1 ] ] ,
144176 ] ;
145- for ( const [ name , runs , statuses , allowed , want ] of cases ) {
146- assert . deepEqual ( await classify ( { runs, statuses, allowed} ) , want , name ) ;
177+ for ( const [ name , runs , statuses , allowed , want , comment ] of cases ) {
178+ if ( process . argv [ 3 ] === 'probe-pinned' && name === 'arbitrary context' ) continue ;
179+ assert . deepEqual ( await classify ( { runs, statuses, allowed, comment, exact, token} ) , want , name ) ;
180+ }
181+ if ( process . argv [ 3 ] !== 'probe-pinned' ) {
182+ const trusted = { app :{ id :15368 } , external_id :token , output :{ text :JSON . stringify ( { schema :1 , pull_number :42 , action :'opened' , base_sha :base } ) } } ;
183+ for ( const checks of [ [ ] , [ { ...trusted , app :{ id :1 } } ] , [ { ...trusted , output :{ text :'malformed' } } ] ,
184+ [ { ...trusted , output :{ text :JSON . stringify ( { schema :1 , pull_number :42 , action :'opened' , base_sha :'c' . repeat ( 40 ) } ) } } ] ,
185+ [ trusted , { ...trusted , external_id :token + '1' } ] ] ) {
186+ assert . deepEqual ( await classify ( { runs :[ run ( 'admin' , 101 , true ) ] , statuses :[ ] , allowed :[ 'admin' ] , exact, token, checks} ) , [ ] , 'materializing request requires unique authenticated current context provenance' ) ;
187+ }
188+ }
189+ if ( process . argv [ 3 ] !== 'probe-context' ) {
190+ for ( const changed of [ null , { id :101 , body :exact + ' edited' , html_url :commentURL , user :{ login :'admin' } , created_at :'2026-10-08T00:00:01Z' , updated_at :'2026-10-08T00:00:02Z' } ] ) {
191+ const runs = [ run ( 'admin' , 101 , true ) ] ;
192+ assert . deepEqual ( await classify ( { runs, statuses :[ ] , allowed :[ 'admin' ] , exact, token, steps :[ { } , { comment :changed } , { runs :[ ] } ] } ) , [ [ 1 ] , [ 1 ] , [ ] ] , 'verified request remains serialized after mutation until its active run ends' ) ;
193+ }
194+ }
195+ if ( process . argv [ 3 ] !== 'probe-context' ) {
196+ assert . deepEqual ( await classify ( { runs :[ run ( 'admin' , 101 , true ) ] , statuses :[ ] , allowed :[ 'admin' ] , exact, token,
197+ steps :[ { } , { allowed :[ ] , comment :null } , { runs :[ ] } ] } ) , [ [ 1 ] , [ 1 ] , [ ] ] , 'verified request stays serialized after authorization loss until its active run ends' ) ;
198+ assert . deepEqual ( await classify ( { runs :[ run ( 'admin' , 101 , true ) ] , statuses :[ ] , allowed :[ 'admin' ] , exact, token,
199+ steps :[ { } , { runs :[ { ...run ( 'admin' , 101 , true ) , id :2 } ] , comment :null } ] } ) , [ [ 1 ] , [ ] ] , 'verified identity does not transfer to another run' ) ;
147200 }
201+ const error = Object . assign ( new Error ( 'comment verification unavailable' ) , { status :500 } ) ;
202+ await assert . rejects ( classify ( { runs :[ run ( 'admin' , 101 , true ) ] , statuses :[ ] , allowed :[ 'admin' ] , exact, token, error} ) , observed => observed === error ) ;
148203}
149204function retargetCases ( ) {
150205 const supported = new Function ( 'pull' , 'context' , 'headRepo' , 'owner' , 'repo' ,
@@ -319,22 +374,22 @@ async function publishedCheckRetryCases(baseFixture,first,selected) {
319374
320375( async ( ) => {
321376 const mode = process . argv [ 3 ] || 'all' ;
322- assert ( [ 'all' , 'probe-invalidation' , 'probe-history' , 'probe-revoked' , 'probe-active' , 'probe-retarget' , 'probe-polling' , 'probe-empty' , 'probe-repair' , 'probe-publication' , 'probe-check-retry' ] . includes ( mode ) ) ;
377+ assert ( [ 'all' , 'probe-invalidation' , 'probe-history' , 'probe-revoked' , 'probe-active' , 'probe-retarget' , 'probe-polling' , 'probe-empty' , 'probe-repair' , 'probe-publication' , 'probe-check-retry' , 'probe-context' , 'probe-pinned' ] . includes ( mode ) ) ;
323378 if ( [ 'all' , 'probe-polling' ] . includes ( mode ) ) {
324379 for ( const action of [ 'created' , 'edited' , 'deleted' ] ) {
325380 await invalidationCase ( `unprivileged marker ${ action } ` , exact , action === 'edited' , false , false , null , action , 'read' , 1 ) ;
326381 }
327382 }
328- if ( [ 'all' , 'probe-active' ] . includes ( mode ) ) await activeCases ( ) ;
383+ if ( [ 'all' , 'probe-active' , 'probe-context' , 'probe-pinned' ] . includes ( mode ) ) await activeCases ( ) ;
329384 if ( [ 'all' , 'probe-retarget' ] . includes ( mode ) ) retargetCases ( ) ;
330385 if ( [ 'all' , 'probe-revoked' ] . includes ( mode ) ) {
331386 for ( const [ action , body ] of [ [ 'edited' , 'erased request' ] , [ 'deleted' , exact ] , [ 'created' , exact ] ] ) {
332387 await invalidationCase ( `revoked registered author ${ action } ` , body , action === 'edited' , true , true , 'failure' , action , 'read' ) ;
333388 }
334389 await invalidationCase ( 'revoked unregistered author' , 'ordinary comment' , false , false , false , null , 'created' , 'read' ) ;
335390 }
336- if ( mode . startsWith ( 'probe-' ) && ! [ 'probe-invalidation' , 'probe-history' , 'probe-empty' , 'probe-repair' , 'probe-publication' , 'probe-check-retry' ] . includes ( mode ) ) return ;
337- if ( ! [ 'probe-history' , 'probe-empty' , 'probe-repair' , 'probe-publication' , 'probe-check-retry' ] . includes ( mode ) ) {
391+ if ( mode . startsWith ( 'probe-' ) && ! [ 'probe-invalidation' , 'probe-history' , 'probe-empty' , 'probe-repair' , 'probe-publication' , 'probe-check-retry' , 'probe-context' , 'probe-pinned' ] . includes ( mode ) ) return ;
392+ if ( ! [ 'probe-history' , 'probe-empty' , 'probe-repair' , 'probe-publication' , 'probe-check-retry' , 'probe-context' , 'probe-pinned' ] . includes ( mode ) ) {
338393 if ( mode === 'all' ) {
339394 assert . match ( source , / i s s u e _ c o m m e n t : \s * t y p e s : \[ c r e a t e d , e d i t e d , d e l e t e d \] / ) ;
340395 const title = / r u n - n a m e : > - \n \s * \$ \{ \{ ( [ \s \S ] * ?) \} \} / . exec ( source ) ;
@@ -395,6 +450,6 @@ async function publishedCheckRetryCases(baseFixture,first,selected) {
395450 }
396451 if ( [ 'all' , 'probe-repair' ] . includes ( mode ) ) await repairCases ( fixture , first , selected ) ;
397452 if ( [ 'all' , 'probe-publication' ] . includes ( mode ) ) await publicationCases ( fixture , first , selected ) ;
398- if ( [ 'all' , 'probe-check-retry' ] . includes ( mode ) ) await publishedCheckRetryCases ( fixture , first , selected ) ;
453+ if ( [ 'all' , 'probe-check-retry' , 'probe-context' , 'probe-pinned' ] . includes ( mode ) ) await publishedCheckRetryCases ( fixture , first , selected ) ;
399454 console . log ( 'Production invalidation and fresh historical-publication regressions passed' ) ;
400455} ) ( ) . catch ( error => { console . error ( error ) ; process . exitCode = 1 ; } ) ;
0 commit comments