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.
This commit is contained in:
sam committed 2026-10-02 11:59:17 +10:00
1 parent 92eabbed17
commit 656d21520f
8 files changed
+427 -68

No files matched your search

+18 -8
View File
@@ -8,6 +8,13 @@ import { parseGoDuration } from "../components/ui/duration-input/duration.ts";
* operator sees the reason beside the field. The rules mirror the server's
* (internal/app/controlplane), and the same map is read by the store, the
* save bar and the pages' inline messages, so a rule is written once.
*
* A hand-written mirror drifts, which is why every rule here is pinned to the
* server's by internal/app/controlplane/testdata/dashboard-validators.json:
* a Go test runs the server validators over that fixture and this file's
* tests run these validators over the same cases, so changing one side alone
* fails a test (archie-core-ui-dashboard-3). Add a case to the fixture, not to
* one side only.
*/
/** One field that must be fixed before its section can be saved. `path` is the
@@ -95,17 +102,20 @@ export function validateSchedules(value: unknown): FieldIssue[] {
return issues;
}
/** The runtime resolves a role as provider/model, so a value with no "/" is
* one the server will refuse. */
const ROLE_MODEL = /^[^/\s]+\/\S+$/;
/** validateModelRoles mirrors validateModelRoles: every role names a model as
* provider/model. */
/** validateModelRoles mirrors validateModelRoles exactly: the server's whole
* predicate is `strings.TrimSpace(role) == "" || !strings.Contains(model,
* "/")`. It deliberately does not impose a stricter shape, such as requiring
* a non-space provider before the slash -- the dashboard refusing a value the
* server would accept blocks a legitimate save. */
export function validateModelRoles(value: unknown): FieldIssue[] {
const roles = (value ?? {}) as Record<string, string>;
return Object.entries(roles)
.filter(([, model]) => model && !ROLE_MODEL.test(model))
.map(([role]) => ({ path: role, label: role, message: "Use provider/model." }));
.filter(([role, model]) => !role.trim() || !String(model).includes("/"))
.map(([role]) => ({
path: role,
label: role.trim() || "Role",
message: role.trim() ? "Use provider/model." : "Role name is required.",
}));
}
/** The rules the store applies to a dirty draft, keyed by resource kind. */