testResultsTravel
Tests' results travel with the code: pulled, a codebase has them, so its tests don't run again (a test's hash covers what it runs); pushed, the other side has what ran here.
import { tempDir } from "#codebase/tcmts/cli/test/e2e/harness"; import { codebase } from "#codebase/tcmts/cli/test/e2e/sync"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testResultsTravel = () => { const root = tempDir("sync results"); const a = codebase(root, "a"); a.scratch( `// tcm: namespace lib\nimport fs from "node:fs";\nexport const square = (x: number) => x * x;\n` + `export const testSquare = () => { if (square(3) !== 9) throw new Error("no"); };\n` + `export const testHere = () => { if (!fs.existsSync(".")) throw new Error("no"); };\n`, ); a.tcm("add"); assert.match(a.tcm("test"), /2 passed, 0 failed\n/); const b = codebase(root, "b"); fs.rmSync(path.join(b.dir, "scratch.ts")); b.tcm("remote", "add", "origin", a.dir); assert.match(b.tcm("pull"), /received 2 test result\(s\)/); assert.match(b.tcm("test"), /2 passed, 0 failed \(2 cached\)/, "pulled, they needn't run"); // a test b ran, pushed: a has its result b.scratch( `// tcm: namespace lib\nimport { square } from "#codebase/lib";\nexport const testFour = () => { if (square(2) !== 4) throw new Error("no"); };\n`, ); b.tcm("add"); assert.match(b.tcm("test"), /3 passed, 0 failed \(2 cached\)/); assert.match(b.tcm("push"), /sent 1 definition\(s\), 1 test result\(s\)/); assert.match(a.tcm("test"), /3 passed, 0 failed \(3 cached\)/); }