From 1a988eba1af1eb8cc31a81dba0f654a8c0047a6b Mon Sep 17 00:00:00 2001 From: devops-engineer Date: Thu, 7 May 2026 05:02:40 -0700 Subject: [PATCH] fix(test): preload env-mock so server.ts can be imported in tests (closes #3 phase 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- bunfig.toml | 6 ++++++ tests/setup.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 bunfig.toml create mode 100644 tests/setup.ts diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..a6eb865 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,6 @@ +# bunfig.toml — preload the test env-mock setup so server.ts's +# required-config guard doesn't call process.exit(1) when test files +# import pure helpers from it. See tests/setup.ts for the full +# rationale. +[test] +preload = ["./tests/setup.ts"] diff --git a/tests/setup.ts b/tests/setup.ts new file mode 100644 index 0000000..8392df7 --- /dev/null +++ b/tests/setup.ts @@ -0,0 +1,15 @@ +// tests/setup.ts — preloaded by bunfig.toml's [test].preload before any +// test file is imported. Sets fake values for the three env vars +// server.ts requires at top-level (MOLECULE_PLATFORM_URL, +// MOLECULE_WORKSPACE_IDS, MOLECULE_WORKSPACE_TOKENS). Without this, +// importing server.ts (which the test files do, to pull +// formatRemovedWorkspaceError + other pure helpers) hits the +// required-config guard at server.ts:92 and calls process.exit(1) — +// killing the test runner before any test runs. +// +// `??=` only assigns when the var is unset, so a developer running +// `bun test` locally with a populated .env file isn't overridden. + +process.env.MOLECULE_PLATFORM_URL ??= 'http://localhost:18080' +process.env.MOLECULE_WORKSPACE_IDS ??= 'ws-test-00000000-0000-0000-0000-000000000001' +process.env.MOLECULE_WORKSPACE_TOKENS ??= 'tok-test'