Skip to content

fix: route metadata through toolkit-lib - #1747

Merged
aws-cdk-automation merged 2 commits into
mainfrom
mrgrain/metadata
Jul 28, 2026
Merged

fix: route metadata through toolkit-lib#1747
aws-cdk-automation merged 2 commits into
mainfrom
mrgrain/metadata

Conversation

@mrgrain

@mrgrain mrgrain commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The cdk metadata command now delegates synthesis and single-stack selection to the existing toolkit-lib Toolkit.list() action instead of maintaining a separate legacy selection path. This keeps the CLI thin while preserving the command's YAML and --json output.

CliIoHost listeners can now override an effective message action, allowing the structured list result to remain tagged as metadata; matching and telemetry continue to use the originally emitted action. Focused IO snapshots protect both output formats and listener tests cover emitted-versus-effective action behavior.

Validation: yarn compile, yarn eslint, and focused Jest coverage for the metadata command, CliIoHost, and IoHostRecorder (90 tests).

Checklist

  • Unit tests added/updated
  • Integration tests added/updated (not required; no AWS interaction changed)
  • No manual edits to generated files
  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version: N/A

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

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 July 22, 2026 13:50
@github-actions github-actions Bot added the p2 label Jul 22, 2026
@mrgrain mrgrain changed the title refactor(aws-cdk): route metadata through toolkit-lib fixc(aws-cdk): route metadata through toolkit-lib Jul 22, 2026
@mrgrain mrgrain changed the title fixc(aws-cdk): route metadata through toolkit-lib fix: route metadata through toolkit-lib Jul 22, 2026
@mrgrain
mrgrain force-pushed the mrgrain/metadata branch from 31a472d to 146d937 Compare July 22, 2026 13:53
Comment on lines +229 to +254
this.ioHost.once(
IO.CDK_TOOLKIT_I2901,
(msg) => ({
action: 'metadata',
message: serializeStructure(msg.data.stacks[0]?.metadata ?? {}, json),
}),
);
this.ioHost.once(
IO.CDK_TOOLKIT_I1001,
() => ({ preventDefault: true }),
);
this.ioHost.once(
IO.CDK_TOOLKIT_I1000,
() => ({ preventDefault: true }),
);

try {
await this.toolkit.list(this.props.cloudExecutable, {
stacks: {
patterns: [stackName],
strategy: StackSelectionStrategy.PATTERN_MUST_MATCH_SINGLE,
expand: ExpandStackSelection.NONE,
},
});
} finally {
this.ioHost.removeAllListeners();

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 is for error-contingent cleanup of the listeners we create with .once right? Why not use the function that removes the listener for each one? Like:

let disposers = [
    this.ioHost.once(...),
    this.ioHost.once(...),
    this.ioHost.once(...)
];

...

try {
    ...
} finally {
    disposers.forEach(cleanupFunc => cleanupFunc());
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could do, but this.ioHost.removeAllListeners(); does the same and is already used elsewhere. I think in general we need a better (more generic) way of handling these. Can I do this as a followup?

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.

It does the same thing now, but would wipe other listeners too, if we introduce them in the future, and might result in an unexpected/difficult to debug situation. But yep, OK as a follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see. But then the CLI only ever runs one command... I think about it.

@aws-cdk-automation
aws-cdk-automation added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit b81e875 Jul 28, 2026
41 checks passed
@aws-cdk-automation
aws-cdk-automation deleted the mrgrain/metadata branch July 28, 2026 14:29
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.

3 participants