Skip to content

fix(core): exit 3 on Ctrl-C at any prompt after the cli-utilities 2 upgrade - #294

Open
Harshi-Shah-CS wants to merge 15 commits into
v2-devfrom
CL-8790
Open

Harshi-Shah-CS wants to merge 15 commits into
v2-devfrom
CL-8790

Conversation

@Harshi-Shah-CS

Copy link
Copy Markdown
Contributor

Fixes CL-8790: since the cli-utilities 2 upgrade (CL-8328), Ctrl-C at an interactive prompt exited 130 instead of 3 (cancelled).

What

  • Ctrl-C at any prompt exits 3 again. cliux.inquire in cli-utilities 2 catches inquirer 12's ExitPromptError and calls process.exit(130) itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process SIGINT, so the SIGINT listener in cancelOnInterrupt never fired. LaunchCommand's ux is now cancelOnInterrupt(terminalUx). terminalUx (src/core/terminal-ux.ts) prompts through the same inquirer instance cli-utilities uses (promptLibrary(), where search-list is registered), so the rejection reaches the wrapper, which maps ExitPromptError to CancelledError.
  • Ctrl-C at a search-list prompt (organization and project pickers) exits 3 too. This case was not in the ticket. inquirer 12 runs search-list as a legacy prompt: on Ctrl-C it rejects with AbortPromptError and then raises a real SIGINT. The wrapper used to stop listening on the rejection, so the command failed as a runtime error (exit 1), or the SIGINT killed it. The wrapper now cancels on the rejection at once and stays attached only to absorb the SIGINT that follows.
  • The prompt-funnel guard covers the new path. It expects cancelOnInterrupt(terminalUx) and flags any use of promptLibrary outside search-list.ts / terminal-ux.ts, and any use of terminalUx other than the funnel line, following import aliases.
  • Tests stub prompts at terminalUx.inquire (new stubPrompts in test/support/terminal.ts) instead of cliux.inquire. answerPrompts' CTRL_C now rejects with ExitPromptError, as a real Ctrl-C does, instead of emitting a SIGINT that no longer reaches an open prompt; at a search-list prompt it rejects with AbortPromptError and raises the SIGINT, as inquirer does.

Tests

  • test/integration/prompt-ctrl-c-on-a-terminal.test.ts (new) opens a real input, password, list, checkbox, confirm and search-list prompt through LaunchCommand's ux on a pseudo-terminal, types Ctrl-C and expects exit 3. The driver is test/support/pty/press-ctrl-c.py (Python stdlib pty, no native module; python3 is on the ubuntu runners). The driver kills the CLI and fails the test if it is still running 30 s after Ctrl-C. Against the old cancelOnInterrupt(cliux) funnel every case fails: 130, and 1 at search-list. This is the class test the ticket asked for; the existing guards simulated SIGINT, which is how this regression stayed green.

  • Unit tests for both rejections in src/core/interruptible-ux.test.ts, and for libraryUx / terminalUx in src/core/terminal-ux.test.ts. projects-command-flows.test.ts presses Ctrl-C at the project picker and expects exit 3.

  • Manual acceptance harness (scripts/launch-cli-manual-tests, LAUNCH_INTERACTIVE=1, dev11) against this branch: every Ctrl-C case passes. That covers the organization picker, the project picker, the first projects:create prompt, the env:get environment picker and the deployments:list environment picker, each exiting 3. 68 passed, 1 failed. The failure is the harness's deployments:get check of the ENVIRONMENT VARIABLES wording, which has been stale since 50a8622 and is unrelated to this PR. The test environment has one domain, so 88's multi-domain Ctrl-C case did not run.

  • Coverage: npm run test:coverage reports branch coverage at 99.75%, under the 100% threshold. v2-dev (43e0d95) reports exactly the same gaps, run locally: one branch each in cache.presenter.ts, logs/get.ts, failure.ts, commit.prompt.ts, deployment.create.ts, deployment.rollback.ts and deployment.watcher.ts. None of them comes from this PR. Every file this PR adds or changes is at 100%.

