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

sharedSettings.test.ts

146 lines4.4 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 supportsSharedSettingsSync,
9} from "./sharedSettings.ts";
10​
11const primaryId = EnvironmentId.make("env-primary");
12const laptopId = EnvironmentId.make("env-laptop");
13const boxId = EnvironmentId.make("env-box");
14​
15describe("supportsSharedSettingsSync", () => {
16 it("accepts only connected servers that advertise the shared-settings capability", () => {
17 expect(
18 supportsSharedSettingsSync({
19 connection: { phase: "connected" },
20 serverConfig: { environment: { capabilities: { threadAutoSettlement: true } } },
21 }),
22 ).toBe(true);
23 expect(
24 supportsSharedSettingsSync({
25 connection: { phase: "connected" },
26 serverConfig: { environment: { capabilities: {} } },
27 }),
28 ).toBe(false);
29 expect(
30 supportsSharedSettingsSync({
31 connection: { phase: "reconnecting" },
32 serverConfig: { environment: { capabilities: { threadAutoSettlement: true } } },
33 }),
34 ).toBe(false);
35 });
36});
37​
38describe("splitSharedServerPatch", () => {
39 it("routes preference keys to the shared patch and machine keys to the local patch", () => {
40 const { sharedPatch, localPatch } = splitSharedServerPatch({
41 sidebarAutoSettleAfterDays: 7,
42 sidebarAutoSettleOnMerge: false,
43 enableAgentBrowserAccess: false,
44 });
45 expect(sharedPatch).toEqual({ sidebarAutoSettleAfterDays: 7, sidebarAutoSettleOnMerge: false });
46 expect(localPatch).toEqual({ enableAgentBrowserAccess: false });
47 });
48});
49​
50describe("pickSharedServerSettings", () => {
51 it("returns only the shared keys", () => {
52 expect(Object.keys(pickSharedServerSettings(DEFAULT_SERVER_SETTINGS)).sort()).toEqual([
53 "defaultThreadEnvMode",
54 "newWorktreesStartFromOrigin",
55 "sidebarAutoSettleAfterDays",
56 "sidebarAutoSettleOnMerge",
57 "sourceControlWritingStyle",
58 ]);
59 });
60});
61​
62describe("findSharedSettingsMismatches", () => {
63 const primarySettings = { ...DEFAULT_SERVER_SETTINGS, sidebarAutoSettleAfterDays: 7 };
64​
65 it("lists sync-eligible environments whose shared settings differ", () => {
66 const mismatches = findSharedSettingsMismatches({
67 primaryEnvironmentId: primaryId,
68 primarySettings,
69 environments: [
70 {
71 environmentId: primaryId,
72 label: "Desktop",
73 syncEligible: true,
74 settings: primarySettings,
75 },
76 {
77 environmentId: laptopId,
78 label: "Laptop",
79 syncEligible: true,
80 settings: primarySettings,
81 },
82 {
83 environmentId: boxId,
84 label: "Remote Box",
85 syncEligible: true,
86 settings: DEFAULT_SERVER_SETTINGS,
87 },
88 ],
89 });
90 expect(mismatches).toEqual([{ environmentId: boxId, label: "Remote Box" }]);
91 });
92​
93 it("ignores machine-only differences", () => {
94 const mismatches = findSharedSettingsMismatches({
95 primaryEnvironmentId: primaryId,
96 primarySettings,
97 environments: [
98 {
99 environmentId: boxId,
100 label: "Remote Box",
101 syncEligible: true,
102 settings: { ...primarySettings, enableAgentBrowserAccess: false },
103 },
104 ],
105 });
106 expect(mismatches).toEqual([]);
107 });
108​
109 it("reports nothing until the primary environment's settings are loaded", () => {
110 const environments = [
111 {
112 environmentId: boxId,
113 label: "Remote Box",
114 syncEligible: true,
115 settings: primarySettings,
116 },
117 ];
118 expect(
119 findSharedSettingsMismatches({ primaryEnvironmentId: null, primarySettings, environments }),
120 ).toEqual([]);
121 expect(
122 findSharedSettingsMismatches({
123 primaryEnvironmentId: primaryId,
124 primarySettings: null,
125 environments,
126 }),
127 ).toEqual([]);
128 });
129​
130 it("skips ineligible environments and environments without a loaded config", () => {
131 const mismatches = findSharedSettingsMismatches({
132 primaryEnvironmentId: primaryId,
133 primarySettings,
134 environments: [
135 {
136 environmentId: laptopId,
137 label: "Laptop",
138 syncEligible: false,
139 settings: DEFAULT_SERVER_SETTINGS,
140 },
141 { environmentId: boxId, label: "Remote Box", syncEligible: true, settings: null },
142 ],
143 });
144 expect(mismatches).toEqual([]);
145 });
146});