2026-06-30 20:57:55 +10:00
|
|
|
import { describe, it } from "node:test";
|
|
|
|
|
import { expect } from "expect";
|
2026-05-09 17:58:44 +10:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
DIAGNOSTIC_CATEGORIES,
|
|
|
|
|
type CommandResult,
|
|
|
|
|
} from "../../src/output/diagnostic.js";
|
|
|
|
|
import { renderHuman, renderJson } from "../../src/output/render.js";
|
|
|
|
|
|
|
|
|
|
describe("output rendering", () => {
|
|
|
|
|
it("renders the command name and summary first for human output", () => {
|
|
|
|
|
const result: CommandResult = {
|
|
|
|
|
command: "check",
|
|
|
|
|
summary: "Found 2 issues to review.",
|
|
|
|
|
diagnostics: [
|
|
|
|
|
{
|
|
|
|
|
category: "config",
|
|
|
|
|
severity: "action",
|
|
|
|
|
message: "Created .truthmark/config.yml.",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const output = renderHuman(result);
|
|
|
|
|
const lines = output.split("\n");
|
|
|
|
|
|
|
|
|
|
expect(lines[0]).toBe("truthmark check");
|
|
|
|
|
expect(lines[1]).toBe("Found 2 issues to review.");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("renders action, review, and error diagnostics consistently", () => {
|
|
|
|
|
const result: CommandResult = {
|
|
|
|
|
command: "check",
|
|
|
|
|
summary: "Found issues.",
|
|
|
|
|
diagnostics: [
|
|
|
|
|
{
|
|
|
|
|
category: "config",
|
|
|
|
|
severity: "action",
|
|
|
|
|
message: "Created .truthmark/config.yml.",
|
|
|
|
|
file: ".truthmark/config.yml",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
category: "coverage",
|
|
|
|
|
severity: "review",
|
|
|
|
|
message: "No truth docs are mapped for src/auth/**.",
|
|
|
|
|
area: "Authentication",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
category: "links",
|
|
|
|
|
severity: "error",
|
|
|
|
|
message: "Broken link to docs/api/authentication.md.",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
expect(renderHuman(result)).toContain(
|
|
|
|
|
"[ACTION] config: Created .truthmark/config.yml. (file: .truthmark/config.yml)",
|
|
|
|
|
);
|
|
|
|
|
expect(renderHuman(result)).toContain(
|
|
|
|
|
"[REVIEW] coverage: No truth docs are mapped for src/auth/**. (area: Authentication)",
|
|
|
|
|
);
|
|
|
|
|
expect(renderHuman(result)).toContain(
|
|
|
|
|
"[ERROR] links: Broken link to docs/api/authentication.md.",
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("renders deterministic JSON that round-trips to the command result", () => {
|
|
|
|
|
const result: CommandResult = {
|
|
|
|
|
command: "init",
|
|
|
|
|
summary: "Created Truthmark files.",
|
|
|
|
|
diagnostics: [
|
|
|
|
|
{
|
|
|
|
|
category: "config",
|
|
|
|
|
severity: "action",
|
|
|
|
|
message: "Created .truthmark/config.yml.",
|
|
|
|
|
data: {
|
|
|
|
|
created: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
data: {
|
2026-06-13 04:09:45 +10:00
|
|
|
files: [".truthmark/config.yml", "docs/truthmark/routes/areas.md"],
|
2026-05-09 17:58:44 +10:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const parsed = JSON.parse(renderJson(result)) as CommandResult;
|
|
|
|
|
|
|
|
|
|
expect(parsed).toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("exports the V1 diagnostic category list", () => {
|
|
|
|
|
expect(DIAGNOSTIC_CATEGORIES).toEqual([
|
|
|
|
|
"config",
|
|
|
|
|
"authority",
|
|
|
|
|
"frontmatter",
|
|
|
|
|
"links",
|
|
|
|
|
"area-index",
|
|
|
|
|
"coverage",
|
|
|
|
|
"truth-sync",
|
|
|
|
|
"realization",
|
|
|
|
|
"doc-structure",
|
2026-06-16 00:54:46 +10:00
|
|
|
"lane-shape",
|
|
|
|
|
"lane-drift",
|
|
|
|
|
"traceability",
|
2026-05-09 17:58:44 +10:00
|
|
|
"generated-surface",
|
2026-05-16 03:55:55 +10:00
|
|
|
"repo-index",
|
|
|
|
|
"impact",
|
|
|
|
|
"freshness",
|
2026-06-13 04:09:45 +10:00
|
|
|
"source-traceability",
|
2026-05-16 03:55:55 +10:00
|
|
|
"context-pack",
|
2026-06-13 04:09:45 +10:00
|
|
|
"workflow-state",
|
2026-05-09 17:58:44 +10:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
});
|