Skip to content

Fix prompt capability checks for redirected consoles - #5581

Merged
Ahmed Muhsin (ahmedmuhsin) merged 3 commits into
Azure:vnextfrom
ahmedmuhsin:fix/5511-prompt-capabilities
Sep 16, 2026
Merged

Ahmed Muhsin (ahmedmuhsin) merged 3 commits into
Azure:vnextfrom
ahmedmuhsin:fix/5511-prompt-capabilities

Conversation

@ahmedmuhsin

@ahmedmuhsin Ahmed Muhsin (ahmedmuhsin) commented Sep 10, 2026 •

Copy link
Copy Markdown

Fixes #5511.

Use injected stdout/stderr input and ANSI capabilities for command-level interactivity. Each prompt checks its actual target console, preserving non-ANSI text and confirmation input, defaults, and cancellation.

Verified failing baseline regressions, capability matrices, a warning-free Release build, all 2,051 solution tests, and redirected new/init CLI smoke checks.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The capability gating changes are well-covered by new tests and align with the reported redirection crash scenario, with only a minor warning-message wording nit noted.

Pull request overview

This PR fixes prompt capability checks to avoid Spectre prompt crashes when stdout or stderr is redirected (Issue #5511). It refines IInteractionService/SpectreInteractionService to base interactivity on the actual injected consoles (stdin + ANSI capabilities per target stream) and adds targeted tests to cover the redirection/capability matrix across prompts and key consumers.

Changes:

  • Update SpectreInteractionService interactivity logic so selection prompts gate on the stderr console’s ANSI + input capabilities, while confirmation/text prompts gate on their own target console.
  • Clarify IInteractionService documentation around output routing and what IsInteractive represents at the command level.
  • Add comprehensive tests (including capability matrices and consumer coverage for new, init, first-run coordination, and dashboard output mode resolution).
File summaries
File Description
test/Func.Tests/Console/SpectreInteractionServiceTests.cs Adds matrix-driven tests for IsInteractive and each prompt method’s capability gating, cancellation, and fallback behavior.
test/Func.Tests/Console/PromptCapabilityConsumerTests.cs Validates key command/service consumers behave correctly under redirected/non-ANSI scenarios (no prompt crashes, correct fallbacks).
test/Func.Tests/Console/BufferedConsole.cs Introduces a buffered Spectre console test double with scripted key input and captured output.
src/Func/Console/SpectreInteractionService.cs Implements per-target capability checks (stdout vs stderr) and updates prompt methods to honor cancellation early and gate selection prompts correctly.
src/Func/Console/IInteractionService.cs Updates contract docs for routing and interactivity semantics to match the new behavior.
src/Func/Commands/Start/StartCommand.cs Adjusts the downgrade warning message when compact mode is unsafe.
src/Func/Commands/Start/Dashboard/Rendering/OutputModeResolver.cs Updates docs to describe the revised capability-based downgrade rule.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Func/Commands/Start/StartCommand.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The capability checks are corrected in the core interaction service and are backed by thorough matrix + consumer-level tests covering the reported redirected-console failure modes.

Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@ahmedmuhsin
Ahmed Muhsin (ahmedmuhsin) marked this pull request as ready for review September 10, 2026 12:40
@ahmedmuhsin
Ahmed Muhsin (ahmedmuhsin) requested a review from a team as a code owner September 10, 2026 12:40
@satvu

Copy link
Copy Markdown
Member

Flagging a potential regression for your review:

IsInteractive now requires ANSI support on both stdout and stderr, but this property is also used to decide whether destructive --force confirmations should be shown.

Both InitCommand.ConfirmClearDirectoryAsync and QuickstartCommand.ConfirmClearDirectoryAsync return true when IsInteractive is false, treating the operation as confirmed.

For example, with func init <dir> --force 2>errors.log, redirected stderr may not support ANSI, so the new check returns false. The command skips ConfirmAsync("Continue?") and proceeds to ClearDirectory even though ConfirmAsync renders on stdout and only requires interactive input not ANSI or stderr.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved blocking issues were identified, and the supplied assessments indicate readiness.

Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@ahmedmuhsin
Ahmed Muhsin (ahmedmuhsin) merged commit 9c41fa2 into Azure:vnext Sep 16, 2026
6 checks passed
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.

3 participants