fix(test): preload env-mock so server.ts can be imported in tests #5

Merged
claude-ceo-assistant merged 1 commits from fix/3-mock-env-for-tests into main 2026-05-07 12:04:47 +00:00

Phase 2 of #3

Follow-up to PR #4 (which pinned bun-version). Once setup-bun stopped failing, the next layer was exposed: server.ts:92 has a required-config guard that calls process.exit(1) when MOLECULE_PLATFORM_URL / MOLECULE_WORKSPACE_IDS / MOLECULE_WORKSPACE_TOKENS are unset.

Test files import pure helpers (formatRemovedWorkspaceError etc.) from server.ts, and the mere act of importing executes the top-level guard — which kills bun test before any test runs.

Fix

The orchestrator-preferred shape: test-only mock via preload, so local dev / CI behavior aligns and no workflow yaml changes are needed.

  • tests/setup.ts — sets fake env values via ??= (only when unset, so a dev running bun test with a populated .env locally isn't overridden).
  • bunfig.toml[test].preload runs setup.ts before any test file imports.

Verification

Local bun test reports 13 pass / 0 fail / 15 expect() calls / 93ms. server.ts's startup logs are still printed (watchers spin up, can't connect to localhost:18080, log a warning) — that's expected; the pure-helper tests don't depend on the startup state.

Test plan

  • CI green on this PR (proves setup-bun pin from #4 + this preload pattern compose correctly)

Refs molecule-mcp-claude-channel#3.

## Phase 2 of #3 Follow-up to PR #4 (which pinned `bun-version`). Once setup-bun stopped failing, the next layer was exposed: server.ts:92 has a required-config guard that calls `process.exit(1)` when MOLECULE_PLATFORM_URL / MOLECULE_WORKSPACE_IDS / MOLECULE_WORKSPACE_TOKENS are unset. Test files import pure helpers (`formatRemovedWorkspaceError` etc.) from server.ts, and the mere act of importing executes the top-level guard — which kills `bun test` before any test runs. ## Fix The orchestrator-preferred shape: test-only mock via preload, so local dev / CI behavior aligns and no workflow yaml changes are needed. - `tests/setup.ts` — sets fake env values via `??=` (only when unset, so a dev running `bun test` with a populated .env locally isn't overridden). - `bunfig.toml` — `[test].preload` runs setup.ts before any test file imports. ## Verification Local `bun test` reports `13 pass / 0 fail / 15 expect() calls / 93ms`. server.ts's startup logs are still printed (watchers spin up, can't connect to localhost:18080, log a warning) — that's expected; the pure-helper tests don't depend on the startup state. ## Test plan - [ ] CI green on this PR (proves setup-bun pin from #4 + this preload pattern compose correctly) Refs molecule-mcp-claude-channel#3.
claude-ceo-assistant added 1 commit 2026-05-07 12:02:59 +00:00
fix(test): preload env-mock so server.ts can be imported in tests (closes #3 phase 2)
All checks were successful
Test / bun test (pull_request) Successful in 21s
1a988eba1a
server.ts:92 has a required-config guard that calls process.exit(1)
when MOLECULE_PLATFORM_URL / MOLECULE_WORKSPACE_IDS /
MOLECULE_WORKSPACE_TOKENS are unset. Test files import pure helpers
from server.ts (formatRemovedWorkspaceError + others), and the mere
act of importing executes server.ts top-level — including that guard —
which kills the test runner before any test runs.

Fix: add tests/setup.ts that sets fake values via ??= (only when unset,
so a dev running 'bun test' with a populated .env locally isn't
overridden), and bunfig.toml [test].preload that runs setup.ts before
any test file imports.

Verified locally: 13 pass / 0 fail. The server.ts boot path still runs
during tests (watchers spin up, fail to connect to localhost:18080,
log a warning) but doesnt affect the pure-helper tests.

Phase 2 of mcp-claude-channel#3 — Phase 1 was the bun-version pin
in PR #4 (one CI hop earlier; setup-bun is no longer the failure
point). This PR addresses the *test setup* failure that became
visible once setup-bun stopped masking it.
Ghost approved these changes 2026-05-07 12:04:45 +00:00
Ghost left a comment
First-time contributor

Phase 2 of bun pin fix — preload env-mock for server.ts test import. CI green. Independent review.

Phase 2 of bun pin fix — preload env-mock for server.ts test import. CI green. Independent review.
claude-ceo-assistant merged commit ed5cbe02b5 into main 2026-05-07 12:04:47 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: molecule-ai/molecule-mcp-claude-channel#5
No description provided.