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