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

sharedSettings.test.ts

94 lines3.3 KB

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