Skip to content
Source
Sign inSign up

sharedSettings.test.ts

82 lines3.0 KB

1import {
2 DEFAULT_SERVER_SETTINGS,
3 ProviderDriverKind,
4 ProviderInstanceId,
5} from "@t3tools/contracts";
6import { describe, expect, it } from "@effect/vitest";
7​
8import { filterSharedServerPatch } from "./sharedSettings.ts";
9​
10describe("filterSharedServerPatch", () => {
11 it("holds the restart preference until the target's config loads", () => {
12 const patch = { continueThreadsAfterServerUpdate: true, sidebarAutoSettleAfterDays: 7 };
13 expect(filterSharedServerPatch(patch, undefined)).toEqual({ sidebarAutoSettleAfterDays: 7 });
14 expect(filterSharedServerPatch(patch, DEFAULT_SERVER_SETTINGS)).toEqual(patch);
15 });
16​
17 it.each([true, false])(
18 "resets a disabled default provider only on the originating environment (%s)",
19 (targetIsSource) => {
20 const settings = {
21 ...DEFAULT_SERVER_SETTINGS,
22 providerInstances: {
23 codex: { driver: ProviderDriverKind.make("codex"), enabled: false, config: {} },
24 claudeAgent: {
25 driver: ProviderDriverKind.make("claudeAgent"),
26 enabled: true,
27 config: {},
28 },
29 },
30 textGenerationModelSelection: {
31 instanceId: ProviderInstanceId.make("claudeAgent"),
32 model: "claude-opus-4-6",
33 },
34 };
35 const patch = {
36 textGenerationModelSelection: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection,
37 continueThreadsAfterServerUpdate: true,
38 sidebarAutoSettleAfterDays: 7,
39 };
40 expect(filterSharedServerPatch(patch, settings, settings, targetIsSource)).toEqual({
41 ...(targetIsSource
42 ? { textGenerationModelSelection: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection }
43 : {}),
44 continueThreadsAfterServerUpdate: true,
45 sidebarAutoSettleAfterDays: 7,
46 });
47 },
48 );
49​
50 it.each(["missing", "disabled", "different-driver", "enabled"] as const)(
51 "shares a custom model only when its target provider is enabled (%s)",
52 (availability) => {
53 const instanceId = ProviderInstanceId.make("codex_personal");
54 const selection = {
55 instanceId,
56 model: "gpt-5.6-luna",
57 options: [{ id: "reasoningEffort", value: "low" }],
58 };
59 const instance = {
60 driver: ProviderDriverKind.make(
61 availability === "different-driver" ? "claudeAgent" : "codex",
62 ),
63 enabled: availability !== "disabled",
64 config: {},
65 };
66 const settings = {
67 ...DEFAULT_SERVER_SETTINGS,
68 providerInstances: availability === "missing" ? {} : { [instanceId]: instance },
69 };
70 const patch = { sidebarAutoSettleAfterDays: 7, textGenerationModelSelection: selection };
71 const sourceSettings = {
72 ...settings,
73 providerInstances: {
74 [instanceId]: { ...instance, driver: ProviderDriverKind.make("codex"), enabled: true },
75 },
76 };
77 expect(filterSharedServerPatch(patch, settings, sourceSettings)).toEqual(
78 availability === "enabled" ? patch : { sidebarAutoSettleAfterDays: 7 },
79 );
80 },
81 );
82});