@@ -27,55 +27,61 @@ function pullRequest(overrides = {}) {
2727 } ;
2828}
2929
30- test ( "selects the requested PR head rather than the trusted workflow commit" , async ( ) => {
31- assert . deepEqual (
32- await resolveScanTargets ( context , async ( number ) => {
33- assert . equal ( number , "7" ) ;
34- return pullRequest ( ) ;
35- } ) ,
36- [ { pr : 7 , sha : sourceSha } ] ,
37- ) ;
38- } ) ;
39-
40- test ( "includes fork and draft PRs without depending on a PR workflow run" , async ( ) => {
41- assert . deepEqual (
42- await resolveScanTargets ( context , async ( ) =>
43- pullRequest ( {
44- draft : true ,
45- head : { sha : sourceSha , repo : { full_name : "contributor/invoices" } } ,
46- } ) ,
47- ) ,
48- [ { pr : 7 , sha : sourceSha } ] ,
49- ) ;
30+ test ( "initial selection and approval recheck require the selected PR and revision to remain eligible" , async ( ) => {
31+ const target = { pr : 7 , sha : sourceSha } ;
32+ // The approval step must use its matrix target even if dispatch inputs differ.
33+ const recheck = {
34+ ...context ,
35+ target : { ...target } ,
36+ event : { inputs : { pr_number : "9" , source_sha : mainSha } } ,
37+ } ;
38+ for ( const request of [ context , recheck ] ) {
39+ for ( const [ overrides , expected ] of [
40+ [ { } , [ target ] ] ,
41+ [
42+ {
43+ draft : true ,
44+ head : { sha : sourceSha , repo : { full_name : "contributor/invoices" } } ,
45+ } ,
46+ [ target ] ,
47+ ] ,
48+ [ { state : "closed" } , [ ] ] ,
49+ [ { base : { ref : "release" , repo : { full_name : repository } } } , [ ] ] ,
50+ [ { base : { ref : "main" , repo : { full_name : "other/invoices" } } } , [ ] ] ,
51+ [ { head : { sha : mainSha } } , [ ] ] ,
52+ [ { head : { sha : "3" . repeat ( 40 ) } } , [ ] ] ,
53+ ] ) {
54+ const actual = await resolveScanTargets ( request , async ( number ) => {
55+ assert . equal ( number , "7" ) ;
56+ return pullRequest ( overrides ) ;
57+ } ) ;
58+ assert . deepEqual ( actual , expected ) ;
59+ }
60+ }
5061} ) ;
5162
52- test ( "rechecking after approval excludes closed, retargeted, and superseded PRs" , async ( ) => {
53- assert . deepEqual (
54- await resolveScanTargets ( context , async ( ) => pullRequest ( ) ) ,
55- [ { pr : 7 , sha : sourceSha } ] ,
56- ) ;
57- for ( const changed of [
58- { state : "closed" } ,
59- { base : { ref : "release" , repo : { full_name : repository } } } ,
60- { base : { ref : "main" , repo : { full_name : "other/invoices" } } } ,
61- { head : { sha : "3" . repeat ( 40 ) } } ,
63+ test ( "manual and scheduled baselines use the trusted workflow commit before and after approval" , async ( ) => {
64+ const target = { pr : 0 , sha : mainSha } ;
65+ const scheduled = {
66+ ...context ,
67+ eventName : "schedule" ,
68+ event : { schedule : "17 3 * * 1" } ,
69+ } ;
70+ for ( const request of [
71+ { ...context , event : { inputs : { } } } ,
72+ scheduled ,
73+ { ...context , target : { ...target } } ,
74+ { ...scheduled , target : { ...target } } ,
6275 ] ) {
6376 assert . deepEqual (
64- await resolveScanTargets ( context , async ( ) => pullRequest ( changed ) ) ,
65- [ ] ,
77+ await resolveScanTargets ( request , ( ) =>
78+ assert . fail ( "unexpected API call" ) ,
79+ ) ,
80+ [ target ] ,
6681 ) ;
6782 }
6883} ) ;
6984
70- test ( "manual baseline scans use the trusted workflow commit" , async ( ) => {
71- assert . deepEqual (
72- await resolveScanTargets ( { ...context , event : { inputs : { } } } , ( ) =>
73- assert . fail ( "unexpected API call" ) ,
74- ) ,
75- [ { pr : 0 , sha : mainSha } ] ,
76- ) ;
77- } ) ;
78-
7985test ( "incomplete or invalid PR inputs fail instead of falling back to a baseline" , async ( ) => {
8086 for ( const inputs of [
8187 { pr_number : "7" } ,
@@ -117,48 +123,6 @@ test("PR events and completed PR workflows do not queue inference or query GitHu
117123 }
118124} ) ;
119125
120- test ( "scheduled baseline scans use the trusted workflow commit" , async ( ) => {
121- assert . deepEqual (
122- await resolveScanTargets (
123- { ...context , eventName : "schedule" , event : { schedule : "17 3 * * 1" } } ,
124- ( ) => assert . fail ( "unexpected API call" ) ,
125- ) ,
126- [ { pr : 0 , sha : mainSha } ] ,
127- ) ;
128- } ) ;
129-
130- test ( "approval recheck stays bound to its matrix PR and source revision" , async ( ) => {
131- const run = { ...context , target : { pr : 7 , sha : sourceSha } } ;
132- for ( const changed of [
133- { state : "closed" } ,
134- { base : { ref : "release" , repo : { full_name : repository } } } ,
135- { head : { sha : mainSha } } ,
136- ] ) {
137- assert . deepEqual (
138- await resolveScanTargets ( run , async ( number ) => {
139- assert . equal ( number , "7" ) ;
140- return pullRequest ( changed ) ;
141- } ) ,
142- [ ] ,
143- ) ;
144- }
145- assert . deepEqual ( await resolveScanTargets ( run , async ( ) => pullRequest ( ) ) , [
146- { pr : 7 , sha : sourceSha } ,
147- ] ) ;
148- } ) ;
149-
150- test ( "baseline approval recheck retains the original trusted workflow commit" , async ( ) => {
151- for ( const eventName of [ "workflow_dispatch" , "schedule" ] ) {
152- assert . deepEqual (
153- await resolveScanTargets (
154- { ...context , eventName, target : { pr : 0 , sha : mainSha } } ,
155- ( ) => assert . fail ( "unexpected API call" ) ,
156- ) ,
157- [ { pr : 0 , sha : mainSha } ] ,
158- ) ;
159- }
160- } ) ;
161-
162126test ( "resolver CLI emits the requested target without dispatching another workflow" , ( t ) => {
163127 const root = mkdtempSync ( join ( tmpdir ( ) , "invoice-desk-target-" ) ) ;
164128 t . after ( ( ) => rmSync ( root , { recursive : true , force : true } ) ) ;
0 commit comments