Skip to content

Conversation

@frankbria
Copy link
Owner

@frankbria frankbria commented Jan 26, 2026

Summary

  • Fixed wizard prompt functions (prompt_text, prompt_number, select_option, select_with_default, confirm) that were writing colored prompts to stdout
  • When used with command substitution in ralph_enable.sh, ANSI codes were captured along with user input, corrupting .ralphrc values
  • Redirected all display output to stderr (>&2) while keeping only the response on stdout

Problem

# Before fix - ANSI codes captured:
PROJECT_NAME="[0;36mProject name[0m [project_name]: project_name"

# After fix - clean value:
PROJECT_NAME="project_name"

Changes

  • lib/wizard_utils.sh: Add >&2 to all display output in 5 functions
  • tests/unit/test_wizard_utils.bats: New test file with 20 tests for stdout/stderr separation
  • CLAUDE.md: Update test count to 420

Test plan

  • Run bats tests/unit/test_wizard_utils.bats - 20 tests pass
  • Run npm test - all 420 tests pass
  • Manual test: Run ralph-enable interactively, verify .ralphrc has clean values
  • Manual test: Verify prompts still display correctly with colors during interaction

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed prompt and error message output handling in interactive utilities to ensure reliable command substitution and piping behavior.
  • Tests

    • Added comprehensive test coverage for interactive prompt and selection utilities, validating input handling, defaults, validation, and output behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

When wizard prompt functions (prompt_text, prompt_number, select_option,
select_with_default) were used with command substitution, ANSI-colored
prompts were captured along with user responses, corrupting .ralphrc
values like: PROJECT_NAME="[0;36mProject name[0m [value]: value"

Fix:
- Redirect all display output (colored prompts, validation messages) to
  stderr using >&2, matching the pattern already used by select_multiple()
- Keep only the actual response/result on stdout for command substitution

Changes:
- lib/wizard_utils.sh: Add >&2 to prompt_text (lines 84-87),
  prompt_number (lines 118-121, 131-151), confirm (lines 44, 60),
  select_option (lines 190-215), select_with_default (lines 330-364)
- tests/unit/test_wizard_utils.bats: Add 20 new tests for stdout/stderr
  separation and clean command substitution results
- CLAUDE.md: Update test count to 420

Test count: 420 (up from 396)
@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Walkthrough

The changes update the wizard utilities library to redirect all user-facing prompts and error messages to stderr while preserving stdout for command substitution capture. A comprehensive Bash/Bats unit test suite is added to validate this behavior alongside input handling, validation, and return codes. Test metadata documentation is updated accordingly.

Changes

Cohort / File(s) Summary
Documentation & Metadata
CLAUDE.md
Updates test count from 396 to 420; adds entry for new test file test_wizard_utils.bats with size reference
Core Library
lib/wizard_utils.sh
Redirects user prompts, option lists, and validation messages from stdout to stderr across confirm, prompt_text, prompt_number, select_option, select_multiple, and select_with_default functions; adds inline comments explaining stderr redirection rationale
Test Suite
tests/unit/test_wizard_utils.bats
Adds 206 lines of comprehensive unit tests covering stdout/stderr separation, input handling with defaults, ANSI code filtering, numeric validation, special character handling, and return codes for all wizard utility functions

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With prompts now whispered to stderr's ear,
And tests to prove the code rings clear,
Our wizard utilities take flight,
Capturing input, getting it right!
A hop, skip, and tested delight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: redirecting wizard prompts to stderr for clean command substitution, which directly addresses the core issue in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/wizard-prompt-stdout-stderr

Comment @coderabbitai help to get the list of available commands and usage tips.

@macroscopeapp
Copy link
Contributor

macroscopeapp bot commented Jan 26, 2026

Redirect wizard prompt outputs to stderr in lib/wizard_utils.sh to support clean command substitution

Route all interactive prompt and validation messages to stderr while emitting only selected/entered values to stdout; update tests to validate stdout/stderr separation and adjust displayed test count in CLAUDE.md.

📍Where to Start

Start with the prompt and selection functions in lib/wizard_utils.sh, focusing on confirm, prompt_text, prompt_number, select_option, and select_with_default.


Macroscope summarized 73fec4b.

@github-actions
Copy link

Code Review

This PR correctly addresses the issue of ANSI codes corrupting values by redirecting prompt display to stderr. The implementation is sound and follows bash best practices.

