|
1 | 1 | import * as Schema from "effect/Schema"; |
2 | 2 | import { describe, expect, it } from "vite-plus/test"; |
3 | 3 |
|
4 | | -import { ServerConfig, ServerProvider, ServerUpsertKeybindingResult } from "./server.ts"; |
| 4 | +import { |
| 5 | + ServerConfig, |
| 6 | + ServerProvider, |
| 7 | + ServerProviders, |
| 8 | + ServerUpsertKeybindingResult, |
| 9 | +} from "./server.ts"; |
5 | 10 |
|
6 | 11 | const decodeServerProvider = Schema.decodeUnknownSync(ServerProvider); |
| 12 | +const decodeServerProviders = Schema.decodeUnknownSync(ServerProviders); |
7 | 13 | const decodeUpsertKeybindingResult = Schema.decodeUnknownSync(ServerUpsertKeybindingResult); |
8 | 14 | const decodeAvailableEditors = Schema.decodeUnknownSync(ServerConfig.fields.availableEditors); |
9 | 15 |
|
| 16 | +const baseProviderSnapshot = { |
| 17 | + instanceId: "codex", |
| 18 | + driver: "codex", |
| 19 | + enabled: true, |
| 20 | + installed: true, |
| 21 | + version: "1.0.0", |
| 22 | + status: "ready", |
| 23 | + auth: { status: "authenticated" }, |
| 24 | + checkedAt: "2026-04-10T00:00:00.000Z", |
| 25 | + models: [], |
| 26 | +}; |
| 27 | + |
10 | 28 | describe("ServerProvider", () => { |
11 | 29 | it("defaults capability arrays when decoding provider snapshots", () => { |
12 | 30 | const parsed = decodeServerProvider({ |
@@ -119,4 +137,21 @@ describe("server config forward compatibility", () => { |
119 | 137 |
|
120 | 138 | expect(parsed).toEqual(["zed", "vscode"]); |
121 | 139 | }); |
| 140 | + |
| 141 | + // A provider status this build has never seen (a new ServerProviderState, |
| 142 | + // ServerProviderAuthStatus, etc. member) previously failed the whole |
| 143 | + // `providers` array, taking every other provider down with it and, since |
| 144 | + // `providers` sits inside `ServerConfig`, failing the whole config decode — |
| 145 | + // an older client would drop its connection over one provider it can't |
| 146 | + // render. Dropping just that element keeps every other provider working. |
| 147 | + it("drops providers this build cannot decode instead of failing the whole array", () => { |
| 148 | + const decodedBase = decodeServerProvider(baseProviderSnapshot); |
| 149 | + |
| 150 | + const parsed = decodeServerProviders([ |
| 151 | + baseProviderSnapshot, |
| 152 | + { ...baseProviderSnapshot, instanceId: "future", status: "some-future-status" }, |
| 153 | + ]); |
| 154 | + |
| 155 | + expect(parsed).toEqual([decodedBase]); |
| 156 | + }); |
122 | 157 | }); |