Open History to see the last commit
1import {
2 DEFAULT_SERVER_SETTINGS,
3 type EnvironmentId,
4 type ProjectId,
5 type ServerSettings,
6} from "@t3tools/contracts";
7import { describe, expect, it } from "vite-plus/test";
8
9import type { SettingsTarget } from "./settings-environment-filter";
10import {
11 planMobileScopedSettingsClear,
12 planMobileScopedSettingsPatch,
13 resolveMobileSettingsTargets,
14} from "./settings-scoped-server";
15
16const firstId = "first" as EnvironmentId;
17const secondId = "second" as EnvironmentId;
18const firstProject = "first-project" as ProjectId;
19const secondProject = "second-project" as ProjectId;
20
21function environment(environmentId: EnvironmentId, settings: ServerSettings): SettingsTarget {
22 return {
23 environmentId,
24 serverConfig: {
25 settings,
26 environment: { capabilities: { projectSettingsOverrides: true } },
27 },
28 } as SettingsTarget;
29}
30
31describe("mobile project settings scope", () => {
32 it("edits each checkout's own override without changing either environment default", () => {
33 const firstSettings: ServerSettings = {
34 ...DEFAULT_SERVER_SETTINGS,
35 responseStreamingMode: "paragraph",
36 projectSettingsOverrides: { [firstProject]: { defaultAutoPull: true } },
37 };
38 const secondSettings: ServerSettings = {
39 ...DEFAULT_SERVER_SETTINGS,
40 responseStreamingMode: "token",
41 projectSettingsOverrides: {},
42 };
43 const targets = resolveMobileSettingsTargets(
44 [environment(firstId, firstSettings), environment(secondId, secondSettings)],
45 [
46 { environmentId: firstId, id: firstProject },
47 { environmentId: secondId, id: secondProject },
48 ],
49 );
50
51 const writes = planMobileScopedSettingsPatch(targets, true, {
52 responseStreamingMode: "turn",
53 });
54 expect(writes).toEqual([
55 {
56 environmentId: firstId,
57 patch: {
58 projectSettingsOverrides: {
59 [firstProject]: { defaultAutoPull: true, responseStreamingMode: "turn" },
60 },
61 },
62 },
63 {
64 environmentId: secondId,
65 patch: { projectSettingsOverrides: { [secondProject]: { responseStreamingMode: "turn" } } },
66 },
67 ]);
68 expect(firstSettings.responseStreamingMode).toBe("paragraph");
69 expect(secondSettings.responseStreamingMode).toBe("token");
70 });
71
72 it("removes a project override when a picker sends null for a key that cannot store it", () => {
73 const settings: ServerSettings = {
74 ...DEFAULT_SERVER_SETTINGS,
75 projectSettingsOverrides: {
76 [firstProject]: { defaultThreadEnvMode: "worktree", defaultAutoPull: true },
77 },
78 };
79 const targets = resolveMobileSettingsTargets(
80 [environment(firstId, settings)],
81 [{ environmentId: firstId, id: firstProject }],
82 );
83 expect(planMobileScopedSettingsPatch(targets, true, { defaultThreadEnvMode: null })).toEqual([
84 {
85 environmentId: firstId,
86 patch: { projectSettingsOverrides: { [firstProject]: { defaultAutoPull: true } } },
87 },
88 ]);
89 expect(planMobileScopedSettingsPatch(targets, true, { defaultModelSelection: null })).toEqual([
90 {
91 environmentId: firstId,
92 patch: {
93 projectSettingsOverrides: {
94 [firstProject]: {
95 defaultThreadEnvMode: "worktree",
96 defaultAutoPull: true,
97 defaultModelSelection: null,
98 },
99 },
100 },
101 },
102 ]);
103 });
104
105 it("resets only the selected page's override and rejects environment-wide writes", () => {
106 const settings: ServerSettings = {
107 ...DEFAULT_SERVER_SETTINGS,
108 projectSettingsOverrides: {
109 [firstProject]: { defaultAutoPull: true, responseStreamingMode: "turn" },
110 },
111 };
112 const targets = resolveMobileSettingsTargets(
113 [environment(firstId, settings)],
114 [{ environmentId: firstId, id: firstProject }],
115 );
116
117 expect(planMobileScopedSettingsClear(targets, ["responseStreamingMode"])).toEqual([
118 {
119 environmentId: firstId,
120 patch: { projectSettingsOverrides: { [firstProject]: { defaultAutoPull: true } } },
121 },
122 ]);
123 expect(
124 planMobileScopedSettingsPatch(targets, true, { enableProviderUpdateChecks: false }),
125 ).toEqual([]);
126 });
127});