testRunKeepsACommandTheCallerSet
tcm run gives what it runs the codebase's commands (<COMMAND>_BIN), but one the caller set is kept, and said:
an end-to-end test run against another build (TCM_BIN=<tcm.js> tcm run <test>). One a tcm run further out set
(TCM_COMMANDS), the build as it was then, is replaced, as is one of the codebase's own runners (a tcm run further
out made it, though a tcm from before TCM_COMMANDS doesn't say so).
import { okIn, plainEnv, strip, tcmBin, tempDir } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; export const testRunKeepsACommandTheCallerSet = () => { const dir = tempDir("suites"); fs.writeFileSync( path.join(dir, "scratch.ts"), `// tcm: namespace greeter export const main = () => console.log("hello"); export const command = () => console.log(process.env.GREET_BIN); export const manifest = { name: "greeter", bin: { greet: "main" } }; `, ); okIn(dir, "init"); okIn(dir, "add"); const own = okIn(dir, "run", "greeter.command").trim(); assert.match(own, /\.tcm/, "the codebase's own build"); const elsewhere = path.join(dir, "other-greet.js"); const run = (env: Record<string, string>) => spawnSync(process.execPath, [tcmBin(), "run", "greeter.command"], { cwd: dir, encoding: "utf8", env: { ...plainEnv(), ...env }, }); const r = run({ GREET_BIN: elsewhere }); assert.equal(r.status, 0, r.stderr); assert.equal(r.stdout.trim(), elsewhere); assert.match(strip(r.stderr), /GREET_BIN is set: .*other-greet\.js, not this codebase's build/); const nested = run({ GREET_BIN: elsewhere, TCM_COMMANDS: JSON.stringify({ GREET_BIN: elsewhere }), }); assert.equal(nested.status, 0, nested.stderr); assert.match(nested.stdout, /\.tcm/); assert.doesNotMatch(nested.stderr, /is set/); const older = run({ GREET_BIN: own }); assert.equal(older.status, 0, older.stderr); assert.equal(older.stdout.trim(), own); assert.doesNotMatch(older.stderr, /is set/); }