85 lines
3.6 KiB
TypeScript
85 lines
3.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
UltraMode,
|
|
buildUltraGuidance,
|
|
formatUltraGuideline,
|
|
formatUltraGuidelineLine,
|
|
parseUltraCommand,
|
|
} from "../src/ultra-mode.ts";
|
|
|
|
test("the size guideline maps each value to its child target and unrestricted gives no advice", () => {
|
|
assert.equal(formatUltraGuideline("small"), "small (aim for fewer than 5 children)");
|
|
assert.equal(formatUltraGuideline("medium"), "medium (aim for fewer than 10 children)");
|
|
assert.equal(formatUltraGuideline("large"), "large (aim for fewer than 50 children)");
|
|
assert.equal(formatUltraGuideline("unrestricted"), "unrestricted (no child-count advice)");
|
|
assert.doesNotMatch(formatUltraGuideline("unrestricted"), /fewer than/);
|
|
});
|
|
|
|
test("the guideline line renders the caller's load-time values and never re-reads the environment", () => {
|
|
const previous = process.env.PI_SUBAGENT_ULTRA_GUIDELINE;
|
|
try {
|
|
process.env.PI_SUBAGENT_ULTRA_GUIDELINE = "small";
|
|
assert.equal(
|
|
formatUltraGuidelineLine("large", 64),
|
|
"Size guideline: large (aim for fewer than 50 children); hard caps: ≤ 64 steps, ≤ 64 items per each-step, ≤ 256 children per run.",
|
|
);
|
|
assert.match(
|
|
formatUltraGuidelineLine("unrestricted", 8),
|
|
/Size guideline: unrestricted \(no child-count advice\); hard caps: ≤ 64 steps, ≤ 8 items per each-step, ≤ 256 children per run\./,
|
|
);
|
|
process.env.PI_SUBAGENT_ULTRA_GUIDELINE = "bogus";
|
|
assert.equal(
|
|
formatUltraGuidelineLine("medium", 32),
|
|
"Size guideline: medium (aim for fewer than 10 children); hard caps: ≤ 64 steps, ≤ 32 items per each-step, ≤ 256 children per run.",
|
|
);
|
|
} finally {
|
|
if (previous === undefined) delete process.env.PI_SUBAGENT_ULTRA_GUIDELINE;
|
|
else process.env.PI_SUBAGENT_ULTRA_GUIDELINE = previous;
|
|
}
|
|
});
|
|
|
|
test("the guidance names the heuristics, every pattern mapping, the guideline, caps, and how to consume a run", () => {
|
|
const guidance = buildUltraGuidance("medium", 32);
|
|
for (const expected of [
|
|
/`ultra` tool/,
|
|
/larger than one agent can hold in context/,
|
|
/same step must run across many items/,
|
|
/cross-checked by another agent/,
|
|
/Fan-out and synthesize → an each-step/,
|
|
/Adversarial verification → a verify step that needs the producer/,
|
|
/Generate and filter → parallel producer steps/,
|
|
/Tournament → pre-expanded competitor steps/,
|
|
/Classify-and-act and loop-until-done are not expressible in one plan/,
|
|
/chain runs instead — one run to understand, one to change, one to verify/,
|
|
/Size guideline: medium \(aim for fewer than 10 children\)/,
|
|
/Hard caps: ≤ 64 steps, ≤ 32 items per each-step, ≤ 256 children per run/,
|
|
/wait for it with `subagent_jobs/,
|
|
/last succeeded step's bounded output — the consolidated answer/,
|
|
]) {
|
|
assert.match(guidance, expected);
|
|
}
|
|
assert.equal(buildUltraGuidance("medium", 32), guidance);
|
|
});
|
|
|
|
test("mode state starts from its default, toggles, and resets", () => {
|
|
const mode = new UltraMode(false);
|
|
assert.equal(mode.on, false);
|
|
mode.set(true);
|
|
assert.equal(mode.on, true);
|
|
mode.reset();
|
|
assert.equal(mode.on, false);
|
|
assert.equal(new UltraMode(true).on, true);
|
|
});
|
|
|
|
test("/ultra parses bare status, on, off, and usage errors", () => {
|
|
assert.deepEqual(parseUltraCommand(""), { kind: "status" });
|
|
assert.deepEqual(parseUltraCommand(" "), { kind: "status" });
|
|
assert.deepEqual(parseUltraCommand("status"), { kind: "status" });
|
|
assert.deepEqual(parseUltraCommand("on"), { kind: "set", enabled: true });
|
|
assert.deepEqual(parseUltraCommand(" off "), { kind: "set", enabled: false });
|
|
for (const args of ["on extra", "off extra", "ON", "sometimes"]) {
|
|
assert.deepEqual(parseUltraCommand(args), { kind: "usage" });
|
|
}
|
|
});
|