/**
 * detector-production-plateau.test.mjs — M048/S03 plateau contracts.
 *
 * Purpose: prove long autonomous runs with no productive delta are detected
 * without flagging normal productive work.
 */
import assert from "node:assert/strict";
import { test } from "vitest";

import { detectProductionPlateau } from "../detectors/production-plateau.js";

test("detectProductionPlateau_when_missing_metrics_degrades_cleanly", () => {
	const result = detectProductionPlateau(null);

	assert.equal(result.stuck, false);
	assert.equal(result.reason, "missing-metrics");
});

test("detectProductionPlateau_when_unchanged_15_and_total_40_fires", () => {
	const result = detectProductionPlateau(
		{ totalCycles: 40, unchangedCycles: 15 },
		{ unitId: "M048/S03/T03" },
	);

	assert.equal(result.stuck, true);
	assert.equal(result.reason, "production-plateau");
	assert.equal(result.signature.unitId, "M048/S03/T03");
	assert.equal(result.signature.totalCycles, 40);
	assert.equal(result.signature.unchangedCycles, 15);
});

test("detectProductionPlateau_when_total_below_threshold_does_not_fire", () => {
	const result = detectProductionPlateau({
		totalCycles: 39,
		unchangedCycles: 20,
	});

	assert.equal(result.stuck, false);
});

test("detectProductionPlateau_when_unchanged_below_threshold_does_not_fire", () => {
	const result = detectProductionPlateau({
		totalCycles: 60,
		unchangedCycles: 14,
	});

	assert.equal(result.stuck, false);
});

test("detectProductionPlateau_when_productive_cycles_exist_does_not_fire", () => {
	const result = detectProductionPlateau({
		totalCycles: 80,
		unchangedCycles: 40,
		productiveCycles: 1,
	});

	assert.equal(result.stuck, false);
});

test("detectProductionPlateau_when_artifacts_changed_does_not_fire", () => {
	const result = detectProductionPlateau({
		totalCycles: 80,
		unchangedCycles: 40,
		filesChanged: 2,
	});

	assert.equal(result.stuck, false);
});
