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

sharedSettings.test.ts

107 lines3.5 KB

1import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3​
4import {
5 findSharedSettingsMismatches,
6 pickSharedServerSettings,
7 splitSharedServerPatch,
8} from "./sharedSettings.ts";
9​
10const primaryId = EnvironmentId.make("env-primary");
11const laptopId = EnvironmentId.make("env-laptop");
12const boxId = EnvironmentId.make("env-box");
13​
14describe("splitSharedServerPatch", () => {
15 it("routes preference keys to the shared patch and machine keys to the local patch", () => {
16 const { sharedPatch, localPatch } = splitSharedServerPatch({
17 sidebarAutoSettleAfterDays: 7,
18 sidebarAutoSettleOnMerge: false,
19 enableAgentBrowserAccess: false,
20 });
21 expect(sharedPatch).toEqual({ sidebarAutoSettleAfterDays: 7, sidebarAutoSettleOnMerge: false });
22 expect(localPatch).toEqual({ enableAgentBrowserAccess: false });
23 });
24});
25​
26describe("pickSharedServerSettings", () => {
27 it("returns only the shared keys", () => {
28 expect(Object.keys(pickSharedServerSettings(DEFAULT_SERVER_SETTINGS)).sort()).toEqual([
29 "defaultThreadEnvMode",
30 "newWorktreesStartFromOrigin",
31 "sidebarAutoSettleAfterDays",
32 "sidebarAutoSettleOnMerge",
33 "sourceControlWritingStyle",
34 ]);
35 });
36});
37​
38describe("findSharedSettingsMismatches", () => {
39 const primarySettings = { ...DEFAULT_SERVER_SETTINGS, sidebarAutoSettleAfterDays: 7 };
40​
41 it("lists connected environments whose shared settings differ", () => {
42 const mismatches = findSharedSettingsMismatches({
43 primaryEnvironmentId: primaryId,
44 primarySettings,
45 environments: [
46 { environmentId: primaryId, label: "Desktop", connected: true, settings: primarySettings },
47 { environmentId: laptopId, label: "Laptop", connected: true, settings: primarySettings },
48 {
49 environmentId: boxId,
50 label: "Remote Box",
51 connected: true,
52 settings: DEFAULT_SERVER_SETTINGS,
53 },
54 ],
55 });
56 expect(mismatches).toEqual([{ environmentId: boxId, label: "Remote Box" }]);
57 });
58​
59 it("ignores machine-only differences", () => {
60 const mismatches = findSharedSettingsMismatches({
61 primaryEnvironmentId: primaryId,
62 primarySettings,
63 environments: [
64 {
65 environmentId: boxId,
66 label: "Remote Box",
67 connected: true,
68 settings: { ...primarySettings, enableAgentBrowserAccess: false },
69 },
70 ],
71 });
72 expect(mismatches).toEqual([]);
73 });
74​
75 it("reports nothing until the primary environment's settings are loaded", () => {
76 const environments = [
77 { environmentId: boxId, label: "Remote Box", connected: true, settings: primarySettings },
78 ];
79 expect(
80 findSharedSettingsMismatches({ primaryEnvironmentId: null, primarySettings, environments }),
81 ).toEqual([]);
82 expect(
83 findSharedSettingsMismatches({
84 primaryEnvironmentId: primaryId,
85 primarySettings: null,
86 environments,
87 }),
88 ).toEqual([]);
89 });
90​
91 it("skips offline environments and environments without a loaded config", () => {
92 const mismatches = findSharedSettingsMismatches({
93 primaryEnvironmentId: primaryId,
94 primarySettings,
95 environments: [
96 {
97 environmentId: laptopId,
98 label: "Laptop",
99 connected: false,
100 settings: DEFAULT_SERVER_SETTINGS,
101 },
102 { environmentId: boxId, label: "Remote Box", connected: true, settings: null },
103 ],
104 });
105 expect(mismatches).toEqual([]);
106 });
107});