fix(riff-raff-generator): Correctly validate stacks#2870
fix(riff-raff-generator): Correctly validate stacks#2870
Conversation
These tests are failing, demonstrating a fault in the current logic.
…adability Removal of the `GroupedCdkStacks` type decreases complexity.
🦋 Changeset detectedLatest commit: 1824bae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
de660ea to
a86b323
Compare
a86b323 to
1824bae
Compare
|
|
||
| expect(actual).toMatchInlineSnapshot(` | ||
| "allowedStages: | ||
| - INFRA |
There was a problem hiding this comment.
Interestingly, this test (added in #2094) was incorrect!
There was a problem hiding this comment.
Pull request overview
Improves RiffRaffYamlFile validation so riff-raff.yaml generation fails when a stack “identity” (class name + stack tag + region) is missing required stage instances, preventing invalid templateStagePaths from being produced.
Changes:
- Refactors stack grouping to validate per
(className, stackTag, region)and records missing stage definitions. - Extracts grouping helpers and updates
RiffRaffYamlFileto use them. - Adds/updates unit tests and includes a changeset entry documenting the behavior change.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/riff-raff-yaml-file/index.ts | Refactors grouping/validation logic; adds missing-stack detection and region validation helper. |
| src/riff-raff-yaml-file/group-by.ts | Exposes grouping helpers and removes the previous combined grouping function. |
| src/riff-raff-yaml-file/types.ts | Removes the GroupedCdkStacks exported type alias. |
| src/riff-raff-yaml-file/index.test.ts | Updates snapshots and adds targeted validation tests for missing definitions/unresolved regions. |
| .changeset/silent-planets-invent.md | Documents the validation fix as a patch changeset. |
Comments suppressed due to low confidence (1)
src/riff-raff-yaml-file/group-by.ts:20
groupByClassNameStackRegionStagewas removed. Since this file is importable via deep paths under@guardian/cdk/lib/..., removing an exported function can be a breaking change for downstream consumers. Consider keeping a compatibility export that delegates to the newgroupByClassName/groupByStackTag/groupByRegion/groupByStageTaghelpers (or add a deprecation period).
export function groupByClassName(cdkStacks: GuStack[]): Record<ClassName, GuStack[]> {
return groupBy(cdkStacks, (stack) => stack.constructor.name);
}
export function groupByStackTag(cdkStacks: GuStack[]): Record<StackTag, GuStack[]> {
return groupBy(cdkStacks, ({ stack }) => stack);
}
export function groupByStageTag(cdkStacks: GuStack[]): Record<StageTag, GuStack[]> {
return groupBy(cdkStacks, ({ stage }) => stage);
}
export function groupByRegion(cdkStacks: GuStack[]): Record<Region, GuStack[]> {
return groupBy(cdkStacks, ({ region }) => region);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Note
Recommended to review commit by commit as I've made some refactors along the way to improve readability.
What does this change?
This change validates more scenarios when instantiating a
RiffRaffYamlFileto generateriff-raff.yaml. Given the below set of stacks, anErrorwill now be thrown as there is a missing instance ofMyDatabaseStackforCODE.Previously, the validation would incorrectly pass, generating the below
riff-raff.yaml.Invalid `riff-raff.yaml`
How to test
See the added unit tests.
How can we measure success?
Correct validation when generating a
riff-raff.yamlfile.Have we considered potential risks?
There are no changes to the public API, so I don't think there are any risks.
Checklist
Footnotes
Consider whether this is something that will mean changes to projects that have already been migrated, or to the CDK CLI tool. If changes are required, consider adding a checklist here and/or linking to related PRs. ↩
If you are adding a new construct or pattern, has new documentation been added? If you are amending defaults or changing behaviour, are the existing docs still valid? ↩