Skip to content

Commit 297274d

Browse files
author
HCL
committed
fix(twitch): export clearRegistryForTest for cross-test isolation (#83887)
`client-manager-registry.ts` holds a module-level `Map<accountId, RegistryEntry>` for `getOrCreateClientManager`. `TwitchClientManager` in the sibling module already acknowledges that module-level state needs a test escape hatch (`clearForTest`), but the registry lacks the equivalent. Under vitest `--isolate=false` (or any harness that keeps the module graph hot across tests) a test that calls `getOrCreateClientManager('default', loggerA)` leaves its entry behind, and the next test calling the same factory silently gets loggerA's manager — chasing a phantom mock-assertion bug becomes the failure mode. Add an exported `clearRegistryForTest()` that calls `registry.clear()`, mirroring `TwitchClientManager.clearForTest`. No production behavior change — production code never calls this.
1 parent 48acdd3 commit 297274d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

extensions/twitch/src/client-manager-registry.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ export async function removeClientManager(accountId: string): Promise<void> {
8585
registry.delete(accountId);
8686
entry.logger.info(`Unregistered client manager for account: ${accountId}`);
8787
}
88+
89+
/**
90+
* Test-only: clear the module-level registry of all client manager entries.
91+
*
92+
* Mirrors the `clearForTest` escape hatch on `TwitchClientManager`. Without
93+
* this, the module-level `registry` Map survives across tests when vitest
94+
* is run with `--isolate=false` (or any harness that does not tear the
95+
* module graph down between cases), and a stale entry from one test will
96+
* shadow `getOrCreateClientManager` calls in subsequent tests — silently
97+
* handing back another test's mocked logger/manager. See #83887.
98+
*
99+
* Production code MUST NOT call this. It is safe to call when the registry
100+
* is empty (clear() is a no-op on an empty Map).
101+
*/
102+
export function clearRegistryForTest(): void {
103+
registry.clear();
104+
}

0 commit comments

Comments
 (0)