@@ -15,36 +15,43 @@ const workflow = parse(
1515)
1616const dispatchScript = workflow . jobs . dispatch . steps [ 0 ] . with . script as string
1717
18- const SHA = "a" . repeat ( 40 )
18+ // Head commit and branch of fork PR #1662 (fork-owner/Zoo-Code), the run
19+ // documented in issue #2133.
20+ const SHA = "029ea76b91f0c784087989470c81ade55b13c82f"
21+ const HEAD_BRANCH = "fix/1591-openai-compatible-cache-reads"
1922const OLD_SHA = "b" . repeat ( 40 )
2023
2124interface HarnessOptions {
2225 workflowRunEvent ?: string
23- fork ?: boolean
2426 associatedPrNumbers ?: number [ ]
25- fallback ?: "match" | "sha-mismatch" | "base-mismatch" | "none"
26- headRepository ?: null
27- headSha ?: string
27+ fallback ?: "match" | "sha-mismatch" | "ref-mismatch" | " base-mismatch" | "none"
28+ headBranch ?: string | null
29+ headSha ?: string | null
2830 failDispatchFor ?: number
2931}
3032
3133function buildForkPr ( ) {
3234 return {
33- number : 1437 ,
35+ number : 1662 ,
3436 state : "open" ,
35- head : { sha : SHA , repo : { full_name : "contributor /Zoo-Code" } } ,
37+ head : { ref : HEAD_BRANCH , sha : SHA , repo : { full_name : "fork-owner /Zoo-Code" } } ,
3638 base : { ref : "main" , repo : { full_name : "Zoo-Code-Org/Zoo-Code" } } ,
3739 }
3840}
3941
4042/** Executes the embedded github-script follow-up against deterministic GitHub API doubles. */
4143async function runFollowup ( options : HarnessOptions = { } ) {
42- const fork = options . fork ?? true
4344 const pr = buildForkPr ( )
44- const listPullRequests = vi . fn ( async ( { state } : { state ?: string } ) => {
45+ // Like the GitHub API, honor a `head` filter ("owner:branch"). A base-owner filter
46+ // matches no fork PR, so the broken request cannot pass the regression scenario.
47+ const listPullRequests = vi . fn ( async ( { state, head } : { state ?: string ; head ?: string } ) => {
4548 if ( state !== "open" ) return [ ]
49+ if ( head !== undefined && head !== `fork-owner:${ HEAD_BRANCH } ` ) return [ ]
4650 if ( options . fallback === "match" ) return [ pr ]
4751 if ( options . fallback === "sha-mismatch" ) return [ { ...pr , head : { ...pr . head , sha : OLD_SHA } } ]
52+ if ( options . fallback === "ref-mismatch" ) {
53+ return [ { ...pr , head : { ...pr . head , ref : "some-other-branch" } } ]
54+ }
4855 if ( options . fallback === "base-mismatch" ) {
4956 return [ { ...pr , base : { ...pr . base , repo : { full_name : "someone-else/Zoo-Code" } } } ]
5057 }
@@ -69,18 +76,21 @@ async function runFollowup(options: HarnessOptions = {}) {
6976 repo : { owner : "Zoo-Code-Org" , repo : "Zoo-Code" } ,
7077 payload : {
7178 workflow_run : {
72- id : 987654 ,
79+ // Fields copied from workflow run 39534658962, the read-only fork
80+ // review run for PR #1662 documented in issue #2133. Fields the
81+ // script never reads are trimmed. GitHub reports the base
82+ // repository as head_repository on every pull_request_review run,
83+ // even for fork PRs, and backfills pull_requests empty for them.
84+ id : 39534658962 ,
7385 event : options . workflowRunEvent ?? "pull_request_review" ,
7486 pull_requests : ( options . associatedPrNumbers ?? [ ] ) . map ( ( number ) => ( { number } ) ) ,
75- head_repository :
76- options . headRepository === null
77- ? null
78- : {
79- owner : { login : fork ? "contributor" : "Zoo-Code-Org" } ,
80- fork,
81- } ,
82- head_branch : "feature/test" ,
83- head_sha : options . headSha ?? SHA ,
87+ head_repository : {
88+ full_name : "Zoo-Code-Org/Zoo-Code" ,
89+ owner : { login : "Zoo-Code-Org" } ,
90+ fork : false ,
91+ } ,
92+ head_branch : options . headBranch === undefined ? HEAD_BRANCH : options . headBranch ,
93+ head_sha : options . headSha === undefined ? SHA : options . headSha ,
8494 } ,
8595 } ,
8696 }
@@ -97,7 +107,7 @@ async function runFollowup(options: HarnessOptions = {}) {
97107 return { listPullRequests, createWorkflowDispatch, info : core . info , setFailed : core . setFailed }
98108}
99109
100- describe ( "fork review follow-up workflow (#2046, #2086)" , ( ) => {
110+ describe ( "fork review follow-up workflow (#2046, #2086, #2133 )" , ( ) => {
101111 it ( "listens to the label workflow without listing itself" , ( ) => {
102112 expect ( workflow . name ) . toBe ( "Label PR review state fork review follow-up" )
103113 expect ( workflow . on . workflow_run . workflows ) . toEqual ( [ "Label PR review state" ] )
@@ -121,26 +131,30 @@ describe("fork review follow-up workflow (#2046, #2086)", () => {
121131 } )
122132
123133 it ( "dispatches a privileged reconciliation for the fork PR a read-only review run targeted" , async ( ) => {
124- // Fork runs backfill pull_requests empty, so the follow-up resolves the
125- // PR by exact head owner, branch, and SHA.
134+ // Fork runs backfill pull_requests empty, and head_repository is the
135+ // base repository (issue #2133), so the follow-up resolves the PR by
136+ // exact head branch, SHA, and base repository.
126137 const result = await runFollowup ( { associatedPrNumbers : [ ] , fallback : "match" } )
127138
128- expect ( result . listPullRequests ) . toHaveBeenCalledWith (
129- expect . objectContaining ( { head : "contributor:feature/test" , state : "open" } ) ,
130- )
139+ expect ( result . listPullRequests ) . toHaveBeenCalledWith ( {
140+ owner : "Zoo-Code-Org" ,
141+ repo : "Zoo-Code" ,
142+ state : "open" ,
143+ per_page : 100 ,
144+ } )
131145 expect ( result . createWorkflowDispatch ) . toHaveBeenCalledTimes ( 1 )
132146 expect ( result . createWorkflowDispatch ) . toHaveBeenCalledWith ( {
133147 owner : "Zoo-Code-Org" ,
134148 repo : "Zoo-Code" ,
135149 workflow_id : "label-pr-review-state.yml" ,
136150 ref : "main" ,
137- inputs : { pull_request_number : "1437 " } ,
151+ inputs : { pull_request_number : "1662 " } ,
138152 } )
139153 expect ( result . setFailed ) . not . toHaveBeenCalled ( )
140154 } )
141155
142156 it ( "dispatches directly for runs whose pull_requests are populated" , async ( ) => {
143- const result = await runFollowup ( { associatedPrNumbers : [ 1437 ] } )
157+ const result = await runFollowup ( { associatedPrNumbers : [ 1662 ] } )
144158
145159 expect ( result . listPullRequests ) . not . toHaveBeenCalled ( )
146160 expect ( result . createWorkflowDispatch ) . toHaveBeenCalledTimes ( 1 )
@@ -169,18 +183,28 @@ describe("fork review follow-up workflow (#2046, #2086)", () => {
169183 }
170184 } )
171185
172- it ( "ignores a same-repository review run, which already wrote its labels" , async ( ) => {
173- const result = await runFollowup ( { fork : false , associatedPrNumbers : [ 1437 ] } )
186+ it ( "dispatches for a same-repository review run, whose payload is indistinguishable from a fork run" , async ( ) => {
187+ // Every pull_request_review run reports head_repository as the base
188+ // repository with fork: false (issue #2133), so fork-ness cannot gate
189+ // the dispatch. Same-repo PRs appear in pull_requests, but resolving
190+ // through the fallback works for them too, and the dispatch is
191+ // idempotent: the reconciliation writes the same labels.
192+ const result = await runFollowup ( { fallback : "match" } )
174193
175- expect ( result . listPullRequests ) . not . toHaveBeenCalled ( )
176- expect ( result . createWorkflowDispatch ) . not . toHaveBeenCalled ( )
194+ expect ( result . createWorkflowDispatch ) . toHaveBeenCalledTimes ( 1 )
195+ expect ( result . createWorkflowDispatch ) . toHaveBeenCalledWith (
196+ expect . objectContaining ( { inputs : { pull_request_number : "1662" } } ) ,
197+ )
198+ expect ( result . setFailed ) . not . toHaveBeenCalled ( )
177199 } )
178200
179- it ( "dispatches nothing when no open PR matches the run's exact head" , async ( ) => {
180- const result = await runFollowup ( { fallback : "sha-mismatch" } )
201+ it ( "dispatches nothing when no open PR matches the run's exact head branch and SHA" , async ( ) => {
202+ for ( const fallback of [ "sha-mismatch" , "ref-mismatch" , "none" ] as const ) {
203+ const result = await runFollowup ( { fallback } )
181204
182- expect ( result . listPullRequests ) . toHaveBeenCalledTimes ( 1 )
183- expect ( result . createWorkflowDispatch ) . not . toHaveBeenCalled ( )
205+ expect ( result . listPullRequests ) . toHaveBeenCalledTimes ( 1 )
206+ expect ( result . createWorkflowDispatch ) . not . toHaveBeenCalled ( )
207+ }
184208 } )
185209
186210 it ( "dispatches nothing when the matching PR targets another base repository" , async ( ) => {
@@ -190,8 +214,8 @@ describe("fork review follow-up workflow (#2046, #2086)", () => {
190214 expect ( result . createWorkflowDispatch ) . not . toHaveBeenCalled ( )
191215 } )
192216
193- it ( "dispatches nothing when the run has no head repository or head SHA to resolve" , async ( ) => {
194- for ( const options of [ { headRepository : null } , { headSha : "" } ] as const ) {
217+ it ( "dispatches nothing when the run has no head branch or head SHA to resolve" , async ( ) => {
218+ for ( const options of [ { headBranch : null } , { headSha : null } ] as const ) {
195219 const result = await runFollowup ( { ...options , fallback : "match" } )
196220
197221 expect ( result . listPullRequests ) . not . toHaveBeenCalled ( )
0 commit comments