Left as is, low:

  • terminalUx no longer runs prompt messages through cli-utilities' message-key lookup (messageHandler.parse), which cliux.inquire did. Every Launch prompt message is a literal English sentence, not a key.
  • search-list is still the one legacy inquirer prompt, hence the abort-then-SIGINT case in the wrapper. Porting the pickers to @inquirer/search would leave one Ctrl-C path. That is a follow-up, not part of this fix.
  • The pty test needs python3 (3.9+, POSIX pty), which the ubuntu runners and macOS have.

Talisman: .talismanrc gets a checksum for the new pty test (its password prompt type trips the scanner) and refreshed checksums for the touched files that already had one.

#claude_code#
🤖 Generated with Claude Code

Harshi-Shah-CS and others added 15 commits November 18, 2026 21:39
In raw mode Ctrl-C reaches inquirer 12 as a keypress, not a process SIGINT,
and the prompt rejects with ExitPromptError. The prompt wrapper now turns
that rejection into CancelledError (exit 3), as it does for a SIGINT.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
inquirer 12 runs search-list as a legacy prompt: on Ctrl-C it rejects with
AbortPromptError and then raises a real SIGINT. The wrapper used to stop
listening on that rejection, so the SIGINT found no listener. It now keeps
listening, and the SIGINT cancels the prompt with CancelledError.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
cliux.inquire catches inquirer's ExitPromptError and calls process.exit(130)
before a caller can see it. terminalUx asks the same inquirer instance
(the one search-list is registered with) and lets the rejection through, so
the Ctrl-C wrapper can map it to exit 3. It prints through cliux as before.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
LaunchCommand's ux is now cancelOnInterrupt(terminalUx) instead of
cancelOnInterrupt(cliux), so inquirer's ExitPromptError reaches the wrapper
and becomes CancelledError rather than cli-utilities' process.exit(130).

Tests stub prompts at terminalUx.inquire (stubPrompts in
test/support/terminal.ts) instead of cliux.inquire, and answerPrompts'
CTRL_C now rejects with ExitPromptError, which is what a real Ctrl-C does,
instead of emitting a SIGINT that no longer reaches an open prompt.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
… wraps terminalUx

The prompt-funnel guard now expects LaunchCommand's ux to be built as
cancelOnInterrupt(terminalUx), and flags two new ways around the wrapper:
any use of promptLibrary outside search-list.ts and terminal-ux.ts, and any
use of terminalUx other than that one funnel line.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The prompt guards simulated Ctrl-C by emitting SIGINT, which is how the
cli-utilities 2 regression (CL-8790) stayed green: in raw mode Ctrl-C reaches
inquirer as typed input, never as a signal. This test opens a real prompt
(input, list, checkbox, confirm, search-list) through LaunchCommand's ux on
a pty, types Ctrl-C, and expects exit 3. Against the old
cancelOnInterrupt(cliux) funnel it fails with 130, and with 1 at search-list.

The driver is a Python stdlib pty script, so it needs no native module.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
AGENTS.md's prompt-funnel guard row now says LaunchCommand's ux is
cancelOnInterrupt(terminalUx), why it skips cliux.inquire, how Ctrl-C
reaches an inquirer 12 prompt and a legacy search-list prompt, and which
test types a real Ctrl-C on a pty. "Driving a prompt" now names the
terminalUx.inquire spy, stubPrompts, and CTRL_C rejecting with
ExitPromptError. Test names and comments that said "the inquirer cliux
prompts with" now say terminalUx.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
On AbortPromptError the wrapper used to wait for the SIGINT inquirer raises
next, so a legacy-prompt abort with no signal after it would hang with the
event loop held. It now rejects with CancelledError and releases the loop
straight away, and stays attached to SIGINT only to absorb that signal, then
detaches. Found in review.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
press-ctrl-c.py now waits for the command to exit only until its deadline,
then kills it and reports 125, and the test gives execFileSync a timeout,
so a regression that leaves the CLI running after Ctrl-C fails the test
instead of hanging the whole jest run. The matrix covers the password prompt
again: askSecret uses it at six call sites and @inquirer/password carries its
own @inquirer/core. The test file gets a per-file checksum in .talismanrc
because the prompt type's name trips Talisman. Found in review.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rs it

