The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 3 | import { |
| 4 | AcpRegistryOperationError, |
| 5 | ProviderInstanceId, |
| 6 | type ServerProvider, |
| 7 | } from "@t3tools/contracts"; |
| 8 | import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; |
| 9 | import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions"; |
| 10 | import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; |
| 11 | import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost"; |
| 12 | import { toCustomModelSetting } from "@t3tools/shared/model"; |
| 13 | import { AcpRegistrySettings } from "../settings.ts"; |
| 14 | import { describe, expect, it } from "@effect/vitest"; |
| 15 | import * as Effect from "effect/Effect"; |
| 16 | import * as Fiber from "effect/Fiber"; |
| 17 | import * as FileSystem from "effect/FileSystem"; |
| 18 | import * as Layer from "effect/Layer"; |
| 19 | import * as Option from "effect/Option"; |
| 20 | import * as Path from "effect/Path"; |
| 21 | import * as Schema from "effect/Schema"; |
| 22 | import * as Stream from "effect/Stream"; |
| 23 | |
| 24 | import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts"; |
| 25 | import * as AcpRegistrySupport from "./AcpRegistrySupport.ts"; |
| 26 | import { |
| 27 | AcpRegistryDriver, |
| 28 | applyAcpRegistryAvailableCommands, |
| 29 | applyAcpRegistryLiveConfiguration, |
| 30 | buildCheckedAcpRegistrySnapshot, |
| 31 | checkAcpRegistryProviderReadiness, |
| 32 | checkAcpRegistryProviderStatus, |
| 33 | isAcpRegistryCacheValid, |
| 34 | updateAcpRegistryEnrichmentCache, |
| 35 | } from "./driver.ts"; |
| 36 | import { |
| 37 | acpRegistryAdvertisesModelCatalog, |
| 38 | acpRegistryProbeResult, |
| 39 | normalizeAcpRegistryLiveConfiguration, |
| 40 | } from "./probe.ts"; |
| 41 | |
| 42 | const decodeSettings = Schema.decodeSync(AcpRegistrySettings); |
| 43 | const identity = { |
| 44 | instanceId: ProviderInstanceId.make("acpRegistry_test"), |
| 45 | displayName: "Test ACP", |
| 46 | accentColor: undefined, |
| 47 | continuationKey: "acpRegistry:instance:acpRegistry_test", |
| 48 | }; |
| 49 | const noSessionManagement = { |
| 50 | canList: false, |
| 51 | canLoad: false, |
| 52 | canResume: false, |
| 53 | canLogout: false, |
| 54 | canDelete: false, |
| 55 | canConfigureProviders: false, |
| 56 | } as const; |
| 57 | |
| 58 | function catalogWithInspection( |
| 59 | inspection: AcpRegistrySupport.AcpRegistryInspection, |
| 60 | ): AcpRegistrySupport.AcpRegistryCatalog["Service"] { |
| 61 | return { |
| 62 | search: () => Effect.die("unused search"), |
| 63 | prepare: () => Effect.die("unused prepare"), |
| 64 | inspect: () => Effect.succeed(inspection), |
| 65 | resolve: () => Effect.die("unused resolve"), |
| 66 | uninstallManagedBinary: () => Effect.die("unused uninstall"), |
| 67 | }; |
| 68 | } |
| 69 | |
| 70 | function providerWithModels( |
| 71 | models: ReadonlyArray<{ |
| 72 | readonly id: string; |
| 73 | readonly name: string; |
| 74 | readonly description: string | null; |
| 75 | }>, |
| 76 | currentModelId: string | null, |
| 77 | ): ReturnType<typeof buildCheckedAcpRegistrySnapshot> { |
| 78 | return buildCheckedAcpRegistrySnapshot({ |
| 79 | ...identity, |
| 80 | settings: decodeSettings({ agentId: "test-agent" }), |
| 81 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 82 | inspection: { |
| 83 | status: "ready", |
| 84 | agentId: "test-agent", |
| 85 | version: "1.0.0", |
| 86 | distribution: "npx", |
| 87 | }, |
| 88 | probe: { |
| 89 | probe: { |
| 90 | instanceId: identity.instanceId, |
| 91 | ready: true, |
| 92 | icon: null, |
| 93 | authMethods: [], |
| 94 | models, |
| 95 | currentModelId, |
| 96 | configOptions: [], |
| 97 | sessionManagement: noSessionManagement, |
| 98 | }, |
| 99 | slashCommands: [], |
| 100 | skills: [], |
| 101 | }, |
| 102 | }); |
| 103 | } |
| 104 | |
| 105 | describe("acpRegistrySnapshotReadiness", () => { |
| 106 | it("keeps the custom model display name and options saved by the Settings editor", () => { |
| 107 | const fastMode = { id: "fast", label: "Fast mode", type: "boolean" } as const; |
| 108 | const snapshot = buildCheckedAcpRegistrySnapshot({ |
| 109 | ...identity, |
| 110 | settings: decodeSettings({ |
| 111 | agentId: "test-agent", |
| 112 | customModels: [ |
| 113 | toCustomModelSetting({ |
| 114 | slug: "gateway/my-model", |
| 115 | name: "My model", |
| 116 | capabilities: { optionDescriptors: [fastMode] }, |
| 117 | }), |
| 118 | ], |
| 119 | }), |
| 120 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 121 | inspection: { status: "ready", agentId: "test-agent", version: "1.0.0", distribution: "npx" }, |
| 122 | }); |
| 123 | const model = snapshot.models.find((entry) => entry.slug === "gateway/my-model"); |
| 124 | expect(model?.name).toBe("My model"); |
| 125 | expect(model?.capabilities?.optionDescriptors).toEqual([fastMode]); |
| 126 | }); |
| 127 | |
| 128 | it("shows the version reported by a local ACP agent", () => { |
| 129 | const probe = acpRegistryProbeResult(identity.instanceId, { |
| 130 | sessionId: "test-session", |
| 131 | initializeResult: { |
| 132 | protocolVersion: 1, |
| 133 | agentInfo: { name: "Example agent", version: "1.5.9" }, |
| 134 | }, |
| 135 | sessionSetupResult: {}, |
| 136 | modelConfigId: undefined, |
| 137 | }); |
| 138 | const snapshot = buildCheckedAcpRegistrySnapshot({ |
| 139 | ...identity, |
| 140 | settings: decodeSettings({ source: "local", commandPath: "example" }), |
| 141 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 142 | inspection: { status: "ready", agentId: "example", version: null, distribution: "local" }, |
| 143 | probe: { probe, slashCommands: [], skills: [] }, |
| 144 | }); |
| 145 | expect(snapshot.version).toBe("1.5.9"); |
| 146 | const withoutVersion = acpRegistryProbeResult(identity.instanceId, { |
| 147 | sessionId: "test-session", |
| 148 | initializeResult: { protocolVersion: 1 }, |
| 149 | sessionSetupResult: {}, |
| 150 | modelConfigId: undefined, |
| 151 | }); |
| 152 | expect( |
| 153 | buildCheckedAcpRegistrySnapshot({ |
| 154 | ...identity, |
| 155 | settings: decodeSettings({ source: "local", commandPath: "example" }), |
| 156 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 157 | inspection: { status: "ready", agentId: "example", version: null, distribution: "local" }, |
| 158 | probe: { probe: withoutVersion, slashCommands: [], skills: [] }, |
| 159 | }).version, |
| 160 | ).toBeNull(); |
| 161 | }); |
| 162 | |
| 163 | it("treats a live empty command advertisement as an authoritative replacement", () => { |
| 164 | const provider = buildCheckedAcpRegistrySnapshot({ |
| 165 | ...identity, |
| 166 | settings: decodeSettings({ agentId: "test-agent" }), |
| 167 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 168 | inspection: { |
| 169 | status: "ready", |
| 170 | agentId: "test-agent", |
| 171 | version: "1.0.0", |
| 172 | distribution: "npx", |
| 173 | documentationUrl: "https://example.test/agent/setup", |
| 174 | }, |
| 175 | probe: { |
| 176 | probe: { |
| 177 | instanceId: identity.instanceId, |
| 178 | ready: true, |
| 179 | icon: null, |
| 180 | authMethods: [], |
| 181 | models: [], |
| 182 | currentModelId: null, |
| 183 | configOptions: [], |
| 184 | sessionManagement: noSessionManagement, |
| 185 | }, |
| 186 | slashCommands: [{ name: "stale" }], |
| 187 | skills: [{ name: "stale-skill", path: "stale", enabled: true }], |
| 188 | }, |
| 189 | }); |
| 190 | |
| 191 | const replaced = applyAcpRegistryAvailableCommands( |
| 192 | provider, |
| 193 | Option.some({ slashCommands: [], skills: [] }), |
| 194 | ); |
| 195 | expect(replaced.slashCommands).toEqual([]); |
| 196 | expect(replaced.skills).toEqual([]); |
| 197 | expect(applyAcpRegistryAvailableCommands(provider, Option.none()).slashCommands).toEqual([ |
| 198 | { name: "stale" }, |
| 199 | ]); |
| 200 | expect(provider.iconUrl).toBe( |
| 201 | "https://cdn.agentclientprotocol.com/registry/v1/latest/test-agent.svg", |
| 202 | ); |
| 203 | expect(provider.setup).toMatchObject({ |
| 204 | canAuthenticate: false, |
| 205 | documentationUrl: "https://example.test/agent/setup", |
| 206 | }); |
| 207 | }); |
| 208 | |
| 209 | it("keeps authentication unknown when an agent permits a discovery session before sign-in", () => { |
| 210 | const snapshot = buildCheckedAcpRegistrySnapshot({ |
| 211 | ...identity, |
| 212 | settings: decodeSettings({ agentId: "test-agent" }), |
| 213 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 214 | inspection: { |
| 215 | status: "ready", |
| 216 | agentId: "test-agent", |
| 217 | version: "1.0.0", |
| 218 | distribution: "binary", |
| 219 | }, |
| 220 | probe: { |
| 221 | probe: { |
| 222 | instanceId: identity.instanceId, |
| 223 | ready: true, |
| 224 | icon: null, |
| 225 | authMethods: [{ id: "browser", name: "Browser", description: null, type: "agent" }], |
| 226 | models: [], |
| 227 | currentModelId: null, |
| 228 | configOptions: [], |
| 229 | sessionManagement: noSessionManagement, |
| 230 | }, |
| 231 | slashCommands: [], |
| 232 | skills: [], |
| 233 | }, |
| 234 | }); |
| 235 | expect(snapshot.auth.status).toBe("unknown"); |
| 236 | expect(snapshot.setup?.canAuthenticate).toBe(true); |
| 237 | expect( |
| 238 | applyAcpRegistryLiveConfiguration( |
| 239 | snapshot, |
| 240 | { models: [], currentModelId: null, configOptions: [], modelsFromModelSelect: false }, |
| 241 | [], |
| 242 | ).auth.status, |
| 243 | ).toBe("unknown"); |
| 244 | }); |
| 245 | |
| 246 | it("overlays live configuration without dropping probe-owned session capabilities", () => { |
| 247 | const provider = buildCheckedAcpRegistrySnapshot({ |
| 248 | ...identity, |
| 249 | settings: decodeSettings({ agentId: "test-agent" }), |
| 250 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 251 | inspection: { |
| 252 | status: "ready", |
| 253 | agentId: "test-agent", |
| 254 | version: "1.0.0", |
| 255 | distribution: "npx", |
| 256 | }, |
| 257 | probe: { |
| 258 | probe: { |
| 259 | instanceId: identity.instanceId, |
| 260 | ready: true, |
| 261 | icon: null, |
| 262 | authMethods: [], |
| 263 | models: [{ id: "probe-model", name: "Probe model", description: null }], |
| 264 | currentModelId: "probe-model", |
| 265 | configOptions: [], |
| 266 | sessionManagement: { |
| 267 | canList: true, |
| 268 | canLoad: true, |
| 269 | canResume: true, |
| 270 | canLogout: true, |
| 271 | canDelete: true, |
| 272 | canConfigureProviders: true, |
| 273 | }, |
| 274 | }, |
| 275 | slashCommands: [], |
| 276 | skills: [], |
| 277 | }, |
| 278 | }); |
| 279 | |
| 280 | expect( |
| 281 | applyAcpRegistryLiveConfiguration( |
| 282 | provider, |
| 283 | { |
| 284 | models: [{ id: "live-model", name: "Live model", description: null }], |
| 285 | currentModelId: "live-model", |
| 286 | configOptions: [], |
| 287 | modelsFromModelSelect: false, |
| 288 | }, |
| 289 | [], |
| 290 | ), |
| 291 | ).toMatchObject({ |
| 292 | auth: { status: "unknown", canLogout: true }, |
| 293 | nativeSessions: { canList: true, canLoad: true, canResume: true }, |
| 294 | models: [{ slug: "live-model", isDefault: true }], |
| 295 | }); |
| 296 | |
| 297 | expect( |
| 298 | applyAcpRegistryLiveConfiguration( |
| 299 | provider, |
| 300 | { models: [], currentModelId: null, configOptions: [], modelsFromModelSelect: false }, |
| 301 | [], |
| 302 | ).models, |
| 303 | ).toEqual(provider.models); |
| 304 | |
| 305 | const liveOptions = [ |
| 306 | { |
| 307 | id: "effort", |
| 308 | label: "Effort", |
| 309 | type: "select" as const, |
| 310 | options: [{ id: "high", label: "High" }], |
| 311 | currentValue: "high", |
| 312 | }, |
| 313 | ]; |
| 314 | expect( |
| 315 | applyAcpRegistryLiveConfiguration( |
| 316 | provider, |
| 317 | { |
| 318 | models: [], |
| 319 | currentModelId: null, |
| 320 | configOptions: liveOptions, |
| 321 | modelsFromModelSelect: false, |
| 322 | }, |
| 323 | [], |
| 324 | ).models, |
| 325 | ).toMatchObject([ |
| 326 | { |
| 327 | slug: "probe-model", |
| 328 | isDefault: true, |
| 329 | capabilities: { optionDescriptors: [{ id: "effort", currentValue: "high" }] }, |
| 330 | }, |
| 331 | ]); |
| 332 | |
| 333 | // Session configOptions describe the current model only. |
| 334 | const sharedMode = { |
| 335 | id: "mode", |
| 336 | label: "Mode", |
| 337 | type: "select" as const, |
| 338 | options: [{ id: "ask", label: "Ask" }], |
| 339 | currentValue: "ask", |
| 340 | }; |
| 341 | const twoModelList = [ |
| 342 | { id: "glm", name: "GLM", description: null }, |
| 343 | { id: "opus", name: "Opus", description: null }, |
| 344 | ]; |
| 345 | const afterGlm = applyAcpRegistryLiveConfiguration( |
| 346 | provider, |
| 347 | { |
| 348 | models: twoModelList, |
| 349 | currentModelId: "glm", |
| 350 | configOptions: [...liveOptions, sharedMode], |
| 351 | modelOptionIds: ["effort"], |
| 352 | }, |
| 353 | [], |
| 354 | ); |
| 355 | const twoModels = afterGlm.models; |
| 356 | expect(twoModels.find((model) => model.slug === "glm")).toMatchObject({ |
| 357 | capabilities: { optionDescriptors: [{ id: "effort" }, { id: "mode" }] }, |
| 358 | }); |
| 359 | expect( |
| 360 | twoModels.find((model) => model.slug === "opus")?.capabilities?.optionDescriptors ?? [], |
| 361 | ).toEqual([sharedMode]); |
| 362 | // A later session on another model keeps the options learned for this one. |
| 363 | const afterOpus = applyAcpRegistryLiveConfiguration( |
| 364 | afterGlm, |
| 365 | { |
| 366 | models: twoModelList, |
| 367 | currentModelId: "opus", |
| 368 | configOptions: [{ ...liveOptions[0]!, id: "thinking" }, sharedMode], |
| 369 | modelOptionIds: ["thinking"], |
| 370 | }, |
| 371 | [], |
| 372 | ).models; |
| 373 | expect(afterOpus.find((model) => model.slug === "glm")).toMatchObject({ |
| 374 | capabilities: { optionDescriptors: [{ id: "mode" }, { id: "effort" }] }, |
| 375 | }); |
| 376 | expect(afterOpus.find((model) => model.slug === "opus")).toMatchObject({ |
| 377 | capabilities: { optionDescriptors: [{ id: "thinking" }, { id: "mode" }] }, |
| 378 | }); |
| 379 | |
| 380 | // Other models take the levels they advertise in `_meta`. |
| 381 | const effort = { |
| 382 | id: "effort", |
| 383 | name: "Effort", |
| 384 | category: "thought_level", |
| 385 | type: "select" as const, |
| 386 | currentValue: "high", |
| 387 | options: [{ value: "high", name: "High" }], |
| 388 | }; |
| 389 | const advertised = applyAcpRegistryLiveConfiguration( |
| 390 | provider, |
| 391 | normalizeAcpRegistryLiveConfiguration([effort], undefined, { |
| 392 | currentModelId: "opus", |
| 393 | availableModels: [ |
| 394 | { modelId: "opus", name: "Opus" }, |
| 395 | { |
| 396 | modelId: "haiku", |
| 397 | name: "Haiku", |
| 398 | _meta: { reasoningEfforts: [{ value: "low", label: "Low" }], reasoningEffort: "low" }, |
| 399 | }, |
| 400 | { modelId: "glm", name: "GLM", _meta: { supportsReasoningEffort: false } }, |
| 401 | ], |
| 402 | }), |
| 403 | [], |
| 404 | ).models.map((model) => model.capabilities?.optionDescriptors ?? []); |
| 405 | expect(advertised).toEqual([ |
| 406 | [{ ...liveOptions[0]!, role: "reasoning" }], |
| 407 | [ |
| 408 | { |
| 409 | ...liveOptions[0]!, |
| 410 | role: "reasoning", |
| 411 | options: [{ id: "low", label: "Low" }], |
| 412 | currentValue: "low", |
| 413 | }, |
| 414 | ], |
| 415 | [], |
| 416 | ]); |
| 417 | }); |
| 418 | |
| 419 | it("keeps each Mistral Vibe model's own thinking levels", () => { |
| 420 | const provider = buildCheckedAcpRegistrySnapshot({ |
| 421 | ...identity, |
| 422 | settings: decodeSettings({ agentId: "mistral-vibe" }), |
| 423 | checkedAt: "2026-11-18T10:00:00.000Z", |
| 424 | inspection: { |
| 425 | status: "ready", |
| 426 | agentId: "mistral-vibe", |
| 427 | version: "3.1.1", |
| 428 | distribution: "binary", |
| 429 | }, |
| 430 | probe: { |
| 431 | probe: { |
| 432 | instanceId: identity.instanceId, |
| 433 | ready: true, |
| 434 | icon: null, |
| 435 | authMethods: [], |
| 436 | models: [], |
| 437 | currentModelId: null, |
| 438 | configOptions: [], |
| 439 | sessionManagement: noSessionManagement, |
| 440 | }, |
| 441 | slashCommands: [], |
| 442 | skills: [], |
| 443 | }, |
| 444 | }); |
| 445 | // Mistral Vibe 3.1.1 sends its levels under category "thinking", for the session's model only. |
| 446 | const vibeSession = (model: string, levels: ReadonlyArray<string>) => |
| 447 | normalizeAcpRegistryLiveConfiguration([ |
| 448 | { |
| 449 | id: "model", |
| 450 | name: "Model", |
| 451 | category: "model", |
| 452 | type: "select", |
| 453 | currentValue: model, |
| 454 | options: ["mistral-large-4-0-3", "mistral-medium-3.5"].map((value) => ({ |
| 455 | value, |
| 456 | name: value, |
| 457 | })), |
| 458 | }, |
| 459 | { |
| 460 | id: "thinking", |
| 461 | name: "Thinking", |
| 462 | category: "thinking", |
| 463 | type: "select", |
| 464 | currentValue: "high", |
| 465 | options: levels.map((value) => ({ value, name: value })), |
| 466 | }, |
| 467 | ]); |
| 468 | const thinking = (levels: ReadonlyArray<string>) => ({ |
| 469 | id: "thinking", |
| 470 | label: "Thinking", |
| 471 | type: "select", |
| 472 | options: levels.map((id) => ({ id, label: id })), |
| 473 | currentValue: "high", |
| 474 | role: "reasoning", |
| 475 | }); |
| 476 | const descriptors = (snapshot: typeof provider) => |
| 477 | snapshot.models.map((model) => [model.slug, model.capabilities?.optionDescriptors ?? []]); |
| 478 | |
| 479 | const onLarge = applyAcpRegistryLiveConfiguration( |
| 480 | provider, |
| 481 | vibeSession("mistral-large-4-0-3", ["low", "medium", "high"]), |
| 482 | [], |
| 483 | ); |
| 484 | expect(descriptors(onLarge)).toEqual([ |
| 485 | ["mistral-large-4-0-3", [thinking(["low", "medium", "high"])]], |
| 486 | ["mistral-medium-3.5", []], |
| 487 | ]); |
| 488 | const onMedium = applyAcpRegistryLiveConfiguration( |
| 489 | onLarge, |
| 490 | vibeSession("mistral-medium-3.5", ["off", "high"]), |
| 491 | [], |
| 492 | ); |
| 493 | expect(descriptors(onMedium)).toEqual([ |
| 494 | ["mistral-large-4-0-3", [thinking(["low", "medium", "high"])]], |
| 495 | ["mistral-medium-3.5", [thinking(["off", "high"])]], |
| 496 | ]); |
| 497 | }); |
| 498 | |
| 499 | it("projects discovery without claiming authentication when no login methods are advertised", () => { |
| 500 | const snapshot = buildCheckedAcpRegistrySnapshot({ |
| 501 | ...identity, |
| 502 | settings: decodeSettings({ |
| 503 | agentId: "test-agent", |
| 504 | customModels: [" custom-model ", "gpt-discovered"], |
| 505 | }), |
| 506 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 507 | inspection: { |
| 508 | status: "ready", |
| 509 | agentId: "test-agent", |
| 510 | version: "1.0.0", |
| 511 | distribution: "npx", |
| 512 | }, |
| 513 | probe: { |
| 514 | probe: { |
| 515 | instanceId: identity.instanceId, |
| 516 | ready: true, |
| 517 | icon: null, |
| 518 | authMethods: [], |
| 519 | models: [{ id: "gpt-discovered", name: "GPT Discovered", description: null }], |
| 520 | currentModelId: "gpt-discovered", |
| 521 | configOptions: [], |
| 522 | sessionManagement: noSessionManagement, |
| 523 | }, |
| 524 | slashCommands: [{ name: "plan", description: "Create a plan", input: { hint: "topic" } }], |
| 525 | skills: [{ name: "workspace-skill", path: "acp://skill/workspace-skill", enabled: true }], |
| 526 | }, |
| 527 | }); |
| 528 | |
| 529 | expect(snapshot.auth).toEqual({ status: "unknown", canLogout: false }); |
| 530 | expect(snapshot.supportsTextGeneration).toBe(false); |
| 531 | expect( |
| 532 | snapshot.models.map(({ slug, name, isCustom, isDefault }) => ({ |
| 533 | slug, |
| 534 | name, |
| 535 | isCustom, |
| 536 | isDefault, |
| 537 | })), |
| 538 | ).toEqual([ |
| 539 | { |
| 540 | slug: "gpt-discovered", |
| 541 | name: "GPT Discovered", |
| 542 | isCustom: false, |
| 543 | isDefault: true, |
| 544 | }, |
| 545 | { |
| 546 | slug: "custom-model", |
| 547 | name: "custom-model", |
| 548 | isCustom: true, |
| 549 | isDefault: undefined, |
| 550 | }, |
| 551 | ]); |
| 552 | expect(snapshot.slashCommands).toEqual([ |
| 553 | { name: "plan", description: "Create a plan", input: { hint: "topic" } }, |
| 554 | ]); |
| 555 | expect(snapshot.skills).toEqual([ |
| 556 | { name: "workspace-skill", path: "acp://skill/workspace-skill", enabled: true }, |
| 557 | ]); |
| 558 | }); |
| 559 | |
| 560 | it("keeps a default model only when the agent advertises none", () => { |
| 561 | const snapshot = buildCheckedAcpRegistrySnapshot({ |
| 562 | ...identity, |
| 563 | settings: decodeSettings({ agentId: "test-agent" }), |
| 564 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 565 | inspection: { |
| 566 | status: "ready", |
| 567 | agentId: "test-agent", |
| 568 | version: "1.0.0", |
| 569 | distribution: "uvx", |
| 570 | }, |
| 571 | probe: { |
| 572 | probe: { |
| 573 | instanceId: identity.instanceId, |
| 574 | ready: true, |
| 575 | icon: null, |
| 576 | authMethods: [], |
| 577 | models: [], |
| 578 | currentModelId: null, |
| 579 | configOptions: [], |
| 580 | sessionManagement: noSessionManagement, |
| 581 | }, |
| 582 | slashCommands: [], |
| 583 | skills: [], |
| 584 | }, |
| 585 | }); |
| 586 | |
| 587 | expect(snapshot.models.map((model) => model.slug)).toEqual(["default"]); |
| 588 | expect(snapshot.models[0]?.isDefault).toBe(true); |
| 589 | }); |
| 590 | |
| 591 | it.each(["registry", "local"] as const)( |
| 592 | "reports failed authentication after successful %s inspection", |
| 593 | (source) => { |
| 594 | const snapshot = buildCheckedAcpRegistrySnapshot({ |
| 595 | ...identity, |
| 596 | settings: decodeSettings({ |
| 597 | source, |
| 598 | ...(source === "local" ? { commandPath: "test-agent" } : { agentId: "test-agent" }), |
| 599 | authMethodId: "grok-login", |
| 600 | }), |
| 601 | checkedAt: "2026-08-13T10:00:00.000Z", |
| 602 | inspection: { |
| 603 | status: "ready", |
| 604 | agentId: "test-agent", |
| 605 | version: source === "local" ? null : "1.0.0", |
| 606 | distribution: source === "local" ? "local" : "binary", |
| 607 | }, |
| 608 | probeError: new AcpRegistryOperationError({ |
| 609 | reason: "authentication_failed", |
| 610 | message: "Login required.", |
| 611 | authMethods: [ |
| 612 | { |
| 613 | id: "api-key", |
| 614 | name: "API key", |
| 615 | description: null, |
| 616 | type: "env_var", |
| 617 | }, |
| 618 | { |
| 619 | id: "grok-login", |
| 620 | name: "Log in with Grok", |
| 621 | description: null, |
| 622 | type: "agent", |
| 623 | }, |
| 624 | ], |
| 625 | }), |
| 626 | }); |
| 627 | |
| 628 | expect(snapshot).toMatchObject({ |
| 629 | installed: true, |
| 630 | version: source === "local" ? null : "1.0.0", |
| 631 | status: "warning", |
| 632 | setup: { canAuthenticate: true }, |
| 633 | auth: { |
| 634 | status: "unauthenticated", |
| 635 | type: "agent", |
| 636 | label: "Log in with Grok", |
| 637 | }, |
| 638 | message: 'Sign in in provider settings using "Log in with Grok".', |
| 639 | }); |
| 640 | }, |
| 641 | ); |
| 642 | |
| 643 | it.effect("runs the disposable probe only after local inspection is ready", () => |
| 644 | Effect.gen(function* () { |
| 645 | const settings = decodeSettings({ agentId: "test-agent" }); |
| 646 | const environment = { PATH: "/provider/bin" }; |
| 647 | let receivedEnvironment: NodeJS.ProcessEnv | undefined; |
| 648 | const snapshot = yield* checkAcpRegistryProviderStatus( |
| 649 | { |
| 650 | ...identity, |
| 651 | settings, |
| 652 | cwd: "/workspace", |
| 653 | environment, |
| 654 | }, |
| 655 | (input) => |
| 656 | Effect.sync(() => { |
| 657 | receivedEnvironment = input.environment; |
| 658 | return { |
| 659 | probe: { |
| 660 | instanceId: identity.instanceId, |
| 661 | ready: true as const, |
| 662 | icon: null, |
| 663 | authMethods: [], |
| 664 | models: [{ id: "agent-model", name: "Agent Model", description: null }], |
| 665 | currentModelId: "agent-model", |
| 666 | configOptions: [], |
| 667 | sessionManagement: noSessionManagement, |
| 668 | }, |
| 669 | slashCommands: [{ name: "review" }], |
| 670 | skills: [], |
| 671 | }; |
| 672 | }), |
| 673 | ).pipe( |
| 674 | Effect.provideService( |
| 675 | AcpRegistrySupport.AcpRegistryCatalog, |
| 676 | catalogWithInspection({ |
| 677 | status: "ready", |
| 678 | agentId: "test-agent", |
| 679 | version: "1.0.0", |
| 680 | distribution: "npx", |
| 681 | }), |
| 682 | ), |
| 683 | ); |
| 684 | |
| 685 | expect(receivedEnvironment).toEqual({ ...environment, MISE_OFFLINE: "1" }); |
| 686 | expect(snapshot).toMatchObject({ |
| 687 | auth: { status: "unknown" }, |
| 688 | models: [{ slug: "agent-model" }], |
| 689 | slashCommands: [{ name: "review" }], |
| 690 | skills: [], |
| 691 | }); |
| 692 | }), |
| 693 | ); |
| 694 | |
| 695 | it.effect("publishes concrete local readiness before background ACP discovery", () => |
| 696 | Effect.gen(function* () { |
| 697 | const snapshot = yield* checkAcpRegistryProviderReadiness({ |
| 698 | ...identity, |
| 699 | settings: decodeSettings({ agentId: "test-agent" }), |
| 700 | environment: { PATH: "/provider/bin" }, |
| 701 | }).pipe( |
| 702 | Effect.provideService( |
| 703 | AcpRegistrySupport.AcpRegistryCatalog, |
| 704 | catalogWithInspection({ |
| 705 | status: "ready", |
| 706 | agentId: "test-agent", |
| 707 | version: "1.0.0", |
| 708 | distribution: "npx", |
| 709 | }), |
| 710 | ), |
| 711 | ); |
| 712 | |
| 713 | expect(snapshot).toMatchObject({ |
| 714 | installed: true, |
| 715 | status: "ready", |
| 716 | version: "1.0.0", |
| 717 | auth: { status: "unknown" }, |
| 718 | message: "Checking ACP authentication, models, and commands in the background...", |
| 719 | }); |
| 720 | }), |
| 721 | ); |
| 722 | |
| 723 | it("keeps a richer probed catalog when a live session reports one provisional model", () => { |
| 724 | const provider = providerWithModels( |
| 725 | [ |
| 726 | { id: "auto", name: "Auto", description: null }, |
| 727 | { id: "qmodel", name: "Qwen", description: null }, |
| 728 | { id: "kmodel", name: "Kimi", description: null }, |
| 729 | ], |
| 730 | "auto", |
| 731 | ); |
| 732 | |
| 733 | const fallbackSelected = applyAcpRegistryLiveConfiguration( |
| 734 | provider, |
| 735 | { |
| 736 | models: [{ id: "smodel", name: "Default", description: null }], |
| 737 | currentModelId: "smodel", |
| 738 | configOptions: [], |
| 739 | modelsFromModelSelect: false, |
| 740 | }, |
| 741 | [], |
| 742 | ); |
| 743 | expect(fallbackSelected.models.map((m) => m.slug)).toEqual(["auto", "qmodel", "kmodel"]); |
| 744 | expect(fallbackSelected.models.find((m) => m.slug === "auto")?.isDefault).toBe(true); |
| 745 | |
| 746 | const liveSelected = applyAcpRegistryLiveConfiguration( |
| 747 | provider, |
| 748 | { |
| 749 | models: [{ id: "auto", name: "Auto", description: null }], |
| 750 | currentModelId: "qmodel", |
| 751 | configOptions: [], |
| 752 | modelsFromModelSelect: false, |
| 753 | }, |
| 754 | [], |
| 755 | ); |
| 756 | expect(liveSelected.models.map((m) => m.slug)).toEqual(["auto", "qmodel", "kmodel"]); |
| 757 | expect(liveSelected.models.find((m) => m.slug === "qmodel")?.isDefault).toBe(true); |
| 758 | expect(liveSelected.models.find((m) => m.slug === "auto")?.isDefault).not.toBe(true); |
| 759 | }); |
| 760 | |
| 761 | it("honors an explicit single-model select even when it is absent from the probe catalog", () => { |
| 762 | const provider = providerWithModels( |
| 763 | [ |
| 764 | { id: "auto", name: "Auto", description: null }, |
| 765 | { id: "qmodel", name: "Qwen", description: null }, |
| 766 | { id: "kmodel", name: "Kimi", description: null }, |
| 767 | ], |
| 768 | "auto", |
| 769 | ); |
| 770 | |
| 771 | const entitled = applyAcpRegistryLiveConfiguration( |
| 772 | provider, |
| 773 | { |
| 774 | models: [{ id: "gmodel", name: "GPT-Pro", description: null }], |
| 775 | currentModelId: "gmodel", |
| 776 | configOptions: [], |
| 777 | modelsFromModelSelect: true, |
| 778 | }, |
| 779 | [], |
| 780 | ); |
| 781 | expect(entitled.models.map((m) => m.slug)).toEqual(["gmodel"]); |
| 782 | expect(entitled.models.find((m) => m.slug === "gmodel")?.isDefault).toBe(true); |
| 783 | |
| 784 | const narrowed = applyAcpRegistryLiveConfiguration( |
| 785 | provider, |
| 786 | { |
| 787 | models: [{ id: "qmodel", name: "Qwen", description: null }], |
| 788 | currentModelId: "qmodel", |
| 789 | configOptions: [], |
| 790 | modelsFromModelSelect: true, |
| 791 | }, |
| 792 | [], |
| 793 | ); |
| 794 | expect(narrowed.models.map((m) => m.slug)).toEqual(["qmodel"]); |
| 795 | expect(narrowed.models.find((m) => m.slug === "qmodel")?.isDefault).toBe(true); |
| 796 | }); |
| 797 | }); |
| 798 | |
| 799 | describe("acpRegistryEnrichmentCache", () => { |
| 800 | it("reuses a local probe until expiry even when inspection has no version", () => { |
| 801 | const entry = { provider: providerWithModels([], null), expiresAt: 1_000 }; |
| 802 | expect(isAcpRegistryCacheValid(entry, null, true, 999)).toBe(true); |
| 803 | expect(isAcpRegistryCacheValid(entry, null, true, 1_000)).toBe(false); |
| 804 | expect(isAcpRegistryCacheValid(entry, "2.0.0", false, 999)).toBe(false); |
| 805 | expect(isAcpRegistryCacheValid(entry, "1.0.0", false, 999)).toBe(true); |
| 806 | }); |
| 807 | const settledConfiguration = { |
| 808 | models: [ |
| 809 | { id: "auto", name: "Auto", description: null }, |
| 810 | { id: "qmodel", name: "Qwen", description: null }, |
| 811 | { id: "kmodel", name: "Kimi", description: null }, |
| 812 | ], |
| 813 | currentModelId: "auto", |
| 814 | configOptions: [], |
| 815 | modelsFromModelSelect: true, |
| 816 | }; |
| 817 | |
| 818 | it("does not renew the cache deadline when live configuration is replayed unchanged", () => { |
| 819 | const provider = providerWithModels(settledConfiguration.models, "auto"); |
| 820 | const cache = { generation: 1, entry: { provider, expiresAt: 1_000 } }; |
| 821 | |
| 822 | const replayed = updateAcpRegistryEnrichmentCache({ |
| 823 | cache, |
| 824 | configuration: settledConfiguration, |
| 825 | customModels: [], |
| 826 | now: 2_000, |
| 827 | }); |
| 828 | |
| 829 | expect(replayed).toBe(cache); |
| 830 | expect(replayed.entry?.expiresAt).toBe(1_000); |
| 831 | }); |
| 832 | |
| 833 | it("updates the cache and promotes the expiry when live configuration discovers a catalog", () => { |
| 834 | const provider = providerWithModels( |
| 835 | [{ id: "smodel", name: "Default", description: null }], |
| 836 | "smodel", |
| 837 | ); |
| 838 | const cache = { generation: 1, entry: { provider, expiresAt: 1_000 } }; |
| 839 | |
| 840 | const updated = updateAcpRegistryEnrichmentCache({ |
| 841 | cache, |
| 842 | configuration: settledConfiguration, |
| 843 | customModels: [], |
| 844 | now: 5_000, |
| 845 | }); |
| 846 | |
| 847 | expect(updated.entry?.provider.models.map((m) => m.slug)).toEqual(["auto", "qmodel", "kmodel"]); |
| 848 | expect((updated.entry?.expiresAt ?? 0) - 5_000).toBe(15 * 60 * 1_000); |
| 849 | expect(updated.generation).toBe(2); |
| 850 | }); |
| 851 | |
| 852 | it("advances the cache epoch when a live update arrives before any probe lands", () => { |
| 853 | const cache = { generation: 4, entry: null }; |
| 854 | |
| 855 | const updated = updateAcpRegistryEnrichmentCache({ |
| 856 | cache, |
| 857 | configuration: settledConfiguration, |
| 858 | customModels: [], |
| 859 | now: 5_000, |
| 860 | }); |
| 861 | |
| 862 | expect(updated.generation).toBe(5); |
| 863 | expect(updated.entry).toBeNull(); |
| 864 | }); |
| 865 | }); |
| 866 | |
| 867 | describe("acpRegistryAdvertisesModelCatalog", () => { |
| 868 | it("counts choices inside option groups and available model state", () => { |
| 869 | expect( |
| 870 | acpRegistryAdvertisesModelCatalog([ |
| 871 | { |
| 872 | id: "model", |
| 873 | name: "Model", |
| 874 | type: "select" as const, |
| 875 | category: "model" as const, |
| 876 | currentValue: "auto", |
| 877 | options: [ |
| 878 | { |
| 879 | groupId: "qwen", |
| 880 | name: "Qwen", |
| 881 | options: [ |
| 882 | { value: "auto", name: "Auto" }, |
| 883 | { value: "qmodel", name: "Qwen3.8-Max" }, |
| 884 | ], |
| 885 | }, |
| 886 | ], |
| 887 | }, |
| 888 | ]), |
| 889 | ).toBe(true); |
| 890 | expect( |
| 891 | acpRegistryAdvertisesModelCatalog([ |
| 892 | { |
| 893 | id: "model", |
| 894 | name: "Model", |
| 895 | type: "select" as const, |
| 896 | category: "model" as const, |
| 897 | currentValue: "smodel", |
| 898 | options: [{ value: "smodel", name: "Sonus" }], |
| 899 | }, |
| 900 | ]), |
| 901 | ).toBe(false); |
| 902 | expect(acpRegistryAdvertisesModelCatalog(undefined)).toBe(false); |
| 903 | expect( |
| 904 | acpRegistryAdvertisesModelCatalog(undefined, { |
| 905 | availableModels: [ |
| 906 | { modelId: "auto", name: "Auto", description: null }, |
| 907 | { modelId: "qmodel", name: "Qwen", description: null }, |
| 908 | ], |
| 909 | currentModelId: "auto", |
| 910 | }), |
| 911 | ).toBe(true); |
| 912 | }); |
| 913 | }); |
| 914 | |
| 915 | const fakeAgentSource = ` |
| 916 | import { readFileSync } from "node:fs"; |
| 917 | import { createInterface } from "node:readline"; |
| 918 | const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); |
| 919 | createInterface({ input: process.stdin }).on("line", (line) => { |
| 920 | const { id, method } = JSON.parse(line); |
| 921 | if (id === undefined) return; |
| 922 | if (method === "initialize") { |
| 923 | send({ |
| 924 | id, |
| 925 | result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [], agentInfo: { name: "fake", version: "1.5.9" } }, |
| 926 | }); |
| 927 | } else if (method === "session/new") { |
| 928 | const modelIds = JSON.parse(readFileSync(process.argv[2], "utf8")); |
| 929 | send({ |
| 930 | id, |
| 931 | result: { |
| 932 | sessionId: "probe-session", |
| 933 | models: { |
| 934 | currentModelId: modelIds[0], |
| 935 | availableModels: modelIds.map((modelId) => ({ modelId, name: modelId })), |
| 936 | }, |
| 937 | }, |
| 938 | }); |
| 939 | send({ |
| 940 | method: "session/update", |
| 941 | params: { |
| 942 | sessionId: "probe-session", |
| 943 | update: { sessionUpdate: "available_commands_update", availableCommands: [] }, |
| 944 | }, |
| 945 | }); |
| 946 | } else { |
| 947 | send({ id, result: {} }); |
| 948 | } |
| 949 | }); |
| 950 | `; |
| 951 | |
| 952 | const driverLayer = TestProviderHost.layer({ runBackgroundWork: false }).pipe( |
| 953 | Layer.provideMerge(AcpRegistryRuntimeCoordinator.layer), |
| 954 | Layer.provideMerge(IdAllocator.layer), |
| 955 | Layer.provideMerge(McpProviderSessions.layer), |
| 956 | Layer.provideMerge( |
| 957 | Layer.succeed( |
| 958 | ProviderEventLoggers.ProviderEventLoggers, |
| 959 | ProviderEventLoggers.NoOpProviderEventLoggers, |
| 960 | ), |
| 961 | ), |
| 962 | Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), |
| 963 | ); |
| 964 | |
| 965 | it.layer(driverLayer, { excludeTestServices: true })("AcpRegistryDriver", (it) => { |
| 966 | it.effect("creates without inspecting the agent, which may fetch the registry", () => |
| 967 | Effect.gen(function* () { |
| 968 | const instance = yield* AcpRegistryDriver.create({ |
| 969 | instanceId: identity.instanceId, |
| 970 | displayName: identity.displayName, |
| 971 | enabled: true, |
| 972 | environment: [], |
| 973 | config: decodeSettings({ agentId: "test-agent" }), |
| 974 | }).pipe( |
| 975 | Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, { |
| 976 | ...catalogWithInspection({ status: "unconfigured" }), |
| 977 | inspect: () => Effect.die("inspected during creation"), |
| 978 | }), |
| 979 | ); |
| 980 | expect(yield* instance.snapshot.getSnapshot).toMatchObject({ |
| 981 | installed: false, |
| 982 | message: "Checking ACP Registry agent readiness...", |
| 983 | }); |
| 984 | }), |
| 985 | ); |
| 986 | |
| 987 | it.effect("drops cached and session-reported models when its caches are invalidated", () => |
| 988 | Effect.gen(function* () { |
| 989 | const fileSystem = yield* FileSystem.FileSystem; |
| 990 | const path = yield* Path.Path; |
| 991 | const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "acp-driver-" }); |
| 992 | const agentPath = path.join(directory, "agent.mjs"); |
| 993 | const modelsPath = path.join(directory, "models.json"); |
| 994 | yield* fileSystem.writeFileString(agentPath, fakeAgentSource); |
| 995 | yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model", "other-model"])); |
| 996 | const coordinator = yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator; |
| 997 | |
| 998 | const instance = yield* AcpRegistryDriver.create({ |
| 999 | instanceId: identity.instanceId, |
| 1000 | displayName: identity.displayName, |
| 1001 | enabled: true, |
| 1002 | environment: [], |
| 1003 | config: decodeSettings({ agentId: "test-agent" }), |
| 1004 | }).pipe( |
| 1005 | Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, { |
| 1006 | ...catalogWithInspection({ |
| 1007 | status: "ready", |
| 1008 | agentId: "test-agent", |
| 1009 | version: "1.0.0", |
| 1010 | distribution: "npx", |
| 1011 | }), |
| 1012 | resolve: () => |
| 1013 | Effect.succeed({ |
| 1014 | distribution: "npx" as const, |
| 1015 | spawn: { command: process.execPath, args: [agentPath, modelsPath] }, |
| 1016 | }), |
| 1017 | }), |
| 1018 | ); |
| 1019 | const modelSlugs = instance.snapshot.streamChanges.pipe( |
| 1020 | Stream.map((snapshot) => snapshot.models.map((model) => model.slug)), |
| 1021 | ); |
| 1022 | const waitForModels = (expected: ReadonlyArray<string>) => |
| 1023 | modelSlugs.pipe( |
| 1024 | Stream.filter((slugs) => slugs.join() === expected.join()), |
| 1025 | Stream.runHead, |
| 1026 | ); |
| 1027 | |
| 1028 | const probed = yield* waitForModels(["old-model", "other-model"]).pipe( |
| 1029 | Effect.forkScoped({ startImmediately: true }), |
| 1030 | ); |
| 1031 | yield* instance.snapshot.refresh; |
| 1032 | yield* Fiber.join(probed); |
| 1033 | yield* coordinator.publishLiveConfiguration( |
| 1034 | identity.instanceId, |
| 1035 | normalizeAcpRegistryLiveConfiguration([], undefined, { |
| 1036 | currentModelId: "old-model", |
| 1037 | availableModels: [ |
| 1038 | { modelId: "old-model", name: "old-model" }, |
| 1039 | { modelId: "session-model", name: "session-model" }, |
| 1040 | ], |
| 1041 | }), |
| 1042 | ); |
| 1043 | yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model", "new-model"])); |
| 1044 | |
| 1045 | const refreshed = yield* waitForModels(["old-model", "new-model"]).pipe( |
| 1046 | Effect.forkScoped({ startImmediately: true }), |
| 1047 | ); |
| 1048 | yield* instance.invalidateCaches ?? Effect.void; |
| 1049 | yield* instance.snapshot.refresh; |
| 1050 | expect(Option.isSome(yield* Fiber.join(refreshed))).toBe(true); |
| 1051 | }), |
| 1052 | ); |
| 1053 | |
| 1054 | it.effect("keeps a local agent's reported version through the next readiness check", () => |
| 1055 | Effect.gen(function* () { |
| 1056 | const fileSystem = yield* FileSystem.FileSystem; |
| 1057 | const path = yield* Path.Path; |
| 1058 | const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "acp-driver-" }); |
| 1059 | const agentPath = path.join(directory, "agent.mjs"); |
| 1060 | const modelsPath = path.join(directory, "models.json"); |
| 1061 | yield* fileSystem.writeFileString(agentPath, fakeAgentSource); |
| 1062 | yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["model-a"])); |
| 1063 | |
| 1064 | const instance = yield* AcpRegistryDriver.create({ |
| 1065 | instanceId: identity.instanceId, |
| 1066 | displayName: identity.displayName, |
| 1067 | enabled: true, |
| 1068 | environment: [], |
| 1069 | config: decodeSettings({ source: "local", commandPath: "agent" }), |
| 1070 | }).pipe( |
| 1071 | Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, { |
| 1072 | ...catalogWithInspection({ |
| 1073 | status: "ready", |
| 1074 | agentId: "agent", |
| 1075 | version: null, |
| 1076 | distribution: "local", |
| 1077 | }), |
| 1078 | resolve: () => |
| 1079 | Effect.succeed({ |
| 1080 | distribution: "local" as const, |
| 1081 | spawn: { command: process.execPath, args: [agentPath, modelsPath] }, |
| 1082 | }), |
| 1083 | }), |
| 1084 | ); |
| 1085 | const probed = yield* instance.snapshot.streamChanges.pipe( |
| 1086 | Stream.filter((snapshot) => snapshot.version === "1.5.9"), |
| 1087 | Stream.runHead, |
| 1088 | Effect.forkScoped({ startImmediately: true }), |
| 1089 | ); |
| 1090 | yield* instance.snapshot.refresh; |
| 1091 | yield* Fiber.join(probed); |
| 1092 | |
| 1093 | const nextPublished = yield* instance.snapshot.streamChanges.pipe( |
| 1094 | Stream.runHead, |
| 1095 | Effect.forkScoped({ startImmediately: true }), |
| 1096 | ); |
| 1097 | yield* instance.invalidateCaches ?? Effect.void; |
| 1098 | yield* instance.snapshot.refresh; |
| 1099 | const next = yield* Fiber.join(nextPublished); |
| 1100 | expect(Option.map(next, (snapshot) => snapshot.version)).toEqual(Option.some("1.5.9")); |
| 1101 | }), |
| 1102 | ); |
| 1103 | |
| 1104 | it.effect("keeps options learned for each model across a refresh", () => |
| 1105 | Effect.gen(function* () { |
| 1106 | const fileSystem = yield* FileSystem.FileSystem; |
| 1107 | const path = yield* Path.Path; |
| 1108 | const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "acp-driver-" }); |
| 1109 | const agentPath = path.join(directory, "agent.mjs"); |
| 1110 | const modelsPath = path.join(directory, "models.json"); |
| 1111 | yield* fileSystem.writeFileString(agentPath, fakeAgentSource); |
| 1112 | yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["model-a", "model-b"])); |
| 1113 | const coordinator = yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator; |
| 1114 | |
| 1115 | const instance = yield* AcpRegistryDriver.create({ |
| 1116 | instanceId: identity.instanceId, |
| 1117 | displayName: identity.displayName, |
| 1118 | enabled: true, |
| 1119 | environment: [], |
| 1120 | config: decodeSettings({ agentId: "test-agent" }), |
| 1121 | }).pipe( |
| 1122 | Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, { |
| 1123 | ...catalogWithInspection({ |
| 1124 | status: "ready", |
| 1125 | agentId: "test-agent", |
| 1126 | version: "1.0.0", |
| 1127 | distribution: "npx", |
| 1128 | }), |
| 1129 | resolve: () => |
| 1130 | Effect.succeed({ |
| 1131 | distribution: "npx" as const, |
| 1132 | spawn: { command: process.execPath, args: [agentPath, modelsPath] }, |
| 1133 | }), |
| 1134 | }), |
| 1135 | ); |
| 1136 | const effortBySlug = (snapshot: ServerProvider) => |
| 1137 | snapshot.models |
| 1138 | .map( |
| 1139 | (model) => |
| 1140 | `${model.slug}:${(model.capabilities?.optionDescriptors ?? []).map((option) => option.id).join("+")}`, |
| 1141 | ) |
| 1142 | .join(); |
| 1143 | const waitFor = (expected: string) => |
| 1144 | instance.snapshot.streamChanges.pipe( |
| 1145 | Stream.filter((snapshot) => effortBySlug(snapshot) === expected), |
| 1146 | Stream.runHead, |
| 1147 | ); |
| 1148 | const session = (currentModelId: string) => |
| 1149 | normalizeAcpRegistryLiveConfiguration( |
| 1150 | [ |
| 1151 | { |
| 1152 | id: "effort", |
| 1153 | name: "Effort", |
| 1154 | category: "thought_level", |
| 1155 | type: "select", |
| 1156 | currentValue: "high", |
| 1157 | options: [ |
| 1158 | { value: "low", name: "Low" }, |
| 1159 | { value: "high", name: "High" }, |
| 1160 | ], |
| 1161 | }, |
| 1162 | ], |
| 1163 | undefined, |
| 1164 | { |
| 1165 | currentModelId, |
| 1166 | availableModels: [ |
| 1167 | { modelId: "model-a", name: "model-a" }, |
| 1168 | { modelId: "model-b", name: "model-b" }, |
| 1169 | ], |
| 1170 | }, |
| 1171 | ); |
| 1172 | |
| 1173 | const probed = yield* waitFor("model-a:,model-b:").pipe( |
| 1174 | Effect.forkScoped({ startImmediately: true }), |
| 1175 | ); |
| 1176 | yield* instance.snapshot.refresh; |
| 1177 | yield* Fiber.join(probed); |
| 1178 | const learned = yield* waitFor("model-a:effort,model-b:effort").pipe( |
| 1179 | Effect.forkScoped({ startImmediately: true }), |
| 1180 | ); |
| 1181 | yield* coordinator.publishLiveConfiguration(identity.instanceId, session("model-b")); |
| 1182 | yield* coordinator.publishLiveConfiguration(identity.instanceId, session("model-a")); |
| 1183 | yield* Fiber.join(learned); |
| 1184 | |
| 1185 | yield* instance.snapshot.refresh; |
| 1186 | expect(effortBySlug(yield* instance.snapshot.getSnapshot)).toBe( |
| 1187 | "model-a:effort,model-b:effort", |
| 1188 | ); |
| 1189 | }), |
| 1190 | ); |
| 1191 | }); |