Open History to see the last commit
1import * as Schema from "effect/Schema";
2import { describe, expect, it } from "vite-plus/test";
3
4import { ServerConfig, ServerProvider, ServerUpsertKeybindingResult } from "./server.ts";
5
6const decodeServerProvider = Schema.decodeUnknownSync(ServerProvider);
7const decodeUpsertKeybindingResult = Schema.decodeUnknownSync(ServerUpsertKeybindingResult);
8const decodeAvailableEditors = Schema.decodeUnknownSync(ServerConfig.fields.availableEditors);
9
10describe("ServerProvider", () => {
11 it("defaults capability arrays when decoding provider snapshots", () => {
12 const parsed = decodeServerProvider({
13 instanceId: "codex",
14 driver: "codex",
15 enabled: true,
16 installed: true,
17 version: "1.0.0",
18 status: "ready",
19 auth: {
20 status: "authenticated",
21 },
22 checkedAt: "2026-04-10T00:00:00.000Z",
23 models: [],
24 });
25
26 expect(parsed.slashCommands).toEqual([]);
27 expect(parsed.skills).toEqual([]);
28 expect(parsed.versionAdvisory).toBeUndefined();
29 expect(parsed.updateState).toBeUndefined();
30 });
31
32 it("defaults one-click update support when decoding older advisory snapshots", () => {
33 const parsed = decodeServerProvider({
34 instanceId: "codex",
35 driver: "codex",
36 enabled: true,
37 installed: true,
38 version: "1.0.0",
39 status: "ready",
40 auth: {
41 status: "authenticated",
42 },
43 checkedAt: "2026-04-10T00:00:00.000Z",
44 models: [],
45 versionAdvisory: {
46 status: "behind_latest",
47 currentVersion: "1.0.0",
48 latestVersion: "1.0.1",
49 updateCommand: "npm install -g @openai/codex@latest",
50 checkedAt: "2026-04-10T00:00:00.000Z",
51 message: "Update available.",
52 },
53 });
54
55 expect(parsed.versionAdvisory?.canUpdate).toBe(false);
56 });
57
58 it("decodes continuation group metadata", () => {
59 const parsed = decodeServerProvider({
60 instanceId: "codex_personal",
61 driver: "codex",
62 continuation: { groupKey: "codex:home:/Users/julius/.codex" },
63 enabled: true,
64 installed: true,
65 version: "1.0.0",
66 status: "ready",
67 auth: {
68 status: "authenticated",
69 },
70 checkedAt: "2026-04-10T00:00:00.000Z",
71 models: [],
72 });
73
74 expect(parsed.continuation?.groupKey).toBe("codex:home:/Users/julius/.codex");
75 });
76
77 it("decodes optional legacy model metadata", () => {
78 const parsed = decodeServerProvider({
79 instanceId: "codex",
80 driver: "codex",
81 enabled: true,
82 installed: true,
83 version: "1.0.0",
84 status: "ready",
85 auth: { status: "authenticated" },
86 checkedAt: "2026-04-10T00:00:00.000Z",
87 models: [
88 {
89 slug: "gpt-5.4",
90 name: "GPT-5.4",
91 isCustom: false,
92 isLegacy: true,
93 capabilities: null,
94 },
95 ],
96 });
97
98 expect(parsed.models[0]?.isLegacy).toBe(true);
99 });
100});
101
102describe("server config forward compatibility", () => {
103 it("drops config issues with kinds this build does not know", () => {
104 const parsed = decodeUpsertKeybindingResult({
105 keybindings: [],
106 issues: [
107 { kind: "keybindings.invalid-entry", message: "Bad entry", index: 2 },
108 { kind: "keybindings.future-issue", message: "From a newer server" },
109 ],
110 });
111
112 expect(parsed.issues).toEqual([
113 { kind: "keybindings.invalid-entry", message: "Bad entry", index: 2 },
114 ]);
115 });
116
117 it("drops editor ids this build does not know", () => {
118 const parsed = decodeAvailableEditors(["zed", "some-future-editor", "vscode"]);
119
120 expect(parsed).toEqual(["zed", "vscode"]);
121 });
122});