answerPrompts' CTRL_C now rejects a search-list prompt with AbortPromptError
and raises a SIGINT on the next tick, as inquirer 12 does for that legacy
prompt, and keeps ExitPromptError for every other prompt. A new
projects:get case presses Ctrl-C at the project picker and expects exit 3
with no SIGINT listener left once the signal is absorbed. The stubPrompts
and ctrlC comments are dropped, per AGENTS.md. Found in review.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The prompt-funnel guard matched only the literal names, so
`import { terminalUx as tty }` or `import { promptLibrary as lib }` reached
the prompt library around the Ctrl-C wrapper unnoticed. It now resolves
aliases the way it already did for cliux. Found in review.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
AGENTS.md asks for no code comments on changes; the reason terminalUx skips
cliux.inquire is in AGENTS.md's prompt-funnel guard row.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…e touched

The pre-push scan reads each changed file whole, so the existing per-file
checksums for launch-command, search-list and the integration tests that now
stub prompts at terminalUx.inquire are refreshed in place. No new secrets:
the flagged lines are the existing password/key test fixtures.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…l docs

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Harshi-Shah-CS
Harshi-Shah-CS requested review from a team as code owners November 18, 2026 18:05
@Harshi-Shah-CS

Copy link
Copy Markdown
Contributor Author

Claude review

/code-review (high effort) over v2-dev...CL-8790 before this PR opened. 10 findings, each checked against the code. 5 are fixed on this branch. The other 5 are left as is, with the reason below.

Fixed

# Finding Fix
1 press-ctrl-c.py waited on the child with no timeout, and execFileSync had none either, so a CLI still running after Ctrl-C would hang the jest run instead of failing the test. The driver now waits only until its 30 s deadline, then kills the child and reports 125, and execFileSync has a 45 s timeout (6aaee6f).
2 On AbortPromptError the wrapper waited for the SIGINT inquirer raises next. If none came, the prompt never settled and the held event loop kept the CLI alive. The wrapper now rejects with CancelledError and releases the loop at once, and stays attached to SIGINT only to absorb that signal (46e86b8).
3 The pty matrix left out password, used by askSecret at six call sites through its own @inquirer/core copy. Added back, with a per-file Talisman checksum (6aaee6f).
4 answerPrompts' CTRL_C rejected every prompt with ExitPromptError, a path the search-list pickers never take. It now rejects a search-list prompt with AbortPromptError and raises the SIGINT, and a new projects:get case presses Ctrl-C at the project picker (499d2a0).
5 The guard matched only the literal names terminalUx / promptLibrary, so an aliased import got around the Ctrl-C wrapper. It now follows import aliases, as it already did for cliux (cf8866a).

Not changed

# Finding Why
6 terminalUx drops cliux.inquire's messageHandler.parse(message). Every Launch prompt message is a literal sentence, not a message key. Noted in the PR description.
7 search-list is the last legacy inquirer prompt. Porting it to @inquirer/search would leave one Ctrl-C path. Worth doing, but it is a picker rewrite, not part of this fix.
8 Comments added despite AGENTS.md's "no code comments" rule. The added comments are removed (38fdadd, 499d2a0). The explanation lives in AGENTS.md's prompt-funnel guard row. The one remaining comment in search-list.ts already existed and is only reworded.
9 The default suite now needs python3 with POSIX pty. The ubuntu runners and macOS have it. A Windows dev box would not, which the team does not use for this repo.
10 promptLibrary is resolved on every prompt, and Prompter repeats PromptRegistry.prompt's signature. require is cached, so the cost is negligible, and Prompter keeps libraryUx testable with a plain fake. Low.

#claude_code#
🤖 Generated with Claude Code

@snyk-io

snyk-io Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security 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.

1 participant

⌂ Proxy