test(plugin): assert shadow retirement without depending on fire-and-forget dispose timing - #471
Merged
ualtinok merged 1 commit intoSep 19, 2026
Conversation
…forget dispose timing Both retire-shadow tests asserted `expect(disposed).toBe(true)` against a provider whose `dispose` was `async` with no await before setting the flag. disposeProvider is fire-and-forget (`void provider.dispose()`), so that assertion only held because the async body happened to run synchronously up to its first await — it measured the microtask schedule, not retirement. If disposal ever deferred, the test would silently stop verifying it. Record the flag when dispose is called and return a resolved promise, so the assertion covers the deterministic contract: dispose was invoked. The outcome assertions (cohort null, primary lane intact) are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
expect(disposed).toBe(true)fails to prove retirement. Both retire-shadow tests install a provider whosedisposeisasyncwith noawaitbefore setting the flag:disposeProvideris fire-and-forget:so the flag is only set because that async body happens to run synchronously up to its first (nonexistent) await. The assertion measures the microtask schedule, not that retirement disposed the provider. If
disposeProviderever defers — or the provider gains anawaitbefore setting its flag — the test would silently stop verifying the behavior it names.Flagged by cubic on #462 as P3. This is a test-only change.
Fix
Record the flag when
disposeis called, and return a resolved promise:Now the assertion covers the deterministic contract —
disposewas invoked — without depending on how far an async body progressed before yielding. The outcome assertions that already prove retirement (shadow cohortnull, primary lane intact) are unchanged and remain the primary evidence.Bodies touched:
packages/pi-plugin/src/embedding-bootstrap.test.ts(both tests) andpackages/plugin/src/plugin/embedding-bootstrap.test.ts(sharedinstallShadowProviderhelper, used by both tests in that file).Verification
packages/pi-plugin/src/embedding-bootstrap.test.ts: 6 pass / 0 fail.tsc --noEmitclean.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Fixes the shadow retirement tests so the
disposedflag is set whendisposeis called, not when the async dispose body happens to run before its firstawait. The providers now use a synchronousdisposethat returnsPromise.resolve(), making the assertion deterministic and independent ofdisposeProvider's fire-and-forget timing.Written for commit f776bfc. Summary will update on new commits.
The test-only change appears safe to merge.
Summary
This PR makes shadow-retirement tests record disposal at invocation time rather than relying on async-function execution timing.
Reviews (1) · Last reviewed commit: "test(plugin): assert shadow retirement w..."