Files
t3code/packages/contracts/src/server.test.ts
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

254 lines
8.0 KiB
TypeScript

import * as Schema from "effect/Schema";
import { describe, expect, it } from "vite-plus/test";
import { ExecutionEnvironmentDescriptor } from "./environment.ts";
import {
resolveEnvironmentMachineKind,
ServerConfig,
ServerObservability,
ServerProvider,
ServerProviders,
ServerUpsertKeybindingResult,
} from "./server.ts";
import { ServerSettings } from "./settings.ts";
const decodeServerProvider = Schema.decodeUnknownSync(ServerProvider);
const decodeServerProviders = Schema.decodeUnknownSync(ServerProviders);
const decodeServerObservability = Schema.decodeUnknownSync(ServerObservability);
const decodeUpsertKeybindingResult = Schema.decodeUnknownSync(ServerUpsertKeybindingResult);
const decodeAvailableEditors = Schema.decodeUnknownSync(ServerConfig.fields.availableEditors);
const baseProviderSnapshot = {
instanceId: "codex",
driver: "codex",
enabled: true,
installed: true,
version: "1.0.0",
status: "ready",
auth: { status: "authenticated" },
checkedAt: "2026-04-10T00:00:00.000Z",
models: [],
};
describe("ServerProvider", () => {
it("defaults capability arrays when decoding provider snapshots", () => {
const parsed = decodeServerProvider({
instanceId: "codex",
driver: "codex",
enabled: true,
installed: true,
version: "1.0.0",
status: "ready",
auth: {
status: "authenticated",
},
checkedAt: "2026-04-10T00:00:00.000Z",
supportedRuntimeModes: ["approval-required", "future-mode", "full-access"],
models: [],
});
expect(parsed.slashCommands).toEqual([]);
expect(parsed.skills).toEqual([]);
expect(parsed.supportedRuntimeModes).toEqual(["approval-required", "full-access"]);
expect(parsed.versionAdvisory).toBeUndefined();
expect(parsed.updateState).toBeUndefined();
});
it("defaults one-click update support when decoding older advisory snapshots", () => {
const parsed = decodeServerProvider({
instanceId: "codex",
driver: "codex",
enabled: true,
installed: true,
version: "1.0.0",
status: "ready",
auth: {
status: "authenticated",
},
checkedAt: "2026-04-10T00:00:00.000Z",
models: [],
versionAdvisory: {
status: "behind_latest",
currentVersion: "1.0.0",
latestVersion: "1.0.1",
updateCommand: "npm install -g @openai/codex@latest",
checkedAt: "2026-04-10T00:00:00.000Z",
message: "Update available.",
},
});
expect(parsed.versionAdvisory?.canUpdate).toBe(false);
});
it("decodes continuation group metadata", () => {
const parsed = decodeServerProvider({
instanceId: "codex_personal",
driver: "codex",
continuation: { groupKey: "codex:home:/Users/julius/.codex" },
enabled: true,
installed: true,
version: "1.0.0",
status: "ready",
auth: {
status: "authenticated",
},
checkedAt: "2026-04-10T00:00:00.000Z",
models: [],
});
expect(parsed.continuation?.groupKey).toBe("codex:home:/Users/julius/.codex");
});
it("decodes optional legacy model metadata", () => {
const parsed = decodeServerProvider({
instanceId: "codex",
driver: "codex",
enabled: true,
installed: true,
version: "1.0.0",
status: "ready",
auth: { status: "authenticated" },
checkedAt: "2026-04-10T00:00:00.000Z",
models: [
{
slug: "gpt-5.4",
name: "GPT-5.4",
isCustom: false,
isLegacy: true,
capabilities: null,
},
],
});
expect(parsed.models[0]?.isLegacy).toBe(true);
});
});
describe("server config forward compatibility", () => {
it("drops config issues with kinds this build does not know", () => {
const parsed = decodeUpsertKeybindingResult({
keybindings: [],
issues: [
{ kind: "keybindings.invalid-entry", message: "Bad entry", index: 2 },
{ kind: "keybindings.future-issue", message: "From a newer server" },
],
});
expect(parsed.issues).toEqual([
{ kind: "keybindings.invalid-entry", message: "Bad entry", index: 2 },
]);
});
it("drops editor ids this build does not know", () => {
const parsed = decodeAvailableEditors(["zed", "some-future-editor", "vscode"]);
expect(parsed).toEqual(["zed", "vscode"]);
});
// A provider status this build has never seen (a new ServerProviderState,
// ServerProviderAuthStatus, etc. member) previously failed the whole
// `providers` array, taking every other provider down with it and, since
// `providers` sits inside `ServerConfig`, failing the whole config decode —
// an older client would drop its connection over one provider it can't
// render. Dropping just that element keeps every other provider working.
it("drops providers this build cannot decode instead of failing the whole array", () => {
const decodedBase = decodeServerProvider(baseProviderSnapshot);
const parsed = decodeServerProviders([
baseProviderSnapshot,
{ ...baseProviderSnapshot, instanceId: "future", status: "some-future-status" },
]);
expect(parsed).toEqual([decodedBase]);
});
it("drops usage windows this build cannot decode instead of failing the provider", () => {
const parsed = decodeServerProvider({
...baseProviderSnapshot,
usageLimits: {
checkedAt: "2026-04-10T00:00:00.000Z",
windows: [
{ id: "primary", kind: "session", label: "Session", usedPercent: 12 },
{ id: "future", kind: "some-future-kind", label: "Future", usedPercent: 1 },
{ id: "bad", kind: "weekly", label: "Weekly", usedPercent: 120 },
],
},
});
expect(parsed.usageLimits?.windows).toEqual([
{ id: "primary", kind: "session", label: "Session", usedPercent: 12 },
]);
});
});
describe("ServerObservability", () => {
it("reads a server from before the log signal as exporting no logs", () => {
const parsed = decodeServerObservability({
logsDirectoryPath: "/tmp/t3/logs",
localTracingEnabled: true,
otlpTracesUrl: "https://collector.example.com/v1/traces",
otlpTracesEnabled: true,
otlpMetricsEnabled: false,
});
expect(parsed.otlpLogsEnabled).toBe(false);
expect(parsed.otlpLogsUrl).toBeUndefined();
});
});
describe("resolveEnvironmentMachineKind", () => {
const decodeDescriptor = Schema.decodeUnknownSync(ExecutionEnvironmentDescriptor);
const decodeSettings = Schema.decodeUnknownSync(ServerSettings);
const descriptor = (platform: Record<string, unknown>) =>
decodeDescriptor({
environmentId: "env-1",
label: "Box",
platform: { os: "linux", arch: "x64", ...platform },
serverVersion: "1.0.0",
capabilities: {},
});
it("prefers the user's pick over what the server detected", () => {
expect(
resolveEnvironmentMachineKind({
environment: descriptor({ machine: "mac-mini" }),
settings: decodeSettings({ environmentIcon: "laptop" }),
}),
).toBe("laptop");
});
it("uses detection when nothing is picked", () => {
expect(
resolveEnvironmentMachineKind({
environment: descriptor({ machine: "mac-mini" }),
settings: decodeSettings({}),
}),
).toBe("mac-mini");
});
it("uses detection from a bare descriptor before connecting", () => {
expect(resolveEnvironmentMachineKind({ environment: descriptor({ machine: "laptop" }) })).toBe(
"laptop",
);
});
it("falls back to a server for older servers and before connect", () => {
expect(
resolveEnvironmentMachineKind({
environment: descriptor({}),
settings: decodeSettings({}),
}),
).toBe("server");
expect(resolveEnvironmentMachineKind(null)).toBe("server");
});
it("drops a machine kind this build does not know instead of failing the descriptor", () => {
const parsed = descriptor({ machine: "toaster" });
expect(parsed.platform.machine).toBeUndefined();
expect(
resolveEnvironmentMachineKind({ environment: parsed, settings: decodeSettings({}) }),
).toBe("server");
});
});