testHistoryFromBeforeTheLibrariesTravels
A codebase whose history predates the server library (tcmts.fixtures.codebase-tcm-server: its first version
imported #tcm/server, as tcm:server) pushes to a server running this tcm, and is pulled from it: history's
definitions are checked by re-hashing as they were, though nothing new can import #tcm/server.
import { okIn, tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import { codebase, startServerInfo } from "#codebase/tcmts/cli/test/e2e/sync"; import { "codebase-tcm-server" as codebase_tcm_server } from "#codebase/tcmts/fixtures"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testHistoryFromBeforeTheLibrariesTravels = () => withChildren(async (keep) => { const root = tempDir("sync retired"); const old = path.join(root, "old"); fs.mkdirSync(path.join(old, ".tcm"), { recursive: true }); fs.writeFileSync(path.join(old, ".tcm", "codebase.sqlite"), codebase_tcm_server); const tcmOld = (...args: string[]) => okIn(old, ...args); // (made by a tcm of an older layout too) tcmOld("migrate", "--if-needed"); assert.match(tcmOld("history"), /add shop\.Item, shop\.items/); const server = codebase(root, "server"); fs.rmSync(path.join(server.dir, "scratch.ts")); const { url } = await startServerInfo(keep, server.dir, "tok"); tcmOld("remote", "add", "origin", url, "--token", "tok"); assert.match(tcmOld("push"), /pushed origin\/main/); const fresh = codebase(root, "fresh"); fs.rmSync(path.join(fresh.dir, "scratch.ts")); fresh.tcm("remote", "add", "origin", url, "--token", "tok"); assert.match(fresh.tcm("pull"), /verified by re-hashing[\s\S]*fast-forwarded main/); assert.equal(fresh.tcm("ls"), tcmOld("ls"), "same names, same hashes"); assert.match(fresh.tcm("history"), /add shop\.Item, shop\.items/); })