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

server.test.ts

157 lines4.7 KB

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