/**
 * headless-status.test.ts — direct headless status rendering.
 *
 * Purpose: prevent `sf headless status` from regressing back to the
 * interactive RPC/v2 path when it only needs DB-backed project state.
 */
import assert from "node:assert/strict";
import { test } from "vitest";
import type { QuerySnapshot } from "../headless-query.js";
import { formatHeadlessStatus } from "../headless-status.js";

function snapshot(overrides: Partial<QuerySnapshot> = {}): QuerySnapshot {
	return {
		schemaVersion: 1,
		state: {
			activeMilestone: { id: "M001", title: "Runtime Hardening" },
			activeSlice: { id: "S01", title: "Headless Status" },
			activeTask: { id: "T01", title: "Bypass v2 init" },
			phase: "executing",
			recentDecisions: [],
			blockers: [],
			nextAction: "Execute T01.",
			registry: [{ id: "M001", title: "Runtime Hardening", status: "active" }],
			requirements: {
				active: 0,
				validated: 0,
				deferred: 0,
				outOfScope: 0,
				blocked: 0,
				total: 0,
			},
			progress: {
				milestones: { done: 0, total: 1 },
				slices: { done: 0, total: 1 },
				tasks: { done: 0, total: 1 },
			},
		},
		next: {
			action: "dispatch",
			unitType: "execute-task",
			unitId: "M001/S01/T01",
		},
		cost: { workers: [], total: 0 },
		runtime: { units: [] },
		uokDiagnostics: { verdict: "clear", classification: "healthy" },
		schedule: { pending_count: 0, overdue_count: 0, due: [], upcoming: [] },
		...overrides,
	};
}

test("formatHeadlessStatus_when_snapshot_available_renders_text_without_rpc", () => {
	const rendered = formatHeadlessStatus(snapshot());

	assert.match(rendered, /^SF Status/);
	assert.match(rendered, /Phase: executing/);
	assert.match(rendered, /Active milestone: M001 - Runtime Hardening/);
	assert.match(rendered, /Dispatch: dispatch execute-task M001\/S01\/T01/);
	assert.match(rendered, /UOK: clear \(healthy\)/);
});
