Open History to see the last commit
1import {
2 AcpRegistryOperationError,
3 AcpRegistrySettings,
4 ProviderInstanceId,
5} from "@t3tools/contracts";
6import { describe, expect, it } from "@effect/vitest";
7import * as Effect from "effect/Effect";
8import * as Option from "effect/Option";
9import * as Schema from "effect/Schema";
10
11import { AcpRegistryCatalog, type AcpRegistryInspection } from "../acp/AcpRegistrySupport.ts";
12import {
13 acpRegistrySnapshotReadiness,
14 applyAcpRegistryAvailableCommands,
15 applyAcpRegistryLiveConfiguration,
16 buildCheckedAcpRegistrySnapshot,
17 checkAcpRegistryProviderReadiness,
18 checkAcpRegistryProviderStatus,
19} from "./AcpRegistryDriver.ts";
20
21const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
22const identity = {
23 instanceId: ProviderInstanceId.make("acpRegistry_test"),
24 displayName: "Test ACP",
25 accentColor: undefined,
26 continuationKey: "acpRegistry:instance:acpRegistry_test",
27};
28const noSessionManagement = {
29 canList: false,
30 canLoad: false,
31 canResume: false,
32 canLogout: false,
33 canDelete: false,
34 canConfigureProviders: false,
35} as const;
36
37function catalogWithInspection(inspection: AcpRegistryInspection): AcpRegistryCatalog["Service"] {
38 return {
39 search: () => Effect.die("unused search"),
40 prepare: () => Effect.die("unused prepare"),
41 inspect: () => Effect.succeed(inspection),
42 resolve: () => Effect.die("unused resolve"),
43 uninstallManagedBinary: () => Effect.die("unused uninstall"),
44 };
45}
46
47describe("acpRegistrySnapshotReadiness", () => {
48 it("treats a live empty command advertisement as an authoritative replacement", () => {
49 const provider = buildCheckedAcpRegistrySnapshot({
50 ...identity,
51 settings: decodeSettings({ agentId: "test-agent" }),
52 checkedAt: "2026-08-13T10:00:00.000Z",
53 inspection: {
54 status: "ready",
55 agentId: "test-agent",
56 version: "1.0.0",
57 distribution: "npx",
58 },
59 probe: {
60 probe: {
61 instanceId: identity.instanceId,
62 ready: true,
63 icon: null,
64 authMethods: [],
65 models: [],
66 currentModelId: null,
67 configOptions: [],
68 sessionManagement: noSessionManagement,
69 },
70 slashCommands: [{ name: "stale" }],
71 skills: [{ name: "stale-skill", path: "stale", enabled: true }],
72 },
73 });
74
75 const replaced = applyAcpRegistryAvailableCommands(
76 provider,
77 Option.some({ slashCommands: [], skills: [] }),
78 );
79 expect(replaced.slashCommands).toEqual([]);
80 expect(replaced.skills).toEqual([]);
81 expect(applyAcpRegistryAvailableCommands(provider, Option.none()).slashCommands).toEqual([
82 { name: "stale" },
83 ]);
84 expect(provider.iconUrl).toBe(
85 "https://cdn.agentclientprotocol.com/registry/v1/latest/test-agent.svg",
86 );
87 });
88
89 it("overlays live configuration without dropping probe-owned session capabilities", () => {
90 const provider = buildCheckedAcpRegistrySnapshot({
91 ...identity,
92 settings: decodeSettings({ agentId: "test-agent" }),
93 checkedAt: "2026-08-13T10:00:00.000Z",
94 inspection: {
95 status: "ready",
96 agentId: "test-agent",
97 version: "1.0.0",
98 distribution: "npx",
99 },
100 probe: {
101 probe: {
102 instanceId: identity.instanceId,
103 ready: true,
104 icon: null,
105 authMethods: [],
106 models: [{ id: "probe-model", name: "Probe model", description: null }],
107 currentModelId: "probe-model",
108 configOptions: [],
109 sessionManagement: {
110 canList: true,
111 canLoad: true,
112 canResume: true,
113 canLogout: true,
114 canDelete: true,
115 canConfigureProviders: true,
116 },
117 },
118 slashCommands: [],
119 skills: [],
120 },
121 });
122
123 expect(
124 applyAcpRegistryLiveConfiguration(
125 provider,
126 {
127 models: [{ id: "live-model", name: "Live model", description: null }],
128 currentModelId: "live-model",
129 configOptions: [],
130 },
131 [],
132 ),
133 ).toMatchObject({
134 auth: { status: "authenticated", canLogout: true },
135 nativeSessions: { canList: true, canLoad: true, canResume: true },
136 models: [{ slug: "live-model", isDefault: true }],
137 });
138 });
139
140 it("maps registry inspection status to provider readiness", () => {
141 expect(
142 acpRegistrySnapshotReadiness({
143 status: "ready",
144 agentId: "gemini-cli",
145 version: "1.2.3",
146 distribution: "npx",
147 }),
148 ).toEqual({ installed: true, version: "1.2.3", status: "ready" });
149
150 expect(
151 acpRegistrySnapshotReadiness({
152 status: "missing_runner",
153 agentId: "gemini-cli",
154 version: "1.2.3",
155 distribution: "npx",
156 runner: "npx",
157 }),
158 ).toMatchObject({ installed: false, version: "1.2.3", status: "error" });
159
160 expect(
161 acpRegistrySnapshotReadiness({
162 status: "unprepared",
163 agentId: "zed-agent",
164 version: "2.0.0",
165 distribution: "binary",
166 }),
167 ).toMatchObject({ installed: false, version: "2.0.0", status: "warning" });
168
169 expect(
170 acpRegistrySnapshotReadiness({ status: "failed", message: "Registry unavailable." }),
171 ).toEqual({
172 installed: false,
173 version: null,
174 status: "error",
175 message: "Registry unavailable.",
176 });
177 });
178
179 it("projects authenticated probes, discovered models, custom models, and commands", () => {
180 const snapshot = buildCheckedAcpRegistrySnapshot({
181 ...identity,
182 settings: decodeSettings({
183 agentId: "test-agent",
184 customModels: [" custom-model ", "gpt-discovered"],
185 }),
186 checkedAt: "2026-08-13T10:00:00.000Z",
187 inspection: {
188 status: "ready",
189 agentId: "test-agent",
190 version: "1.0.0",
191 distribution: "npx",
192 },
193 probe: {
194 probe: {
195 instanceId: identity.instanceId,
196 ready: true,
197 icon: null,
198 authMethods: [],
199 models: [{ id: "gpt-discovered", name: "GPT Discovered", description: null }],
200 currentModelId: "gpt-discovered",
201 configOptions: [],
202 sessionManagement: noSessionManagement,
203 },
204 slashCommands: [{ name: "plan", description: "Create a plan", input: { hint: "topic" } }],
205 skills: [{ name: "workspace-skill", path: "acp://skill/workspace-skill", enabled: true }],
206 },
207 });
208
209 expect(snapshot.auth).toEqual({ status: "authenticated", canLogout: false });
210 expect(snapshot.supportsTextGeneration).toBe(false);
211 expect(
212 snapshot.models.map(({ slug, name, isCustom, isDefault }) => ({
213 slug,
214 name,
215 isCustom,
216 isDefault,
217 })),
218 ).toEqual([
219 {
220 slug: "gpt-discovered",
221 name: "GPT Discovered",
222 isCustom: false,
223 isDefault: true,
224 },
225 {
226 slug: "custom-model",
227 name: "custom-model",
228 isCustom: true,
229 isDefault: undefined,
230 },
231 ]);
232 expect(snapshot.slashCommands).toEqual([
233 { name: "plan", description: "Create a plan", input: { hint: "topic" } },
234 ]);
235 expect(snapshot.skills).toEqual([
236 { name: "workspace-skill", path: "acp://skill/workspace-skill", enabled: true },
237 ]);
238 });
239
240 it("keeps a default model only when the agent advertises none", () => {
241 const snapshot = buildCheckedAcpRegistrySnapshot({
242 ...identity,
243 settings: decodeSettings({ agentId: "test-agent" }),
244 checkedAt: "2026-08-13T10:00:00.000Z",
245 inspection: {
246 status: "ready",
247 agentId: "test-agent",
248 version: "1.0.0",
249 distribution: "uvx",
250 },
251 probe: {
252 probe: {
253 instanceId: identity.instanceId,
254 ready: true,
255 icon: null,
256 authMethods: [],
257 models: [],
258 currentModelId: null,
259 configOptions: [],
260 sessionManagement: noSessionManagement,
261 },
262 slashCommands: [],
263 skills: [],
264 },
265 });
266
267 expect(snapshot.models.map((model) => model.slug)).toEqual(["default"]);
268 expect(snapshot.models[0]?.isDefault).toBe(true);
269 });
270
271 it("reports failed authentication without hiding successful local inspection", () => {
272 const snapshot = buildCheckedAcpRegistrySnapshot({
273 ...identity,
274 settings: decodeSettings({ agentId: "test-agent", authMethodId: "grok-login" }),
275 checkedAt: "2026-08-13T10:00:00.000Z",
276 inspection: {
277 status: "ready",
278 agentId: "test-agent",
279 version: "1.0.0",
280 distribution: "binary",
281 },
282 probeError: new AcpRegistryOperationError({
283 reason: "authentication_failed",
284 message: "Login required.",
285 authMethods: [
286 {
287 id: "api-key",
288 name: "API key",
289 description: null,
290 type: "env_var",
291 },
292 {
293 id: "grok-login",
294 name: "Log in with Grok",
295 description: null,
296 type: "agent",
297 },
298 ],
299 }),
300 });
301
302 expect(snapshot).toMatchObject({
303 installed: true,
304 version: "1.0.0",
305 status: "warning",
306 auth: {
307 status: "unauthenticated",
308 type: "agent",
309 label: "Log in with Grok",
310 },
311 message:
312 'Complete the advertised "Log in with Grok" authentication method on the server. T3 Code will detect it automatically on the next provider refresh.',
313 });
314 });
315
316 it.effect("runs the disposable probe only after local inspection is ready", () =>
317 Effect.gen(function* () {
318 const settings = decodeSettings({ agentId: "test-agent" });
319 const environment = { PATH: "/provider/bin" };
320 let receivedEnvironment: NodeJS.ProcessEnv | undefined;
321 const snapshot = yield* checkAcpRegistryProviderStatus(
322 {
323 ...identity,
324 settings,
325 cwd: "/workspace",
326 environment,
327 },
328 (input) =>
329 Effect.sync(() => {
330 receivedEnvironment = input.environment;
331 return {
332 probe: {
333 instanceId: identity.instanceId,
334 ready: true as const,
335 icon: null,
336 authMethods: [],
337 models: [{ id: "agent-model", name: "Agent Model", description: null }],
338 currentModelId: "agent-model",
339 configOptions: [],
340 sessionManagement: noSessionManagement,
341 },
342 slashCommands: [{ name: "review" }],
343 skills: [],
344 };
345 }),
346 ).pipe(
347 Effect.provideService(
348 AcpRegistryCatalog,
349 catalogWithInspection({
350 status: "ready",
351 agentId: "test-agent",
352 version: "1.0.0",
353 distribution: "npx",
354 }),
355 ),
356 );
357
358 expect(receivedEnvironment).toBe(environment);
359 expect(snapshot).toMatchObject({
360 auth: { status: "authenticated" },
361 models: [{ slug: "agent-model" }],
362 slashCommands: [{ name: "review" }],
363 skills: [],
364 });
365 }),
366 );
367
368 it.effect("publishes concrete local readiness before background ACP discovery", () =>
369 Effect.gen(function* () {
370 const snapshot = yield* checkAcpRegistryProviderReadiness({
371 ...identity,
372 settings: decodeSettings({ agentId: "test-agent" }),
373 environment: { PATH: "/provider/bin" },
374 }).pipe(
375 Effect.provideService(
376 AcpRegistryCatalog,
377 catalogWithInspection({
378 status: "ready",
379 agentId: "test-agent",
380 version: "1.0.0",
381 distribution: "npx",
382 }),
383 ),
384 );
385
386 expect(snapshot).toMatchObject({
387 installed: true,
388 status: "ready",
389 version: "1.0.0",
390 auth: { status: "unknown" },
391 message: "Checking ACP authentication, models, and commands in the background...",
392 });
393 }),
394 );
395});