mirror of
https://github.com/merlinhu1/truthmark.git
synced 2026-08-25 07:53:25 +02:00
* feat: add interactive platform selection to init * chore: remove completed OpenSpec artifacts * chore: remove implemented design note * fix: protect init lifecycle from unsafe config paths * fix: support clearing init platforms from CLI * docs: retire config command from repository rules * docs: align init lifecycle and clear-platform contracts * docs: keep repository guidance current-state focused * docs: limit cleanup to repository-native documents * docs: preserve historical version notes --------- Co-authored-by: MerlinH <merlinh221@gmail.com>
128 lines
4.3 KiB
TypeScript
128 lines
4.3 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import { expect } from "expect";
|
|
|
|
import { runCheck } from "../../src/checks/check.js";
|
|
import { writeTruthmarkConfig } from "../helpers/truthmark-config.js";
|
|
import { runInit } from "../../src/init/init.js";
|
|
import { createWorktreeRepo } from "../helpers/worktree-repo.js";
|
|
|
|
describe("branch-scoped truth integration", () => {
|
|
it("reports branch name and head sha for a normal branch checkout", async () => {
|
|
const repo = await createWorktreeRepo();
|
|
|
|
try {
|
|
await writeTruthmarkConfig(repo.rootDir);
|
|
await runInit(repo.rootDir);
|
|
await repo.runGit(["add", "."]);
|
|
await repo.runGit(["commit", "-m", "test: baseline"]);
|
|
|
|
const result = await runCheck(repo.rootDir);
|
|
const branchScope = result.data?.branchScope as
|
|
| {
|
|
branchName: string | null;
|
|
headSha: string | null;
|
|
}
|
|
| undefined;
|
|
|
|
expect(branchScope?.branchName).toBe("main");
|
|
expect(branchScope?.headSha).toMatch(/^[0-9a-f]{40}$/);
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
|
|
it("reports detached checkout identity cleanly", async () => {
|
|
const repo = await createWorktreeRepo();
|
|
|
|
try {
|
|
await writeTruthmarkConfig(repo.rootDir);
|
|
await runInit(repo.rootDir);
|
|
await repo.runGit(["add", "."]);
|
|
await repo.runGit(["commit", "-m", "test: baseline"]);
|
|
const headSha = (await repo.runGit(["rev-parse", "HEAD"])).stdout.trim();
|
|
await repo.runGit(["checkout", "--detach"]);
|
|
|
|
const result = await runCheck(repo.rootDir);
|
|
const branchScope = result.data?.branchScope as
|
|
| {
|
|
identity: string;
|
|
branchName: string | null;
|
|
}
|
|
| undefined;
|
|
|
|
expect(branchScope?.branchName).toBeNull();
|
|
expect(branchScope?.identity).toBe(`detached:${headSha}`);
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
|
|
it("reports the active worktree path without leaking the primary checkout context", async () => {
|
|
const repo = await createWorktreeRepo();
|
|
|
|
try {
|
|
await writeTruthmarkConfig(repo.rootDir);
|
|
await runInit(repo.rootDir);
|
|
await repo.runGit(["add", "."]);
|
|
await repo.runGit(["commit", "-m", "test: baseline"]);
|
|
|
|
const secondary = await repo.addWorktree("feature/worktree");
|
|
const result = await runCheck(secondary.rootDir);
|
|
const branchScope = result.data?.branchScope as
|
|
| {
|
|
branchName: string | null;
|
|
worktreePath: string;
|
|
}
|
|
| undefined;
|
|
|
|
expect(branchScope?.branchName).toBe("feature/worktree");
|
|
expect(branchScope?.worktreePath).toBe(secondary.rootDir);
|
|
expect(branchScope?.worktreePath).not.toBe(repo.rootDir);
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
|
|
it("keeps truth surface changes isolated to the checked out branch", async () => {
|
|
const repo = await createWorktreeRepo();
|
|
|
|
try {
|
|
await writeTruthmarkConfig(repo.rootDir);
|
|
await runInit(repo.rootDir);
|
|
await repo.runGit(["add", "."]);
|
|
await repo.runGit(["commit", "-m", "test: baseline"]);
|
|
|
|
const secondary = await repo.addWorktree("feature/docs");
|
|
await secondary.writeFile(
|
|
"docs/truthmark/routes/areas.md",
|
|
`${await secondary.readFile("docs/truthmark/routes/areas.md")}\n## Feature Branch Notes\nOnly here.\n`,
|
|
);
|
|
|
|
const primaryResult = await runCheck(repo.rootDir);
|
|
const secondaryResult = await runCheck(secondary.rootDir);
|
|
const primaryHash = (
|
|
primaryResult.data?.branchScope as {
|
|
relevantFileHashes: Record<string, string>;
|
|
}
|
|
).relevantFileHashes["docs/truthmark/routes/areas.md"];
|
|
const secondaryHash = (
|
|
secondaryResult.data?.branchScope as {
|
|
relevantFileHashes: Record<string, string>;
|
|
}
|
|
).relevantFileHashes["docs/truthmark/routes/areas.md"];
|
|
|
|
expect(primaryHash).toBeTruthy();
|
|
expect(secondaryHash).toBeTruthy();
|
|
expect(primaryHash).not.toBe(secondaryHash);
|
|
expect(
|
|
await repo.readFile("docs/truthmark/routes/areas.md"),
|
|
).not.toContain("Feature Branch Notes");
|
|
expect(
|
|
await secondary.readFile("docs/truthmark/routes/areas.md"),
|
|
).toContain("Feature Branch Notes");
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
});
|