Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { reuseUnchanged } from "./serverConfigProjection.ts";
4
5describe("reuseUnchanged", () => {
6 const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({
7 instanceId: "claude",
8 checkedAt,
9 models: [{ slug: "opus", name: "Opus" }],
10 skills: skills.map((name) => ({ name })),
11 });
12
13 it("returns the previous value when nothing changed", () => {
14 const previous = [provider("a", ["x"])];
15 expect(reuseUnchanged(previous, [provider("a", ["x"])])).toBe(previous);
16 });
17
18 it("keeps unchanged parts when one field changes", () => {
19 const previous = [provider("a", ["x"]), { ...provider("a", ["y"]), instanceId: "codex" }];
20 const next = reuseUnchanged(previous, [
21 provider("b", ["x"]),
22 { ...provider("a", ["y"]), instanceId: "codex" },
23 ]);
24 expect(next).not.toBe(previous);
25 expect(next[0]).not.toBe(previous[0]);
26 expect(next[0]!.checkedAt).toBe("b");
27 expect(next[0]!.models).toBe(previous[0]!.models);
28 expect(next[0]!.skills).toBe(previous[0]!.skills);
29 expect(next[1]).toBe(previous[1]);
30 });
31
32 it("takes the new value when keys or lengths change", () => {
33 const previous = [provider("a", ["x"])];
34 const next = reuseUnchanged(previous, [provider("a", ["x", "z"])]);
35 expect(next[0]!.skills).toHaveLength(2);
36 expect(next[0]!.models).toBe(previous[0]!.models);
37 const dropped = reuseUnchanged({ a: 1, b: 2 }, { a: 1 });
38 expect(dropped).toEqual({ a: 1 });
39 });
40});