testASessionWhoseBranchIsGoneGoesOn
A session whose branch is deleted while its server runs (as a tcm from before branches were claimed could) has it made again from main, and the call made again, rather than every call failing; the session goes on.
import { okIn, tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import { startedSession } from "#codebase/tcmts/cli/test/e2e/mcp"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { DatabaseSync } from "node:sqlite"; export const testASessionWhoseBranchIsGoneGoesOn = () => withChildren(async (keep) => { const dir = tempDir("mcp branch gone"); const tcm = (...args: string[]) => okIn(dir, ...args); tcm("init"); fs.rmSync(path.join(dir, "scratch.ts"), { force: true }); const s = await startedSession(dir, keep); const db = new DatabaseSync(path.join(dir, ".tcm", "codebase.sqlite")); db.exec("PRAGMA busy_timeout = 15000"); const { id } = db.prepare("SELECT id FROM branches WHERE name = ?").get(s.branch) as { id: number; }; for (const table of ["names", "patches", "todo", "name_log"]) db.prepare(`DELETE FROM ${table} WHERE branch_id = ?`).run(id); db.prepare("DELETE FROM branches WHERE id = ?").run(id); db.close(); assert.doesNotMatch(tcm("branch"), new RegExp(s.branch)); const status = await s.call("tcm_status"); assert.equal(status.isError, false, status.text); assert.match( status.text, new RegExp(`this session's branch, ${s.branch}, was gone: it's made again from main`), ); assert.match(status.text, new RegExp(`^branch\\s+${s.branch}`, "m")); assert.match(tcm("branch"), new RegExp(s.branch)); const added = await s.call("tcm_add", { code: "export const after = 1;\n", namespace: "lib" }); assert.equal(added.isError, false, added.text); s.close(); })