Skip to content

[codex] Fix confirm prompt default regression#78

Open
Oranquelui wants to merge 4 commits intogaureshpai:mainfrom
Oranquelui:codex/fix-confirm-prompt-defaults
Open

[codex] Fix confirm prompt default regression#78
Oranquelui wants to merge 4 commits intogaureshpai:mainfrom
Oranquelui:codex/fix-confirm-prompt-defaults

Conversation

@Oranquelui
Copy link
Copy Markdown

@Oranquelui Oranquelui commented Mar 29, 2026

Summary

  • avoid duplicating (default: ...) in confirm prompts when the message already includes a default suffix
  • normalize empty confirm answers to a boolean instead of returning raw string defaults
  • add regression coverage for both prompt behaviors

Root Cause

The previous fix switched confirm rendering from message to displayMessage, but some callers already embed (default: Yes) in the prompt text. That caused duplicated default text in the rendered confirm line. The confirm handler also returned the raw default value on empty input, which could leak string defaults instead of a boolean.

Validation

  • COREPACK_ENABLE_AUTO_PIN=0 pnpm exec biome check src/lib/prompts.js src/test/test.js
  • COREPACK_ENABLE_AUTO_PIN=0 pnpm test

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed default value display in confirm prompts to prevent duplicate default indicators when already specified in the message
    • Improved default value handling with stricter boolean logic for Yes/No interpretation
    • Corrected empty response behavior to properly apply default values
  • Tests

    • Added comprehensive test coverage for confirm prompt rendering, default labels, and value normalization

itniuma2026 and others added 4 commits March 22, 2026 10:14
The Docker prompt's default value is not properly configured, causing it to display incorrectly when the user accepts the default. The default should be 'N' (No) and should be displayed/selected properly.

Fixes gaureshpai#74
The confirm prompts now display '(default: Yes)' or '(default: No)' text
in addition to the (Y/n) hint, making the default option much clearer.

Before: ? Do you want to use TypeScript? (Y/n)
After: ? Do you want to use TypeScript? (default: Yes) (Y/n)

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Make displayMessage use strict boolean check (defaultVal === true) to match confirmHint behavior and prevent contradictory hints when non-boolean truthy values are passed as defaultVal.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f287a322-d215-4f33-8d78-3cd37b9dd6bd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🎉 Hi @Oranquelui!

Thanks for submitting your first Pull Request!
We’re thrilled to have your contribution and will review it shortly.

Copy link
Copy Markdown
Owner

@gaureshpai gaureshpai left a comment

Choose a reason for hiding this comment

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

Also can we please re-render the line once an option is selected irrespective of prompt based input or default selection so that the (Y/n) would be vanished once an option will be selected

Rest LGTM! Good work

const displayMessage = `${message}${defaultVal !== undefined && !hasDefaultSuffix ? ` (default: ${defaultDisplay})` : ""} `;

const confirmHint = defaultVal ? "(Y/n)" : "(y/N)";
const confirmHint = defaultVal === true ? "(Y/n)" : "(y/N)";
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

? Do you want to use Shadcn UI? (default: Yes) (Y/n)
? Do you want to add Docker support? (default: No) (y/N)

(Y/n) ✅
(y/N) ❌

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/test/test.js (1)

58-67: Make RESULT extraction less regex-greedy for future-proofing.

/RESULT=(\{.*\})/s can over-capture when additional brace-containing output appears. Parsing the explicit RESULT= line is safer.

Proposed hardening
-      const resultMatch = cleanOutput.match(/RESULT=(\{.*\})/s);
-
-      if (!resultMatch) {
+      const resultLine = cleanOutput
+        .split(/\r?\n/)
+        .find((line) => line.startsWith("RESULT="));
+
+      if (!resultLine) {
         reject(new Error(`Prompt runner did not emit result.\nstdout:\n${cleanOutput}`));
         return;
       }
 
       resolve({
         output: cleanOutput,
-        result: JSON.parse(resultMatch[1]),
+        result: JSON.parse(resultLine.slice("RESULT=".length)),
       });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/test.js` around lines 58 - 67, The RESULT extraction uses a greedy
regex (resultMatch computed from cleanOutput) which can over-capture; change the
match to target the explicit RESULT= line and use a non-greedy, multiline-safe
pattern so only the JSON payload on that line is captured (e.g. anchor to the
line start and stop at the closing brace or use a non-greedy capture across
newlines). Update the code that builds resultMatch and keep the subsequent
JSON.parse(resultMatch[1]) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/test.js`:
- Around line 58-67: The RESULT extraction uses a greedy regex (resultMatch
computed from cleanOutput) which can over-capture; change the match to target
the explicit RESULT= line and use a non-greedy, multiline-safe pattern so only
the JSON payload on that line is captured (e.g. anchor to the line start and
stop at the closing brace or use a non-greedy capture across newlines). Update
the code that builds resultMatch and keep the subsequent
JSON.parse(resultMatch[1]) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91f0899a-8d94-4078-bce4-ca164ca56889

📥 Commits

Reviewing files that changed from the base of the PR and between 3d76ba0 and a92fa36.

📒 Files selected for processing (2)
  • src/lib/prompts.js
  • src/test/test.js
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Node 20.x - yarn
  • GitHub Check: Node 22.x - npm
  • GitHub Check: Node 20.x - npm
  • GitHub Check: Node 20.x - pnpm
  • GitHub Check: Node 22.x - yarn
  • GitHub Check: Node 22.x - pnpm
🔇 Additional comments (4)
src/lib/prompts.js (2)

24-26: Default-label dedup logic is clean and targeted.

This avoids repeated (default: ...) rendering while still preserving explicit defaults embedded in the message.


28-37: Confirm default normalization is now type-safe.

Using strict boolean checks for hint rendering and empty-input fallback ensures confirm answers resolve to booleans consistently.

src/test/test.js (2)

17-73: Subprocess-based prompt harness is a solid regression-testing approach.

Running prompts in a separate Node process is a good fit for validating interactive rendering behavior end-to-end.


74-102: Great regression coverage for both confirm-default bugs.

These two tests directly validate the duplicate-default rendering fix and the empty-answer boolean normalization behavior.

@github-actions
Copy link
Copy Markdown
Contributor

✅ CI/CD Test Results

Overall Status: success


View full workflow run

@gaureshpai gaureshpai marked this pull request as ready for review March 31, 2026 12:14
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