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