Fix wave chunk 2: thinking levels auto-populate everywhere; legacy records show the resolved level
- thinking-default.ts: defaultOrderLevel (the ordering's first supported, the client twin of the server's defaultThinkingLevel) + populateLevel (an explicit level always rides; the WRITE clamps server-side, bd68486, and the cross-surface signal re-reads the clamped truth; only absence populates from the ordering) + THINKING_LABEL shared. - Setup dialog (item 5): per-slot thinking selectors pre-populated with the default-order level per picked model, editable; disabled until the model pick; prefillLevelFromPin keeps a stored level as-is and populates legacy pins from the ordering. - Composer + agent section (item 6): fresh model picks always write a level: the stored one rides, absence populates; the unset state can never re-enter. Item 4: records with a model but no stored level display the RESOLVED level (ordering's first supported) instead of a dash, in the composer pill and the settings slot triggers/menus. - Item 7 verified live end-to-end: an explicit level rides into the PUT, the server clamps, the signal re-reads, the pill shows the clamped truth.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { parseModelsRefusal } from "../components/chat.tsx";
|
||||
import { prefillFromSlots, setupStage } from "../components/setup-dialog.tsx";
|
||||
import { prefillFromSlots, prefillLevelFromPin, setupStage } from "../components/setup-dialog.tsx";
|
||||
import { isModelsRefusal, modelsNotConfigured } from "../src/core/settings.ts";
|
||||
import type { ModelCatalogEntry, ModelSlotName } from "../src/core/index.ts";
|
||||
|
||||
@@ -90,6 +90,24 @@ describe("prefillFromSlots — the SetupDialog prefill (BYOK wave)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("prefillLevelFromPin — the setup dialog's level prefill (chunk 2)", () => {
|
||||
const entry = (levels: string[]) =>
|
||||
({ id: "m", name: "M", provider: "p", reasoning: true, input: ["text"], supportedLevels: levels, cost: { input: 1, output: 1, cacheRead: 0, cacheWrite: 0 }, contextWindow: 1000, maxTokens: 1000 }) as never;
|
||||
|
||||
it("a stored level the pinned model still supports prefills as-is", () => {
|
||||
assert.equal(prefillLevelFromPin(entry(["low", "high"]), { thinkingLevel: "high" }), "high");
|
||||
});
|
||||
|
||||
it("a stored level the model LOST rides as-is — Save clamps server-side (bd68486)", () => {
|
||||
assert.equal(prefillLevelFromPin(entry(["minimal", "medium"]), { thinkingLevel: "xhigh" }), "xhigh");
|
||||
});
|
||||
|
||||
it("a legacy pin with no stored level prefills the ordering's level", () => {
|
||||
assert.equal(prefillLevelFromPin(entry(["low", "medium"]), {}), "medium");
|
||||
assert.equal(prefillLevelFromPin(entry(["low", "medium"]), null), "medium");
|
||||
});
|
||||
});
|
||||
|
||||
describe("setupStage — unchanged by the BYOK wave", () => {
|
||||
it("keys first (owner ordering), pickers when a provider is keyed", () => {
|
||||
assert.equal(setupStage(null), "keys");
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* The default-order resolution, client-side (chunk 2): the UI populates a
|
||||
* fresh model pick's thinking level with the SAME level the engine build
|
||||
* runs for an unset record — first DEFAULT_THINKING_ORDER entry the model
|
||||
* supports (Platform's interlude bd68486 moved the ordering into the core
|
||||
* barrel exactly for this). These tests pin the helper against the
|
||||
* server's defaultThinkingLevel semantics (src/agent/models.ts).
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { DEFAULT_THINKING_ORDER } from "../src/core/settings.ts";
|
||||
import { defaultOrderLevel, populateLevel } from "../components/thinking-default.ts";
|
||||
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
||||
|
||||
const tl = (levels: string[]) => levels as ThinkingLevel[];
|
||||
|
||||
describe("defaultOrderLevel — the ordering's first supported", () => {
|
||||
it("a reasoning model taking the ladder's head (medium) resolves medium", () => {
|
||||
assert.equal(defaultOrderLevel(tl(["minimal", "low", "medium", "high"])), "medium");
|
||||
});
|
||||
|
||||
it("a model without medium falls to the NEXT order entry it supports", () => {
|
||||
// order: medium, low, high, minimal, xhigh, max — low wins here
|
||||
assert.equal(defaultOrderLevel(tl(["minimal", "low", "high"])), "low");
|
||||
assert.equal(defaultOrderLevel(tl(["high", "xhigh", "max"])), "high");
|
||||
});
|
||||
|
||||
it("a non-reasoning model (pi reports exactly [off]) resolves off", () => {
|
||||
assert.equal(defaultOrderLevel(tl(["off"])), "off");
|
||||
});
|
||||
|
||||
it("empty support resolves off (the server's fallback), never crashes", () => {
|
||||
assert.equal(defaultOrderLevel(tl([])), "off");
|
||||
});
|
||||
|
||||
it("the full ladder resolves its head", () => {
|
||||
const full = tl(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
||||
assert.equal(defaultOrderLevel(full), DEFAULT_THINKING_ORDER[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("populateLevel — an explicit pick always rides; absence populates", () => {
|
||||
it("a supported explicit level rides unchanged", () => {
|
||||
assert.equal(populateLevel("high", tl(["low", "high"])), "high");
|
||||
});
|
||||
|
||||
it("an UNSUPPORTED explicit level STILL rides — the write clamps server-side (bd68486), the signal re-reads the clamped truth", () => {
|
||||
// xhigh rides even though unsupported here; never re-populated client-side
|
||||
assert.equal(populateLevel("xhigh", tl(["minimal", "medium", "high"])), "xhigh");
|
||||
});
|
||||
|
||||
it("no explicit level populates the ordering's level (the fresh-pick case)", () => {
|
||||
assert.equal(populateLevel(undefined, tl(["low", "high"])), "low");
|
||||
});
|
||||
|
||||
it("off as an explicit level rides when supported", () => {
|
||||
assert.equal(populateLevel("off", tl(["off"])), "off");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user