@@ -2404,7 +2404,11 @@ describe("PR review-state workflow concurrency groups (#1707)", () => {
24042404 event_name : string
24052405 run_id : number
24062406 event : {
2407- pull_request ?: { number : number }
2407+ pull_request ?: {
2408+ number : number
2409+ head ?: { repo ?: { full_name ?: string } | null }
2410+ base ?: { repo ?: { full_name ?: string } | null }
2411+ }
24082412 issue ?: { number : number }
24092413 workflow_run ?: { id ?: number ; pull_requests ?: Array < { number : number } > }
24102414 inputs ?: { pull_request_number : number }
@@ -2420,7 +2424,7 @@ describe("PR review-state workflow concurrency groups (#1707)", () => {
24202424 matrix ?: MatrixContext
24212425 }
24222426
2423- function splitTopLevel ( expression : string , operator : "||" | "&&" | "==" ) : string [ ] {
2427+ function splitTopLevel ( expression : string , operator : "||" | "&&" | "==" | "!=" ) : string [ ] {
24242428 const parts : string [ ] = [ ]
24252429 let depth = 0
24262430 let inString = false
@@ -2510,6 +2514,10 @@ describe("PR review-state workflow concurrency groups (#1707)", () => {
25102514 }
25112515
25122516 function evaluateComparison ( expression : string , roots : ExpressionRoots ) : unknown {
2517+ const notEquals = splitTopLevel ( expression , "!=" )
2518+ if ( notEquals . length > 1 ) {
2519+ return ! looseEquals ( evaluatePrimary ( notEquals [ 0 ] , roots ) , evaluatePrimary ( notEquals [ 1 ] , roots ) )
2520+ }
25132521 const parts = splitTopLevel ( expression , "==" )
25142522 if ( parts . length === 1 ) {
25152523 return evaluatePrimary ( parts [ 0 ] , roots )
@@ -2540,7 +2548,7 @@ describe("PR review-state workflow concurrency groups (#1707)", () => {
25402548 }
25412549
25422550 function evaluateTemplate ( template : string , roots : ExpressionRoots ) : string {
2543- return template . replace ( / \$ \{ \{ ( .+ ?) \} \} / s , ( _match , expression : string ) => {
2551+ return template . replace ( / \$ \{ \{ ( .+ ?) \} \} / gs , ( _match , expression : string ) => {
25442552 const value = evaluateExpression ( expression , roots )
25452553 return isTruthy ( value ) ? String ( value ) : ""
25462554 } )
@@ -2719,6 +2727,69 @@ describe("PR review-state workflow concurrency groups (#1707)", () => {
27192727 }
27202728 } )
27212729
2730+ it ( "keys read-only fork review runs per-run at both levels so they cannot starve mutating runs" , ( ) => {
2731+ // Fork pull_request_review runs get a read-only token (see isReadOnlyRun
2732+ // in the reconcile script) and write nothing, so they must not hold the
2733+ // PR-keyed groups whose newest-pending-wins could supersede a queued
2734+ // mutating run for the same PR.
2735+ const forkReview = contextFor ( {
2736+ event_name : "pull_request_review" ,
2737+ run_id : 606000111 ,
2738+ event : {
2739+ pull_request : {
2740+ number : 1664 ,
2741+ head : { repo : { full_name : "contributor/Zoo-Code" } } ,
2742+ base : { repo : { full_name : "Zoo-Code-Org/Zoo-Code" } } ,
2743+ } ,
2744+ } ,
2745+ } )
2746+ const mutating = contextFor ( { event_name : "issue_comment" , event : { issue : { number : 1664 } } } )
2747+
2748+ expect ( workflowGroupFor ( forkReview ) ) . toBe ( "label-pr-review-state-606000111" )
2749+ expect ( workflowGroupFor ( mutating ) ) . toBe ( "label-pr-review-state-1664" )
2750+ expect ( workflowGroupFor ( forkReview ) ) . not . toBe ( workflowGroupFor ( mutating ) )
2751+
2752+ // The `-ro-` infix keeps the read-only shard group from ever numerically
2753+ // colliding with a mutating shard group for the same PR.
2754+ expect ( shardGroupFor ( forkReview , { pr_number : 1664 } ) ) . toBe ( "label-pr-review-state-reconcile-ro-606000111" )
2755+ expect ( shardGroupFor ( mutating , { pr_number : 1664 } ) ) . toBe ( "label-pr-review-state-reconcile-1664" )
2756+ expect ( shardGroupFor ( forkReview , { pr_number : 1664 } ) ) . not . toBe ( shardGroupFor ( mutating , { pr_number : 1664 } ) )
2757+ } )
2758+
2759+ it ( "keeps same-repo review events PR-keyed at both levels" , ( ) => {
2760+ const sameRepoReview = contextFor ( {
2761+ event_name : "pull_request_review" ,
2762+ event : {
2763+ pull_request : {
2764+ number : 1664 ,
2765+ head : { repo : { full_name : "Zoo-Code-Org/Zoo-Code" } } ,
2766+ base : { repo : { full_name : "Zoo-Code-Org/Zoo-Code" } } ,
2767+ } ,
2768+ } ,
2769+ } )
2770+
2771+ expect ( workflowGroupFor ( sameRepoReview ) ) . toBe ( "label-pr-review-state-1664" )
2772+ expect ( shardGroupFor ( sameRepoReview , { pr_number : 1664 } ) ) . toBe ( "label-pr-review-state-reconcile-1664" )
2773+ } )
2774+
2775+ it ( "fails toward run-scoped groups when review head repository metadata is missing" , ( ) => {
2776+ // A missing head.repo cannot be proven same-repo, so the guard treats the
2777+ // run as read-only-safe (run-scoped) rather than PR-keyed.
2778+ const missingHead = contextFor ( {
2779+ event_name : "pull_request_review" ,
2780+ run_id : 606000222 ,
2781+ event : {
2782+ pull_request : {
2783+ number : 1664 ,
2784+ base : { repo : { full_name : "Zoo-Code-Org/Zoo-Code" } } ,
2785+ } ,
2786+ } ,
2787+ } )
2788+
2789+ expect ( workflowGroupFor ( missingHead ) ) . toBe ( "label-pr-review-state-606000222" )
2790+ expect ( shardGroupFor ( missingHead , { pr_number : 1664 } ) ) . toBe ( "label-pr-review-state-reconcile-ro-606000222" )
2791+ } )
2792+
27222793 it ( "keeps the empty-resolution shard fallback unique per run" , ( ) => {
27232794 const runA = contextFor ( {
27242795 event_name : "workflow_run" ,
0 commit comments