feat(core): integrate construct annotations into validation report#37712
feat(core): integrate construct annotations into validation report#37712mergify[bot] merged 40 commits intomainfrom
Conversation
The merge from main duplicated full-body deprecated interfaces (from #37613) alongside the extends-based aliases that this PR uses. Restored report.ts and validation.ts to their correct pre-merge state.
This reverts commit 5d7d4b9.
…rface, prefixed IDs, metadata recording
- Remove KNOWN_PREFIXES array; use colon detection in ensurePrefix instead of maintaining a hardcoded list of known prefixes. Any 'prefix:id' format is treated as already-prefixed; only bare IDs get the 'annotation:' prefix added. - Replace findLast (ES2023) with filter + last element for ES2020 compatibility. - Revert unrelated Location string test changes (scope creep).
|
➡️ PR build request submitted to A maintainer must now check the pipeline and add the |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Merge Queue Status
This pull request spent 29 minutes 27 seconds in the queue, including 29 minutes 11 seconds running CI. Required conditions to merge
|
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Comments on closed issues and PRs are hard for our team to see. |
Reason for this change
Part of the Validations RFC.
This PR furthers the RFC by integrating construct annotations (warnings and errors added via
Annotations.of()orValidations.of()) into the existing policy validation report. Currently, annotations are only surfaced through the CLI's standard metadata display and are not part of the validation report, meaning users who rely on the report for compliance visibility don't see annotation-based issues alongside plugin violations.Description of changes
Integrate construct annotations into the existing validation report pipeline by collecting annotation metadata post-synthesis and converting it into a
NamedValidationPluginReportwith source"Construct Annotations". This is not the final unified report format discussed in the RFC — it is an integration of annotations as a "plugin" into the existing report framework and structure.core/lib/private/synthesis.ts:collectAnnotationReport()— walks the full construct tree (including across Stage boundaries viaiterateDfsPreorder) to collectaws:cdk:warningandaws:cdk:errormetadata entries, converting them toPolicyViolationformat. Violations are grouped by rule name + severity + description so that multiple constructs triggering the same rule appear as one violation with multiple resources.extractRuleName()— extracts the rule ID from[ack: <id>]tags when available; falls back to genericaws-cdk:warning/aws-cdk:errorfor untagged annotations (these cannot be acknowledged, so uniqueness is not required). Includes a coupling note documenting the dependency on theackTag()format inannotations.ts.findNearestResource()— maps a construct to its nearestCfnResourcefor logical ID and template path resolutioninvokeValidationPlugins()— callscollectAnnotationReport()after plugin execution and merges the result into thereports[]arraycore/lib/validation/private/report.ts:formatJsonfilter changed from!rep.successto!rep.success || rep.violations.length > 0so that warning-only reports (which aresuccess: true) still render their violations. This is intentional — violations should always be visible regardless of the overall success status. This broadens behavior for all validation sources: a plugin returningsuccess: truewith violations would now appear in the report when it previously didn't.Plugin Report→Validation Report,Plugin:→Source:,Plugincolumn →Source). CI scripts or tools that parse the text report output may need updating.core/test/validation/validation.test.ts:Validations.of().acknowledge(), annotations alongside plugins, annotations without plugins, orphan constructs (verifying construct path fallback),Validations.of().addWarning,Validations.of().addError, andextractRuleNameregex coupling withaddWarningV2formatSample output
Below is the validation report output showing a plugin (CfnGuardValidator) and construct annotations side-by-side:
Describe any new or updated permissions being added
N/A
Description of how you validated changes
tsc --noEmitpasses cleanlyAnnotations.of().addWarningV2,Annotations.of().addError,Validations.of().addWarning)Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license