Skip to content

refactor(cli): make IoHost listener removers using-compatible - #1888

Merged
mrgrain merged 2 commits into
mrgrain/refactor/cli/suppress-messages-decoratorfrom
mrgrain/refactor/cli/disposable-listeners
Aug 24, 2026
Merged

refactor(cli): make IoHost listener removers using-compatible#1888
mrgrain merged 2 commits into
mrgrain/refactor/cli/suppress-messages-decoratorfrom
mrgrain/refactor/cli/disposable-listeners

Conversation

@mrgrain

@mrgrain mrgrain commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1887.

After the suppressMessages decorator took over the static message drops, the remaining dynamic listeners in CdkToolkit — deploy's approval-framing rewrite, destroy's level override, decline-aborts, and --force responder, and the one-shot listing formatters — still required collecting dispose functions and calling them in a finally block, which is verbose and easy to get wrong.

This change makes the listener registration methods on CliIoHost (on, once, rewrite, rewriteOnce, respond, respondOnce) return a DisposeListener: still a plain callable remover, but also a Disposable, so call sites can bind it with a using declaration and drop the try/finally entirely. Disposal then happens at scope exit, including early returns and throws, and conditional listeners come for free because using x = cond ? ioHost.respondOnce(...) : undefined simply skips disposal for undefined. The repository already relies on TypeScript explicit resource management (using for telemetry timers), so no toolchain change is needed, and the return type change is backwards compatible for every existing caller. Most of the diff in deploy() is the mechanical de-indent from removing its try/finally wrapper.

Tested with a new unit test asserting the remover works as a using resource (listener active inside the block, gone at scope exit), plus the existing decorator and command suites; 234 tests across the affected suites pass and lint is clean.

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

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

The remaining dynamic listeners in CdkToolkit (deploy's approval
rewrite, destroy's level/decline/force listeners, the one-shot listing
formatters) still required collecting dispose functions and calling
them in a finally block.

Listener registration methods on CliIoHost (on/once/rewrite/rewriteOnce/
respond/respondOnce) now return a DisposeListener: still a plain
callable, but also a Disposable, so call sites can bind it with a
`using` declaration and drop the try/finally entirely. Disposal happens
at scope exit, including early returns and throws, and conditional
listeners come for free since `using x = cond ? ... : undefined` skips
disposal for undefined.

The suppressMessages decorator uses the same mechanism internally.
@mrgrain
mrgrain deployed to automation August 24, 2026 12:22 — with GitHub Actions Active
@mrgrain
mrgrain deployed to no-approval August 24, 2026 12:23 — with GitHub Actions Active
@github-actions github-actions Bot added the p2 label Aug 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

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

Scanned Files

None

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.13527% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.34%. Comparing base (8d85981) to head (d21aa20).

Files with missing lines Patch % Lines
packages/aws-cdk/lib/cli/cdk-toolkit.ts 95.06% 8 Missing ⚠️
Additional details and impacted files
@@                                 Coverage Diff                                  @@
##           mrgrain/refactor/cli/suppress-messages-decorator    #1888      +/-   ##
====================================================================================
- Coverage                                             91.37%   91.34%   -0.03%     
====================================================================================
  Files                                                    80       80              
  Lines                                                 12254    12261       +7     
  Branches                                               1749     1743       -6     
====================================================================================
+ Hits                                                  11197    11200       +3     
- Misses                                                 1021     1025       +4     
  Partials                                                 36       36              
Flag Coverage Δ
suite.unit 91.34% <96.13%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrgrain
mrgrain added this pull request to the merge queue Aug 24, 2026
Merged via the queue into main with commit c31e049 Aug 24, 2026
72 of 73 checks passed
@mrgrain
mrgrain deleted the mrgrain/refactor/cli/disposable-listeners branch August 24, 2026 14:08
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