@@ -30,7 +30,6 @@ function global:New-PrePushTestRepository {
3030 Set-Content - LiteralPath (Join-Path $cqDir ' run-pester-changed-shards.ps1' ) - Value " exit $ChangedShardsExitCode " - NoNewline
3131 }
3232
33- # Mirror real layout: scripts/git/hooks/pre-push.ps1 (install-githooks wrappers call this path)
3433 $hooksDir = Join-Path $scriptsDir ' git' ' hooks'
3534 New-Item - ItemType Directory - Path $hooksDir - Force | Out-Null
3635 Copy-Item - LiteralPath $script :PrePushHookScript - Destination (Join-Path $hooksDir ' pre-push.ps1' ) - Force
@@ -87,58 +86,69 @@ BeforeAll {
8786}
8887
8988Describe ' pre-push.ps1 execution' {
90- It ' Passes when validate-profile and changed-shards succeed ' {
91- $repo = New-PrePushTestRepository - ValidateExitCode 0 - ChangedShardsExitCode 0
89+ It ' Passes quickly by default without running validate or shard tests ' {
90+ $repo = New-PrePushTestRepository - ValidateExitCode 1 - ChangedShardsExitCode 1
9291 $result = Invoke-PrePushHook - RepositoryRoot $repo
9392 $result.ExitCode | Should - Be 0
93+ $result.Output | Should -Match ' skipping validate-profile'
94+ $result.Output | Should -Match ' skipping changed-shard tests'
95+ $result.Output | Should -Match ' pre-push: all checks passed'
9496 }
9597
96- It ' Prints validate-profile and changed-shard status before completing successfully' {
97- $repo = New-PrePushTestRepository - ValidateExitCode 0 - ChangedShardsExitCode 0
98- $result = Invoke-PrePushHook - RepositoryRoot $repo
99-
98+ It ' Runs validate-profile when PS_PROFILE_PUSH_VALIDATE=1' {
99+ $repo = New-PrePushTestRepository - ValidateExitCode 0 - ChangedShardsExitCode 1
100+ $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
101+ PS_PROFILE_PUSH_VALIDATE = ' 1'
102+ }
100103 $result.ExitCode | Should - Be 0
101- $result.Output | Should -Match ' pre-push: running validate-profile'
102- $result.Output | Should -Match ' pre-push: running Pester CI shards'
103- $result.Output | Should -Match ' pre-push: all checks passed'
104+ $result.Output | Should -Match ' running validate-profile'
105+ $result.Output | Should -Match ' skipping changed-shard tests'
104106 }
105107
106- It ' Fails when validate-profile returns a non-zero exit code ' {
108+ It ' Fails when opt-in validate-profile returns non-zero' {
107109 $repo = New-PrePushTestRepository - ValidateExitCode 1
108- $result = Invoke-PrePushHook - RepositoryRoot $repo
110+ $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
111+ PS_PROFILE_PUSH_VALIDATE = ' 1'
112+ }
109113 $result.ExitCode | Should - BeIn @ (1 , 2 )
110114 $result.Output | Should -Match ' validate-profile failed|pre-push: validate-profile failed'
111115 }
112116
113- It ' Fails when validate-profile.ps1 is missing from the repository ' {
117+ It ' Fails when validate-profile.ps1 is missing and validate is opted in ' {
114118 $repo = New-PrePushTestRepository - OmitValidateScript
115- $result = Invoke-PrePushHook - RepositoryRoot $repo
119+ $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
120+ PS_PROFILE_PUSH_VALIDATE = ' 1'
121+ }
116122 $result.ExitCode | Should - BeIn @ (1 , 2 , 3 )
117- $result.Output | Should -Match ' validate-profile|Cannot bind| not found|failed'
123+ $result.Output | Should -Match ' validate-profile|not found|failed'
118124 }
119125
120- It ' Fails when changed-shard runner returns a non-zero exit code' {
126+ It ' Runs changed-shard tests when PS_PROFILE_PUSH_TESTS=1' {
127+ $repo = New-PrePushTestRepository - ValidateExitCode 1 - ChangedShardsExitCode 0
128+ $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
129+ PS_PROFILE_PUSH_TESTS = ' 1'
130+ }
131+ $result.ExitCode | Should - Be 0
132+ $result.Output | Should -Match ' running Pester CI shards'
133+ $result.Output | Should -Match ' skipping validate-profile'
134+ }
135+
136+ It ' Fails when opt-in changed-shard runner returns non-zero' {
121137 $repo = New-PrePushTestRepository - ValidateExitCode 0 - ChangedShardsExitCode 1
122- $result = Invoke-PrePushHook - RepositoryRoot $repo
138+ $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
139+ PS_PROFILE_PUSH_TESTS = ' 1'
140+ }
123141 $result.ExitCode | Should - BeIn @ (1 , 2 )
124142 $result.Output | Should -Match ' changed-shard Pester run failed'
125143 }
126144
127- It ' Skips changed-shard tests when PS_PROFILE_SKIP_PUSH_TESTS=1' {
145+ It ' Skips opt-in tests when PS_PROFILE_SKIP_PUSH_TESTS=1' {
128146 $repo = New-PrePushTestRepository - ValidateExitCode 0 - ChangedShardsExitCode 1
129147 $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
148+ PS_PROFILE_PUSH_TESTS = ' 1'
130149 PS_PROFILE_SKIP_PUSH_TESTS = ' 1'
131150 }
132151 $result.ExitCode | Should - Be 0
133152 $result.Output | Should -Match ' skipping changed-shard tests'
134153 }
135-
136- It ' Skips validate-profile when PS_PROFILE_SKIP_PUSH_VALIDATE=1' {
137- $repo = New-PrePushTestRepository - ValidateExitCode 1 - ChangedShardsExitCode 0
138- $result = Invoke-PrePushHook - RepositoryRoot $repo - Environment @ {
139- PS_PROFILE_SKIP_PUSH_VALIDATE = ' 1'
140- }
141- $result.ExitCode | Should - Be 0
142- $result.Output | Should -Match ' skipping validate-profile'
143- }
144154}
0 commit comments