import assert from "node:assert/strict";
import { test } from "vitest";

import {
	resolveManifest,
	validateManifestPromptParts,
} from "../unit-context-manifest.js";

test("unit_manifest_promptParts_when_declared_use_canonical_part_names", () => {
	const manifest = resolveManifest("plan-milestone");

	assert.deepEqual(manifest.promptParts, [
		"aiSafety",
		"toolInstructions",
		"environmentContext",
	]);
	assert.deepEqual(validateManifestPromptParts(manifest), []);
});

test("unit_manifest_promptParts_when_legacy_boolean_shape_is_used_rejects_it", () => {
	assert.deepEqual(
		validateManifestPromptParts({
			promptParts: { includeAISafety: true },
		}),
		["promptParts must be an array of canonical part names"],
	);
});

test("unit_manifest_computed_context_when_execution_or_project_planning_units_need_memory_declares_it", () => {
	const expected = {
		"execute-task": ["knowledge", "graph"],
		"reactive-execute": ["knowledge", "graph"],
		"discuss-project": ["knowledge", "graph"],
		"discuss-requirements": ["knowledge", "graph"],
		"research-project": ["knowledge", "graph"],
		"workflow-preferences": ["knowledge"],
	};

	for (const [unitType, computed] of Object.entries(expected)) {
		assert.deepEqual(resolveManifest(unitType).artifacts.computed, computed);
	}
});
