testMakeABuildFromHistory
tcm builds make <entry> builds the codebase's tcm (its package whose command is tcm) as it was at a history
entry, and keeps it with the others to run by its id; making it again is the one kept.
import { okIn, plainEnv, 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 testMakeABuildFromHistory = () => { const root = tempDir("builds made"); const dir = tempDir("builds history"); okIn(dir, "init"); const save = (code: string) => { fs.writeFileSync(path.join(dir, "scratch.ts"), `// tcm: namespace faketcm\n${code}`); okIn(dir, "update"); }; save( `export const main = (...args: string[]) => console.log(\`before the fix: \${args.join(" ")}\`); export const manifest = { name: "faketcm", bin: { tcm: "main" } }; `, ); save(`export const main = (...args: string[]) => console.log(\`fixed: \${args.join(" ")}\`);\n`); const tcm = (...args: string[]) => { const r = spawnSync(process.execPath, [tcmBin(), ...args], { cwd: dir, encoding: "utf8", env: { ...plainEnv(), TCM_BUILDS: root }, }); assert.equal(r.status, 0, r.stdout + r.stderr); return r.stdout; }; const made = tcm("builds", "make", "1"); const id = /^made ([a-z2-7]{8}) /.exec(made)?.[1]; assert.ok(id, made); assert.ok( fs.existsSync(path.join(root, "builds", id, "node_modules", "faketcm", "bin", "tcm.js")), ); assert.equal(tcm("--build", id, "go").trim(), "before the fix: go"); assert.match(tcm("builds", "make", `#${id}`), new RegExp(`^kept already: ${id} `)); assert.match(tcm("builds"), new RegExp(`${id} #${id} made [\\d-]+ [\\d:]+ 1 back: update`)); }