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