|
1 | | -import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + DEFAULT_SERVER_SETTINGS, |
| 3 | + ServerSettings, |
| 4 | + type ServerConfig, |
| 5 | + type ServerConfigStreamEvent, |
| 6 | +} from "@t3tools/contracts"; |
2 | 7 | import * as Option from "effect/Option"; |
| 8 | +import * as Schema from "effect/Schema"; |
3 | 9 | import { describe, expect, it } from "vite-plus/test"; |
4 | 10 |
|
5 | 11 | import { applyServerConfigProjection, reuseUnchanged } from "./serverConfigProjection.ts"; |
6 | 12 |
|
| 13 | +const encodeSettings = Schema.encodeSync(ServerSettings); |
| 14 | +const decodeSettings = Schema.decodeSync(ServerSettings); |
| 15 | + |
7 | 16 | describe("reuseUnchanged", () => { |
8 | 17 | const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({ |
9 | 18 | instanceId: "claude", |
@@ -53,4 +62,20 @@ describe("applyServerConfigProjection settingsUpdated", () => { |
53 | 62 | expect(nextSettings.providerInstances.codex).toBe(settings.providerInstances.codex); |
54 | 63 | expect(nextSettings.providerInstances.claude.config.launchArgs).toBe("--verbose"); |
55 | 64 | }); |
| 65 | + |
| 66 | + it("keeps the settings object when an update repeats the current settings", () => { |
| 67 | + const wire = encodeSettings(DEFAULT_SERVER_SETTINGS); |
| 68 | + const decode = () => decodeSettings(structuredClone(wire)); |
| 69 | + const settings = decode(); |
| 70 | + const current = Option.some({ |
| 71 | + config: { settings } as unknown as ServerConfig, |
| 72 | + latestEvent: {} as ServerConfigStreamEvent, |
| 73 | + source: "live" as const, |
| 74 | + }); |
| 75 | + const next = applyServerConfigProjection(current, { |
| 76 | + type: "settingsUpdated", |
| 77 | + payload: { settings: decode() }, |
| 78 | + } as ServerConfigStreamEvent); |
| 79 | + expect(Option.getOrThrow(next).config).toBe(Option.getOrThrow(current).config); |
| 80 | + }); |
56 | 81 | }); |
0 commit comments