diff --git a/test/engines.test.mjs b/test/engines.test.mjs index e6cd7406..231c5ab6 100644 --- a/test/engines.test.mjs +++ b/test/engines.test.mjs @@ -14,7 +14,14 @@ import { fileURLToPath } from "node:url"; import { spawn } from "node:child_process"; import test from "node:test"; -import { ENGINES, agentLaunchArgs, aiExecArgs, engineBinOverride, exitReason, isInstalled, openPassthrough, pickAiEngine, ranOk, resolveEngine, runCmd } from "../src/engines.mjs"; +// engines.mjs applies MOSHCODE_ENGINE_BIN_ to ENGINES.*.bin at import, and +// run() hands process.env to every child. An override exported in the shell +// running the suite (a local codex build, say) would otherwise swap the stubs +// below for that build. Scrub them first; the override tests set their own. +for (const name of Object.keys(process.env)) { + if (name.startsWith("MOSHCODE_ENGINE_BIN_")) delete process.env[name]; +} +const { ENGINES, agentLaunchArgs, aiExecArgs, engineBinOverride, exitReason, isInstalled, openPassthrough, pickAiEngine, ranOk, resolveEngine, runCmd } = await import("../src/engines.mjs"); const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url)); // The autonomous-session bypass flags each engine declares (engine.agentArgs). diff --git a/test/mcp.test.mjs b/test/mcp.test.mjs index 6d55d53c..6d725e98 100644 --- a/test/mcp.test.mjs +++ b/test/mcp.test.mjs @@ -13,6 +13,14 @@ import { parseMcp } from "../src/integrations.mjs"; const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url)); +// The fan-out test below puts stub engines on PATH and hands process.env to the +// CLI. A MOSHCODE_ENGINE_BIN_ exported in the shell running the suite +// would send that engine's `mcp add` to the real build instead of the stub — +// writing into the operator's own engine config. +for (const name of Object.keys(process.env)) { + if (name.startsWith("MOSHCODE_ENGINE_BIN_")) delete process.env[name]; +} + test("deriveName pulls a sane name from a remote host", () => { assert.equal(deriveName("https://mcp.sentry.dev/mcp"), "sentry"); assert.equal(deriveName("https://api.githubcopilot.com/mcp/"), "githubcopilot"); diff --git a/test/tui-prd-errors.test.mjs b/test/tui-prd-errors.test.mjs index f52284e2..88921612 100644 --- a/test/tui-prd-errors.test.mjs +++ b/test/tui-prd-errors.test.mjs @@ -29,6 +29,13 @@ const replied = (out) => strip(out).split("to leave")[1] || ""; // the child nothing else. const NO_ENGINES = mkdtempSync(join(tmpdir(), "moshcode-no-engines-")); +// An empty PATH is not the whole of "no engines": MOSHCODE_ENGINE_BIN_ +// names an engine by absolute path, so one exported in the shell running the +// suite made codex "installed" here and /prd launched that real build. +for (const name of Object.keys(process.env)) { + if (name.startsWith("MOSHCODE_ENGINE_BIN_")) delete process.env[name]; +} + function runTui(input, cwd) { return new Promise((resolve, reject) => { const child = spawn(process.execPath, [BIN], {