@@ -466,3 +466,45 @@ func TestJobDependencies(t *testing.T) {
466466 })
467467 }
468468}
469+
470+ // TestGitHubAppWithPushToPRBranch tests that GitHub App token step is not duplicated
471+ // when both app and push-to-pull-request-branch are configured
472+ // Regression test for duplicate step bug reported in issue
473+ func TestGitHubAppWithPushToPRBranch (t * testing.T ) {
474+ compiler := NewCompiler ()
475+ compiler .jobManager = NewJobManager ()
476+
477+ workflowData := & WorkflowData {
478+ Name : "Test Workflow" ,
479+ SafeOutputs : & SafeOutputsConfig {
480+ App : & GitHubAppConfig {
481+ AppID : "${{ vars.ACTIONS_APP_ID }}" ,
482+ PrivateKey : "${{ secrets.ACTIONS_PRIVATE_KEY }}" ,
483+ },
484+ PushToPullRequestBranch : & PushToPullRequestBranchConfig {},
485+ },
486+ }
487+
488+ job , _ , err := compiler .buildConsolidatedSafeOutputsJob (workflowData , string (constants .AgentJobName ), "test.md" )
489+
490+ require .NoError (t , err , "Should successfully build job" )
491+ require .NotNil (t , job , "Job should not be nil" )
492+
493+ stepsContent := strings .Join (job .Steps , "" )
494+
495+ // Should include app token minting step exactly once
496+ tokenMintCount := strings .Count (stepsContent , "Generate GitHub App token" )
497+ assert .Equal (t , 1 , tokenMintCount , "App token minting step should appear exactly once, found %d times" , tokenMintCount )
498+
499+ // Should include app token invalidation step exactly once
500+ tokenInvalidateCount := strings .Count (stepsContent , "Invalidate GitHub App token" )
501+ assert .Equal (t , 1 , tokenInvalidateCount , "App token invalidation step should appear exactly once, found %d times" , tokenInvalidateCount )
502+
503+ // Token step should come before checkout step (checkout references the token)
504+ tokenIndex := strings .Index (stepsContent , "Generate GitHub App token" )
505+ checkoutIndex := strings .Index (stepsContent , "Checkout repository" )
506+ assert .Less (t , tokenIndex , checkoutIndex , "Token minting step should come before checkout step" )
507+
508+ // Verify step ID is set correctly
509+ assert .Contains (t , stepsContent , "id: safe-outputs-app-token" )
510+ }
0 commit comments