summaryrefslogtreecommitdiffhomepage
path: root/src/features/named-agents/logic/validate.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-08-20 19:36:12 +0900
committerAdam Malczewski <[email protected]>2026-08-20 19:36:12 +0900
commitfb7eb3105e1fbbdefdad9348f9132815b5bbe52d (patch)
treedeb95e97a917424ea67470b168b91349a41d1c08 /src/features/named-agents/logic/validate.test.ts
parent63588c3c69b32d180dc78a2cc187cc8aa22ad7e0 (diff)
downloaddispatch-web-fb7eb3105e1fbbdefdad9348f9132815b5bbe52d.tar.gz
dispatch-web-fb7eb3105e1fbbdefdad9348f9132815b5bbe52d.zip
feat(named-agents): sidebar view, synthetic provider, auto-save, snapshot semantics
Implement the frontend of the Named Agents feature (plan §5-§9): - New features/named-agents module: pure logic (types re-exported from @dispatch/wire + transport-contract, validation, provider/model options, snapshot helpers, network normalizers, auto-save status model) + an injected auto-save controller (name debounce, immediate provider/model save, monotonic stale-response guard) + the collapsible sidebar card view. - Store: /named-agents CRUD + boot seed; selectModel(model, snapshot?) persists the raw model WITH the namedAgent snapshot; draft promotion carries it; refreshModel restores ModelResponse.namedAgent. - Chat store setNamedAgent (sends namedAgent on chat.send); Tab.snapshot + setSnapshot (retained across rename/remove, persisted with tabs). - Model selector: synthetic Named Agents provider ALWAYS first; selecting one resolves to the raw model + records a snapshot; a retained snapshot of a renamed/removed agent still displays as unavailable (plan §7). - Composition root wires the view (viewKinds + loaded-modules manifest) + feeds the selector. Tests: logic + controller + selector + app-store CRUD (1246 pass), typecheck 0, biome clean (only pre-existing config infos pending a future migrate), build OK.
Diffstat (limited to 'src/features/named-agents/logic/validate.test.ts')
-rw-r--r--src/features/named-agents/logic/validate.test.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/features/named-agents/logic/validate.test.ts b/src/features/named-agents/logic/validate.test.ts
new file mode 100644
index 0000000..d647354
--- /dev/null
+++ b/src/features/named-agents/logic/validate.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, it } from "vitest";
+import { isUsableModel, isUsableName, nameError, normalizeName } from "./validate";
+
+describe("normalizeName", () => {
+ it("trims surrounding whitespace", () => {
+ expect(normalizeName(" Coding ")).toBe("Coding");
+ });
+
+ it("collapses internal runs of whitespace to one space", () => {
+ expect(normalizeName(" Research Agent ")).toBe("Research Agent");
+ });
+
+ it("collapses an all-whitespace name to empty", () => {
+ expect(normalizeName(" ")).toBe("");
+ });
+});
+
+describe("nameError", () => {
+ it("returns null for a nonempty unique name", () => {
+ expect(nameError("Coding", ["Research", "Fast"])).toBeNull();
+ });
+
+ it("flags an empty/normalized-empty name", () => {
+ expect(nameError("", ["Research"])).toBe("Name is required.");
+ expect(nameError(" ", ["Research"])).toBe("Name is required.");
+ });
+
+ it("flags a name duplicate case-insensitively", () => {
+ expect(nameError("coding", ["Coding"])).toBe("A named agent with this name already exists.");
+ expect(nameError("FAST", ["Fast"])).toBe("A named agent with this name already exists.");
+ });
+
+ it("ignores whitespace when comparing uniqueness", () => {
+ expect(nameError(" coding ", ["Coding "])).toBe(
+ "A named agent with this name already exists.",
+ );
+ });
+});
+
+describe("isUsableName", () => {
+ it("is true only for a unique nonempty name", () => {
+ expect(isUsableName("Coding", ["Research"])).toBe(true);
+ expect(isUsableName("coding", ["Coding"])).toBe(false);
+ expect(isUsableName("", [])).toBe(false);
+ });
+});
+
+describe("isUsableModel", () => {
+ it("accepts a canonical provider/model pair", () => {
+ expect(isUsableModel("opencode-1/claude-sonnet-4.5")).toBe(true);
+ });
+
+ it("rejects a slashless / provider-only value", () => {
+ expect(isUsableModel("opencode-1")).toBe(false);
+ expect(isUsableModel("/claude")).toBe(false);
+ expect(isUsableModel("")).toBe(false);
+ });
+});