fix(sync): honor -WhatIf in Resolve-SyncAnchor bootstrap prompt#115
Open
MarkMichaelis wants to merge 1 commit into
Open
fix(sync): honor -WhatIf in Resolve-SyncAnchor bootstrap prompt#115MarkMichaelis wants to merge 1 commit into
MarkMichaelis wants to merge 1 commit into
Conversation
Resolve-SyncAnchor used a custom Read-Host prompt that fired even under -WhatIf, forcing the user to answer `Proceed with bootstrap? [y/N]` interactively during a dry-run. -WhatIf must never block on user input. Changes: - Add [CmdletBinding(SupportsShouldProcess)] to Resolve-SyncAnchor. - When `False` is set, auto-return the bootstrap anchor with a `What if: would prompt to bootstrap; proceeding with dry-run preview` notice so the rest of the flow prints the would-be op list. - Replace Read-Host with a new Confirm-SyncBootstrap helper that wraps `.ShouldContinue` -- idiomatic PowerShell yes/no prompt; mockable in tests. Tests: - 4 new tests under `Describe 'Resolve-SyncAnchor -- WhatIf semantics (#114)'` covering WhatIf short-circuit, ShouldContinue invocation, decline path, and an end-to-end Invoke-PullSDLC -WhatIf on a fresh repo without prompting or writing state. - All 70 Pester tests pass. Closes #114 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a -WhatIf usability bug in the PowerShell sync bootstrap flow so a dry-run no longer blocks on an interactive prompt when no prior sync anchor exists (fresh repo case).
Changes:
- Add a
Confirm-SyncBootstraphelper that uses$PSCmdlet.ShouldContinue()instead ofRead-Hostfor interactive bootstrap confirmation. - Update
Resolve-SyncAnchorto honor$WhatIfPreferenceby auto-returning a bootstrap anchor (and emitting a dry-run banner) rather than prompting. - Add Pester coverage validating
Resolve-SyncAnchorWhatIf semantics and an end-to-endInvoke-PullSDLC -WhatIf“fresh repo” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Pull-SDLC.ai.ps1 | Replaces Read-Host bootstrap prompting with ShouldContinue and short-circuits prompting under $WhatIfPreference. |
| Pull-SDLC.ai.Tests.ps1 | Adds behavior-first Pester tests asserting no prompting under -WhatIf and correct interactive prompting behavior otherwise. |
| @@ -263,8 +286,11 @@ function Resolve-SyncAnchor { | |||
| Write-Host '' | |||
| Write-Host 'No .sdlc-ai-sync.json and no prior sync commit found.' -ForegroundColor Yellow | |||
| Write-Host 'Bootstrap will perform a full refresh from upstream HEAD (empty-tree anchor).' -ForegroundColor Yellow | |||
| #> | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory)]$PSCmdletRef |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #114.
Pull-SDLC.ai.ps1 -WhatIfno longer blocks on an interactive bootstrap prompt in a fresh repo. The prompt now respects-WhatIf(auto-accept + dry-run banner) and uses.ShouldContinueinstead ofRead-Hostfor the real interactive case.What changed
Resolve-SyncAnchor:[CmdletBinding(SupportsShouldProcess)]so the function can call `` methods.Falseshort-circuit -- auto-returns a bootstrap anchor with aWhat if: would prompt to bootstrap; proceeding with dry-run previewline so the rest of the dry-run prints the would-be op list. Real writes / sync commit are still gated byShouldProcessinInvoke-PullSDLC.Read-Hostreplaced with a newConfirm-SyncBootstraphelper that wraps.ShouldContinue. The helper is its own function purely so tests can mock the prompt deterministically.Tests (TDD)
New
Describe 'Resolve-SyncAnchor -- WhatIf semantics (#114)'block with four behavior-first tests:Falseis set (mocks bothRead-HostandConfirm-SyncBootstrapto throw if invoked).Confirm-SyncBootstrap(notRead-Host) for the interactive prompt.Confirm-SyncBootstrapdeclines.Invoke-PullSDLC -WhatIf -NoFetch -AllowDefaultBranchon a fresh fixture exits 0, never prompts, and never writes.sdlc-ai-sync.json.Verified Red phase before applying the fix: 3 tests failed with
CommandNotFoundException: Could not find Command Confirm-SyncBootstrapand 1 failed becauseRead-Hostwas invoked. After the fix: 70/70 pass (Invoke-Pester -Path .\Pull-SDLC.ai.Tests.ps1, ~75s).Out of scope
sync-manifest.jsonat runtime (tracked separately; noted in fix(sync): add Pull-SDLC.ai.ps1 (and siblings) to $script:UpstreamManagedPaths so sync self-commits #112 / fix(sync): include sync-tooling files in $script:UpstreamManagedPaths #113).-WhatIfbehavior -- already intentionally exempt, fixed in fix(sync): self-refresh re-exec fails with 'parameter RemoteUrl not found' when local script is stale #110.-Bootstrap/-NoPrompt/-Forcesemantics -- unchanged.Closes #114