Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/model-choice.test.mjs
iris 479cdd6efb swarm-ui: say why the model dropdown has no models, and let it retry
The model list read swallowed every failure, so a swarm that timed out
answering /api/models looked the same as one with no models: the dropdown
held only the agent's own value and "other…", with nothing to say why.
The failure now shows as a warning with the controller's reason and a
retry button, and the answer is read through a parser that ignores any
shape but a list of names.
2026-11-24 10:39:29 +01:00

54 lines
1.8 KiB
JavaScript

// The model dropdown: which names it lists itself and when the text box opens.
// Run by `npm test`, which imports the `.ts` module as it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
CUSTOM_MODEL,
isListedModel,
modelOptions,
modelSelectValue,
parseKnownModels,
} from "../src/agent/detail/model-choice.ts";
const KNOWN = ["haiku", "opus"];
test("the options are the agent's own, the known models and other", () => {
assert.deepEqual(
modelOptions(KNOWN).map((o) => o.value),
["", "haiku", "opus", CUSTOM_MODEL],
);
assert.deepEqual(
modelOptions([]).map((o) => o.value),
["", CUSTOM_MODEL],
);
});
test("the agent's own value and the known models are listed", () => {
assert.ok(isListedModel("", KNOWN));
assert.ok(isListedModel("opus", KNOWN));
assert.ok(!isListedModel("claude-opus-4-8", KNOWN));
});
test("a name the list lacks selects the custom entry", () => {
assert.equal(modelSelectValue("claude-opus-4-8", KNOWN, false), CUSTOM_MODEL);
assert.equal(modelSelectValue("opus", KNOWN, false), "opus");
assert.equal(modelSelectValue("", KNOWN, false), "");
});
test("an open custom entry stays selected while its name is empty or listed", () => {
assert.equal(modelSelectValue("", KNOWN, true), CUSTOM_MODEL);
assert.equal(modelSelectValue("opus", KNOWN, true), CUSTOM_MODEL);
});
test("the model list is read from the answer, and any other shape is none", () => {
assert.deepEqual(parseKnownModels({ models: ["opus", "sonnet"] }), [
"opus",
"sonnet",
]);
assert.deepEqual(parseKnownModels({ models: ["opus", "", 3, null] }), [
"opus",
]);
assert.deepEqual(parseKnownModels({}), []);
assert.deepEqual(parseKnownModels({ models: "opus" }), []);
assert.deepEqual(parseKnownModels(null), []);
});