Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

acpRegistry.test.ts

183 lines6.0 KB

1import { describe, expect, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3​
4import {
5 AcpRegistryImportSessionInput,
6 AcpRegistryManagedBinaryUninstallInput,
7 AcpRegistryManagedBinaryUninstallResult,
8 AcpRegistryOperationError,
9 AcpRegistryPrepareResult,
10 AcpRegistryProbeResult,
11 AcpRegistrySearchAgent,
12 AcpRegistrySearchInput,
13 officialAcpRegistryIconUrlForAgentId,
14 resolveOfficialAcpRegistryIconUrl,
15} from "./acpRegistry.ts";
16​
17const decodeSearchInput = Schema.decodeUnknownSync(AcpRegistrySearchInput);
18const decodeImportSessionInput = Schema.decodeUnknownSync(AcpRegistryImportSessionInput);
19const decodePrepareResult = Schema.decodeUnknownSync(AcpRegistryPrepareResult);
20const decodeSearchAgent = Schema.decodeUnknownSync(AcpRegistrySearchAgent);
21const decodeUninstallInput = Schema.decodeUnknownSync(AcpRegistryManagedBinaryUninstallInput);
22const decodeUninstallResult = Schema.decodeUnknownSync(AcpRegistryManagedBinaryUninstallResult);
23const decodeProbeResult = Schema.decodeUnknownSync(AcpRegistryProbeResult);
24const decodeOperationError = Schema.decodeUnknownSync(AcpRegistryOperationError);
25​
26describe("ACP Registry contracts", () => {
27 it("accepts only official Registry icon URLs and safe agent IDs", () => {
28 expect(officialAcpRegistryIconUrlForAgentId("antigravity-acp")).toBe(
29 "https://cdn.agentclientprotocol.com/registry/v1/latest/antigravity-acp.svg",
30 );
31 expect(officialAcpRegistryIconUrlForAgentId("../antigravity-acp")).toBeNull();
32 expect(
33 resolveOfficialAcpRegistryIconUrl(
34 "https://cdn.agentclientprotocol.com/registry/v1/latest/pi-acp.svg",
35 ),
36 ).toBe("https://cdn.agentclientprotocol.com/registry/v1/latest/pi-acp.svg");
37 expect(
38 resolveOfficialAcpRegistryIconUrl(
39 "https://cdn.agentclientprotocol.com.evil/registry/v1/latest/pi-acp.svg",
40 ),
41 ).toBeNull();
42 expect(
43 resolveOfficialAcpRegistryIconUrl(
44 "https://user@cdn.agentclientprotocol.com/registry/v1/latest/pi-acp.svg",
45 ),
46 ).toBeNull();
47 });
48​
49 it("decodes bounded search and prepare payloads", () => {
50 expect(decodeSearchInput({ query: " codex " })).toEqual({
51 query: "codex",
52 });
53 expect(decodeSearchInput({ query: "", limit: 512 })).toEqual({ query: "", limit: 512 });
54 expect(
55 decodePrepareResult({
56 agentId: "codex-acp",
57 version: "1.2.0",
58 distribution: "npx",
59 prepared: true,
60 }),
61 ).toMatchObject({ agentId: "codex-acp", distribution: "npx", prepared: true });
62 });
63​
64 it("rejects oversized queries and result metadata", () => {
65 expect(() => decodeSearchInput({ query: "x".repeat(121) })).toThrow();
66 expect(() => decodeSearchInput({ query: "", limit: 0 })).toThrow();
67 expect(() => decodeSearchInput({ query: "", limit: 513 })).toThrow();
68 expect(() =>
69 decodeSearchAgent({
70 id: "agent",
71 name: "Agent",
72 version: "1.0.0",
73 description: "x".repeat(1_025),
74 authors: [],
75 license: null,
76 website: null,
77 repository: null,
78 icon: null,
79 distribution: "binary",
80 integrity: "sha256",
81 }),
82 ).toThrow();
83 });
84​
85 it("decodes managed binary uninstall payloads and rejects unsafe agent IDs", () => {
86 expect(decodeUninstallInput({ agentId: " example-agent " })).toEqual({
87 agentId: "example-agent",
88 });
89 expect(decodeUninstallResult({ agentId: "example-agent", removed: false })).toEqual({
90 agentId: "example-agent",
91 removed: false,
92 });
93 expect(() => decodeUninstallInput({ agentId: "../example-agent" })).toThrow();
94 });
95​
96 it("decodes bounded native session import metadata", () => {
97 expect(
98 decodeImportSessionInput({
99 instanceId: "acpRegistry_example",
100 projectId: "project-1",
101 sessionId: "native-session-1",
102 title: " Native session ",
103 updatedAt: " 2026-08-23T00:00:00Z ",
104 }),
105 ).toEqual({
106 instanceId: "acpRegistry_example",
107 projectId: "project-1",
108 sessionId: "native-session-1",
109 title: "Native session",
110 updatedAt: "2026-08-23T00:00:00Z",
111 });
112 expect(() =>
113 decodeImportSessionInput({
114 instanceId: "acpRegistry_example",
115 projectId: "project-1",
116 sessionId: "native-session-1",
117 title: "x".repeat(1_025),
118 }),
119 ).toThrow();
120 });
121​
122 it("decodes valid probe metadata and rejects oversized or invalid payloads", () => {
123 const authMethod = {
124 id: "oauth",
125 name: "Browser login",
126 description: null,
127 type: "agent",
128 };
129 expect(
130 decodeProbeResult({
131 instanceId: "acpRegistry_example",
132 ready: true,
133 icon: null,
134 authMethods: [authMethod],
135 models: [{ id: "default", name: "Default", description: "Agent-selected model" }],
136 currentModelId: "default",
137 configOptions: [],
138 }),
139 ).toMatchObject({ ready: true, currentModelId: "default" });
140 expect(() =>
141 decodeProbeResult({
142 instanceId: "acpRegistry_example",
143 ready: true,
144 icon: null,
145 authMethods: Array.from({ length: 33 }, () => authMethod),
146 models: [],
147 currentModelId: null,
148 }),
149 ).toThrow();
150 expect(() =>
151 decodeProbeResult({
152 instanceId: "acpRegistry_example",
153 ready: true,
154 icon: null,
155 authMethods: [{ ...authMethod, type: "passive" }],
156 models: [],
157 currentModelId: null,
158 }),
159 ).toThrow();
160 expect(() =>
161 decodeProbeResult({
162 instanceId: "acpRegistry_example",
163 ready: true,
164 icon: null,
165 authMethods: [],
166 models: Array.from({ length: 257 }, () => ({
167 id: "default",
168 name: "Default",
169 description: null,
170 })),
171 currentModelId: null,
172 }),
173 ).toThrow();
174 expect(() =>
175 decodeOperationError({
176 _tag: "AcpRegistryOperationError",
177 reason: "authentication_failed",
178 message: "Authentication required.",
179 authMethods: Array.from({ length: 33 }, () => authMethod),
180 }),
181 ).toThrow();
182 });
183});