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

AcpRegistryDriver.test.ts

459 lines13.7 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 * 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 };
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: "missing_runner",
207 version: null,
208 distribution: "local",
209 }),
210 ).toEqual({
211 installed: false,
212 version: null,
213 status: "error",
214 message: "Local ACP executable is not available on this environment's PATH.",
215 });
216​
217 expect(
218 acpRegistrySnapshotReadiness({
219 status: "unprepared",
220 agentId: "zed-agent",
221 version: "2.0.0",
222 distribution: "binary",
223 }),
224 ).toMatchObject({ installed: false, version: "2.0.0", status: "warning" });
225​
226 expect(
227 acpRegistrySnapshotReadiness({ status: "failed", message: "Registry unavailable." }),
228 ).toEqual({
229 installed: false,
230 version: null,
231 status: "error",
232 message: "Registry unavailable.",
233 });
234 });
235​
236 it("projects discovery without claiming authentication when no login methods are advertised", () => {
237 const snapshot = buildCheckedAcpRegistrySnapshot({
238 ...identity,
239 settings: decodeSettings({
240 agentId: "test-agent",
241 customModels: [" custom-model ", "gpt-discovered"],
242 }),
243 checkedAt: "2026-08-13T10:00:00.000Z",
244 inspection: {
245 status: "ready",
246 agentId: "test-agent",
247 version: "1.0.0",
248 distribution: "npx",
249 },
250 probe: {
251 probe: {
252 instanceId: identity.instanceId,
253 ready: true,
254 icon: null,
255 authMethods: [],
256 models: [{ id: "gpt-discovered", name: "GPT Discovered", description: null }],
257 currentModelId: "gpt-discovered",
258 configOptions: [],
259 sessionManagement: noSessionManagement,
260 },
261 slashCommands: [{ name: "plan", description: "Create a plan", input: { hint: "topic" } }],
262 skills: [{ name: "workspace-skill", path: "acp://skill/workspace-skill", enabled: true }],
263 },
264 });
265​
266 expect(snapshot.auth).toEqual({ status: "unknown", canLogout: false });
267 expect(snapshot.supportsTextGeneration).toBe(false);
268 expect(
269 snapshot.models.map(({ slug, name, isCustom, isDefault }) => ({
270 slug,
271 name,
272 isCustom,
273 isDefault,
274 })),
275 ).toEqual([
276 {
277 slug: "gpt-discovered",
278 name: "GPT Discovered",
279 isCustom: false,
280 isDefault: true,
281 },
282 {
283 slug: "custom-model",
284 name: "custom-model",
285 isCustom: true,
286 isDefault: undefined,
287 },
288 ]);
289 expect(snapshot.slashCommands).toEqual([
290 { name: "plan", description: "Create a plan", input: { hint: "topic" } },
291 ]);
292 expect(snapshot.skills).toEqual([
293 { name: "workspace-skill", path: "acp://skill/workspace-skill", enabled: true },
294 ]);
295 });
296​
297 it("keeps a default model only when the agent advertises none", () => {
298 const snapshot = buildCheckedAcpRegistrySnapshot({
299 ...identity,
300 settings: decodeSettings({ agentId: "test-agent" }),
301 checkedAt: "2026-08-13T10:00:00.000Z",
302 inspection: {
303 status: "ready",
304 agentId: "test-agent",
305 version: "1.0.0",
306 distribution: "uvx",
307 },
308 probe: {
309 probe: {
310 instanceId: identity.instanceId,
311 ready: true,
312 icon: null,
313 authMethods: [],
314 models: [],
315 currentModelId: null,
316 configOptions: [],
317 sessionManagement: noSessionManagement,
318 },
319 slashCommands: [],
320 skills: [],
321 },
322 });
323​
324 expect(snapshot.models.map((model) => model.slug)).toEqual(["default"]);
325 expect(snapshot.models[0]?.isDefault).toBe(true);
326 });
327​
328 it.each(["registry", "local"] as const)(
329 "reports failed authentication after successful %s inspection",
330 (source) => {
331 const snapshot = buildCheckedAcpRegistrySnapshot({
332 ...identity,
333 settings: decodeSettings({
334 source,
335 ...(source === "local" ? { commandPath: "test-agent" } : { agentId: "test-agent" }),
336 authMethodId: "grok-login",
337 }),
338 checkedAt: "2026-08-13T10:00:00.000Z",
339 inspection: {
340 status: "ready",
341 agentId: "test-agent",
342 version: source === "local" ? null : "1.0.0",
343 distribution: source === "local" ? "local" : "binary",
344 },
345 probeError: new AcpRegistryOperationError({
346 reason: "authentication_failed",
347 message: "Login required.",
348 authMethods: [
349 {
350 id: "api-key",
351 name: "API key",
352 description: null,
353 type: "env_var",
354 },
355 {
356 id: "grok-login",
357 name: "Log in with Grok",
358 description: null,
359 type: "agent",
360 },
361 ],
362 }),
363 });
364​
365 expect(snapshot).toMatchObject({
366 installed: true,
367 version: source === "local" ? null : "1.0.0",
368 status: "warning",
369 setup: { canAuthenticate: true },
370 auth: {
371 status: "unauthenticated",
372 type: "agent",
373 label: "Log in with Grok",
374 },
375 message: 'Sign in in provider settings using "Log in with Grok".',
376 });
377 },
378 );
379​
380 it.effect("runs the disposable probe only after local inspection is ready", () =>
381 Effect.gen(function* () {
382 const settings = decodeSettings({ agentId: "test-agent" });
383 const environment = { PATH: "/provider/bin" };
384 let receivedEnvironment: NodeJS.ProcessEnv | undefined;
385 const snapshot = yield* checkAcpRegistryProviderStatus(
386 {
387 ...identity,
388 settings,
389 cwd: "/workspace",
390 environment,
391 },
392 (input) =>
393 Effect.sync(() => {
394 receivedEnvironment = input.environment;
395 return {
396 probe: {
397 instanceId: identity.instanceId,
398 ready: true as const,
399 icon: null,
400 authMethods: [],
401 models: [{ id: "agent-model", name: "Agent Model", description: null }],
402 currentModelId: "agent-model",
403 configOptions: [],
404 sessionManagement: noSessionManagement,
405 },
406 slashCommands: [{ name: "review" }],
407 skills: [],
408 };
409 }),
410 ).pipe(
411 Effect.provideService(
412 AcpRegistrySupport.AcpRegistryCatalog,
413 catalogWithInspection({
414 status: "ready",
415 agentId: "test-agent",
416 version: "1.0.0",
417 distribution: "npx",
418 }),
419 ),
420 );
421​
422 expect(receivedEnvironment).toBe(environment);
423 expect(snapshot).toMatchObject({
424 auth: { status: "unknown" },
425 models: [{ slug: "agent-model" }],
426 slashCommands: [{ name: "review" }],
427 skills: [],
428 });
429 }),
430 );
431​
432 it.effect("publishes concrete local readiness before background ACP discovery", () =>
433 Effect.gen(function* () {
434 const snapshot = yield* checkAcpRegistryProviderReadiness({
435 ...identity,
436 settings: decodeSettings({ agentId: "test-agent" }),
437 environment: { PATH: "/provider/bin" },
438 }).pipe(
439 Effect.provideService(
440 AcpRegistrySupport.AcpRegistryCatalog,
441 catalogWithInspection({
442 status: "ready",
443 agentId: "test-agent",
444 version: "1.0.0",
445 distribution: "npx",
446 }),
447 ),
448 );
449​
450 expect(snapshot).toMatchObject({
451 installed: true,
452 status: "ready",
453 version: "1.0.0",
454 auth: { status: "unknown" },
455 message: "Checking ACP authentication, models, and commands in the background...",
456 });
457 }),
458 );
459});