Skip to content

test: restore leaked provider mocks and Concentrate env in single-process runs - #2328

Merged
jatmn merged 1 commit into
mainfrom
test/ta001-provider-leak-restores
Oct 22, 2026
Merged

jatmn merged 1 commit into
mainfrom
test/ta001-provider-leak-restores

Conversation

@jatmn

@jatmn jatmn commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • First TA-001 slice (Phase 0 item 6): stop three test files from leaking provider state into later files in a single-process bun test run.
  • src/utils/status.test.ts and src/utils/thinking.test.ts register mock.module('./model/providers.js', ...), which Bun keeps process-wide; mock.restore() does not unregister it. Both files now take a cache-busted snapshot of the real module before mocking and re-register it right after mock.restore() in their existing afterEach (same pattern as src/tools/WebFetchTool/domainCheck.test.ts). thinking.test.ts builds its override from that snapshot instead of the live namespace.
  • src/utils/envFile.test.ts loads CONCENTRATE_API_KEY, CONCENTRATE_BASE_URL and CONCENTRATE_MODEL from a fixture but did not list them in TEST_ENV_KEYS, so they stayed in process.env and later files routed to Concentrate. They are now in the list its hooks already clear and restore.
  • Why: together these made src/utils/http.test.ts ("WebFetch preserves the Anthropic support URL for first-party endpoints") fail when run after them in one process: getAPIProvider() returned openai, so isFirstPartyAnthropicProvider() was false.

Impact

  • user-facing impact: none (test-only).
  • developer/maintainer impact: fewer cross-file failures in a single-process run. No production code, CI or scripts/run-tests.ts change; --isolate stays in CI until all TA-001 slices land.

Testing

  • I ran the required local preflight.
  • exact commands and results:
    • bun run check: pass
    • bun run typecheck: pass
    • bun run security:pr-scan -- --base origin/main --head HEAD: no suspicious additions
    • git diff --check: clean
  • focused tests (single process, no --isolate):
    • on main: bun test src/utils/status.test.ts src/utils/http.test.ts 14 pass / 1 fail; bun test src/utils/thinking.test.ts src/utils/http.test.ts 7 pass / 1 fail
    • with this PR: status + http 15/0; thinking + http 8/0; envFile + http 48/0; envFile + thinking + status + http 67/0
    • bun run scripts/run-tests.ts --feature=UNATTENDED_RETRY --max-concurrency=1 src/utils/envFile.test.ts src/utils/thinking.test.ts src/utils/status.test.ts src/utils/http.test.ts (isolated, as CI): 67 pass / 0 fail
  • whole-repo single-process bun test after bun run build (Bun 1.3.14, base 19bb39c): main 10,375 pass / 44 skip / 40 fail / 4 errors; this PR 10,394 pass / 44 skip / 21 fail / 0 errors. The http victim now passes, and 40 other previously failing betas, fastMode, context, claude.lifecycle, set-context-window and some attribution cases pass too (sideQuery attribution, MiniMax China, modelCost, mcp/config, profiles, paths, PromptInput and commit-message still fail). One test newly fails in that run, a launch that only runs local commands leaves no transcript (sessionStorage.commandOnlySession). It was already on the TA-001 pollution list from an earlier run, runs before status/thinking, and passes alone; it is left for a later slice.
  • documented skipped checks, platform limitations, or verified pre-existing failures: the other TA-001 single-process failures (attribution, lifecycle, betas, fastMode, context, MiniMax China, modelCost, mcp/config, profiles, paths, PromptInput, commit-message, set-context-window, model picker discovery) are out of scope here and still fail without --isolate.

Notes

  • provider/model path tested: provider detection for first-party Anthropic vs. OpenAI-compatible and Concentrate env-only routes (test-only).
  • screenshots attached (if UI changed): n/a
  • follow-up work or known limitations: standalone, no CONTRIBUTING change. Later TA-001 slices: other surviving module mocks, a shared provider env scrub, attribution-suite isolation detection, model picker discovery-mock cleanup, and launcher compile-cache tests without isolation.

