Open History to see the last commit
1import { DEFAULT_SERVER_SETTINGS, EnvironmentId, ProjectId } from "@t3tools/contracts";
2import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
3import { describe, expect, it } from "vite-plus/test";
4
5import { settingInheritanceLayers } from "./SettingInheritance";
6
7const environmentId = EnvironmentId.make("laptop");
8const projectId = ProjectId.make("project");
9
10describe("worktree cleanup inheritance", () => {
11 it("distinguishes project and environment worktree cleanup policies", () => {
12 const settings = {
13 ...DEFAULT_SERVER_SETTINGS,
14 worktreeCleanup: {
15 mode: "custom" as const,
16 rules: DEFAULT_SERVER_SETTINGS.storageCleanup,
17 },
18 projectSettingsOverrides: {
19 [projectId]: { worktreeCleanup: { mode: "off" as const } },
20 },
21 };
22 const layers = settingInheritanceLayers(
23 {
24 environmentId,
25 label: "Laptop",
26 projectId,
27 ...resolveProjectSettings(settings, projectId),
28 },
29 settings,
30 "worktreeCleanup",
31 );
32 expect(layers.map((layer) => [layer.key, layer.value, layer.effective])).toEqual([
33 ["project", "Off", true],
34 ["environment", "Custom", false],
35 ["built-in", "Not set", false],
36 ]);
37 });
38});
39
40describe("settingInheritanceLayers", () => {
41 it("identifies the background activity profile supplied by each layer", () => {
42 const settings = {
43 ...DEFAULT_SERVER_SETTINGS,
44 backgroundActivity: {
45 schemaVersion: 1 as const,
46 profile: "performance" as const,
47 overrides: {},
48 },
49 };
50 const layers = settingInheritanceLayers(
51 {
52 environmentId,
53 label: "Laptop",
54 projectId: null,
55 ...resolveProjectSettings(settings, projectId),
56 },
57 settings,
58 "backgroundActivity",
59 );
60 expect(layers.map((layer) => [layer.key, layer.value, layer.effective])).toEqual([
61 ["environment", "Performance", true],
62 ["built-in", "Balanced", false],
63 ]);
64 });
65
66 it("shows the checkout's t3.json as a layer for file-backed keys", () => {
67 const file = { defaultThreadEnvMode: "worktree" as const };
68 const fromFile = settingInheritanceLayers(
69 {
70 environmentId,
71 label: "Laptop",
72 projectId,
73 ...resolveProjectSettings(DEFAULT_SERVER_SETTINGS, projectId, null, file),
74 },
75 DEFAULT_SERVER_SETTINGS,
76 "defaultThreadEnvMode",
77 );
78 expect(fromFile.map((layer) => [layer.label, layer.value, layer.effective])).toEqual([
79 ["Project", "Inherits", false],
80 ["Laptop", "Inherits", false],
81 ["t3.json", "New worktree", true],
82 ["Default", "Current checkout", false],
83 ]);
84 const settings = { ...DEFAULT_SERVER_SETTINGS, defaultThreadEnvMode: "local" as const };
85 const fromEnvironment = settingInheritanceLayers(
86 {
87 environmentId,
88 label: "Laptop",
89 projectId,
90 ...resolveProjectSettings(settings, projectId, null, file),
91 },
92 settings,
93 "defaultThreadEnvMode",
94 );
95 expect(fromEnvironment.map((layer) => [layer.value, layer.effective])).toEqual([
96 ["Inherits", false],
97 ["Current checkout", true],
98 ["Inherits", false],
99 ["Current checkout", false],
100 ]);
101 });
102});