Open History to see the last commit
1import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
2import * as Option from "effect/Option";
3import { describe, expect, it } from "vite-plus/test";
4
5import { applyServerConfigProjection, reuseUnchanged } from "./serverConfigProjection.ts";
6
7describe("reuseUnchanged", () => {
8 const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({
9 instanceId: "claude",
10 checkedAt,
11 models: [{ slug: "opus", name: "Opus" }],
12 skills: skills.map((name) => ({ name })),
13 });
14
15 it("takes the new value when keys or lengths change", () => {
16 const previous = [provider("a", ["x"])];
17 const next = reuseUnchanged(previous, [provider("a", ["x", "z"])]);
18 expect(next[0]!.skills).toHaveLength(2);
19 expect(next[0]!.models).toBe(previous[0]!.models);
20 const dropped = reuseUnchanged({ a: 1, b: 2 }, { a: 1 });
21 expect(dropped).toEqual({ a: 1 });
22 });
23});
24
25describe("applyServerConfigProjection settingsUpdated", () => {
26 it("keeps unchanged settings sections when one field changes", () => {
27 const settings = {
28 favorites: [{ provider: "claude", model: "opus" }],
29 providerInstances: {
30 claude: { driver: "claudeAgent", config: { launchArgs: "" } },
31 codex: { driver: "codex" },
32 },
33 };
34 const current = Option.some({
35 config: { settings } as unknown as ServerConfig,
36 latestEvent: {} as ServerConfigStreamEvent,
37 source: "live" as const,
38 });
39 const next = applyServerConfigProjection(current, {
40 type: "settingsUpdated",
41 payload: {
42 settings: {
43 favorites: [{ provider: "claude", model: "opus" }],
44 providerInstances: {
45 claude: { driver: "claudeAgent", config: { launchArgs: "--verbose" } },
46 codex: { driver: "codex" },
47 },
48 },
49 },
50 } as unknown as ServerConfigStreamEvent);
51 const nextSettings = Option.getOrThrow(next).config.settings as unknown as typeof settings;
52 expect(nextSettings.favorites).toBe(settings.favorites);
53 expect(nextSettings.providerInstances.codex).toBe(settings.providerInstances.codex);
54 expect(nextSettings.providerInstances.claude.config.launchArgs).toBe("--verbose");
55 });
56});