diff --git a/tests/helpers.mjs b/tests/helpers.mjs index ecf4297..30a0b12 100644 --- a/tests/helpers.mjs +++ b/tests/helpers.mjs @@ -9,6 +9,14 @@ export const CLI = join(ROOT, 'src', 'cli.mjs'); const created = []; +/** + * `lh doctor`/`lh init` treat CONTEXT7_API_KEY as a required, env-only value + * (never persisted, never inferred). Tests must not depend on whatever the + * developer's shell happens to export — inject an obviously-fake fixture so + * behaviour is identical locally and in CI, without ever touching a real key. + */ +export const TEST_ENV = { ...process.env, CONTEXT7_API_KEY: process.env.CONTEXT7_API_KEY ?? 'fixture-not-a-real-key' }; + export function tempRepo(files = {}) { const dir = mkdtempSync(join(tmpdir(), 'lh-test-')); created.push(dir); @@ -41,7 +49,7 @@ export function commitAll(dir, msg) { export function lh(dir, args) { try { const stdout = execFileSync(process.execPath, [CLI, ...args], { - cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], + cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env: TEST_ENV, }); return { code: 0, stdout, stderr: '' }; } catch (e) { diff --git a/tests/onboard.test.mjs b/tests/onboard.test.mjs index 5fc6982..1f0dd19 100644 --- a/tests/onboard.test.mjs +++ b/tests/onboard.test.mjs @@ -5,7 +5,7 @@ import { join, dirname } from 'node:path'; import { execFileSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; -import { tempRepo, cleanup } from './helpers.mjs'; +import { tempRepo, cleanup, TEST_ENV } from './helpers.mjs'; after(cleanup); @@ -18,6 +18,7 @@ function onboard(args) { const stdout = execFileSync(process.execPath, [ONBOARD, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], + env: TEST_ENV, }); return { code: 0, stdout, stderr: '' }; } catch (e) {