5682aadfaa
A markdown/text artifact hit now opens the artifact viewer (with its Open run action) instead of a raw browser tab, and the run Summary's Pipeline row shows the pipeline's name beside its id and version, all in the link to the definition.
634 lines
25 KiB
JavaScript
634 lines
25 KiB
JavaScript
// Pure unit tests for the run-detail helpers: the tab set, the summary rows and
|
|
// identity line, input/output field display, the timeline derivation and its
|
|
// one-line text, the stage-pane section ordering and field split, the
|
|
// file-change/notification formatters and the verdict reason segmentation.
|
|
// No server, no DOM.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
RUN_DETAIL_TABS,
|
|
looksLikeMarkdown,
|
|
RENDERED_RUN_TABS,
|
|
EMPTY_INPUT_MESSAGE,
|
|
EMPTY_OUTPUT_MESSAGE,
|
|
EMPTY_TIMELINE_MESSAGE,
|
|
NO_STAGE_DETAILS_MESSAGE,
|
|
STAGE_SESSION_TITLE,
|
|
STAGE_EVIDENCE_TITLE,
|
|
STAGE_DEFINITION_TITLE,
|
|
displayText,
|
|
displayMap,
|
|
fieldSections,
|
|
fieldSectionTitle,
|
|
summaryRows,
|
|
resourceWaitLine,
|
|
runIdentityLine,
|
|
runDurationText,
|
|
runTimeline,
|
|
timelineDescription,
|
|
hasArtifacts,
|
|
nodeLabel,
|
|
resolveTarget,
|
|
stageOutcomes,
|
|
headlineFields,
|
|
evidenceFields,
|
|
runStepFields,
|
|
stageDefinitionFields,
|
|
terminalFields,
|
|
controlVisitLabel,
|
|
clampVisitIndex,
|
|
stageSectionSpecs,
|
|
referencedVerdictArtifacts,
|
|
verdictReasonSegments,
|
|
artifactBaseName,
|
|
fileChangeLine,
|
|
notificationLine,
|
|
fileChangesSummary,
|
|
outcomeColorToken,
|
|
stateGlyph,
|
|
} from "../src/runDetail.js";
|
|
import { showRunChangesSummary } from "../src/changes.js";
|
|
|
|
function step(overrides = {}) {
|
|
return {
|
|
sequence: 1,
|
|
stage: "implementer",
|
|
status: "completed",
|
|
outcome: "success",
|
|
target: "",
|
|
diagnostic: "",
|
|
started_at: "",
|
|
finished_at: "",
|
|
control: null,
|
|
artifacts: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
const TIME_OPTS = { zone: "UTC", locale: "en-GB" };
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Tabs and empty states
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("RUN_DETAIL_TABS is the Android order, Summary first, Timeline keyed 'steps'", () => {
|
|
assert.deepEqual(
|
|
RUN_DETAIL_TABS.map((tab) => tab.key),
|
|
["summary", "graph", "input", "output", "steps"],
|
|
);
|
|
assert.deepEqual(
|
|
RUN_DETAIL_TABS.map((tab) => tab.label),
|
|
["Summary", "Graph", "Input", "Output", "Timeline"],
|
|
);
|
|
// The Graph body (R5) now renders too, so every tab is present.
|
|
assert.deepEqual(
|
|
RENDERED_RUN_TABS.map((tab) => tab.label),
|
|
["Summary", "Graph", "Input", "Output", "Timeline"],
|
|
);
|
|
});
|
|
|
|
test("the empty-state strings are exactly the app's wording", () => {
|
|
assert.equal(EMPTY_INPUT_MESSAGE, "No input recorded.");
|
|
assert.equal(EMPTY_OUTPUT_MESSAGE, "No output recorded.");
|
|
assert.equal(EMPTY_TIMELINE_MESSAGE, "No visits recorded.");
|
|
assert.equal(NO_STAGE_DETAILS_MESSAGE, "No details recorded for this node.");
|
|
assert.equal(STAGE_SESSION_TITLE, "Session");
|
|
assert.equal(STAGE_EVIDENCE_TITLE, "This run");
|
|
assert.equal(STAGE_DEFINITION_TITLE, "Stage definition");
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Field display text
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("displayText renders primitives, arrays and objects like Format.kt", () => {
|
|
assert.equal(displayText("hello"), "hello");
|
|
assert.equal(displayText(42), "42");
|
|
assert.equal(displayText(true), "true");
|
|
assert.equal(displayText(null), "null");
|
|
assert.equal(displayText(["a", "b", "c"]), "a, b, c");
|
|
assert.equal(displayText({ a: 1, b: "x" }), "a=1, b=x");
|
|
assert.equal(displayText([{ k: 1 }, 2]), "k=1, 2");
|
|
});
|
|
|
|
test("displayMap renders one `key: value` line per entry in insertion order", () => {
|
|
assert.equal(displayMap({ prompt: "do it", files: ["a", "b"] }), "prompt: do it\nfiles: a, b");
|
|
assert.equal(displayMap(null), "");
|
|
assert.equal(displayMap({}), "");
|
|
});
|
|
|
|
test("fieldSections keeps insertion order and titles each entry", () => {
|
|
const sections = fieldSections({ prompt: "do it", pwd: "/tmp" }, "input");
|
|
assert.deepEqual(sections, [
|
|
{ key: "prompt", title: "prompt", value: "do it" },
|
|
{ key: "pwd", title: "pwd", value: "/tmp" },
|
|
]);
|
|
assert.deepEqual(fieldSections(null, "input"), []);
|
|
});
|
|
|
|
test("fieldSectionTitle falls back to the prefix and is never empty", () => {
|
|
assert.equal(fieldSectionTitle("plan", "input"), "plan");
|
|
assert.equal(fieldSectionTitle("", "input"), "input");
|
|
assert.equal(fieldSectionTitle(" ", "output"), "output");
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Summary
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("runIdentityLine carries recorded and completed visits in order", () => {
|
|
const run = { id: 430, steps: [step(), step(), step()], completed_steps: 3 };
|
|
assert.equal(runIdentityLine(run), "run 430 · 3 recorded visits · 3 completed visits");
|
|
assert.equal(
|
|
runIdentityLine({ id: 7, steps: [step()], completed_steps: 0 }),
|
|
"run 7 · 1 recorded visit · 0 completed visits",
|
|
);
|
|
});
|
|
|
|
test("resourceWaitLine appears only when the run is waiting on a resource", () => {
|
|
assert.equal(resourceWaitLine({ resource_wait: { resource: "pixel-9" } }), "Waiting for resource pixel-9");
|
|
assert.equal(resourceWaitLine({ resource_wait: null }), "");
|
|
assert.equal(resourceWaitLine({}), "");
|
|
});
|
|
|
|
test("summaryRows is the Android order, omitting blank values", () => {
|
|
const run = {
|
|
id: 430,
|
|
pipeline_id: 12,
|
|
version: 5,
|
|
status: "succeeded",
|
|
executing: false,
|
|
current_stage: "committer",
|
|
workspace: "/tmp/wt",
|
|
content_hash: "abc123",
|
|
created_at: "2026-10-19T09:30:00Z",
|
|
finished_at: "2026-10-19T09:32:05Z",
|
|
retry_of: 409,
|
|
diagnostic: "boom",
|
|
resource_wait: { resource: "phone" },
|
|
steps: [step(), step(), step()],
|
|
completed_steps: 3,
|
|
};
|
|
const rows = summaryRows(run, 0, TIME_OPTS);
|
|
assert.deepEqual(
|
|
rows.map((row) => row.key ?? row.kind),
|
|
["Pipeline", "Stage", "wait", "Workspace", "Content hash", "Started", "Finished", "Duration", "Retry of", "Diagnostic"],
|
|
);
|
|
assert.equal(rows[0].value, "id 12 · v5");
|
|
assert.equal(rows[2].value, "Waiting for resource phone");
|
|
assert.equal(rows[4].monospace, true);
|
|
assert.equal(rows[7].value, "2m 5s");
|
|
assert.equal(rows[8].value, "run 409");
|
|
assert.equal(rows[9].kind, "block");
|
|
});
|
|
|
|
test("the Pipeline summary row carries the pipeline and version for navigation", () => {
|
|
const rows = summaryRows({ pipeline_id: 24, name: "Plan and land", version: 6, status: "succeeded" }, 0, TIME_OPTS);
|
|
const row = rows.find((entry) => entry.kind === "pipeline");
|
|
assert.ok(row, "a pipeline row rather than plain text");
|
|
assert.equal(row.key, "Pipeline");
|
|
assert.equal(row.value, "id 24 · v6");
|
|
assert.equal(row.pipelineId, 24);
|
|
assert.equal(row.pipelineName, "Plan and land");
|
|
assert.equal(row.version, 6);
|
|
});
|
|
|
|
test("summaryRows omits blank values and the wait line when there is none", () => {
|
|
const rows = summaryRows(
|
|
{ id: 1, pipeline_id: 2, version: 1, status: "running", executing: false, steps: [], completed_steps: 0 },
|
|
0,
|
|
TIME_OPTS,
|
|
);
|
|
assert.ok(rows.every((row) => row.kind !== "wait"));
|
|
assert.ok(rows.every((row) => row.value.trim() !== ""));
|
|
assert.ok(!rows.some((row) => row.key === "Stage" || row.key === "Workspace"));
|
|
});
|
|
|
|
test("runDurationText is live while executing and stored at rest", () => {
|
|
assert.equal(
|
|
runDurationText({ executing: true, created_at: "2026-10-19T09:30:00Z" }, Date.parse("2026-10-19T09:31:05Z")),
|
|
"1m 5s",
|
|
);
|
|
assert.equal(runDurationText({ executing: false, created_at: "2026-10-19T09:30:00Z", finished_at: "2026-10-19T09:32:05Z" }, 0), "2m 5s");
|
|
assert.equal(runDurationText({ executing: false, created_at: "", finished_at: "" }, 0), null);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Timeline
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("runTimeline is one entry per visit with the display visit and index", () => {
|
|
const { entries, visitsByStage } = runTimeline([
|
|
step({ sequence: 5, stage: "reviewer", outcome: "rejected", control: { visit: 2 } }),
|
|
step({ sequence: 2, stage: "reviewer", outcome: "success", control: { visit: 1 } }),
|
|
]);
|
|
assert.deepEqual(entries.map((entry) => entry.step.sequence), [5, 2]);
|
|
const bySeq = new Map(entries.map((entry) => [entry.step.sequence, entry]));
|
|
assert.equal(bySeq.get(2).visit, 1);
|
|
assert.equal(bySeq.get(2).visitIndex, 0);
|
|
assert.equal(bySeq.get(5).visit, 2);
|
|
assert.equal(bySeq.get(5).visitIndex, 1);
|
|
assert.deepEqual(visitsByStage.get("reviewer").map((s) => s.sequence), [2, 5]);
|
|
});
|
|
|
|
test("runTimeline falls back to the position when control is missing", () => {
|
|
const { entries } = runTimeline([step({ sequence: 1 }), step({ sequence: 2 })]);
|
|
assert.deepEqual(entries.map((entry) => entry.visit), [1, 2]);
|
|
assert.deepEqual(entries.map((entry) => entry.visitIndex), [0, 1]);
|
|
assert.deepEqual(runTimeline([]).entries, []);
|
|
});
|
|
|
|
test("timeline entry text prefers the first diagnostic line, else → target", () => {
|
|
const { entries } = runTimeline([
|
|
step({ diagnostic: "\n first line \nsecond" }),
|
|
step({ target: "#success" }),
|
|
step({ target: "reviewer" }),
|
|
step({}),
|
|
]);
|
|
assert.equal(entries[0].description, "first line");
|
|
assert.equal(entries[1].description, "→ SUCCESS");
|
|
assert.equal(entries[2].description, "→ reviewer");
|
|
assert.equal(entries[3].description, "");
|
|
});
|
|
|
|
test("timelineDescription mirrors nodeLabel for the terminals", () => {
|
|
assert.equal(timelineDescription(step({ target: "#failure" })), "→ FAILURE");
|
|
assert.equal(nodeLabel("#success"), "SUCCESS");
|
|
assert.equal(nodeLabel("#failure"), "FAILURE");
|
|
assert.equal(nodeLabel("reviewer"), "reviewer");
|
|
});
|
|
|
|
test("timeline entries carry the outcome label and the artifact flag", () => {
|
|
const { entries } = runTimeline([
|
|
step({ outcome: "", status: "running" }),
|
|
step({ outcome: "approved", status: "completed", artifacts: [{ name: "session.md" }] }),
|
|
step({ outcome: "approved", status: "completed", artifacts: [{ name: "shot.png" }] }),
|
|
]);
|
|
assert.equal(entries[0].outcomeLabel, "running");
|
|
assert.equal(entries[1].outcomeLabel, "approved");
|
|
assert.equal(entries[1].hasArtifacts, false);
|
|
assert.equal(entries[2].hasArtifacts, true);
|
|
assert.equal(hasArtifacts(step()), false);
|
|
});
|
|
|
|
test("timeline duration comes from the shared formatter", () => {
|
|
const { entries } = runTimeline([
|
|
step({ started_at: "2026-10-15T02:00:00Z", finished_at: "2026-10-15T02:02:05Z" }),
|
|
]);
|
|
assert.equal(entries[0].duration, "2m 5s");
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Stage pane
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("controlVisitLabel covers a missing max and the limit", () => {
|
|
assert.equal(controlVisitLabel({ visit: 2 }), "2");
|
|
assert.equal(controlVisitLabel({ visit: 2, max_visits: 4 }), "2 / 4");
|
|
assert.equal(controlVisitLabel({ visit: 2, max_visits: 4, limit_reached: true }), "2 / 4 (limit reached)");
|
|
});
|
|
|
|
test("clampVisitIndex keeps a valid visit and handles an empty list", () => {
|
|
assert.equal(clampVisitIndex(0, 3), 0);
|
|
assert.equal(clampVisitIndex(99, 3), 2);
|
|
assert.equal(clampVisitIndex(-4, 3), 0);
|
|
assert.equal(clampVisitIndex(5, 0), 0);
|
|
});
|
|
|
|
test("runStepFields skips blanks and formats the visit", () => {
|
|
assert.deepEqual(runStepFields({}), []);
|
|
const fields = runStepFields({
|
|
status: "completed",
|
|
outcome: "success",
|
|
target: "#success",
|
|
session_id: "sess-1",
|
|
agent_active: true,
|
|
control: { visit: 3, max_visits: 5, limit_reached: true, model_target: "gpt" },
|
|
});
|
|
assert.equal(fields.find((f) => f.label === "Visit").value, "3 / 5 (limit reached)");
|
|
assert.equal(fields.find((f) => f.label === "Agent").value, "active");
|
|
assert.ok(fields.every((f) => f.value.trim() !== ""));
|
|
});
|
|
|
|
test("runStepFields carries every evidence kind the timeline dropped", () => {
|
|
const fields = runStepFields({
|
|
status: "completed",
|
|
diagnostic: "why",
|
|
transcript: "said something",
|
|
input: { prompt: "do it" },
|
|
output: { result: "done" },
|
|
file_changes: { status: "partial", files: [{ kind: "modified", path: "a.kt" }], skipped: 2 },
|
|
notifications: [{ status: "delivered", destination: "ntfy" }],
|
|
});
|
|
const labels = fields.map((f) => f.label);
|
|
for (const label of ["Status", "Diagnostic", "Transcript", "Input", "Output", "File changes", "Changed files", "Notification"]) {
|
|
assert.ok(labels.includes(label), `missing ${label}`);
|
|
}
|
|
assert.equal(fields.find((f) => f.label === "Input").block, true);
|
|
});
|
|
|
|
test("each visit's pane formats its own capture, never the run aggregate", () => {
|
|
const first = step({
|
|
sequence: 1,
|
|
file_changes: {
|
|
status: "partial",
|
|
skipped: 2,
|
|
diagnostic: "Excluded protected files.",
|
|
files: [
|
|
{ kind: "added", path: "docs/one.md", patch: "@@ -0,0 +1 @@\n+one" },
|
|
{ kind: "modified", path: "src/runner.go", patch: "@@ -1 +1 @@\n-old\n+new" },
|
|
],
|
|
},
|
|
});
|
|
const second = step({
|
|
sequence: 2,
|
|
file_changes: {
|
|
status: "complete",
|
|
files: [{ kind: "modified", path: "src/retry_test.go", patch: "@@ -1 +3 @@\n-old\n+a\n+b\n+c" }],
|
|
},
|
|
});
|
|
const third = step({
|
|
sequence: 3,
|
|
file_changes: { status: "complete", files: [] },
|
|
});
|
|
|
|
const firstFields = runStepFields(first);
|
|
assert.equal(
|
|
firstFields.find((field) => field.label === "File changes").value,
|
|
"partial (2 files), 2 skipped · Excluded protected files.",
|
|
);
|
|
assert.equal(
|
|
firstFields.find((field) => field.label === "Changed files").value,
|
|
"added docs/one.md +1\nmodified src/runner.go +1 -1",
|
|
);
|
|
|
|
const secondFields = runStepFields(second);
|
|
assert.equal(secondFields.find((field) => field.label === "File changes").value, "complete (1 files)");
|
|
assert.equal(
|
|
secondFields.find((field) => field.label === "Changed files").value,
|
|
"modified src/retry_test.go +3 -1",
|
|
);
|
|
|
|
// A captured no-change still shows its honest summary but has no file rows.
|
|
const thirdFields = runStepFields(third);
|
|
assert.equal(thirdFields.find((field) => field.label === "File changes").value, "complete");
|
|
assert.equal(thirdFields.find((field) => field.label === "Changed files"), undefined);
|
|
});
|
|
|
|
test("a step that recorded no capture shows neither File changes nor Changed files", () => {
|
|
const fields = runStepFields(step({ file_changes: null }));
|
|
assert.ok(!fields.some((field) => field.label === "File changes"));
|
|
assert.ok(!fields.some((field) => field.label === "Changed files"));
|
|
});
|
|
|
|
test("showRunChangesSummary gates the Summary aggregate to succeeded only", () => {
|
|
assert.equal(showRunChangesSummary("succeeded"), true);
|
|
assert.equal(showRunChangesSummary(" SUCCEEDED "), true);
|
|
for (const status of ["failed", "running", "waiting", "canceled", "interrupted", ""]) {
|
|
assert.equal(showRunChangesSummary(status), false);
|
|
}
|
|
});
|
|
|
|
test("headline and evidence split the visit's facts without duplication", () => {
|
|
const fields = runStepFields({
|
|
status: "completed",
|
|
outcome: "success",
|
|
target: "cleanup",
|
|
session_id: "sess-1",
|
|
diagnostic: "why",
|
|
transcript: "said",
|
|
control: { visit: 2, max_visits: 4, model_target: "gpt" },
|
|
started_at: "2026-01-01T00:00:00Z",
|
|
finished_at: "2026-01-01T00:00:05Z",
|
|
input: { prompt: "x" },
|
|
});
|
|
const headline = headlineFields(fields).map((f) => f.label);
|
|
assert.deepEqual(headline, ["Status", "Outcome", "Duration", "Visit", "Model target", "Target", "Session"]);
|
|
const evidence = evidenceFields(fields).map((f) => f.label);
|
|
assert.ok(!evidence.some((label) => headline.includes(label)));
|
|
assert.ok(evidence.includes("Diagnostic") && evidence.includes("Transcript"));
|
|
assert.ok(!evidence.includes("Input") && !evidence.includes("Output"));
|
|
});
|
|
|
|
test("stageSectionSpecs orders the run sections and puts the definition last", () => {
|
|
const graph = {
|
|
stages: [{ key: "implementer", type: "model", prompt: "do", output: "done", edges: { success: "reviewer" } }],
|
|
};
|
|
const step1 = step({
|
|
stage: "implementer",
|
|
input: { prompt: "do it" },
|
|
output: { result: "done" },
|
|
diagnostic: "why",
|
|
});
|
|
const specs = stageSectionSpecs("implementer", graph, [step1], 0, true);
|
|
assert.deepEqual(specs.map((spec) => spec.key), ["artifacts", "output", "input", "run", "definition"]);
|
|
assert.deepEqual(specs.map((spec) => spec.title), [
|
|
"Artifacts · 0 recorded",
|
|
"Output",
|
|
"Input",
|
|
"This run",
|
|
"Stage definition",
|
|
]);
|
|
assert.equal(specs[0].artifacts, true);
|
|
assert.ok(specs.find((spec) => spec.key === "definition").fields.length > 0);
|
|
});
|
|
|
|
test("a session export inserts the Session section after Artifacts", () => {
|
|
const graph = { stages: [{ key: "reviewer", type: "model" }] };
|
|
const withSession = step({
|
|
stage: "reviewer",
|
|
session_export: { html: "session.html" },
|
|
artifacts: [{ name: "session.html", url: "/a" }],
|
|
});
|
|
const specs = stageSectionSpecs("reviewer", graph, [withSession], 0, true);
|
|
assert.deepEqual(specs.map((spec) => spec.key), ["artifacts", "session", "definition"]);
|
|
assert.equal(specs[1].session, true);
|
|
});
|
|
|
|
test("a visit with no results still lists the artifacts gallery and the definition", () => {
|
|
const graph = { stages: [{ key: "s", type: "model" }] };
|
|
const specs = stageSectionSpecs("s", graph, [step({ stage: "s" })], 0, true);
|
|
assert.deepEqual(specs.map((spec) => spec.key), ["artifacts", "definition"]);
|
|
assert.ok(specs.every((spec) => spec.artifacts || spec.fields.length > 0));
|
|
});
|
|
|
|
test("stageDefinitionFields labels outcomes with resolved terminals", () => {
|
|
const stage = {
|
|
key: "planner",
|
|
type: "model",
|
|
prompt: "do the thing",
|
|
output: "plan",
|
|
configs: { model: "gpt", provider: "" },
|
|
edges: { success: "#", error: "cleanup" },
|
|
blocks: { tools: "read\nwrite" },
|
|
limits: { max_visits: 3, on: ["exceeded"] },
|
|
memory: { notes: "notes.md" },
|
|
notify: { on: ["failure"], destination: "ntfy", artifacts: ["log"] },
|
|
};
|
|
const fields = stageDefinitionFields(stage);
|
|
const labels = fields.map((f) => f.label);
|
|
for (const label of ["Type", "Prompt", "Output", "Outcomes", "Model", "Tools", "Max visits", "Limit on", "Memory", "Notify on", "Notify destination", "Notify artifacts"]) {
|
|
assert.ok(labels.includes(label), `missing ${label}`);
|
|
}
|
|
assert.ok(fields.every((f) => f.value.trim() !== ""));
|
|
const outcomes = fields.find((f) => f.label === "Outcomes").value;
|
|
assert.ok(outcomes.includes("success → SUCCESS (terminal)"));
|
|
assert.ok(outcomes.includes("error → cleanup"));
|
|
assert.equal(stageDefinitionFields({ key: "p" }).map((f) => f.value)[0], "model");
|
|
});
|
|
|
|
test("terminalFields lists incoming routes only", () => {
|
|
const graph = { stages: [{ key: "a", edges: { success: "#success" } }] };
|
|
assert.deepEqual(terminalFields(graph, "a"), []);
|
|
const incoming = terminalFields(graph, "#success");
|
|
assert.deepEqual(incoming.map((f) => f.label), ["Incoming routes"]);
|
|
assert.ok(incoming[0].value.includes("a · success → SUCCESS"));
|
|
});
|
|
|
|
test("resolveTarget and stageOutcomes mirror the graph semantics", () => {
|
|
assert.equal(resolveTarget("error", "#"), "#failure");
|
|
assert.equal(resolveTarget("success", "#"), "#success");
|
|
assert.equal(resolveTarget("success", "reviewer"), "reviewer");
|
|
assert.deepEqual(stageOutcomes({ edges: { error: "x", success: "y", advisory: "z" } }), [
|
|
"success",
|
|
"advisory",
|
|
"error",
|
|
]);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Verdict
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("verdictReasonSegments splits a reason around every referenced name", () => {
|
|
const png = { name: "review.png", url: "/review.png" };
|
|
const txt = { name: "report.txt", url: "/report.txt" };
|
|
assert.deepEqual(
|
|
verdictReasonSegments("Approved: review.png shows the fix; report.txt lists the checks.", [png, txt]),
|
|
[
|
|
{ text: "Approved: " },
|
|
{ text: "review.png", artifact: png },
|
|
{ text: " shows the fix; " },
|
|
{ text: "report.txt", artifact: txt },
|
|
{ text: " lists the checks." },
|
|
],
|
|
);
|
|
});
|
|
|
|
test("verdictReasonSegments matches a basename and prefers the longer token", () => {
|
|
const nested = { name: "shots/wide.png" };
|
|
assert.deepEqual(verdictReasonSegments("See wide.png for the wide layout.", [nested]), [
|
|
{ text: "See " },
|
|
{ text: "wide.png", artifact: nested },
|
|
{ text: " for the wide layout." },
|
|
]);
|
|
const bare = { name: "wide.png" };
|
|
assert.deepEqual(verdictReasonSegments("shots/wide.png is the shot", [bare, nested]), [
|
|
{ text: "shots/wide.png", artifact: nested },
|
|
{ text: " is the shot" },
|
|
]);
|
|
assert.deepEqual(verdictReasonSegments("nothing referenced here", [{ name: "x.png" }]), [
|
|
{ text: "nothing referenced here" },
|
|
]);
|
|
assert.deepEqual(verdictReasonSegments("", [{ name: "x.png" }]), []);
|
|
assert.equal(artifactBaseName("shots\\x.png"), "x.png");
|
|
});
|
|
|
|
test("referencedVerdictArtifacts resolves names to recorded files in recorded order", () => {
|
|
const a = { name: "a.png" };
|
|
const b = { name: "b.png" };
|
|
const verdict = { option: "approved → success", reason: "b.png then a.png", artifacts: ["b.png", "a.png", "invented.png"] };
|
|
assert.deepEqual(referencedVerdictArtifacts(verdict, [a, b]), [a, b]);
|
|
assert.deepEqual(referencedVerdictArtifacts(null, [a]), []);
|
|
assert.deepEqual(referencedVerdictArtifacts({ artifacts: [] }, [a]), []);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Formatters and colours
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("fileChangeLine adds a parseable stat, never a fabricated one", () => {
|
|
assert.equal(fileChangeLine({ kind: "modified", path: "src/a.kt" }), "modified src/a.kt");
|
|
assert.equal(
|
|
fileChangeLine({ kind: "modified", path: "src/a.kt", binary: true, truncated: true }),
|
|
"modified src/a.kt (binary) (truncated)",
|
|
);
|
|
// A binary file keeps its marker and never gets a text stat, even if a patch
|
|
// string was recorded alongside it.
|
|
assert.equal(
|
|
fileChangeLine({ kind: "added", path: "shot.png", binary: true, patch: "@@ -1 +1 @@\n-a\n+b" }),
|
|
"added shot.png (binary)",
|
|
);
|
|
assert.equal(
|
|
fileChangeLine({
|
|
kind: "modified",
|
|
path: "src/a.kt",
|
|
patch: "@@ -1,2 +1,3 @@\n ctx\n-old\n+new\n+more",
|
|
}),
|
|
"modified src/a.kt +2 -1",
|
|
);
|
|
assert.equal(
|
|
fileChangeLine({
|
|
kind: "modified",
|
|
path: "src/a.kt",
|
|
truncated: true,
|
|
patch: "@@ -1 +1 @@\n-old\n+new",
|
|
}),
|
|
"modified src/a.kt +1 -1 (truncated)",
|
|
);
|
|
// Header-only/unparseable text is not a diff and earns no stat.
|
|
assert.equal(fileChangeLine({ kind: "modified", path: "src/a.kt", patch: "not a patch" }), "modified src/a.kt");
|
|
});
|
|
|
|
test("notificationLine appends a non-blank diagnostic only", () => {
|
|
assert.equal(notificationLine({ status: "delivered", destination: "ntfy" }), "delivered → ntfy");
|
|
assert.equal(
|
|
notificationLine({ status: "delivered", destination: "ntfy", diagnostic: "ok" }),
|
|
"delivered → ntfy · ok",
|
|
);
|
|
});
|
|
|
|
test("fileChangesSummary carries status, count, skipped, omitted and diagnostic", () => {
|
|
assert.equal(fileChangesSummary({ status: "partial", files: [{}, {}], skipped: 1 }), "partial (2 files), 1 skipped");
|
|
assert.equal(
|
|
fileChangesSummary({
|
|
status: "partial",
|
|
files: [{}, {}],
|
|
skipped: 1,
|
|
omitted: 3,
|
|
diagnostic: " Excluded protected files. ",
|
|
}),
|
|
"partial (2 files), 1 skipped, 3 omitted · Excluded protected files.",
|
|
);
|
|
assert.equal(
|
|
fileChangesSummary({ status: "unavailable", files: [], diagnostic: "snapshot unreadable" }),
|
|
"unavailable · snapshot unreadable",
|
|
);
|
|
assert.equal(fileChangesSummary({ status: "complete", files: [] }), "complete");
|
|
assert.equal(fileChangesSummary({}), "");
|
|
assert.equal(fileChangesSummary(null), "");
|
|
});
|
|
|
|
test("outcomeColorToken uses the status palette then the flow palette", () => {
|
|
assert.equal(outcomeColorToken("success"), "state succeeded");
|
|
assert.equal(outcomeColorToken("error"), "state failed");
|
|
assert.equal(outcomeColorToken("blocked"), "state blocked");
|
|
assert.equal(outcomeColorToken("approved"), "flow 3");
|
|
assert.equal(outcomeColorToken("rejected"), "flow 0");
|
|
assert.equal(outcomeColorToken("", "running"), "state running");
|
|
assert.equal(stateGlyph("succeeded"), "✓");
|
|
assert.equal(stateGlyph("nonsense"), "?");
|
|
});
|
|
|
|
test("looksLikeMarkdown recognises stage bodies and leaves legacy maps alone", () => {
|
|
assert.equal(looksLikeMarkdown("# outcome\nsuccess\n\n# notes\nDone."), true);
|
|
assert.equal(looksLikeMarkdown("Some text\n\n- one\n- two"), true);
|
|
assert.equal(looksLikeMarkdown("```js\nconst a = 1;\n```"), true);
|
|
assert.equal(looksLikeMarkdown("| a | b |\n| --- | --- |\n| 1 | 2 |"), true);
|
|
// Historical field text is a plain map, not markdown.
|
|
assert.equal(looksLikeMarkdown("summary: ok\nfindings: none"), false);
|
|
assert.equal(looksLikeMarkdown(""), false);
|
|
assert.equal(looksLikeMarkdown(null), false);
|
|
});
|