| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { applyChanges } from "./definition.ts"; |
| 5 | import { clampTier, effortOf, effortPlan, higherEffort, lowerEffort, reasoningEffort } from "./routing.ts"; |
| 6 | import { TEMPLATE_IDS } from "./templates.ts"; |
| 7 | import { runTurn } from "./turn.ts"; |
| 8 | |
| 9 | const input = { handle: "ship", display_name: "Ship", role: "Release manager", title: "Release Manager", instructions: "Ship releases." }; |
| 10 | |
| 11 | test("each setting moves the starting tier, the reasoning and a session's steps together", () => { |
| 12 | assert.deepEqual(effortPlan("low", "large"), { level: "low", start: "small", steps: 5 }); |
| 13 | assert.deepEqual(effortPlan("medium", "large"), { level: "medium", start: "large", steps: 8 }); |
| 14 | assert.deepEqual(effortPlan("medium", "small"), { level: "medium", start: "small", steps: 8 }, "medium keeps where the work starts"); |
| 15 | assert.deepEqual(effortPlan("high", "small"), { level: "high", start: "large", steps: 10 }, "high starts on large at least"); |
| 16 | assert.deepEqual(effortPlan("high", "frontier"), { level: "high", start: "frontier", steps: 10 }); |
| 17 | assert.deepEqual(effortPlan("max", "small"), { level: "max", start: "frontier", steps: 12 }); |
| 18 | }); |
| 19 | |
| 20 | test("auto runs at medium, and works harder on a session someone had to steer", () => { |
| 21 | assert.equal(effortPlan("auto", "small").level, "medium"); |
| 22 | assert.equal(effortPlan(undefined, "large").level, "medium", "no setting is auto"); |
| 23 | assert.deepEqual(effortPlan("auto", "large", { raised: true }), { level: "high", start: "large", steps: 10 }); |
| 24 | // An explicit setting is never raised. |
| 25 | assert.equal(effortPlan("low", "large", { raised: true }).level, "low"); |
| 26 | }); |
| 27 | |
| 28 | test("the floor and the ceiling still hold over effort", () => { |
| 29 | assert.equal(clampTier(effortPlan("max", "small").start, null, "large"), "large", "the ceiling is the spending rail"); |
| 30 | assert.equal(clampTier(effortPlan("low", "large").start, "large", null), "large", "a floor lifts low effort's small tier"); |
| 31 | }); |
| 32 | |
| 33 | test("reasoning is sent only to g1t's tiers whose model takes it", () => { |
| 34 | assert.equal(reasoningEffort("high", { capabilities: ["effort", "tools"] }, false), "high"); |
| 35 | assert.equal(reasoningEffort("high", { capabilities: ["tools"] }, false), null, "a model without effort"); |
| 36 | assert.equal(reasoningEffort("low", {}, false), "low", "a route from configuration says nothing, so it is sent"); |
| 37 | assert.equal(reasoningEffort("max", { capabilities: ["effort"] }, true), null, "never to a model the workspace's route names"); |
| 38 | }); |
| 39 | |
| 40 | test("levels order and step", () => { |
| 41 | assert.equal(higherEffort(null, "medium"), "medium"); |
| 42 | assert.equal(higherEffort("high", "medium"), "high"); |
| 43 | assert.equal(lowerEffort("max"), "high"); |
| 44 | assert.equal(lowerEffort("low"), null); |
| 45 | assert.equal(effortOf({ effort: "max" }), "max"); |
| 46 | assert.equal(effortOf({ effort: "enormous" as never }), "auto"); |
| 47 | assert.equal(effortOf(null), "auto"); |
| 48 | }); |
| 49 | |
| 50 | test("effort is part of the definition, and only the five settings are taken", () => { |
| 51 | const made = applyChanges(null, { ...input, routing: { effort: "high" } }, TEMPLATE_IDS); |
| 52 | assert.ok(made.ok); |
| 53 | if (!made.ok) return; |
| 54 | assert.equal(made.value.routing.effort, "high"); |
| 55 | // Changing other routing keeps it. |
| 56 | const next = applyChanges(made.value, { routing: { ceiling: "large" } }, TEMPLATE_IDS); |
| 57 | assert.ok(next.ok && next.value.routing.effort === "high"); |
| 58 | const bad = applyChanges(made.value, { routing: { effort: "turbo" as never } }, TEMPLATE_IDS); |
| 59 | assert.ok(!bad.ok); |
| 60 | if (!bad.ok) assert.match(bad.message, /auto, low, medium, high or max/); |
| 61 | }); |
| 62 | |
| 63 | test("a turn sends the effort as output_config, and nothing when there is none", async () => { |
| 64 | const sent: Record<string, unknown>[] = []; |
| 65 | const send = async (body: Record<string, unknown>) => { |
| 66 | sent.push(body); |
| 67 | return { content: [{ type: "text", text: "ok" }], usage: { input_tokens: 1, output_tokens: 1 } }; |
| 68 | }; |
| 69 | await runTurn(send, { model: "m", system: "s", messages: [{ role: "user", content: "hi" }], tools: null, price: null, effort: "low" }); |
| 70 | await runTurn(send, { model: "m", system: "s", messages: [{ role: "user", content: "hi" }], tools: null, price: null }); |
| 71 | assert.deepEqual(sent[0].output_config, { effort: "low" }); |
| 72 | assert.equal(sent[1].output_config, undefined); |
| 73 | }); |