59 lines
2.6 KiB
JavaScript
59 lines
2.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { buildTaskContext, CONTEXT_LIMITS } 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.estimatedContextTokens <= CONTEXT_LIMITS.contextTokens);
|
|
assert.ok(result.report.serializedContextTokens <= CONTEXT_LIMITS.contextEnvelopeTokens);
|
|
});
|
|
|
|
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"));
|
|
});
|
|
|
|
test("governance reports a serialized context envelope that exceeds its reserved budget", () => {
|
|
const bundle = buildTaskContext();
|
|
const oversized = {
|
|
...bundle,
|
|
context: { ...bundle.context, commands: ["node "+"x".repeat(6000)] },
|
|
};
|
|
const result = validateContextBundle(oversized);
|
|
assert.ok(result.violations.some(({ code }) => code === "CONTEXT_ENVELOPE_OVER_BUDGET"));
|
|
});
|