testSessionPageIsSavedByItsName
In a session, tcm check of a page in its own directory says to save it by its name alone (tcm update guide.md), as a .ts scratch file is named there, rather than its whole path in .tcm/sessions/….
import { okIn, plainEnv, strip, 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 testSessionPageIsSavedByItsName = () => { const dir = tempDir("session page"); okIn(dir, "init"); fs.mkdirSync(path.join(dir, "docs")); fs.writeFileSync(path.join(dir, "docs", "guide.md"), "# Guide\n\nHello.\n"); okIn(dir, "add", "docs/guide.md", "--into", "docs"); okIn(dir, "branch", "session/s"); const inSession = (...args: string[]) => { const r = spawnSync(process.execPath, [tcmBin(), ...args], { cwd: dir, encoding: "utf8", env: { ...plainEnv(), TCM_BRANCH: "session/s" }, }); const out = strip(r.stdout + r.stderr); if (r.status !== 0) throw new Error(`tcm ${args.join(" ")} (in the session) exited ${r.status}:\n${out}`); return out; }; const wrote = inSession("edit", "docs.guide"); const file = /wrote docs\.guide to (.+)$/m.exec(wrote)![1]!.trim(); const abs = path.resolve(dir, file); assert.ok(abs.includes(path.join(".tcm", "sessions")), wrote); fs.writeFileSync(abs, fs.readFileSync(abs, "utf8").replace("Hello.", "Hello again.")); const checked = inSession("check", "guide.md"); assert.match(checked, /run `tcm update guide\.md` to save it/); assert.doesNotMatch(checked, /sessions/); inSession("update", "guide.md"); assert.match(inSession("view", "docs.guide"), /Hello again\./); }