Summary by CodeRabbit

  • Tests
    • Environment test setup and teardown now include the Concentrate API key, base URL, and model settings.
    • Status and thinking tests restore the real provider state after mocked tests, helping keep test results isolated and consistent.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Twigpine/openclaude/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 13317c3f-3520-4dde-8001-c9c5b6dcbb00
📥 Commits

Reviewing files that changed from the base of the PR and between 3a29928 and 834751a.

📒 Files selected for processing: 3
  • src/utils/envFile.test.ts
  • src/utils/status.test.ts
  • src/utils/thinking.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 18
  • GitHub Check: unit-tests (7)
  • GitHub Check: unit-tests (1)
  • GitHub Check: unit-tests (8)
  • GitHub Check: unit-tests (2)
  • GitHub Check: launcher-node-floor
  • GitHub Check: unit-tests (4)
  • GitHub Check: launcher-compatibility (22)
  • GitHub Check: unit-tests (3)
  • GitHub Check: dedicated-tests
  • GitHub Check: unit-tests (5)
  • GitHub Check: unit-tests (6)
  • GitHub Check: launcher-compatibility (24.11.x)
  • GitHub Check: typecheck
  • GitHub Check: smoke-and-tests
  • GitHub Check: CodeQL (actions)
  • GitHub Check: CodeQL (javascript-typescript)
  • GitHub Check: pr-intent-scan
  • GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions: 2
Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions.

⚙️ CodeRabbit configuration file

Files:

  • src/utils/status.test.ts
  • src/utils/envFile.test.ts
  • src/utils/thinking.test.ts
Apply the OpenClaude maintainer review rubric from AGENTS.md.

⚙️ CodeRabbit configuration file

Files:

  • src/utils/status.test.ts
  • src/utils/envFile.test.ts
  • src/utils/thinking.test.ts
🔇 Additional comments: 4
src/utils/envFile.test.ts: 1

26-28: LGTM!

src/utils/status.test.ts: 2

9-12: LGTM!

90-90: 🩺 Stability & Availability

The provider mock does not establish a cause for this failure.

The failing test loads ./model/providers.js indirectly, but messages.ts only imports getAPIProvider and does not use it. The replacement returns the complete real provider exports. The failing test is unchanged from the merge base, so no provider-related correction is supported.

src/utils/thinking.test.ts: 1

8-11: LGTM!

Also applies to: 70-70

📝 Walkthrough

The test setup now includes three Concentrate environment variables. The status and thinking tests retain the real providers module and restore it after tests that install mocks.

Changes: Test setup

Layer / File(s) Summary
Environment cleanup
src/utils/envFile.test.ts
The test environment key list now includes CONCENTRATE_API_KEY, CONCENTRATE_BASE_URL, and CONCENTRATE_MODEL.
Provider mock restoration
src/utils/status.test.ts, src/utils/thinking.test.ts
The tests retain real provider exports and reinstall the real providers module during teardown. The thinking test builds its mock from the retained exports and overrides getAPIProvider.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: chioarub

Merge Risk: ⚪ Minimal · up to 83475

The test-isolation changes are mergeable after normal checks. The reported single-process transcript-test failure has not been linked to these changes.

Pre-merge checks: Passed 6 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 6 passed
Check name Status Explanation
Title check Passed The title is concise, scoped to tests, and accurately describes restoring leaked provider mocks and Concentrate environment handling in single-process runs.
Description check Passed The description includes all required sections, explains the changes and rationale, documents impact, provides detailed validation results, and records limitations and follow-up work.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Risk Surface Disclosed Passed PASS. The diff changes only test files, but it does cover provider routing and Concentrate environment handling. The PR description identifies this risk surface, explains the provider-mock and environ…
No Hidden Policy Change Passed PASS. The PR changes only src/utils/envFile.test.ts, src/utils/status.test.ts, and src/utils/thinking.test.ts. The diff adds test environment cleanup and restores the real provider module after …
Full details: Risk Surface Disclosed

Explanation

PASS. The diff changes only test files, but it does cover provider routing and Concentrate environment handling. The PR description identifies this risk surface, explains the provider-mock and environment leakage, and states that the change is test-only with no user-facing impact. This discloses that it introduces no blocker.

Full details: No Hidden Policy Change

Explanation

