fix(cli): --yes mode requires a TTY when a request's default is falsy - #1892
Merged
aws-cdk-automation merged 1 commit intoAug 25, 2026
Merged
Conversation
CliIoHost.resolveRequest's auto-respond path checked `if (msg.defaultResponse)` before returning the default in --yes/autoRespond mode. A falsy-but-defined default (empty string '', or 0) fails that truthy check, so the code falls through past the auto-respond block to the isTTY check and throws TtyNotAttached instead of returning the default — even though --yes was passed specifically to avoid needing a TTY. This is user-visible today: the resource-import prompt (importer.ts) and the SDK MFA-token prompt (awscli-compatible.ts) both pass an empty-string defaultResponse, so `cdk import --yes` (or any non-interactive/CI run hitting these prompts) aborts with TtyNotAttached instead of silently taking the default, unlike NonInteractiveIoHost's equivalent codepath which returns the default unconditionally. Fixes aws#1891
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1892 +/- ##
==========================================
- Coverage 91.38% 91.34% -0.04%
==========================================
Files 80 80
Lines 12264 12264
Branches 1747 1746 -1
==========================================
- Hits 11207 11203 -4
- Misses 1021 1025 +4
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mrgrain
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for this change
CliIoHost.resolveRequest's--yesauto-respond path used a truthy check (if (msg.defaultResponse)) before returning the request's default response. Non-boolean prompts (booleans are handled separately viaisConfirmationPrompt) whose default is falsy-but-valid — an empty string''or the number0— fail this check and fall through to theisTTYgate, throwingTtyNotAttachedinstead of using the default, even though--yeswas passed specifically so the CLI wouldn't need a TTY.This is inconsistent with the sibling
NonInteractiveIoHostimplementation, which handles the boolean case separately and then unconditionally returnsmsg.defaultResponse— the intended semanticsCliIoHost's--yesmode is supposed to mirror.Two real call sites already pass an empty-string default and are affected today:
cdk import's per-property resource-identifier prompt (importer.ts) — empty default means "skip this identifier"awscli-compatible.ts,CDK_SDK_I1100)So
cdk import --yes(or any non-interactive/CI run hitting one of these prompts) currently aborts withTtyNotAttachedinstead of silently taking the default.Description of changes
Changed the truthy check to a definedness check:
if (msg.defaultResponse !== undefined), mirroring thetypeof ... === 'string' || 'number'checks already used a few lines below inisPromptableRequest.Description of how you validated changes
Added a regression test in
cli-io-host.test.tsthat constructs aCliIoHostwithautoRespond: true, isTTY: falseand asserts that requests withdefaultResponse: ''anddefaultResponse: 0resolve to those values instead of throwing. Verified the test fails withTtyNotAttachedagainst the old code and passes with the fix. Ran the fullcli-io-hosttest suite (91 tests) — all pass.Checklist
Fixes #1891
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license