Skip to content

[codex] test(desktop): isolate host-service coordinator mocks#4448

Merged
Kitenite merged 1 commit into
mainfrom
codex/host-service-test-mock-restore
May 12, 2026
Merged

[codex] test(desktop): isolate host-service coordinator mocks#4448
Kitenite merged 1 commit into
mainfrom
codex/host-service-test-mock-restore

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented May 12, 2026

Summary

Follow-up to #4395. The host-service coordinator test used broad Bun mock.module replacements that leaked through Bun's process-global mock registry into unrelated desktop tests.

This narrows the mocks by preserving real exports for partially mocked modules, removes unused broad mocks, and restores Bun mocks in afterAll.

Impact

Desktop tests can run in the same Bun process without unrelated modules observing incomplete mock exports or test-only environment values.

Validation

  • bun test apps/desktop/src/main/lib/host-service-coordinator.test.ts
  • bunx biome check apps/desktop/src/main/lib/host-service-coordinator.test.ts
  • bun run lint:fix
  • bun run lint

Summary by cubic

Isolated and cleaned up Bun mocks in the host-service coordinator tests to stop leaking partial module exports and test-only env into other desktop tests. Partially mock only what’s needed and restore mocks after the suite.

  • Bug Fixes
    • Preserve real exports when mocking ./host-service-manifest, ./host-service-utils, and @superset/shared/host-info.
    • Remove broad, unused mocks for main/env.main, shared/env.shared, ./app-environment, ./terminal/env, and ../../lib/trpc/routers/workspaces/utils/shell-env.
    • Restore Bun’s mock registry in afterAll via mock.restore().

Written for commit 64c5c95. Summary will update on new commits.

Summary by CodeRabbit

  • Tests
    • Improved test setup and mock management for more reliable testing.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 28832502-5afa-408d-a4f1-989c77b02349

📥 Commits

Reviewing files that changed from the base of the PR and between 8057272 and 64c5c95.

📒 Files selected for processing (1)
  • apps/desktop/src/main/lib/host-service-coordinator.test.ts

📝 Walkthrough

Walkthrough

Test file host-service-coordinator.test.ts refactored mock setup to import real modules first, spread their exports, then override only selected functions. Added import formatting and suite cleanup hook to restore mocks after tests.

Changes

Test Setup Refactoring

Layer / File(s) Summary
Import formatting
apps/desktop/src/main/lib/host-service-coordinator.test.ts
bun:test import converted from single-line to multi-line destructured form.
Mock setup pattern improvements
apps/desktop/src/main/lib/host-service-coordinator.test.ts
host-service-manifest, host-service-utils, @superset/shared/host-info, and ./local-db mocks now dynamically import real modules, spread their exports, and override only selected functions/constants instead of using inline factories.
Test suite cleanup
apps/desktop/src/main/lib/host-service-coordinator.test.ts
Added afterAll hook to call mock.restore() and reset Bun mocks after test suite completes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Mocks now import the real, then play pretend,
With exports spread wide and tweaks at the end,
Cleanup hooks shine when the tests are all done,
Mock restoration brings order and fun!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/host-service-test-mock-restore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Kitenite Kitenite marked this pull request as ready for review May 12, 2026 17:08
@Kitenite Kitenite merged commit bb31359 into main May 12, 2026
9 checks passed
@Kitenite Kitenite deleted the codex/host-service-test-mock-restore branch May 12, 2026 17:08
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch

Thank you for your contribution! 🎉

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR tightens mock isolation in the host-service coordinator test suite to prevent Bun's process-global mock registry from leaking partial module exports into unrelated desktop tests. The approach is correct: real module exports are captured with top-level await import() before each mock.module() call, so only the specific functions under test are overridden.

  • Partial mocking of ./host-service-manifest, ./host-service-utils, and @superset/shared/host-info now spreads real exports first, preventing other code paths that import these modules in the same process from seeing broken (stub-only) module shapes.
  • Broad, unused mocks (main/env.main, shared/env.shared, ./app-environment, ./terminal/env, ../../lib/trpc/routers/workspaces/utils/shell-env, @superset/local-db) are removed since no test path exercises them.
  • afterAll(() => mock.restore()) is added at file scope to flush all Bun module mocks after the suite completes, preventing them from persisting into subsequently-loaded test files in the same worker.

Confidence Score: 5/5

Test-only change with no production code impact; mock isolation patterns are applied correctly.

All changes are confined to a single test file. The partial-mock pattern (capture real exports then spread then override) is idiomatic for Bun and correct here. The mock.restore() in afterAll fires after all tests in the file complete, so it cannot interfere with any in-file test assertions. The removed mocks are confirmed unused by the PR author's validation run, and the test logic itself is unchanged.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src/main/lib/host-service-coordinator.test.ts Mock isolation improvements: partial mocks now spread real exports, unused broad mocks removed, and afterAll restores Bun's mock registry — all changes are correct and test-only.

Reviews (1): Last reviewed commit: "test(desktop): isolate host-service coor..." | Re-trigger Greptile

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