diff --git a/packages/aws-cdk/lib/cli/io-host/cli-io-host.ts b/packages/aws-cdk/lib/cli/io-host/cli-io-host.ts index 768c76c7d..90c13b796 100644 --- a/packages/aws-cdk/lib/cli/io-host/cli-io-host.ts +++ b/packages/aws-cdk/lib/cli/io-host/cli-io-host.ts @@ -1003,7 +1003,7 @@ export class CliIoHost implements IIoHost, ObservableIoHost { } // respond with the default for all other messages - if (msg.defaultResponse) { + if (msg.defaultResponse !== undefined) { await this.writeMessage({ ...msg, message: `${chalk.cyan(msg.message)} (auto-responded with default: ${util.format(msg.defaultResponse)})`, diff --git a/packages/aws-cdk/test/cli/io-host/cli-io-host.test.ts b/packages/aws-cdk/test/cli/io-host/cli-io-host.test.ts index d03d1af2a..087468280 100644 --- a/packages/aws-cdk/test/cli/io-host/cli-io-host.test.ts +++ b/packages/aws-cdk/test/cli/io-host/cli-io-host.test.ts @@ -1336,6 +1336,37 @@ describe('CliIoHost', () => { })); expect(response).toBe('foobar'); }); + + test('falsy defaults (empty string, zero) are auto-responded instead of requiring a TTY', async () => { + const nonTtyAutoRespondingIoHost = CliIoHost.instance({ + logLevel: 'trace', + autoRespond: true, + isCI: false, + isTTY: false, + }, true); + + // empty string default + const stringResponse = await nonTtyAutoRespondingIoHost.requestResponse(plainMessage({ + time: new Date(), + level: 'info', + action: 'synth', + code: 'CDK_TOOLKIT_I5060', + message: 'test message', + defaultResponse: '', + })); + expect(stringResponse).toBe(''); + + // zero default + const numberResponse = await nonTtyAutoRespondingIoHost.requestResponse(plainMessage({ + time: new Date(), + level: 'info', + action: 'synth', + code: 'CDK_TOOLKIT_I0001', + message: 'test message', + defaultResponse: 0, + })); + expect(numberResponse).toBe(0); + }); }); describe('non-promptable data', () => {