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

AcpRegistryDriver.test.ts

436 lines13.0 KB

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