|
1 | | -import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + DEFAULT_SERVER_SETTINGS, |
| 3 | + EnvironmentId, |
| 4 | + ProviderDriverKind, |
| 5 | + ProviderInstanceId, |
| 6 | +} from "@t3tools/contracts"; |
2 | 7 | import { describe, expect, it } from "@effect/vitest"; |
3 | 8 |
|
4 | 9 | import { |
@@ -38,6 +43,47 @@ describe("supportsSharedSettingsSync", () => { |
38 | 43 | }); |
39 | 44 |
|
40 | 45 | describe("splitSharedServerPatch", () => { |
| 46 | + it.each([ |
| 47 | + { |
| 48 | + instanceId: ProviderInstanceId.make("codex"), |
| 49 | + model: "gpt-5.6-sol", |
| 50 | + options: [{ id: "reasoningEffort", value: "low" }], |
| 51 | + }, |
| 52 | + { |
| 53 | + instanceId: ProviderInstanceId.make("claudeAgent"), |
| 54 | + model: "claude-sonnet-4-6", |
| 55 | + options: [{ id: "effort", value: "high" }], |
| 56 | + }, |
| 57 | + DEFAULT_SERVER_SETTINGS.textGenerationModelSelection, |
| 58 | + ])("shares the text generation model and options, including reset (%j)", (selection) => { |
| 59 | + const patch = { textGenerationModelSelection: selection }; |
| 60 | + expect(splitSharedServerPatch(patch)).toEqual({ sharedPatch: patch, localPatch: {} }); |
| 61 | + expect(pickSharedServerSettings({ ...DEFAULT_SERVER_SETTINGS, ...patch })).toMatchObject(patch); |
| 62 | + const environment = { |
| 63 | + environmentId: boxId, |
| 64 | + label: "Remote Box", |
| 65 | + syncEligible: true, |
| 66 | + settings: { |
| 67 | + ...DEFAULT_SERVER_SETTINGS, |
| 68 | + textGenerationModelSelection: { ...selection, model: "different-model" }, |
| 69 | + }, |
| 70 | + }; |
| 71 | + const input = { |
| 72 | + primaryEnvironmentId: primaryId, |
| 73 | + primarySettings: { ...DEFAULT_SERVER_SETTINGS, ...patch }, |
| 74 | + environments: [environment], |
| 75 | + }; |
| 76 | + expect(findSharedSettingsMismatches(input)).toEqual([ |
| 77 | + { environmentId: boxId, label: "Remote Box" }, |
| 78 | + ]); |
| 79 | + expect( |
| 80 | + findSharedSettingsMismatches({ |
| 81 | + ...input, |
| 82 | + environments: [{ ...environment, settings: input.primarySettings }], |
| 83 | + }), |
| 84 | + ).toEqual([]); |
| 85 | + }); |
| 86 | + |
41 | 87 | it("routes preference keys to the shared patch and machine keys to the local patch", () => { |
42 | 88 | const { sharedPatch, localPatch } = splitSharedServerPatch({ |
43 | 89 | sidebarAutoSettleAfterDays: 7, |
@@ -70,11 +116,92 @@ describe("pickSharedServerSettings", () => { |
70 | 116 | "sidebarAutoSettleAfterDays", |
71 | 117 | "sidebarAutoSettleOnMerge", |
72 | 118 | "sourceControlWritingStyle", |
| 119 | + "textGenerationModelSelection", |
73 | 120 | ]); |
74 | 121 | }); |
75 | 122 | }); |
76 | 123 |
|
77 | 124 | describe("filterSharedServerPatch", () => { |
| 125 | + it.each([true, false])( |
| 126 | + "resets a disabled default provider only on the originating environment (%s)", |
| 127 | + (targetIsSource) => { |
| 128 | + const settings = { |
| 129 | + ...DEFAULT_SERVER_SETTINGS, |
| 130 | + providerInstances: { |
| 131 | + codex: { driver: ProviderDriverKind.make("codex"), enabled: false, config: {} }, |
| 132 | + claudeAgent: { |
| 133 | + driver: ProviderDriverKind.make("claudeAgent"), |
| 134 | + enabled: true, |
| 135 | + config: {}, |
| 136 | + }, |
| 137 | + }, |
| 138 | + textGenerationModelSelection: { |
| 139 | + instanceId: ProviderInstanceId.make("claudeAgent"), |
| 140 | + model: "claude-opus-4-6", |
| 141 | + }, |
| 142 | + }; |
| 143 | + const patch = { |
| 144 | + textGenerationModelSelection: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection, |
| 145 | + continueThreadsAfterServerUpdate: true, |
| 146 | + sidebarAutoSettleAfterDays: 7, |
| 147 | + }; |
| 148 | + expect(filterSharedServerPatch(patch, undefined, settings, settings, targetIsSource)).toEqual( |
| 149 | + { |
| 150 | + ...(targetIsSource |
| 151 | + ? { textGenerationModelSelection: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection } |
| 152 | + : {}), |
| 153 | + sidebarAutoSettleAfterDays: 7, |
| 154 | + }, |
| 155 | + ); |
| 156 | + }, |
| 157 | + ); |
| 158 | + |
| 159 | + it.each(["missing", "disabled", "different-driver", "enabled"] as const)( |
| 160 | + "shares a custom model only when its target provider is enabled (%s)", |
| 161 | + (availability) => { |
| 162 | + const instanceId = ProviderInstanceId.make("codex_personal"); |
| 163 | + const selection = { |
| 164 | + instanceId, |
| 165 | + model: "gpt-5.6-luna", |
| 166 | + options: [{ id: "reasoningEffort", value: "low" }], |
| 167 | + }; |
| 168 | + const instance = { |
| 169 | + driver: ProviderDriverKind.make( |
| 170 | + availability === "different-driver" ? "claudeAgent" : "codex", |
| 171 | + ), |
| 172 | + enabled: availability !== "disabled", |
| 173 | + config: {}, |
| 174 | + }; |
| 175 | + const settings = { |
| 176 | + ...DEFAULT_SERVER_SETTINGS, |
| 177 | + providerInstances: availability === "missing" ? {} : { [instanceId]: instance }, |
| 178 | + }; |
| 179 | + const patch = { sidebarAutoSettleAfterDays: 7, textGenerationModelSelection: selection }; |
| 180 | + const sourceSettings = { |
| 181 | + ...settings, |
| 182 | + providerInstances: { |
| 183 | + [instanceId]: { ...instance, driver: ProviderDriverKind.make("codex"), enabled: true }, |
| 184 | + }, |
| 185 | + }; |
| 186 | + expect(filterSharedServerPatch(patch, restartCapabilities, settings, sourceSettings)).toEqual( |
| 187 | + availability === "enabled" ? patch : { sidebarAutoSettleAfterDays: 7 }, |
| 188 | + ); |
| 189 | + const primarySettings = { |
| 190 | + ...sourceSettings, |
| 191 | + textGenerationModelSelection: selection, |
| 192 | + }; |
| 193 | + expect( |
| 194 | + findSharedSettingsMismatches({ |
| 195 | + primaryEnvironmentId: primaryId, |
| 196 | + primarySettings, |
| 197 | + environments: [ |
| 198 | + { environmentId: boxId, label: "Remote Box", syncEligible: true, settings }, |
| 199 | + ], |
| 200 | + }), |
| 201 | + ).toEqual(availability === "enabled" ? [{ environmentId: boxId, label: "Remote Box" }] : []); |
| 202 | + }, |
| 203 | + ); |
| 204 | + |
78 | 205 | it.each([true, false])("preserves supported restart preference %s", (enabled) => { |
79 | 206 | const patch = { continueThreadsAfterServerUpdate: enabled, sidebarAutoSettleAfterDays: 7 }; |
80 | 207 | expect(filterSharedServerPatch(patch, restartCapabilities)).toEqual(patch); |
|
0 commit comments