Skip to content

fix(init): remove triple confirm prompt on Windows CP950 terminals (#602)#647

Open
sergio-sisternes-epam wants to merge 2 commits intomicrosoft:mainfrom
sergio-sisternes-epam:fix/602-init-confirm-loop
Open

fix(init): remove triple confirm prompt on Windows CP950 terminals (#602)#647
sergio-sisternes-epam wants to merge 2 commits intomicrosoft:mainfrom
sergio-sisternes-epam:fix/602-init-confirm-loop

Conversation

@sergio-sisternes-epam
Copy link
Copy Markdown
Collaborator

@sergio-sisternes-epam sergio-sisternes-epam commented Apr 9, 2026

Summary

Fixes #602 — On Windows systems with non-UTF-8 console encoding (CP950, CP936, CP932), apm init in an existing project showed the overwrite confirmation prompt three times.

Root Cause

Rich Confirm.ask() would:

  1. Prompt once
  2. Fail to decode input on CP950, retry internally (prompt Integrate copilot runtime #2)
  3. Raise an exception — the except block called click.confirm() again (prompt Will there be MCP coverage? #3)

Fix

Simplified the overwrite confirmation to always use click.confirm() directly. This is a simple y/n prompt where cross-platform reliability matters more than Rich styling. The interactive setup section retains its own Rich/click fallback pattern.

Changes

  • src/apm_cli/commands/init.py — Replace Rich Confirm.ask fallback with direct click.confirm() (-9 lines, +1 line)
  • tests/unit/test_init_command.py — Add 2 regression tests
  • CHANGELOG.md — Add fix entry

Testing

All 17 init tests pass. Two new regression tests verify:

  • The prompt appears exactly once
  • click.confirm is the function called (not Rich)

Copilot AI review requested due to automatic review settings April 9, 2026 17:21
Copy link
Copy Markdown
Contributor

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 Windows non-UTF-8 terminal (e.g., CP950) regression where apm init could show the overwrite confirmation prompt multiple times by removing the Rich Confirm.ask() + fallback pattern and always using click.confirm() for the overwrite prompt.

Changes:

  • Replace Rich overwrite confirmation (and fallback) with a single click.confirm() call in apm init.
  • Add regression tests ensuring the overwrite prompt appears once and that click.confirm is the mechanism used.
  • Add a Fixed entry to CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/apm_cli/commands/init.py Simplifies overwrite confirmation prompt to use click.confirm() directly to avoid Rich input-decoding retries on Windows code pages.
tests/unit/test_init_command.py Adds regression coverage for single prompt emission and validates click.confirm usage.
CHANGELOG.md Documents the fix under ## [Unreleased] / ### Fixed.

Comment thread tests/unit/test_init_command.py
Comment thread tests/unit/test_init_command.py
@danielmeppiel danielmeppiel added CI/CD and removed CI/CD labels Apr 19, 2026
…icrosoft#602)

Replace Rich Confirm.ask() with click.confirm() for the overwrite prompt
in 'apm init'. Rich's internal retry on encoding errors caused the prompt
to appear up to three times on Windows CP950 terminals.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel
Copy link
Copy Markdown
Collaborator

danielmeppiel commented Apr 20, 2026

APM Review Panel — PR #647

[!] Verdict: REQUEST CHANGES — three must-fix items before merge

Re-running the panel verdict with stricter gating: the items below are all same-PR required, not optional follow-ups. The fix itself is correct and well-tested — but the CHANGELOG drift and the residual CP950 bugs in two other call sites mean we'd be shipping a "fixes #602" PR that leaves #602's bug class half-fixed, plus a duplicate changelog line.

Already approved earlier by @danielmeppiel — superseding with REQUEST CHANGES so the items below land before merge.

What's excellent

  • Symptom-targeted test. assert result.output.count("Continue and overwrite?") == 1 (test file, line 70) tests the bug directly — a future Rich-confirm regression will fail loudly. Rare and excellent test design.
  • Right-sized fix in scope. Drops Rich for one binary y/n gate where styling adds zero signal; keeps Rich on the interactive setup wizard where it does. "Pay only for what you touch" applied correctly.
  • High-impact for a small diff. APAC enterprise contributors are a real adoption segment — a triple-prompt on the very first command (apm init) is the kind of bug that turns into a "this tool is broken" tweet.

Required changes (must land in this PR)

  1. [x] Drop the duplicate CHANGELOG entry for #622. Diff line 10 adds:

    Propagate headers and environment variables through OpenCode MCP adapter with defensive copies to prevent mutation (#622)

    That entry is already shipped in the v0.8.12 section at CHANGELOG.md:70. PR fix: propagate headers through OpenCode MCP adapter #622 was merged on 2026-04-09. This is a merge-base artifact — please remove the line from the [Unreleased] section. Only the #602 line for this PR should remain. Shipping with this duplicate would put #622 in the changelog twice.

  2. [x] Fix the same bug in src/apm_cli/commands/init.py:212. This is in the same file as the fix, immediately after the prompt this PR corrects. The interactive setup section still calls Rich Confirm.ask("Is this OK?") and will triple-prompt on CP950/CP936/CP932 — meaning bug: apm init asks "Continue and overwrite?" three times on Windows CP950 terminals #602's reproduction (apm init in a Windows non-UTF-8 terminal) will still triple-prompt, just on the next prompt instead of the first. We can't merge a "fixes bug: apm init asks "Continue and overwrite?" three times on Windows CP950 terminals #602" PR that only fixes the first of two prompts in the same command flow. Please replace Confirm.ask() here with click.confirm() (same one-line change as the rest of this PR), and extend the regression test to cover this prompt too.

  3. [x] Fix the same bug in src/apm_cli/commands/deps/cli.py:455. Rich Confirm.ask("Continue?") in the deps clean flow — same triple-prompt failure mode on CP950. apm deps clean is one of the first 5 commands a Windows user is likely to run. Same one-line replacement; add a minimal test.

A _safe_confirm() helper in _helpers.py would also be reasonable (same fix, three call sites — meets the codebase's "abstract when 3+" rule), but it's not required — three direct replacements are fine if simpler. Architect's call.

Cleanup also wanted (low-effort, same PR)

  1. [!] Delete the now-dead _lazy_confirm() helper. After this PR removes the only two callers (the import on diff line 22 and the use replaced by diff line 38), _lazy_confirm() at src/apm_cli/commands/_helpers.py:103 has zero callers in src/. Architect verified. One-line deletion. With the two new replacements above, this helper becomes dead permanently — drop it now while you're in the area.

Optional polish

  1. [i] Inline comment to lock in intent. A one-liner above confirm = click.confirm("Continue and overwrite?") like # Plain click.confirm: Rich Confirm.ask triple-prompts on CP950 terminals; see #602 would prevent a well-meaning future PR from "modernizing" this back to Rich. Cheap, valuable.

Merge call

Land items 1-4 in this PR, then re-request review. The bug fix itself is excellent — the test design alone is worth merging. But the scope is half of #602, and we should ship the full reproduction fix in one PR rather than chase the same bug across follow-ups. With the three call-site changes plus the CHANGELOG cleanup, this becomes a definitive close on the CP950 confirmation-prompt class.

Growth angle

  • APAC contributor signal. This bug was caught and fixed by an external contributor (Sergio). A Windows + CP950 reproduction means someone in the APAC enterprise dev pipeline tried APM and cared enough to fix it — leading indicator worth tracking.
  • Cross-platform parity narrative. With fix(auth): thread dep_ref.port into credential resolution (#785) #788 (auth port-threading parity) and fix: VS Code adapter fails to configure HTTP/SSE remote MCP servers (#654) #656 (cross-runtime adapter parity) both landing, this is the third recent PR landing "APM works the same regardless of where/how you run it." Worth amplifying once shipped completely.
  • Release-notes one-liner (post-fix): "apm init and apm deps clean no longer triple-prompt on Windows non-UTF-8 terminals (Taiwan/HK/Japan code pages)." — naming both commands and the affected regions resonates.

Thanks @sergio-sisternes-epam — happy to re-approve as soon as the four required items land. The fix you've already shipped here is the template; extending it to the two siblings is mechanical.

Reviewed via the apm-review-panel skill: python-architect, cli-logging-expert, devx-ux-expert; convergent verdict, escalated to REQUEST CHANGES on follow-up scope.

Copy link
Copy Markdown
Collaborator

@danielmeppiel danielmeppiel left a comment

Choose a reason for hiding this comment

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

Escalating to REQUEST CHANGES per the updated panel verdict above (#647 (comment)). Three required same-PR items:

  1. Drop the duplicate #622 CHANGELOG line (already shipped in v0.8.12 at CHANGELOG.md:70).
  2. Fix Confirm.ask() at src/apm_cli/commands/init.py:212 — same file, same command, same bug class.
  3. Fix Confirm.ask() at src/apm_cli/commands/deps/cli.py:455 — same triple-prompt failure mode on CP950.

Plus a low-effort cleanup (delete dead _lazy_confirm() helper in _helpers.py:103, zero callers after this PR).

The fix you've already shipped here is correct and well-tested — the test design (output.count(...) == 1) is exemplary. Extending it to the two sibling call sites is mechanical and gives us a definitive close on the CP950 confirmation-prompt class in one PR rather than chasing it across follow-ups.

Happy to re-approve as soon as the four items land. This supersedes my earlier approval.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel danielmeppiel self-requested a review April 20, 2026 23:44
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.

bug: apm init asks "Continue and overwrite?" three times on Windows CP950 terminals

3 participants