@@ -13,11 +13,12 @@ import (
1313// TestBuildSharedPRCheckoutSteps tests shared PR checkout step generation
1414func TestBuildSharedPRCheckoutSteps (t * testing.T ) {
1515 tests := []struct {
16- name string
17- safeOutputs * SafeOutputsConfig
18- trialMode bool
19- trialRepo string
20- checkContains []string
16+ name string
17+ safeOutputs * SafeOutputsConfig
18+ trialMode bool
19+ trialRepo string
20+ checkContains []string
21+ checkNotContains []string
2122 }{
2223 {
2324 name : "create pull request only" ,
@@ -120,6 +121,46 @@ func TestBuildSharedPRCheckoutSteps(t *testing.T) {
120121 "token: ${{ secrets.GH_AW_CROSS_REPO_PAT }}" ,
121122 "GIT_TOKEN: ${{ secrets.GH_AW_CROSS_REPO_PAT }}" ,
122123 `REPO_NAME: "org/target-repo"` ,
124+ // Cross-repo checkout must not use github.ref_name
125+ "ref: ${{ github.base_ref || github.event.pull_request.base.ref || github.event.repository.default_branch }}" ,
126+ },
127+ },
128+ {
129+ name : "cross-repo without base-branch uses safe ref omitting github.ref_name" ,
130+ safeOutputs : & SafeOutputsConfig {
131+ CreatePullRequests : & CreatePullRequestsConfig {
132+ TargetRepoSlug : "org/other-repo" ,
133+ },
134+ },
135+ checkContains : []string {
136+ "ref: ${{ github.base_ref || github.event.pull_request.base.ref || github.event.repository.default_branch }}" ,
137+ },
138+ checkNotContains : []string {
139+ "github.ref_name" ,
140+ },
141+ },
142+ {
143+ name : "trial mode cross-repo omits github.ref_name from checkout ref" ,
144+ trialMode : true ,
145+ trialRepo : "org/trial-repo" ,
146+ safeOutputs : & SafeOutputsConfig {
147+ CreatePullRequests : & CreatePullRequestsConfig {},
148+ },
149+ checkContains : []string {
150+ "repository: org/trial-repo" ,
151+ "ref: ${{ github.base_ref || github.event.pull_request.base.ref || github.event.repository.default_branch }}" ,
152+ },
153+ },
154+ {
155+ name : "cross-repo with explicit base-branch uses base-branch not cross-repo fallback" ,
156+ safeOutputs : & SafeOutputsConfig {
157+ CreatePullRequests : & CreatePullRequestsConfig {
158+ TargetRepoSlug : "org/other-repo" ,
159+ BaseBranch : "develop" ,
160+ },
161+ },
162+ checkContains : []string {
163+ "ref: develop" ,
123164 },
124165 },
125166 {
@@ -212,6 +253,10 @@ func TestBuildSharedPRCheckoutSteps(t *testing.T) {
212253 for _ , expected := range tt .checkContains {
213254 assert .Contains (t , stepsContent , expected , "Expected to find: " + expected )
214255 }
256+
257+ for _ , notExpected := range tt .checkNotContains {
258+ assert .NotContains (t , stepsContent , notExpected , "Expected NOT to find: " + notExpected )
259+ }
215260 })
216261 }
217262}
0 commit comments