testScratchShown
tcmts.cli.ui.testScratchShown · #4vyuga3u · term
import { scratchShown } from "#codebase/tcmts/cli/ui";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
export const testScratchShown = () => {
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "tcm scratch shown ")));
try {
const session = path.join(dir, ".tcm", "sessions", "s");
fs.mkdirSync(session, { recursive: true });
// (through a link, as a worktree's codebase is)
fs.symlinkSync(dir, path.join(dir, "link"));
assert.equal(scratchShown(path.join(session, "agents.md"), session), "agents.md");
assert.equal(
scratchShown(path.join(dir, "link", ".tcm", "sessions", "s", "agents.md"), session),
"agents.md",
);
// elsewhere, or with no session: as shownPath says it (whole, outside where the test runs)
assert.equal(scratchShown(path.join(dir, "page.md"), session), path.join(dir, "page.md"));
assert.equal(scratchShown(path.join(session, "agents.md")), path.join(session, "agents.md"));
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
}
uses