Skip to content

Conversation

@iankhou
Copy link
Contributor

@iankhou iankhou commented Aug 28, 2025

Fixes #724

Description

Setting "notices": false in cdk.json doesn't suppress notices.

The root cause is that we handle logic to determine whether we should print notices at yargs. Yargs had a default value determined by a helper function (YARGS_HELPERS.shouldDisplayNotices()) that returned true when not in CI, or when in a safe CI.

This meant that any setting in our configuration would be overwritten by the output of this helper, because it looks like it's coming from the command line!

Solution

Centralize logic for notices in cli.ts.

Made the notices option in yargs undefined by default. Moved the logic from YARGS_HELPERS.shouldDisplayNotices() into the cli.ts. This has several implications.

  • Setting notices in config now functions as expected; it will still not override the command line setting
  • If a CDK app is running in a CI environment where it would not be safe to print notices
    • NEW BEHAVIOR: Notices WILL be printed if notices: true or notices: [truthy value] is set in config
    • Notices WILL be printed if flag --notices is passed, and NOT printed if --no-notices / --notices=false is passed at the command line (was already the case)

Caveat: "notices": "false" in the config will suppress notices, but other "truthy" values will cause them to be printed.

Testing

Added unit tests to verify the hierarchy of behavior:

  1. Flags in CLI (--notices or --no-notices)
  2. Setting in configuration ("notices": false in cdk.json)
  3. Print notices if not in CI or in CI where it is safe

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

@iankhou iankhou self-assigned this Aug 28, 2025
@iankhou iankhou changed the title Iankhou fix notices fix: notice suppression is not respected when in cdk.json Aug 28, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team August 28, 2025 19:34
@github-actions github-actions bot added bug effort/medium 1-3 days of effort p2 labels Aug 28, 2025
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.42%. Comparing base (6f4e98a) to head (e57c5de).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #821      +/-   ##
==========================================
- Coverage   82.82%   82.42%   -0.41%     
==========================================
  Files          65       65              
  Lines        9509     9523      +14     
  Branches     1119     1109      -10     
==========================================
- Hits         7876     7849      -27     
- Misses       1599     1643      +44     
+ Partials       34       31       -3     
Flag Coverage Δ
suite.unit 82.42% <100.00%> (-0.41%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

const configNotices = configuration.settings.get(['notices']);
if (configNotices !== undefined) {
// Consider string "false" to be falsy in this context
shouldDisplayNotices = configNotices !== "false" && Boolean(configNotices);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handle "false" as falsy.

Handle "", 0, null, and undefined as falsy.

Comment on lines -61 to -63
export function shouldDisplayNotices(): boolean {
return !isCI() || Boolean(ciSystemIsStdErrSafe());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this logic to cli code.

Signed-off-by: github-actions <[email protected]>
@iankhou iankhou changed the title fix: notice suppression is not respected when in cdk.json fix: notices key in cdk.json is not respected Aug 29, 2025
Signed-off-by: github-actions <[email protected]>
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Sep 3, 2025
Merged via the queue into main with commit 1ab5a09 Sep 3, 2025
28 checks passed
@aws-cdk-automation aws-cdk-automation deleted the iankhou-fix-notices branch September 3, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug effort/medium 1-3 days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: notice suppression via cdk.json is not working

4 participants