1import { DEFAULT_SERVER_SETTINGS, EnvironmentId, ProjectId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { planAutoSettleSettingsSync } from "./autoSettleSettingsSync";
5
6const reference = {
7 environmentId: EnvironmentId.make("reference"),
8 settings: {
9 ...DEFAULT_SERVER_SETTINGS,
10 sidebarAutoSettleAfterDays: 7,
11 sidebarAutoSettleOnMerge: true,
12 newWorktreesStartFromOrigin: false,
13 continueThreadsAfterServerUpdate: false,
14 },
15};
16
17describe("auto-settle settings sync", () => {
18 it("ignores differences in independently configured environment settings", () => {
19 const target = {
20 environmentId: EnvironmentId.make("remote"),
21 label: "Remote",
22 settings: {
23 ...reference.settings,
24 newWorktreesStartFromOrigin: true,
25 continueThreadsAfterServerUpdate: true,
26 sourceControlWritingStyle: {
27 ...reference.settings.sourceControlWritingStyle,
28 customInstructions: "Keep this environment's writing instructions.",
29 },
30 },
31 };
32
33 const plan = planAutoSettleSettingsSync(reference, [target]);
34
35 expect(plan.mismatches).toEqual([]);
36 expect(plan.patch).toEqual({
37 sidebarAutoSettleAfterDays: 7,
38 sidebarAutoSettleOnMerge: true,
39 });
40 });
41
42 it("applies only auto-settle defaults when another environment differs", () => {
43 const target = {
44 environmentId: EnvironmentId.make("remote"),
45 label: "Remote",
46 settings: {
47 ...reference.settings,
48 sidebarAutoSettleAfterDays: null,
49 sidebarAutoSettleOnMerge: false,
50 newWorktreesStartFromOrigin: true,
51 continueThreadsAfterServerUpdate: true,
52 sourceControlWritingStyle: {
53 ...reference.settings.sourceControlWritingStyle,
54 customInstructions: "Preserve these instructions.",
55 },
56 },
57 };
58
59 const plan = planAutoSettleSettingsSync(reference, [target]);
60 const updated = { ...target.settings, ...plan.patch };
61
62 expect(plan.mismatches).toEqual([target]);
63 expect(updated.sidebarAutoSettleAfterDays).toBe(7);
64 expect(updated.sidebarAutoSettleOnMerge).toBe(true);
65 expect(updated.newWorktreesStartFromOrigin).toBe(true);
66 expect(updated.continueThreadsAfterServerUpdate).toBe(true);
67 expect(updated.sourceControlWritingStyle).toEqual(target.settings.sourceControlWritingStyle);
68 });
69
70 it("does not compare the reference or a target without loaded settings", () => {
71 const plan = planAutoSettleSettingsSync(reference, [
72 { ...reference, label: "Reference" },
73 { environmentId: EnvironmentId.make("loading"), label: "Loading", settings: null },
74 ]);
75
76 expect(plan.mismatches).toEqual([]);
77 });
78
79 it("notices different project checkouts on the same environment", () => {
80 const projectReference = { ...reference, projectId: ProjectId.make("one") };
81 const otherCheckout = {
82 environmentId: reference.environmentId,
83 projectId: ProjectId.make("two"),
84 label: "Other checkout",
85 settings: { ...reference.settings, sidebarAutoSettleAfterDays: null },
86 };
87
88 expect(planAutoSettleSettingsSync(projectReference, [otherCheckout]).mismatches).toEqual([
89 otherCheckout,
90 ]);
91 });
92});