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

server.test.ts

54 lines1.6 KB

1import { type ServerConfig, type ServerLifecycleWelcomePayload } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3import * as Option from "effect/Option";
4​
5import { applyServerConfigProjection, projectServerWelcome } from "./server.ts";
6​
7const CONFIG = {
8 availableEditors: [],
9 issues: [],
10 keybindings: {},
11 keybindingsConfigPath: null,
12 observability: null,
13 providers: [],
14 settings: {},
15} as unknown as ServerConfig;
16​
17describe("server state projection", () => {
18 it("applies every config category to the projected snapshot", () => {
19 const snapshot = applyServerConfigProjection(Option.none(), {
20 version: 1,
21 type: "snapshot",
22 config: CONFIG,
23 });
24 const settings = { ...CONFIG.settings };
25 const projected = applyServerConfigProjection(snapshot, {
26 version: 1,
27 type: "settingsUpdated",
28 payload: { settings },
29 });
30​
31 const result = Option.getOrThrow(projected);
32 expect(result.config.settings).toBe(settings);
33 expect(result.latestEvent.type).toBe("settingsUpdated");
34 });
35​
36 it("retains welcome when a ready event follows in the same stream chunk", () => {
37 const welcome = {
38 environment: {} as ServerLifecycleWelcomePayload["environment"],
39 cwd: "/repo",
40 projectName: "repo",
41 } as ServerLifecycleWelcomePayload;
42 const [afterWelcome] = projectServerWelcome(Option.none(), {
43 type: "welcome",
44 payload: welcome,
45 });
46 const [afterReady, emitted] = projectServerWelcome(afterWelcome, {
47 type: "ready",
48 payload: {},
49 });
50​
51 expect(Option.getOrThrow(afterReady)).toBe(welcome);
52 expect(emitted).toEqual([]);
53 });
54});