Skip to content

feat(cli): cdk validate --online#1539

Open
kaizencc wants to merge 5 commits into
conroyka/cli-validatefrom
conroyka/cli-validate-online
Open

feat(cli): cdk validate --online#1539
kaizencc wants to merge 5 commits into
conroyka/cli-validatefrom
conroyka/cli-validate-online

Conversation

@kaizencc
Copy link
Copy Markdown
Contributor

@kaizencc kaizencc commented May 21, 2026

Summary

Screenshot 2026-05-21 at 7 56 05 PM

Adds cdk validate --online which submits synthesized CloudFormation templates for early validation via non-executing change sets. This catches errors that offline policy plugins can't — invalid resource types, property validation failures, name conflicts, etc.

  • Adds online option to ValidateOptions (defaults to true)
  • Refactors waitForChangeSet into waitForChangeSetReport (non-throwing) + wrapper, extracting shared prepareChangeSetEnv helper to deduplicate with the diff change set path
  • Adds createValidationChangeSet() — creates a non-executing change set per stack, collects early validation errors via the diagnoser, reports them as a synthetic "CloudFormation" plugin, always cleans up
  • Extends validate() to merge offline (policy report) + online (CFN) results
  • Wires --online / --no-online flag through CLI (cli-config.ts, cli.ts)
  • Unit tests for the online path (mocked createValidationChangeSet)
  • Integration tests with a fixture app using AWS::Fake::DoesNotExist to trigger CFN rejection

Depends on

Test plan

  • Unit tests: offline path (12 tests), online path (4 tests), validate-formatting (9 tests)
  • Integration tests: cdk validate --online catches invalid resource type, passes valid template, --no-online skips CFN validation
  • Manual: cd packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/validate-online-app && STACK_NAME_PREFIX=test node ../../../../../aws-cdk/bin/cdk --app "node app.js" --unstable=validate validate --online

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@aws-cdk-automation aws-cdk-automation requested a review from a team May 21, 2026 01:15
@kaizencc kaizencc changed the title feat(toolkit-lib): cdk validate --online feat(cli): cdk validate --online May 21, 2026
kaizencc added 3 commits May 21, 2026 19:28
…ly validation

Refactor waitForChangeSet into waitForChangeSetReport (returns diagnosis
without throwing) + waitForChangeSet wrapper (throws, preserving existing
behavior for deploy/diff).

Add createValidationChangeSet() which creates a non-executing change set,
collects early validation errors via the existing diagnoser infrastructure,
and always cleans up afterwards.

Extend validate() to optionally run online validation after reading the
offline report, merging CloudFormation early validation errors into the
combined result as a synthetic "CloudFormation" plugin report using proper
schema types (PluginReportJson, ViolatingConstructJson).
Tests cover:
- Invalid resource type (AWS::Fake::DoesNotExist) is caught by CFN
- Valid template passes online validation
- --no-online flag skips CloudFormation validation
…it tests

Extract prepareChangeSetEnv() to share env setup between diff and
validate change set creation. Restore JSDoc on waitForChangeSet.

Add unit tests for the online validation path:
- Reports CFN errors as a CloudFormation plugin report
- Passes when CFN finds no problems
- Merges offline + online results
- Gracefully handles errors (warns instead of throwing)
@kaizencc kaizencc force-pushed the conroyka/cli-validate-online branch from 595fe9a to 747dffe Compare May 21, 2026 23:29
@kaizencc kaizencc force-pushed the conroyka/cli-validate-online branch from 4b289b5 to 11d577c Compare May 21, 2026 23:34
@kaizencc kaizencc force-pushed the conroyka/cli-validate-online branch from 11d577c to 0bebffb Compare May 21, 2026 23:52
…ations

- Add --online option to parse-command-line-arguments.ts so yargs
  recognizes it instead of warning "Unknown option"
- Report CloudFormation errors (like template format errors) as
  violations instead of swallowing them with a warning
@kaizencc kaizencc force-pushed the conroyka/cli-validate-online branch from 0bebffb to 703b125 Compare May 21, 2026 23:52
Adds a CombinedStack fixture with both an S3 bucket (triggers
SecurityPlugin offline) and AWS::Fake::DoesNotExist (rejected by
CFN online). Test verifies both violations appear in one report.
Copy link
Copy Markdown
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Broadly alright with this, modulo an error handling case.

So this is turning diagnosis errors into policy validation errors, right?

});
}
}
} catch (e: any) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't feel correct. An SDK failure or whatever is not the same as a policy violation.

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.

2 participants