Open History to see the last commit
1import {
2 DEFAULT_SERVER_SETTINGS,
3 ProviderDriverKind,
4 ProviderInstanceId,
5} from "@t3tools/contracts";
6import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
7import { describe, expect, it } from "vite-plus/test";
8
9import { mergeEnvironmentSettings, resolveEnvironmentIdentificationMode } from "./useSettings";
10
11describe("resolveEnvironmentIdentificationMode", () => {
12 it("keeps identification hidden until client settings hydrate", () => {
13 expect(resolveEnvironmentIdentificationMode({ mode: "artwork", settingsHydrated: false })).toBe(
14 "none",
15 );
16 expect(resolveEnvironmentIdentificationMode({ mode: "pill", settingsHydrated: true })).toBe(
17 "pill",
18 );
19 });
20
21 it("uses a pill instead of artwork with a palette theme", () => {
22 expect(
23 resolveEnvironmentIdentificationMode({
24 mode: "artwork",
25 settingsHydrated: true,
26 paletteThemeActive: true,
27 }),
28 ).toBe("pill");
29 });
30
31 it("respects none with a palette theme", () => {
32 expect(
33 resolveEnvironmentIdentificationMode({
34 mode: "none",
35 settingsHydrated: true,
36 paletteThemeActive: true,
37 }),
38 ).toBe("none");
39 });
40
41 it("keeps artwork when the palette theme opts into it", () => {
42 expect(
43 resolveEnvironmentIdentificationMode({
44 mode: "artwork",
45 settingsHydrated: true,
46 paletteThemeActive: true,
47 paletteThemeAllowsArtwork: true,
48 }),
49 ).toBe("artwork");
50 });
51});
52
53describe("mergeEnvironmentSettings", () => {
54 it("combines the selected environment's server settings with client preferences", () => {
55 const serverSettings = {
56 ...DEFAULT_SERVER_SETTINGS,
57 providerInstances: {
58 [ProviderInstanceId.make("codex_remote")]: {
59 driver: ProviderDriverKind.make("codex"),
60 enabled: true,
61 },
62 },
63 };
64 const clientSettings = {
65 ...DEFAULT_CLIENT_SETTINGS,
66 favorites: [
67 {
68 provider: ProviderInstanceId.make("codex_remote"),
69 model: "gpt-5.4",
70 },
71 ],
72 };
73
74 const settings = mergeEnvironmentSettings(serverSettings, clientSettings);
75
76 expect(settings.providerInstances).toBe(serverSettings.providerInstances);
77 expect(settings.favorites).toBe(clientSettings.favorites);
78 });
79
80 it("keeps server settlement settings when legacy client data contains retired keys", () => {
81 const serverSettings = {
82 ...DEFAULT_SERVER_SETTINGS,
83 sidebarAutoSettleAfterDays: 14,
84 sidebarAutoSettleOnMerge: false,
85 };
86 const legacyClientSettings = {
87 ...DEFAULT_CLIENT_SETTINGS,
88 sidebarAutoSettleAfterDays: 1,
89 sidebarAutoSettleOnMerge: true,
90 };
91
92 const settings = mergeEnvironmentSettings(serverSettings, legacyClientSettings);
93
94 expect(settings.sidebarAutoSettleAfterDays).toBe(14);
95 expect(settings.sidebarAutoSettleOnMerge).toBe(false);
96 });
97});