mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-10 00:42:21 +03:00
Lets the combo dashboard builder order models manually/by-provider/by-score/by-name — the choice is stored in config.modelSort and re-applied on load and after adding models. Score-based ordering fetches provider rankings from the existing /api/free-provider-rankings endpoint; the field is inert on execution (client-side hint only). 9/9 focused tests passing (schema, sort logic, and rendered component). Thanks!
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { comboRuntimeConfigSchema, updateComboSchema } from "@/shared/validation/schemas/combo";
|
|
|
|
describe("comboRuntimeConfigSchema.modelSort", () => {
|
|
it("accepts a valid modelSort method", () => {
|
|
const parsed = comboRuntimeConfigSchema.parse({ modelSort: { method: "provider" } });
|
|
assert.deepEqual(parsed.modelSort, { method: "provider" });
|
|
});
|
|
|
|
it("rejects an invalid method", () => {
|
|
assert.throws(() => comboRuntimeConfigSchema.parse({ modelSort: { method: "bogus" } }));
|
|
});
|
|
|
|
it("allows extra keys on the modelSort sub-object (passthrough)", () => {
|
|
const parsed = comboRuntimeConfigSchema.parse({ modelSort: { method: "name", future: 1 } });
|
|
assert.equal(parsed.modelSort?.method, "name");
|
|
});
|
|
|
|
it("is optional", () => {
|
|
const parsed = comboRuntimeConfigSchema.parse({});
|
|
assert.equal(parsed.modelSort, undefined);
|
|
});
|
|
});
|
|
|
|
describe("modelSort persistence", () => {
|
|
it("round-trips through updateComboSchema (models + config)", () => {
|
|
const parsed = updateComboSchema.parse({
|
|
models: [{ id: "m1", kind: "model", model: "openai/gpt", providerId: "openai", weight: 0 }],
|
|
config: { modelSort: { method: "score" } },
|
|
});
|
|
assert.equal(parsed.config?.modelSort?.method, "score");
|
|
});
|
|
|
|
it("passes through comboRuntimeConfigSchema", () => {
|
|
const parsed = comboRuntimeConfigSchema.parse({ modelSort: { method: "provider" } });
|
|
assert.equal(parsed.modelSort?.method, "provider");
|
|
});
|
|
});
|