PASS. The PR changes only src/utils/envFile.test.ts, src/utils/status.test.ts, and src/utils/thinking.test.ts. The diff adds test environment cleanup and restores the real provider module after test mocks. It changes no product routing, trust, telemetry/network, permission, or production policy code. No maintainer policy alignment is required.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

— jatmn's PR Review agent

🟢 Thanks for the contribution. I do not see any actionable issues from my review.

Merge readiness

Rebase onto current main before merge when convenient: the branch is 2 commits behind live main (3a299281bacfb14bcf73a8c7d871477fbe2c6f49). GitHub reports mergeable_state: blocked (required checks / branch policy), not a textual conflict on this diff.

CI at head 834751a2c860ffac73e412d681c141425c8f5661: all required PR checks observed success — PR Checks (typecheck, smoke-and-tests, dedicated-tests, unit-tests shards 1–8, launcher jobs), Code Quality: PR #2328, and CodeQL (CodeQL, CodeQL (javascript-typescript), CodeQL (actions)). web skipped (no web diff). CodeRabbit commit status was still pending during preparation; no inline CodeRabbit review threads exist yet on this head.

Merge-base decision: live-base-three-dot — reviewed 19bb39c8845a6920bb04ad8d70652ad520861b87..834751a2c860ffac73e412d681c141425c8f5661 (one commit).

Scope: Surgical TA-001 slice — three test files only (+18/−2). No production, workflow, or scripts/run-tests.ts changes. Appropriate for upgrade-plan sequencing.

Assessment (requested judgments)

Cache-bust restore pattern: Correct and consistent with the established pattern in domainCheck.test.ts (and siblings such as client.test.ts / compact.test.ts). Top-level import(\./model/providers.js?real=…`)snapshots real exports before any test mocks;afterEachcallsmock.restore()thenmock.module('./model/providers.js', () => realProviders)because Bun keepsmock.moduleregistrations process-wide aftermock.restore(). Spreading into realProvidersis intentional:thinking.test.tsmust notimport('./model/providers.js')after restore (that would re-enter the stale mock). This does not affect production module loading. Under CI--isolate` (per-file processes), the restore is harmless extra hygiene; under single-process local runs it fixes the stated leak class.

Concentrate TEST_ENV_KEYS: Fixes the real leak for the in-file test loads documented Concentrate env-only provider setup values, which sets CONCENTRATE_* via loadEnvFile but previously omitted those keys from TEST_ENV_KEYS, so afterEach could leave them in process.env for later files. The three keys match the documented Concentrate env-only surface and align with other provider triples in the same list. This test does not use rememberLoadedEnvFileValues; clearing process.env is the right boundary.

Root cause claim: Accurate for the two leak classes this PR targets: (1) persistent Bun mock.module on providers.js after status / thinking tests, and (2) Concentrate env vars surviving envFile.test.ts cleanup.

commandOnlySession / “a launch that only runs local commands leaves no transcript”: Not a required finding against this PR. The diff does not touch sessionStorage.commandOnlySession.test.ts. In default path ordering, envFile.test.ts runs before sessionStorage.commandOnlySession.test.ts, which runs before status.test.ts / thinking.test.ts, so provider-mock restores here cannot run before that test. I ran bun test src/utils/envFile.test.ts src/utils/sessionStorage.commandOnlySession.test.ts at both merge-base 19bb39c8 and head 834751a2 — 50 pass / 0 fail both times. Sharded CI (scripts/run-tests.ts --max-concurrency=1) is green at head. The author’s whole-repo single-process tally showing this case among remaining failures is consistent with broader TA-001 order pollution, not causation from this three-file patch; treat it as a follow-up slice, not a regression introduced by these hunks.

Validation run (review checkout, head): bun test src/utils/status.test.ts src/utils/thinking.test.ts src/utils/envFile.test.ts src/utils/sessionStorage.commandOnlySession.test.ts — 69 pass / 0 fail.

@jatmn
jatmn marked this pull request as ready for review October 22, 2026 05:27
@jatmn
jatmn merged commit dea4d39 into main Oct 22, 2026
22 checks passed
@jatmn
jatmn deleted the test/ta001-provider-leak-restores branch October 22, 2026 05:29
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.

1 participant