Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 deriveAvailableInstanceId,
5 getProviderIdentityDraft,
6 resolveAcpRegistryWizardNavigation,
7 resolveWizardNavigation,
8 updateProviderIdentityDraft,
9} from "./AddProviderInstanceDialog.logic";
10
11describe("resolveWizardNavigation", () => {
12 const invalidId = { instanceIdError: "Instance ID is required." };
13
14 // regression: #2813 the wizard advanced past an invalid instance id
15 it("blocks Next from Identity to Config while the instance id is invalid", () => {
16 expect(resolveWizardNavigation(1, 2, 3, invalidId)).toEqual({
17 kind: "blocked",
18 step: 1,
19 error: "Instance ID is required.",
20 });
21 });
22
23 it("stops a direct Driver-to-Config skip at Identity and surfaces its error", () => {
24 expect(resolveWizardNavigation(0, 2, 3, invalidId)).toEqual({
25 kind: "blocked",
26 step: 1,
27 error: "Instance ID is required.",
28 });
29 });
30});
31
32describe("ACP Registry wizard", () => {
33 it("requires a prepared result or valid manual configuration before Identity", () => {
34 expect(
35 resolveAcpRegistryWizardNavigation(0, 1, {
36 instanceIdError: null,
37 selectionError: "Select an ACP or configure one manually.",
38 }),
39 ).toEqual({
40 kind: "blocked",
41 step: 0,
42 error: "Select an ACP or configure one manually.",
43 });
44
45 expect(
46 resolveAcpRegistryWizardNavigation(0, 1, {
47 instanceIdError: null,
48 selectionError: null,
49 }),
50 ).toEqual({ kind: "navigate", step: 1 });
51 });
52
53 it("derives a collision-free instance id without exceeding the slug limit", () => {
54 const derive = (label: string) => `acpRegistry_${label}`;
55 const existing = new Set(["acpRegistry_gemini", "acpRegistry_gemini_2"]);
56
57 expect(deriveAvailableInstanceId(derive, "gemini", existing)).toBe("acpRegistry_gemini_3");
58
59 const longBase = `acpRegistry_${"a".repeat(48)}`;
60 expect(deriveAvailableInstanceId(() => longBase, "ignored", new Set([longBase]))).toHaveLength(
61 62,
62 );
63 });
64
65 it("keeps registry-prefilled identity separate from other drivers", () => {
66 const registryDrafts = updateProviderIdentityDraft({}, "acpRegistry", {
67 label: "Gemini CLI",
68 instanceIdOverride: "acpRegistry_gemini_cli",
69 });
70
71 expect(getProviderIdentityDraft(registryDrafts, "codex")).toEqual({
72 label: "",
73 accentColor: "",
74 instanceIdOverride: null,
75 });
76
77 const drafts = updateProviderIdentityDraft(registryDrafts, "codex", {
78 label: "Work",
79 instanceIdOverride: "codex_work",
80 });
81 expect(getProviderIdentityDraft(drafts, "acpRegistry")).toMatchObject({
82 label: "Gemini CLI",
83 instanceIdOverride: "acpRegistry_gemini_cli",
84 });
85 });
86});