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

providerCompatibility.test.ts

353 lines13.4 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​
54describe("provider compatibility", () => {
55 it("bundles a compatibility policy for every built-in harness", () => {
56 for (const builtIn of BUILT_IN_DRIVERS) {
57 // Registry entries are arbitrary external ACP agents, not one versioned harness.
58 if (builtIn.driverKind === "acpRegistry") continue;
59 assert.isDefined(
60 resolveProviderCompatibility(
61 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
62 builtIn.driverKind,
63 null,
64 ),
65 `Missing bundled compatibility policy for ${builtIn.driverKind}`,
66 );
67 }
68 });
69​
70 it("supports OpenCode 2 and gives OpenCode 1.x limited support", () => {
71 const opencode = ProviderDriverKind.make("opencode");
72 for (const [version, expected] of [
73 ["2.0.18", "supported"],
74 ["2.1.0", "supported"],
75 // Early OpenCode 2 releases predate the API the adapter was built against.
76 ["2.0.17", "unsupported"],
77 ["2.0.0", "unsupported"],
78 ["1.99.0", "graceful"],
79 ["1.14.19", "graceful"],
80 ["1.14.18", "broken"],
81 ] as const) {
82 const advisory = resolveProviderCompatibility(
83 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
84 opencode,
85 version,
86 );
87 assert.strictEqual(advisory?.status, expected, `OpenCode ${version}`);
88 assert.strictEqual(advisory?.recommendedRange, ">=2.0.18");
89 }
90 // The advisory rides beside the probe: a ready 1.x instance stays ready and selectable.
91 const ready = applyProviderCompatibility(
92 { ...provider, driver: opencode, version: "1.18.33", status: "ready", message: undefined },
93 undefined,
94 ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
95 );
96 assert.strictEqual(ready.status, "ready");
97 assert.strictEqual(ready.compatibilityAdvisory?.status, "graceful");
98 });
99​
100 it("compares Cursor build dates without treating semver prereleases as stable", () => {
101 const cursor = ProviderDriverKind.make("cursor");
102 const cursorPolicy: ProviderCompatibilityPolicy = {
103 driver: cursor,
104 t3CodeRange: policy.t3CodeRange,
105 ranges: [
106 { range: "<2026.05.09", status: "unsupported" },
107 { range: ">=2026.05.09", status: "supported" },
108 ],
109 };
110 for (const [version, expected] of [
111 ["2026.05.08-a1b2c3d", "unsupported"],
112 ["2026.05.09-a1b2c3d", "supported"],
113 ["2026.09.22-f2b0fcd", "supported"],
114 ["2026.05.09", "supported"],
115 ["2026.05.09-beta.1", "unknown"],
116 ] as const) {
117 assert.strictEqual(
118 resolveProviderCompatibility([cursorPolicy], cursor, version)?.status,
119 expected,
120 );
121 }
122 assert.strictEqual(
123 resolveProviderCompatibility([policy], driver, "2.0.0-a1b2c3d")?.status,
124 "unknown",
125 );
126 });
127​
128 it("recognizes Antigravity semver release tags while keeping dated candidates unknown", () => {
129 const antigravity = ProviderDriverKind.make("antigravity");
130 const taggedPolicy = {
131 ...policy,
132 driver: antigravity,
133 ranges: [{ range: "=2.0.0", status: "supported" as const }],
134 };
135 for (const [version, expected] of [
136 ["agy_acp_server_2.0.0", "supported"],
137 ["2.0.0", "supported"],
138 ["agy_acp_server_2.0.1", "unknown"],
139 ["agy_acp_server_2.0.0-beta.1", "unknown"],
140 ["agy_acp_server_20260818_01_RC01", "unknown"],
141 ] as const) {
142 assert.strictEqual(
143 resolveProviderCompatibility([taggedPolicy], antigravity, version)?.status,
144 expected,
145 );
146 }
147 });
148​
149 it("classifies boundaries and treats unlisted versions and release tags as unknown", () => {
150 for (const [version, expected] of [
151 ["0.9.9", "broken"],
152 ["1.0.0", "unsupported"],
153 ["1.5.0", "graceful"],
154 ["2.0.0", "supported"],
155 ["v2.0.0", "supported"],
156 ["3.0.0", "unknown"],
157 ["2.0.0-beta.1", "unknown"],
158 ["agy_acp_server_20260818_01_RC01", "unknown"],
159 [null, "unknown"],
160 ] as const) {
161 assert.strictEqual(resolveProviderCompatibility([policy], driver, version)?.status, expected);
162 }
163 assert.isUndefined(resolveProviderCompatibility([policy], driver, "0.9.0", "0.1.0"));
164 });
165​
166 it("supports every driver without inventing policies for uncovered adapters", () => {
167 for (const kind of [
168 "codex",
169 "claudeAgent",
170 "cursor",
171 "grok",
172 "opencode",
173 "antigravity",
174 "customDriver",
175 ]) {
176 const adapter = ProviderDriverKind.make(kind);
177 assert.strictEqual(
178 resolveProviderCompatibility([{ ...policy, driver: adapter }], adapter, "2.0.0")?.status,
179 "supported",
180 );
181 assert.isUndefined(resolveProviderCompatibility([], adapter, "2.0.0"));
182 }
183 });
184​
185 it("relaxes remote policy without losing probe errors, and falls back when a policy is omitted", () => {
186 const broken = applyProviderCompatibility(provider, [], [policy]);
187 assert.strictEqual(broken.compatibilityAdvisory?.status, "broken");
188 const relaxed = { ...policy, ranges: [{ range: ">=0.0.0", status: "supported" as const }] };
189 const supported = applyProviderCompatibility(broken, [relaxed], [policy]);
190 assert.strictEqual(supported.compatibilityAdvisory?.status, "supported");
191 assert.strictEqual(supported.status, "error");
192 assert.strictEqual(supported.message, "Authentication failed");
193 assert.strictEqual(
194 applyProviderCompatibility(supported, [{ ...policy, t3CodeRange: ">=9.0.0" }], [policy])
195 .compatibilityAdvisory?.status,
196 "broken",
197 );
198 const removed = applyProviderCompatibility(supported, [], []);
199 assert.isUndefined(removed.compatibilityAdvisory);
200 assert.strictEqual(removed.status, "error");
201 assert.strictEqual(removed.message, "Authentication failed");
202 assert.isUndefined(
203 applyProviderCompatibility({ ...broken, enabled: false }, [], [policy]).compatibilityAdvisory,
204 );
205 assert.isUndefined(
206 applyProviderCompatibility({ ...broken, installed: false }, [], [policy])
207 .compatibilityAdvisory,
208 );
209 });
210​
211 it("rejects invalid ranges and recommendations outside the first supported match", () => {
212 const decode = Schema.decodeUnknownSync(ProviderCompatibilityPolicy);
213 assert.doesNotThrow(() => decode(policy));
214 const prefixed = decode({
215 ...policy,
216 t3CodeRange: ">=v0.0.42 <v0.1",
217 recommendedRange: "^v2",
218 ranges: [{ range: ">=v2.0 <v3", status: "supported" }],
219 });
220 assert.strictEqual(
221 resolveProviderCompatibility([prefixed], driver, "2.0.0")?.status,
222 "supported",
223 );
224 assert.strictEqual(
225 resolveProviderCompatibility([prefixed], driver, "3.0.0")?.status,
226 "unknown",
227 );
228 for (const invalid of [
229 { ...policy, t3CodeRange: "*" },
230 { ...policy, recommendedVersion: "3.0.0" },
231 { ...policy, ranges: [{ range: ">=2.0.0 garbage", status: "supported" }] },
232 { ...policy, recommendedVersion: "2.0.0; echo unsafe" },
233 { ...policy, ranges: [{ range: ">=0.0.0", status: "broken" }, ...policy.ranges] },
234 ])
235 assert.throws(() => decode(invalid));
236 });
237});
238​
239it.effect("a remote policy refresh preserves a newer health result on the registry stream", () =>
240 Effect.gen(function* () {
241 const started = yield* Deferred.make<void>();
242 const release = yield* Deferred.make<void>();
243 const health = yield* Ref.make<ServerProvider>({
244 ...provider,
245 status: "ready" as ServerProvider["status"],
246 message: "Healthy",
247 });
248 const manifest = yield* Ref.make<ModelManifest.ModelManifestData>({
249 version: 1,
250 currentModels: {},
251 compatibility: [policy],
252 });
253 const instance: ProviderInstance = {
254 instanceId: provider.instanceId,
255 driverKind: driver,
256 enabled: true,
257 displayName: undefined,
258 continuationIdentity: { driverKind: driver, continuationKey: "test-codex" },
259 snapshot: {
260 getSnapshot: Ref.get(health),
261 refresh: Ref.get(health),
262 streamChanges: Stream.empty,
263 applyUsageLimits: () => Effect.void,
264 resolveMaintenance: () =>
265 Effect.succeed(
266 makeManualOnlyProviderMaintenanceCapabilities({ provider: driver, packageName: null }),
267 ),
268 },
269 orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
270 textGeneration: {} as ProviderInstance["textGeneration"],
271 };
272 const refresh = Deferred.succeed(started, undefined).pipe(
273 Effect.andThen(Deferred.await(release)),
274 Effect.andThen(
275 Ref.updateAndGet(manifest, (current) => ({
276 ...current,
277 compatibility: [
278 { ...policy, ranges: [{ range: ">=0.0.0", status: "supported" as const }] },
279 ],
280 })),
281 ),
282 );
283 const dependencies = Layer.mergeAll(
284 Layer.succeed(ModelManifest.ModelManifest, {
285 current: Ref.get(manifest),
286 refresh,
287 forceRefresh: refresh,
288 refreshInBackground: Effect.void,
289 }),
290 Layer.succeed(ProviderInstanceRegistry.ProviderInstanceRegistry, {
291 getInstance: (id) => Effect.succeed(id === instance.instanceId ? instance : undefined),
292 listInstances: Effect.succeed([instance]),
293 listUnavailable: Effect.succeed([]),
294 streamChanges: Stream.empty,
295 subscribeChanges: Effect.flatMap(PubSub.unbounded<void>(), PubSub.subscribe),
296 }),
297 ServerConfig.layerTest(process.cwd(), { prefix: "compatibility-registry-test" }).pipe(
298 Layer.provideMerge(NodeServices.layer),
299 ),
300 );
301 yield* Effect.gen(function* () {
302 const registry = yield* ProviderRegistry.ProviderRegistry;
303 yield* Deferred.await(started);
304 assert.strictEqual(
305 (yield* registry.getProviders)[0]?.compatibilityAdvisory?.status,
306 "broken",
307 );
308 yield* Ref.set(health, provider);
309 const latestHealth = yield* registry.refreshInstance(provider.instanceId);
310 assert.strictEqual(latestHealth[0]?.message, "Authentication failed");
311 const supported = yield* Stream.toPull(
312 registry.streamChanges.pipe(
313 Stream.filter((snapshots) => snapshots[0]?.compatibilityAdvisory?.status === "supported"),
314 ),
315 );
316 const subscribed = yield* supported.pipe(Effect.forkScoped({ startImmediately: true }));
317 yield* Deferred.succeed(release, undefined);
318 const updated = (yield* Fiber.join(subscribed))[0]?.[0];
319 assert.strictEqual(updated?.compatibilityAdvisory?.status, "supported");
320 assert.strictEqual(updated?.status, "error");
321 assert.strictEqual(updated?.message, "Authentication failed");
322 }).pipe(Effect.provide(ProviderRegistryLive.pipe(Layer.provide(dependencies))));
323 }).pipe(Effect.scoped),
324);
325​
326it("recomputes latest-version compatibility without losing the underlying update advisory", () => {
327 const snapshot: ServerProvider = {
328 ...provider,
329 version: "2.0.0",
330 versionAdvisory: {
331 status: "behind_latest",
332 currentVersion: "2.0.0",
333 latestVersion: "4.0.0",
334 canUpdate: true,
335 updateCommand: "npm install -g fixture@latest",
336 checkedAt: provider.checkedAt,
337 message: null,
338 },
339 };
340 const blockedPolicy: ProviderCompatibilityPolicy = {
341 ...policy,
342 ranges: [...policy.ranges, { range: ">=3.0.0", status: "broken" }],
343 };
344 const blocked = applyProviderCompatibility(snapshot, [blockedPolicy], []);
345 assert.strictEqual(blocked.compatibilityAdvisory?.latestVersionStatus, "broken");
346 const relaxed = applyProviderCompatibility(
347 blocked,
348 [{ ...policy, ranges: [{ range: ">=2.0.0", status: "supported" }] }],
349 [],
350 );
351 assert.strictEqual(relaxed.compatibilityAdvisory?.latestVersionStatus, "supported");
352 assert.deepStrictEqual(relaxed.versionAdvisory, snapshot.versionAdvisory);
353});