test(plugin): assert shadow retirement without depending on fire-and-forget dispose timing
Merged
QI
2mo ago
+17+17+01234567890123456789-3-3-0123456789
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:
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).
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.
Confidence 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.