testResultsKeptForWhatTheyDependOn
A test's result is kept for the runtime and test framework; one whose code reaches files (or the environment, or other processes) is kept for the platform too, which those differ by.
import { okIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { DatabaseSync } from "node:sqlite"; export const testResultsKeptForWhatTheyDependOn = () => { const dir = tempDir("result keys"); const ok = (...args: string[]) => okIn(dir, ...args); ok("init"); fs.writeFileSync( path.join(dir, "scratch.ts"), [ "// tcm: namespace lib", 'import fs from "node:fs";', "export const testPure = () => { if (1 + 1 !== 2) throw new Error('no'); };", "export const testFiles = () => { if (!fs.existsSync('.')) throw new Error('no'); };", "", ].join("\n"), ); ok("add"); assert.match(ok("test"), /2 passed/); const db = new DatabaseSync(path.join(dir, ".tcm", "codebase.sqlite")); const keys = db .prepare( "SELECT n.path, t.node_version AS key FROM test_results t JOIN names n ON n.hash = t.hash ORDER BY n.path", ) .all() as { path: string; key: string }[]; db.close(); const platform = `${process.platform}-${process.arch}`; assert.equal(keys.length, 2); assert.ok( keys[0]!.path === "lib.testFiles" && keys[0]!.key.endsWith(` ${platform}`), keys[0]!.key, ); assert.ok(keys[1]!.path === "lib.testPure" && !keys[1]!.key.includes(platform), keys[1]!.key); assert.match(ok("test"), /2 passed \(2 cached\)|2 cached/); }