Skip to content

test(plugin): assert shadow retirement without depending on fire-and-forget dispose timing - #471

Merged
ualtinok merged 1 commit into
cortexkit:masterfrom
Qiiks:fix/test-dispose-determinism-master
Sep 19, 2026
Merged

ualtinok merged 1 commit into
cortexkit:masterfrom
Qiiks:fix/test-dispose-determinism-master

Conversation

@Qiiks

@Qiiks Qiiks commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Problem

expect(disposed).toBe(true) fails to prove retirement. Both retire-shadow tests install a provider whose dispose is async with no await before setting the flag:

dispose: async () => {
    disposed = true;
},

disposeProvider is fire-and-forget:

void provider.dispose().catch(...)

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 disposeProvider ever defers — or the provider gains an await before 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 dispose is called, and return a resolved promise:

dispose: () => {
    disposed = true;
    return Promise.resolve();
},

Now the assertion covers the deterministic contract — dispose was invoked — without depending on how far an async body progressed before yielding. The outcome assertions that already prove retirement (shadow cohort null, primary lane intact) are unchanged and remain the primary evidence.

Bodies touched: packages/pi-plugin/src/embedding-bootstrap.test.ts (both tests) and packages/plugin/src/plugin/embedding-bootstrap.test.ts (shared installShadowProvider helper, used by both tests in that file).

Verification

packages/pi-plugin/src/embedding-bootstrap.test.ts: 6 pass / 0 fail. tsc --noEmit clean.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes the shadow retirement tests so the disposed flag is set when dispose is called, not when the async dispose body happens to run before its first await. The providers now use a synchronous dispose that returns Promise.resolve(), making the assertion deterministic and independent of disposeProvider's fire-and-forget timing.

Written for commit f776bfc. Summary will update on new commits.

Review in cubic

RetriggerConfidence Score: 5/5

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.

  • Replaces async disposal stubs with synchronous flag updates followed by resolved promises.
  • Applies the deterministic assertion pattern to both Pi and OpenCode plugin tests.
  • Preserves the existing provider contract and retirement outcome assertions.

Reviews (1) · Last reviewed commit: "test(plugin): assert shadow retirement w..."

…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.
Copilot AI lite review requested due to automatic review settings September 19, 2026 01:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ualtinok
ualtinok merged commit 261c96a into cortexkit:master Sep 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants