Skip to content

feat(cli): cdk validate command (behind --unstable flag)#1527

Open
kaizencc wants to merge 8 commits into
mainfrom
conroyka/cli-validate
Open

feat(cli): cdk validate command (behind --unstable flag)#1527
kaizencc wants to merge 8 commits into
mainfrom
conroyka/cli-validate

Conversation

@kaizencc
Copy link
Copy Markdown
Contributor

@kaizencc kaizencc commented May 18, 2026

Wires up cdk validate as a CLI command behind the --unstable=validate feature flag. The command synthesizes the app, reads the validation report JSON from the cloud assembly, and renders results with per-severity coloring, construct paths, source locations, and acknowledge instructions.

Screenshot 2026-05-21 at 7 08 07 PM

Changes

  • cli-config.ts / cli.ts — Adds validate command behind --unstable=validate, sets @aws-cdk/core:failSynthOnValidationErrors context to suppress synthesis-time reporting
  • cdk-toolkit.ts — Adds validate() method that delegates to toolkit-lib
  • validate-formatting.ts — Formatter that renders violations sorted by severity (fatal > error > warning > info > custom) with chalk coloring, construct paths with logical IDs, underlined source locations, and acknowledge instructions
  • toolkit.ts — Reads validation-report.json via Manifest.loadValidationReport, emits result at info level so IoHost doesn't override per-severity colors
  • Integ testsvalidate-app (SecurityPlugin + Construct Annotations) and validate-passing-app (AlwaysPassesPlugin) fixtures with tests for violations and clean pass

Test plan

  • Unit tests: 12 offline validate tests + 9 formatter tests
  • Integration tests: violations reported correctly, clean app passes
  • Manual: verified colored output with all severity levels (fatal/error/warning/custom)

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

@github-actions github-actions Bot added the p2 label May 18, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team May 18, 2026 18:17
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

Dependency Review

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

Scanned Files

  • yarn.lock

@kaizencc kaizencc force-pushed the conroyka/validate branch from 72951bb to 152e026 Compare May 20, 2026 17:43
Base automatically changed from conroyka/validate to main May 20, 2026 18:30
@kaizencc kaizencc force-pushed the conroyka/cli-validate branch from 06c9381 to 4c04289 Compare May 20, 2026 18:39
Comment thread packages/@aws-cdk/toolkit-lib/test/actions/validate.test.ts Outdated
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.

Conditionally ok. Let's speak to a human like a human.

kaizencc added 8 commits May 22, 2026 10:14
Wire up the `cdk validate` command in the CLI package, gated behind
the `--unstable=validate` flag. Adds:
- CLI command routing, config, and user input parsing
- Validate output formatting with severity-sorted violations
- Integration test fixtures and tests
- Multi-plugin validation fixture for formatter testing
hostMessageFromValidation was incorrectly always emitting at info level
(CDK_TOOLKIT_I9600). Now uses CDK_TOOLKIT_E9600 (error level) when
conclusion is 'failure', preserving the IO contract for consumers that
rely on message level to detect problems.
Covers severity sorting, construct path formatting, stack trace
parsing (both paren and bare formats), acknowledge line omission
for fatal, and constructFqn display.
…rors

Update to @aws-cdk/core:failSynthOnValidationErrors=false to match
the aws-cdk PR (aws/aws-cdk#37909) which introduces this key.
The old @aws-cdk/core:validationReportOnly was a placeholder.
- Use fs.readJson instead of Manifest.loadValidationReport (aws-cdk-lib
  doesn't write a version field yet, so schema validation throws)
- Emit validate results at info level so the CLI IoHost doesn't wrap
  the entire output in red — the formatter handles per-severity coloring
- Update fixture app to use cdk.Validations.of(app).addPlugins()
- Use @aws-cdk/core:failSynthOnValidationErrors context key (2.257.0)
… update integ tests

- Look for validation-report.json only (new format from aws-cdk-lib)
- Strip [ack: ...] tags from descriptions, use dashes in acknowledge IDs
- Underline file locations, add colon after severity, capitalize custom
- Use relative paths for stack trace locations
- Separate integ test apps: validate-app (failing) and validate-passing-app
- Remove acknowledge integ test (depends on unreleased APIs)
- Enable @aws-cdk/core:annotationsInValidationReport for Construct Annotations
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