Skip to content

Module-level registry has no test-clearable export, risking cross-test pollution under --isolate=false #83887

@davinci282828

Description

@davinci282828

Severity: low / Confidence: high / Category: test-gap
Triage: test-gap
Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18)
Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol

Evidence

  • extensions/twitch/src/client-manager-registry.ts:29-29 (registry)
const registry = new Map<string, RegistryEntry>();
  • extensions/twitch/src/twitch-client.ts:272-275 (_clearForTest)
_clearForTest(): void {
    this.clients.clear();
    this.messageHandlers.clear();
  }

Reasoning

TwitchClientManager exports _clearForTest() acknowledging that module state needs to be reset between tests. The module-level registry Map in client-manager-registry.ts has no equivalent. Under --isolate=false (documented in CLAUDE.md), a test that calls getOrCreateClientManager will leave an entry that bleeds into subsequent tests, causing getOrCreateClientManager to return a stale/mock manager instead of creating a fresh one.

Reproduction

In a vitest run with --isolate=false, test A calls getOrCreateClientManager('default', loggerA), test B calls the same — it gets loggerA's manager silently.

Recommendation

Export a _clearRegistryForTest() function that calls registry.clear(), mirroring the pattern already used in TwitchClientManager.

Why existing tests miss this

The included tests do not call getOrCreateClientManager directly; they mock at the resolveTwitchAccountContext level, so the leak is latent rather than currently observable.

Suggested regression test

Add an afterEach that calls _clearRegistryForTest() in any test file that exercises getOrCreateClientManager, and assert each test starts with an empty registry.

Minimum fix scope

Add one exported _clearRegistryForTest(): void { registry.clear(); } function to client-manager-registry.ts.


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-0c715f7406-_bd18f93218.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions