Skip to content

fix(tests): derive the sam init parameter guidance from the command - #9212

Merged
roger-zhangg merged 1 commit into
developfrom
fix-init-incompatible-param-message
Sep 1, 2026
Merged

roger-zhangg merged 1 commit into
developfrom
fix-init-incompatible-param-message

Conversation

@roger-zhangg

@roger-zhangg roger-zhangg commented Aug 31, 2026

Copy link
Copy Markdown
Member

Which issue(s) does this change fix?

N/A — 4 nightly failures, e.g. run 33379671789.

Why is this change necessary?

Four TestInitForParametersCompatibility tests fail on an expected string that no longer matches what sam init prints:

expected: --name, --runtime, --app-template, --dependency-manager
actual:   --name, --runtime, --dependency-manager, --app-template

#9176 replaced the hand-written INCOMPATIBLE_PARAMS_HINT with one generated from NON_INTERACTIVE_PARAM_COMBINATIONS, which is also passed as required_param_lists — so the hint can no longer drift from the check it describes. That list orders --dependency-manager first, so the printed message changed and the test's hardcoded copy was left behind.

It escaped PR CI because that class is pr_skip and runs only in the nightly.

How does it address the issue?

Rather than restate the new order and wait for the next drift, only the part that drifts is derived. _render_combinations() re-renders the accepted combinations from NON_INTERACTIVE_PARAM_COMBINATIONS, and the wording around them stays written out in the test so it is still asserted. Both messages share it, with the separator each one uses ("\n" for the missing-parameters list, ", or\n" for the hint).

MISSING_REQUIRED_PARAM_MESSAGE was not failing, but it restated the same list and would have drifted next — it only matched because it happened to track a message ClickMutex has always generated from that list.

Deliberately not importing the rendered hint wholesale: that would make the assertion self-referential, so a bad edit to the hint's wording or separators would change both sides at once and the tests would stay green. Nothing else in the suite pins that user-facing string.

What side effects does this change have?

Verified against the real CLI via CliRunner rather than by comparing the constants to themselves — all five messages the tests assert, all exit code 2:

app-template/location      exit=2 match=True
runtime/location           exit=2 match=True
base-image/location        exit=2 match=True
package-type/location      exit=2 match=True
missing-required           exit=2 match=True

Then confirmed both halves of the intent by mutating the command and re-running with no test change:

list reordered to ['name','app_template','dependency_manager','runtime']  -> assertion passes
", or" separator broken to ","                                            -> assertion FAILS

The first is the maintenance burden this removes; the second is the wording protection it keeps.

One trade-off worth naming: in the nightly release runs these constants come from the checked-out source while the assertion is against the installed binary, so the tests now also require those two to agree. For a nightly built from the same commit that is the correct expectation, and it replaces a failure mode where a stale copy could disagree with both.

make pr passes (9401 unit tests, 94.09% coverage).

Mandatory Checklist

PRs will only be reviewed after checklist is complete

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

@roger-zhangg
roger-zhangg requested a review from a team as a code owner August 31, 2026 23:43
@roger-zhangg
roger-zhangg force-pushed the fix-init-incompatible-param-message branch from e955e72 to 5c98241 Compare August 31, 2026 23:51
@roger-zhangg roger-zhangg changed the title fix(tests): match the parameter order sam init actually prints fix(tests): derive the sam init parameter guidance from the command Aug 31, 2026

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Results

Reviewed: 19c5ae0..5c98241
Files: 1
Comments: 1

Comment thread tests/integration/init/test_init_command.py Outdated
INCOMPATIBLE_PARAM_MESSAGE restated the parameter order and fell behind #9176,
which generates the hint from the enforced parameter combinations. Re-render the
combinations from those constants so a future change cannot strand them, while
keeping the wording around them written out so it is still asserted.
@roger-zhangg
roger-zhangg force-pushed the fix-init-incompatible-param-message branch from 5c98241 to 5cdd254 Compare September 1, 2026 00:00

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Results

Reviewed: 19c5ae0..5cdd254
Files: 1
Comments: 1

Comment thread tests/integration/init/test_init_command.py
@roger-zhangg
roger-zhangg added this pull request to the merge queue Sep 1, 2026
Merged via the queue into develop with commit 9d99af2 Sep 1, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants