syntaxai/tdd.md · main · src / c14_real_tests.test.ts
// Sibling test for c32_real_tests.ts. buildLiveTestData fans out to
// loadTestBundle + fetchRepoCommits (both network/disk) so the
// end-to-end is covered by the live /reports/live/tests route. The
// pure helpers — agent attribution and the file/name label shortener —
// are unit-testable here.
import { describe, test, expect } from "bun:test";
import {
detectAgent,
shortenTestLabel,
buildLiveTestData,
} from "./c14_real_tests.ts";
describe("c32_real_tests — detectAgent", () => {
test("recognises Claude Code via Co-Authored-By: Claude", () => {
expect(detectAgent("Add feature\n\nCo-Authored-By: Claude <noreply>")).toBe("claude-code");
});
test("recognises Cursor", () => {
expect(detectAgent("Fix bug\n\nCo-Authored-By: Cursor <[email protected]>")).toBe("cursor");
});
test("recognises Aider", () => {
expect(detectAgent("Refactor x\n\nCo-Authored-By: aider")).toBe("aider");
});
test("returns null when no recognised footer is present (distinct from c32_real_reports which returns 'unknown')", () => {
// The two real_* files made different choices here: real_reports
// buckets unknown into its own slug; real_tests returns null so
// the caller can filter or fall back. Document the difference.
expect(detectAgent("Just a commit")).toBeNull();
expect(detectAgent("")).toBeNull();
});
test("the regex is case-insensitive on the agent token", () => {
expect(detectAgent("Co-Authored-By: CLAUDE")).toBe("claude-code");
expect(detectAgent("co-authored-by: aider")).toBe("aider");
});
});
describe("c32_real_tests — shortenTestLabel", () => {
test("keeps only the basename of the file path + the test name", () => {
expect(shortenTestLabel("src/foo/bar/baz.test.ts", "handles X")).toBe("baz.test.ts > handles X");
});
test("handles a bare filename (no path) without splitting weirdly", () => {
expect(shortenTestLabel("baz.test.ts", "handles X")).toBe("baz.test.ts > handles X");
});
test("handles an empty file string (falls back to the empty basename)", () => {
// .split('/').pop() on '' yields ''. Documented behaviour: the
// helper never throws; the caller decides whether to filter empties.
expect(shortenTestLabel("", "name")).toBe(" > name");
});
test("preserves spaces and special chars in the test name", () => {
expect(shortenTestLabel("a.ts", "rejects `bad input`")).toBe("a.ts > rejects `bad input`");
});
});
describe("c32_real_tests — orchestrator entry point", () => {
test("buildLiveTestData is exported as an async function", () => {
expect(typeof buildLiveTestData).toBe("function");
expect(buildLiveTestData.length).toBe(2);
});
});