import test from "node:test"; import assert from "node:assert/strict"; import { buildTaskContext } from "../../../tools/web/task-context-lib.mjs"; import { validateContextBundle } from "../../../tools/web/context-governance.mjs"; test("current context satisfies document, task-card, and pointer budgets", () => { const bundle = buildTaskContext(); const result = validateContextBundle(bundle); assert.deepEqual(result.violations, []); assert.ok(result.report.totalTokens <= 3500); }); test("task cards cannot smuggle full plans or history into the default context", () => { const bundle = buildTaskContext(); const taskSource = `${bundle.sources.taskSource}\nnext-task-plan.json\n`; const result = validateContextBundle({ ...bundle, sources: { ...bundle.sources, taskSource }, }); assert.ok(result.violations.some(({ code }) => code === "FORBIDDEN_CONTEXT_REFERENCE")); }); test("governance rejects forged selection totals and unaudited exclusions", () => { const bundle = buildTaskContext(); const forged = { ...bundle, context: { ...bundle.context, inputPaths: ["tools/web/generated/M16-GAP-00022.py"], inputSelection: { ...bundle.context.inputSelection, selected: [{ path: "tools/web/generated/M16-GAP-00022.py", bytes: 9000, tokens: 1 }], excluded: [ { path: "tests/files/web/generated/M16-GAP-00022-datablock-Sound.blend", reason: "FORGED_REASON" }, { path: "tests/golden/M16-GAP-00022/" }, ], totals: { files: 1, bytes: 9000, tokens: 2250 }, }, }, }; const result = validateContextBundle(forged); assert.ok(result.violations.some(({ code }) => code === "EVIDENCE_BYTES_OVER_BUDGET")); assert.ok(result.violations.some(({ code }) => code === "CONTEXT_REMAINING_BYTES_OVER_BUDGET")); assert.ok(result.violations.some(({ code }) => code === "INPUT_EXCLUSION_REASON_MISSING")); assert.ok(result.violations.some(({ code }) => code === "INPUT_EXCLUSION_REASON_UNKNOWN")); assert.ok(result.violations.some(({ code }) => code === "INPUT_SELECTION_ENTRY_INVALID")); });