fix(cli): guide Stage users to a working pattern in stack-selection error - #1847
fix(cli): guide Stage users to a working pattern in stack-selection error#1847lemon0333 wants to merge 2 commits into
Conversation
…rror When an app has more than one stack and no selector is given, the CLI prints "specify which stacks to use ... or `--all`". When the stacks live inside a Stage, `--all` and a bare stack name are not the obvious way to target them, so the message was unhelpful for Stage users. Detect stacks that are nested inside a Stage (i.e. not top-level stacks) and additionally point the user at a wildcard pattern that selects them, e.g. `'StageName/*'`. Applied to both the CLI stack selection path and the toolkit-lib `selectStacksV2` path, which share the same message. Fixes aws#1451
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1847 +/- ##
==========================================
+ Coverage 90.31% 90.44% +0.12%
==========================================
Files 80 80
Lines 12159 12188 +29
Branches 1725 1737 +12
==========================================
+ Hits 10982 11024 +42
+ Misses 1143 1130 -13
Partials 34 34
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
left a comment
There was a problem hiding this comment.
Nice! Can you please add test cases to the CLI packages that logs io snpashots? See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk/test/commands and https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk/test/commands/__io_snapshots__/deploy
Add command-level tests under packages/aws-cdk/test/commands that drive `cdk deploy` through the io-snapshot harness for the no-selector stack selection error path: - A Stage-nested app (no top-level stacks) asserts the thrown error guides the user towards the Stage wildcard pattern, e.g. `'MyStage/*'`. - A flat multi-stack app asserts the error does not mention Stages. Both tests record an `__io_snapshots__/deploy` entry capturing the IO stream up to the point the command aborts at stack selection. The guidance itself is surfaced as a thrown ToolkitError (printed at the CLI top level), so it is asserted on the rejected error rather than appearing in the recorded IO stream.
Head branch was pushed to by a user without write access
|
Thanks for the review, @mrgrain! I've added command-level tests that go through the io-snapshot harness. In
Each records an entry under One thing worth flagging: the guidance itself is raised as a thrown If you'd prefer the guidance to also be emitted through the |
Fixes #1451
When an app has more than one stack and no selector is given,
cdk deployprints:When the stacks live inside a Stage, this message is unhelpful: their ids are namespaced like
StageName/StackName, and neither a bare stack name nor--allis the obvious way to target them, so users are left guessing (see #1451).This change detects stacks that are nested inside a Stage (i.e. stacks that are not top-level stacks) and additionally points the user at a wildcard pattern that selects them, e.g.:
The hint is only appended when staged stacks are actually present, so flat apps are unaffected. The Stage detection is structural (stacks present recursively but not at the top level) rather than string-based, so a top-level stack whose display name happens to contain
/is not misclassified. The same message is shared by the CLI stack-selection path (cloud-assembly.ts) and thetoolkit-libselectStacksV2path, so both are updated for consistency.Unit tests were added on both selector/error paths (Stage guidance present when nested, absent for flat apps, and stage patterns de-duplicated across multiple stages).
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license