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

providerCompatibility.test.ts

396 lines14.8 KB

1import { assert, describe, it } from "@effect/vitest";
2import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import * as Deferred from "effect/Deferred";
5import * as Fiber from "effect/Fiber";
6import * as Effect from "effect/Effect";
7import * as Layer from "effect/Layer";
8import * as PubSub from "effect/PubSub";
9import * as Ref from "effect/Ref";
10import * as Stream from "effect/Stream";
11import * as ServerConfig from "../config.ts";
12import * as ModelManifest from "./ModelManifest.ts";
13import { ProviderRegistryLive } from "./Layers/ProviderRegistry.ts";
14import * as ProviderRegistry from "./Services/ProviderRegistry.ts";
15import * as ProviderInstanceRegistry from "./Services/ProviderInstanceRegistry.ts";
16import type { ProviderInstance } from "./ProviderDriver.ts";
17import { makeManualOnlyProviderMaintenanceCapabilities } from "./providerMaintenance.ts";
18import { BUILT_IN_DRIVERS } from "./builtInDrivers.ts";
19import * as Schema from "effect/Schema";
20import {
21 applyProviderCompatibility,
22 ProviderCompatibilityPolicy,
23 resolveProviderCompatibility,
24} from "./providerCompatibility.ts";
25​
26const driver = ProviderDriverKind.make("codex");
27const policy: ProviderCompatibilityPolicy = {
28 driver,
29 t3CodeRange: ">=0.0.42 <0.1.0",
30 recommendedVersion: "2.0.0",
31 recommendedRange: ">=2.0.0 <3.0.0",
32 ranges: [
33 { range: "<1.0.0", status: "broken" },
34 { range: ">=1.0.0 <1.5.0", status: "unsupported" },
35 { range: ">=1.5.0 <2.0.0", status: "graceful" },
36 { range: ">=2.0.0 <3.0.0", status: "supported" },
37 ],
38};
39const provider: ServerProvider = {
40 driver,
41 instanceId: ProviderInstanceId.make("codex-work"),
42 enabled: true,
43 installed: true,
44 version: "0.9.0",
45 status: "error",
46 message: "Authentication failed",
47 checkedAt: "2026-09-22T00:00:00Z",
48 auth: { status: "unauthenticated" },
49 models: [],
50 skills: [],
51 slashCommands: [],
52};
53​
54// The first release that runs the V2 orchestrator.
55const V2_RELEASE = "0.0.46";
56​
57describe("provider compatibility", () => {
58 it("bundles a compatibility policy for every built-in harness", () => {
59 for (const builtIn of BUILT_IN_DRIVERS) {
60 // Registry entries are arbitrary external ACP agents, not one versioned harness.
61 if (builtIn.driverKind === "acpRegistry") continue;
62 assert.isDefined(
63 resolveProviderCompatibility(
64 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
65 builtIn.driverKind,
66 null,
67 V2_RELEASE,
68 ),
69 `Missing bundled compatibility policy for ${builtIn.driverKind}`,
70 );
71 }
72 });
73​
74 it("keeps releases before V2 on the OpenCode 1 policy they shipped with", () => {
75 // Every installed build fetches main's manifest, and 0.0.45 and older run the
76 // V1 orchestrator, which cannot drive OpenCode 2.
77 const opencode = ProviderDriverKind.make("opencode");
78 for (const [version, expected] of [
79 ["1.14.19", "supported"],
80 ["2.0.18", "broken"],
81 ["1.14.18", "broken"],
82 ] as const) {
83 const advisory = resolveProviderCompatibility(
84 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
85 opencode,
86 version,
87 "0.0.45",
88 );
89 assert.strictEqual(advisory?.status, expected, `OpenCode ${version} on 0.0.45`);
90 assert.strictEqual(advisory?.recommendedVersion, "1.14.19");
91 }
92 // Pi has no driver before V2.
93 assert.isUndefined(
94 resolveProviderCompatibility(
95 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
96 ProviderDriverKind.make("pi"),
97 "1.0.0",
98 "0.0.45",
99 ),
100 );
101 });
102​
103 it("supports OpenCode 2 and gives OpenCode 1.x limited support", () => {
104 const opencode = ProviderDriverKind.make("opencode");
105 for (const [version, expected] of [
106 ["2.0.18", "supported"],
107 ["2.1.0", "supported"],
108 // Early OpenCode 2 releases predate the API the adapter was built against.
109 ["2.0.17", "unsupported"],
110 ["2.0.0", "unsupported"],
111 ["1.99.0", "graceful"],
112 ["1.14.19", "graceful"],
113 ["1.14.18", "broken"],
114 ] as const) {
115 for (const t3CodeVersion of [V2_RELEASE, "0.0.46-preview.20261002.2598"]) {
116 const advisory = resolveProviderCompatibility(
117 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
118 opencode,
119 version,
120 t3CodeVersion,
121 );
122 assert.strictEqual(advisory?.status, expected, `OpenCode ${version} on ${t3CodeVersion}`);
123 assert.strictEqual(advisory?.recommendedRange, ">=2.0.18");
124 }
125 }
126 // The advisory rides beside the probe: a ready 1.x instance stays ready and selectable.
127 const ready = applyProviderCompatibility(
128 { ...provider, driver: opencode, version: "1.18.33", status: "ready", message: undefined },
129 undefined,
130 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
131 );
132 assert.strictEqual(ready.status, "ready");
133 assert.strictEqual(
134 ready.compatibilityAdvisory?.status,
135 resolveProviderCompatibility(
136 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
137 opencode,
138 "1.18.33",
139 )?.status,
140 );
141 });
142​
143 it("compares Cursor build dates without treating semver prereleases as stable", () => {
144 const cursor = ProviderDriverKind.make("cursor");
145 const cursorPolicy: ProviderCompatibilityPolicy = {
146 driver: cursor,
147 t3CodeRange: policy.t3CodeRange,
148 ranges: [
149 { range: "<2026.05.09", status: "unsupported" },
150 { range: ">=2026.05.09", status: "supported" },
151 ],
152 };
153 for (const [version, expected] of [
154 ["2026.05.08-a1b2c3d", "unsupported"],
155 ["2026.05.09-a1b2c3d", "supported"],
156 ["2026.09.22-f2b0fcd", "supported"],
157 ["2026.05.09", "supported"],
158 ["2026.05.09-beta.1", "unknown"],
159 ] as const) {
160 assert.strictEqual(
161 resolveProviderCompatibility([cursorPolicy], cursor, version)?.status,
162 expected,
163 );
164 }
165 assert.strictEqual(
166 resolveProviderCompatibility([policy], driver, "2.0.0-a1b2c3d")?.status,
167 "unknown",
168 );
169 });
170​
171 it("recognizes Antigravity semver release tags while keeping dated candidates unknown", () => {
172 const antigravity = ProviderDriverKind.make("antigravity");
173 const taggedPolicy = {
174 ...policy,
175 driver: antigravity,
176 ranges: [{ range: "=2.0.0", status: "supported" as const }],
177 };
178 for (const [version, expected] of [
179 ["agy_acp_server_2.0.0", "supported"],
180 ["2.0.0", "supported"],
181 ["agy_acp_server_2.0.1", "unknown"],
182 ["agy_acp_server_2.0.0-beta.1", "unknown"],
183 ["agy_acp_server_20260818_01_RC01", "unknown"],
184 ] as const) {
185 assert.strictEqual(
186 resolveProviderCompatibility([taggedPolicy], antigravity, version)?.status,
187 expected,
188 );
189 }
190 });
191​
192 it("classifies boundaries and treats unlisted versions and release tags as unknown", () => {
193 for (const [version, expected] of [
194 ["0.9.9", "broken"],
195 ["1.0.0", "unsupported"],
196 ["1.5.0", "graceful"],
197 ["2.0.0", "supported"],
198 ["v2.0.0", "supported"],
199 ["3.0.0", "unknown"],
200 ["2.0.0-beta.1", "unknown"],
201 ["agy_acp_server_20260818_01_RC01", "unknown"],
202 [null, "unknown"],
203 ] as const) {
204 assert.strictEqual(resolveProviderCompatibility([policy], driver, version)?.status, expected);
205 }
206 assert.isUndefined(resolveProviderCompatibility([policy], driver, "0.9.0", "0.1.0"));
207 });
208​
209 it("supports every driver without inventing policies for uncovered adapters", () => {
210 for (const kind of [
211 "codex",
212 "claudeAgent",
213 "cursor",
214 "grok",
215 "opencode",
216 "antigravity",
217 "customDriver",
218 ]) {
219 const adapter = ProviderDriverKind.make(kind);
220 assert.strictEqual(
221 resolveProviderCompatibility([{ ...policy, driver: adapter }], adapter, "2.0.0")?.status,
222 "supported",
223 );
224 assert.isUndefined(resolveProviderCompatibility([], adapter, "2.0.0"));
225 }
226 });
227​
228 it("relaxes remote policy without losing probe errors, and falls back when a policy is omitted", () => {
229 const broken = applyProviderCompatibility(provider, [], [policy]);
230 assert.strictEqual(broken.compatibilityAdvisory?.status, "broken");
231 const relaxed = { ...policy, ranges: [{ range: ">=0.0.0", status: "supported" as const }] };
232 const supported = applyProviderCompatibility(broken, [relaxed], [policy]);
233 assert.strictEqual(supported.compatibilityAdvisory?.status, "supported");
234 assert.strictEqual(supported.status, "error");
235 assert.strictEqual(supported.message, "Authentication failed");
236 assert.strictEqual(
237 applyProviderCompatibility(supported, [{ ...policy, t3CodeRange: ">=9.0.0" }], [policy])
238 .compatibilityAdvisory?.status,
239 "broken",
240 );
241 const removed = applyProviderCompatibility(supported, [], []);
242 assert.isUndefined(removed.compatibilityAdvisory);
243 assert.strictEqual(removed.status, "error");
244 assert.strictEqual(removed.message, "Authentication failed");
245 assert.isUndefined(
246 applyProviderCompatibility({ ...broken, enabled: false }, [], [policy]).compatibilityAdvisory,
247 );
248 assert.isUndefined(
249 applyProviderCompatibility({ ...broken, installed: false }, [], [policy])
250 .compatibilityAdvisory,
251 );
252 });
253​
254 it("rejects invalid ranges and recommendations outside the first supported match", () => {
255 const decode = Schema.decodeUnknownSync(ProviderCompatibilityPolicy);
256 assert.doesNotThrow(() => decode(policy));
257 const prefixed = decode({
258 ...policy,
259 t3CodeRange: ">=v0.0.42 <v0.1",
260 recommendedRange: "^v2",
261 ranges: [{ range: ">=v2.0 <v3", status: "supported" }],
262 });
263 assert.strictEqual(
264 resolveProviderCompatibility([prefixed], driver, "2.0.0")?.status,
265 "supported",
266 );
267 assert.strictEqual(
268 resolveProviderCompatibility([prefixed], driver, "3.0.0")?.status,
269 "unknown",
270 );
271 for (const invalid of [
272 { ...policy, t3CodeRange: "*" },
273 { ...policy, recommendedVersion: "3.0.0" },
274 { ...policy, ranges: [{ range: ">=2.0.0 garbage", status: "supported" }] },
275 { ...policy, recommendedVersion: "2.0.0; echo unsafe" },
276 { ...policy, ranges: [{ range: ">=0.0.0", status: "broken" }, ...policy.ranges] },
277 ])
278 assert.throws(() => decode(invalid));
279 });
280});
281​
282it.effect("a remote policy refresh preserves a newer health result on the registry stream", () =>
283 Effect.gen(function* () {
284 const started = yield* Deferred.make<void>();
285 const release = yield* Deferred.make<void>();
286 const health = yield* Ref.make<ServerProvider>({
287 ...provider,
288 status: "ready" as ServerProvider["status"],
289 message: "Healthy",
290 });
291 const manifest = yield* Ref.make<ModelManifest.ModelManifestData>({
292 version: 1,
293 currentModels: {},
294 compatibility: [policy],
295 });
296 const instance: ProviderInstance = {
297 instanceId: provider.instanceId,
298 driverKind: driver,
299 enabled: true,
300 displayName: undefined,
301 continuationIdentity: { driverKind: driver, continuationKey: "test-codex" },
302 snapshot: {
303 getSnapshot: Ref.get(health),
304 refresh: Ref.get(health),
305 streamChanges: Stream.empty,
306 applyUsageLimits: () => Effect.void,
307 resolveMaintenance: () =>
308 Effect.succeed(
309 makeManualOnlyProviderMaintenanceCapabilities({ provider: driver, packageName: null }),
310 ),
311 },
312 orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
313 textGeneration: {} as ProviderInstance["textGeneration"],
314 };
315 const refresh = Deferred.succeed(started, undefined).pipe(
316 Effect.andThen(Deferred.await(release)),
317 Effect.andThen(
318 Ref.updateAndGet(manifest, (current) => ({
319 ...current,
320 compatibility: [
321 { ...policy, ranges: [{ range: ">=0.0.0", status: "supported" as const }] },
322 ],
323 })),
324 ),
325 );
326 const dependencies = Layer.mergeAll(
327 Layer.succeed(ModelManifest.ModelManifest, {
328 current: Ref.get(manifest),
329 refresh,
330 forceRefresh: refresh,
331 refreshInBackground: Effect.void,
332 }),
333 Layer.succeed(ProviderInstanceRegistry.ProviderInstanceRegistry, {
334 getInstance: (id) => Effect.succeed(id === instance.instanceId ? instance : undefined),
335 listInstances: Effect.succeed([instance]),
336 listUnavailable: Effect.succeed([]),
337 streamChanges: Stream.empty,
338 subscribeChanges: Effect.flatMap(PubSub.unbounded<void>(), PubSub.subscribe),
339 }),
340 ServerConfig.layerTest(process.cwd(), { prefix: "compatibility-registry-test" }).pipe(
341 Layer.provideMerge(NodeServices.layer),
342 ),
343 );
344 yield* Effect.gen(function* () {
345 const registry = yield* ProviderRegistry.ProviderRegistry;
346 yield* Deferred.await(started);
347 assert.strictEqual(
348 (yield* registry.getProviders)[0]?.compatibilityAdvisory?.status,
349 "broken",
350 );
351 yield* Ref.set(health, provider);
352 const latestHealth = yield* registry.refreshInstance(provider.instanceId);
353 assert.strictEqual(latestHealth[0]?.message, "Authentication failed");
354 const supported = yield* Stream.toPull(
355 registry.streamChanges.pipe(
356 Stream.filter((snapshots) => snapshots[0]?.compatibilityAdvisory?.status === "supported"),
357 ),
358 );
359 const subscribed = yield* supported.pipe(Effect.forkScoped({ startImmediately: true }));
360 yield* Deferred.succeed(release, undefined);
361 const updated = (yield* Fiber.join(subscribed))[0]?.[0];
362 assert.strictEqual(updated?.compatibilityAdvisory?.status, "supported");
363 assert.strictEqual(updated?.status, "error");
364 assert.strictEqual(updated?.message, "Authentication failed");
365 }).pipe(Effect.provide(ProviderRegistryLive.pipe(Layer.provide(dependencies))));
366 }).pipe(Effect.scoped),
367);
368​
369it("recomputes latest-version compatibility without losing the underlying update advisory", () => {
370 const snapshot: ServerProvider = {
371 ...provider,
372 version: "2.0.0",
373 versionAdvisory: {
374 status: "behind_latest",
375 currentVersion: "2.0.0",
376 latestVersion: "4.0.0",
377 canUpdate: true,
378 updateCommand: "npm install -g fixture@latest",
379 checkedAt: provider.checkedAt,
380 message: null,
381 },
382 };
383 const blockedPolicy: ProviderCompatibilityPolicy = {
384 ...policy,
385 ranges: [...policy.ranges, { range: ">=3.0.0", status: "broken" }],
386 };
387 const blocked = applyProviderCompatibility(snapshot, [blockedPolicy], []);
388 assert.strictEqual(blocked.compatibilityAdvisory?.latestVersionStatus, "broken");
389 const relaxed = applyProviderCompatibility(
390 blocked,
391 [{ ...policy, ranges: [{ range: ">=2.0.0", status: "supported" }] }],
392 [],
393 );
394 assert.strictEqual(relaxed.compatibilityAdvisory?.latestVersionStatus, "supported");
395 assert.deepStrictEqual(relaxed.versionAdvisory, snapshot.versionAdvisory);
396});