Skip to content

fix(cli): --yes mode requires a TTY when a request's default is falsy - #1892

Merged
aws-cdk-automation merged 1 commit into
aws:mainfrom
Adityaj0:fix/auto-respond-ignores-falsy-default
Aug 25, 2026
Merged

fix(cli): --yes mode requires a TTY when a request's default is falsy#1892
aws-cdk-automation merged 1 commit into
aws:mainfrom
Adityaj0:fix/auto-respond-ignores-falsy-default

Conversation

@Adityaj0

Copy link
Copy Markdown
Contributor

Reason for this change

CliIoHost.resolveRequest's --yes auto-respond path used a truthy check (if (msg.defaultResponse)) before returning the request's default response. Non-boolean prompts (booleans are handled separately via isConfirmationPrompt) whose default is falsy-but-valid — an empty string '' or the number 0 — fail this check and fall through to the isTTY gate, throwing TtyNotAttached instead of using the default, even though --yes was passed specifically so the CLI wouldn't need a TTY.

This is inconsistent with the sibling NonInteractiveIoHost implementation, which handles the boolean case separately and then unconditionally returns msg.defaultResponse — the intended semantics CliIoHost's --yes mode 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"
  • The SDK's MFA-token prompt (awscli-compatible.ts, CDK_SDK_I1100)

So cdk import --yes (or any non-interactive/CI run hitting one of these prompts) currently aborts with TtyNotAttached instead of silently taking the default.

Description of changes

Changed the truthy check to a definedness check: if (msg.defaultResponse !== undefined), mirroring the typeof ... === 'string' || 'number' checks already used a few lines below in isPromptableRequest.

Description of how you validated changes

Added a regression test in cli-io-host.test.ts that constructs a CliIoHost with autoRespond: true, isTTY: false and asserts that requests with defaultResponse: '' and defaultResponse: 0 resolve to those values instead of throwing. Verified the test fails with TtyNotAttached against the old code and passes with the fix. Ran the full cli-io-host test suite (91 tests) — all pass.

Checklist

  • Unit tests added/updated
  • Integration tests added/updated (if deploying new resource types or cross-service interactions) — not applicable, no AWS resource interaction
  • No manual edits to generated files

Fixes #1891

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

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
@Adityaj0
Adityaj0 deployed to automation August 25, 2026 08:20 — with GitHub Actions Active
@Adityaj0
Adityaj0 deployed to automation August 25, 2026 08:20 — with GitHub Actions Active
@Adityaj0
Adityaj0 deployed to integ-approval August 25, 2026 08:20 — with GitHub Actions Active
@github-actions github-actions Bot added the p2 label Aug 25, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 25, 2026 08:20
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.34%. Comparing base (ca8a14a) to head (d70fe1d).

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              
Flag Coverage Δ
suite.unit 91.34% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation
aws-cdk-automation added this pull request to the merge queue Aug 25, 2026
Merged via the queue into aws:main with commit acc6f4d Aug 25, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CliIoHost --yes mode throws TtyNotAttached for falsy default responses (empty string, 0)

4 participants