✅ Strengths

  1. Correct solution: Using to separate display output (stderr) from return values (stdout) is the standard approach for bash prompt functions
  2. Consistent across all functions: All 5 prompt functions (, , , , ) properly redirect to stderr
  3. Comprehensive test coverage: 20 tests validate ANSI code removal, prompt text exclusion, and variable assignment safety
  4. Well-structured tests: Tests are grouped by function with clear descriptions of what's being verified
  5. No breaking changes: Display utilities ( functions) still output to stdout, maintaining backward compatibility

📝 Minor Suggestions

  1. Consider testing function as well (currently only 4 functions are tested)
  2. The tests use pattern - consider documenting this test pattern in for consistency

✅ Verification

All 20 tests properly verify:

  • ANSI escape sequences () are not in captured output
  • Prompt text is not in captured output
  • Output is safe for shell variable assignment

This PR is ready to merge.

@github-actions
Copy link

The review has been posted to PR #130. The PR correctly fixes the ANSI code capture issue by redirecting prompt displays to stderr, with comprehensive test coverage. Ready to merge.

New%20session%20-%202026-01-26T21%3A43%3A20.079Z
opencode session  |  github run

@claude
Copy link

claude bot commented Jan 26, 2026

Code Review: Wizard Prompt stdout/stderr Separation Fix

This is an excellent bug fix that addresses a critical issue with ANSI escape codes being captured in command substitution, corrupting configuration values in .ralphrc. The implementation is clean, well-tested, and follows bash best practices.

Strengths

1. Root Cause Analysis
The PR correctly identifies and fixes the core problem: when using command substitution, all stdout output (including ANSI color codes) was being captured, resulting in corrupted values.

2. Consistent stderr Redirection Pattern
All five affected functions now properly redirect display output to stderr using >&2:

  • confirm() - Line 45, 61
  • prompt_text() - Lines 86, 88
  • prompt_number() - Lines 121, 123, 134, 141, 147, 152
  • select_option() - Lines 191-192, 197, 201, 204, 215
  • select_with_default() - Lines 331-332, 338, 340, 345, 348, 364

3. Comprehensive Test Coverage
The new test file test_wizard_utils.bats provides 20 well-structured tests organized into logical sections:

  • prompt_text: 4 tests (basic input, defaults, empty handling, special chars)
  • prompt_number: 5 tests (numeric validation, defaults, min/max ranges, non-numeric rejection)
  • confirm: 3 tests (stderr separation, yes/no return codes)
  • select_option: 3 tests (selection, first option, retry on invalid)
  • select_with_default: 3 tests (selection, default handling, non-first defaults)
  • Integration: 2 tests (shell variable assignment, arithmetic operations)

4. Test Quality

  • Tests verify absence of ANSI codes using pattern matching
  • Tests verify prompt text is not captured in the result
  • Tests validate return codes (especially for confirm())
  • Integration tests ensure output is safe for real-world usage

5. No Functional Changes
The fix only changes where output goes (stderr vs stdout), not what is displayed. User experience remains identical.

Code Quality Observations

1. Edge Case Handling
The tests cover important edge cases:

  • Empty input with and without defaults
  • Invalid input requiring retry
  • Special characters in user input
  • Min/max boundary validation for numbers

2. Consistent Implementation
All validation error messages correctly go to stderr, maintaining consistency even in error paths.

3. Documentation Alignment
CLAUDE.md is properly updated with the new test count (420 tests) and test file description in the Test Suite table.

Security and Best Practices

No Security Concerns

  • No user input is evaluated or executed
  • stderr redirection does not introduce injection risks
  • Command substitution usage is safe and idiomatic

Follows Bash Best Practices

  • Uses >&2 for stderr redirection (POSIX compliant)
  • Maintains existing validation logic
  • Preserves function return codes

Recommendation

Approve - Production Ready

This PR is production-ready and should be merged. The fix is:

  • Correct and minimal
  • Well-tested (20 new tests)
  • Maintains backward compatibility
  • Follows project conventions
  • Properly documented

Test Coverage Impact:

  • Previous: 396 tests
  • New: 420 tests (+24 tests)
  • Pass rate: 100%

Excellent work on identifying and fixing this subtle but critical bug! The stdout/stderr separation is textbook bash scripting best practice.

@frankbria frankbria linked an issue Jan 26, 2026 that may be closed by this pull request
@frankbria frankbria merged commit 05c5720 into main Jan 26, 2026
7 checks passed
@frankbria frankbria deleted the fix/wizard-prompt-stdout-stderr branch January 26, 2026 21:47
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: Interactive prompts capture ANSI codes into .ralphrc values

2 participants