Skip to content

fix(sync): honor -WhatIf in Resolve-SyncAnchor bootstrap prompt#115

Open
MarkMichaelis wants to merge 1 commit into
mainfrom
fix/114-whatif-bootstrap
Open

fix(sync): honor -WhatIf in Resolve-SyncAnchor bootstrap prompt#115
MarkMichaelis wants to merge 1 commit into
mainfrom
fix/114-whatif-bootstrap

Conversation

@MarkMichaelis
Copy link
Copy Markdown
Contributor

Summary

Fixes #114. Pull-SDLC.ai.ps1 -WhatIf no longer blocks on an interactive bootstrap prompt in a fresh repo. The prompt now respects -WhatIf (auto-accept + dry-run banner) and uses .ShouldContinue instead of Read-Host for the real interactive case.

What changed

Resolve-SyncAnchor:

  • [CmdletBinding(SupportsShouldProcess)] so the function can call `` methods.
  • False short-circuit -- auto-returns a bootstrap anchor with a What if: would prompt to bootstrap; proceeding with dry-run preview line so the rest of the dry-run prints the would-be op list. Real writes / sync commit are still gated by ShouldProcess in Invoke-PullSDLC.
  • Read-Host replaced with a new Confirm-SyncBootstrap helper 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:

  1. Auto-bootstraps without prompting when False is set (mocks both Read-Host and Confirm-SyncBootstrap to throw if invoked).
  2. Uses Confirm-SyncBootstrap (not Read-Host) for the interactive prompt.
  3. Returns `` when Confirm-SyncBootstrap declines.
  4. End-to-end Invoke-PullSDLC -WhatIf -NoFetch -AllowDefaultBranch on 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-SyncBootstrap and 1 failed because Read-Host was invoked. After the fix: 70/70 pass (Invoke-Pester -Path .\Pull-SDLC.ai.Tests.ps1, ~75s).

Out of scope

Closes #114

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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-SyncBootstrap helper that uses $PSCmdlet.ShouldContinue() instead of Read-Host for interactive bootstrap confirmation.
  • Update Resolve-SyncAnchor to honor $WhatIfPreference by auto-returning a bootstrap anchor (and emitting a dry-run banner) rather than prompting.
  • Add Pester coverage validating Resolve-SyncAnchor WhatIf semantics and an end-to-end Invoke-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.

Comment thread Pull-SDLC.ai.ps1
@@ -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
Comment thread Pull-SDLC.ai.ps1
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]$PSCmdletRef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pull-SDLC.ai.ps1: -WhatIf still prompts at bootstrap (use ShouldContinue / WhatIfPreference)

2 participants