Files
archie/ui/test/settings-validation.test.ts
T
sam 656d21520f fix(webui): pin the dashboard validators to the control plane's
ui/src/settings/validation.ts hand-mirrors three control-plane validators with
no shared source, and the model-role rule had already diverged: the dashboard
required a stricter regex while the server only asks for a slash, so it refused
values the server accepts.

Add a shared fixture (internal/app/controlplane/testdata/dashboard-validators.json)
that both sides run through their real implementations: a Go test over the
server validators and ui/test/control-plane-validator-parity.test.ts over the
dashboard ones. Either side changing a rule alone now fails the other's test.

Fix the diverged rule to mirror the server's predicate exactly (non-blank role,
model containing a slash), so an empty or whitespace-padded model is judged the
same way the control plane judges it. Regenerate ui/dist and the dev-docs
artifact.
2026-10-02 11:59:17 +10:00

107 lines
3.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
collectIssues,
draftValidators,
validateModelRoles,
validateSchedules,
validateSchedulingPolicy,
type DraftValidator,
} from "../src/settings/validation.ts";
test("scheduling policy refuses a non-positive interval and accepts a positive one", () => {
assert.deepEqual(
validateSchedulingPolicy({
poll_interval: "0s",
label: "archie",
dispatch: { trigger: "assignee" },
}),
[{ path: "poll_interval", label: "Poll interval", message: "Must be longer than zero." }],
);
assert.deepEqual(
validateSchedulingPolicy({
poll_interval: "1m0s",
label: "archie",
dispatch: { trigger: "assignee" },
}),
[],
);
});
test("scheduling policy requires a label only for a label-matching trigger", () => {
const missing = validateSchedulingPolicy({
poll_interval: "30s",
label: "",
dispatch: { trigger: "either" },
});
assert.deepEqual(missing, [
{ path: "label", label: "Label", message: "Required when the trigger is label or either." },
]);
assert.deepEqual(
validateSchedulingPolicy({
poll_interval: "30s",
label: "",
dispatch: { trigger: "assignee" },
}),
[],
);
});
test("schedules refuse an empty id and a duplicate, keeping each row's path", () => {
const issues = validateSchedules([
{ id: "daily" },
{ id: "" },
{ id: "daily" },
]);
assert.deepEqual(issues, [
{ path: "1.id", label: "Schedule 2", message: "ID is required." },
{ path: "2.id", label: "Schedule 3", message: 'Duplicate schedule "daily".' },
]);
assert.deepEqual(validateSchedules([{ id: "daily" }, { id: "weekly" }]), []);
});
test("model roles require provider/model", () => {
assert.deepEqual(validateModelRoles({ builder: "gpt-4o" }), [
{ path: "builder", label: "builder", message: "Use provider/model." },
]);
assert.deepEqual(validateModelRoles({ builder: "openai/gpt-4o" }), []);
// An empty value is refused, not treated as unset: the server refuses it too
// (SystemModelsPage deletes the key rather than storing one).
assert.deepEqual(validateModelRoles({ planner: "" }), [
{ path: "planner", label: "planner", message: "Use provider/model." },
]);
});
test("collectIssues runs only dirty sections' validators and stamps the kind", () => {
const validators: Record<string, DraftValidator | undefined> = {
a: () => [{ path: "x", label: "X", message: "bad" }],
b: () => [{ path: "y", label: "Y", message: "also bad" }],
};
const values: Record<string, unknown> = { a: { x: 1 }, b: { y: 2 } };
const issues = collectIssues(["a", "b"], (kind) => values[kind], validators);
assert.deepEqual(issues, [
{ path: "x", label: "X", message: "bad", kind: "a" },
{ path: "y", label: "Y", message: "also bad", kind: "b" },
]);
// A dirty section with no validator contributes nothing; a clean section is
// never asked.
assert.deepEqual(collectIssues(["a"], (kind) => values[kind], {}), []);
});
test("a dirty scheduling draft is blocked through the real validator map", () => {
const issues = collectIssues(
["scheduling-policy"],
() => ({ poll_interval: "0s", label: "archie", dispatch: { trigger: "assignee" } }),
draftValidators,
);
assert.deepEqual(issues, [
{
path: "poll_interval",
label: "Poll interval",
message: "Must be longer than zero.",
kind: "scheduling-policy",
},
]);
});