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

DesktopEarlyElectronStartup.test.ts

271 lines9.4 KB

1// @effect-diagnostics nodeBuiltinImport:off - tests use POSIX path joining to match the Linux startup boundary.
2import * as NodePath from "node:path";
3import { assert, describe, it } from "@effect/vitest";
4​
5import {
6 resolveEarlyLinuxElectronOptions,
7 resolveEarlyLinuxPasswordStorePreference,
8 resolveLinuxDisableFeaturesSwitch,
9} from "./DesktopEarlyElectronStartup.ts";
10​
11describe("DesktopEarlyElectronStartup", () => {
12 const joinPath = NodePath.posix.join;
13​
14 it("reads the persisted linux password-store preference before Electron is ready", () => {
15 const preference = resolveEarlyLinuxPasswordStorePreference({
16 env: { T3CODE_HOME: "/home/user/.t3-test" },
17 homeDirectory: "/home/user",
18 joinPath,
19 readFileString: (path) => {
20 assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json");
21 return JSON.stringify({ linuxPasswordStore: "kwallet6" });
22 },
23 });
24​
25 assert.equal(preference, "kwallet6");
26 });
27​
28 it("accepts JSONC in the early desktop settings file", () => {
29 const preference = resolveEarlyLinuxPasswordStorePreference({
30 env: { T3CODE_HOME: "/home/user/.t3-test" },
31 homeDirectory: "/home/user",
32 joinPath,
33 readFileString: () => `{
34 // manually edited setting
35 "linuxPasswordStore": "gnome-libsecret",
36 }`,
37 });
38​
39 assert.equal(preference, "gnome-libsecret");
40 });
41​
42 it("falls back to auto when the early settings document is missing or invalid", () => {
43 const preference = resolveEarlyLinuxPasswordStorePreference({
44 env: {},
45 homeDirectory: "/home/user",
46 joinPath,
47 readFileString: () => {
48 throw new Error("missing");
49 },
50 });
51​
52 assert.equal(preference, "auto");
53 });
54​
55 it("preserves absolute root paths when resolving early settings", () => {
56 const preference = resolveEarlyLinuxPasswordStorePreference({
57 env: { T3CODE_HOME: "/" },
58 homeDirectory: "/home/user",
59 joinPath,
60 readFileString: (path) => {
61 assert.equal(path, "/userdata/desktop-settings.json");
62 return JSON.stringify({ linuxPasswordStore: "kwallet6" });
63 },
64 });
65​
66 assert.equal(preference, "kwallet6");
67 });
68​
69 it("resolves the early linux Electron switches", () => {
70 const options = resolveEarlyLinuxElectronOptions({
71 env: {
72 T3CODE_HOME: "/home/user/.t3-test",
73 XDG_CURRENT_DESKTOP: "niri",
74 VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
75 },
76 homeDirectory: "/home/user",
77 joinPath,
78 readFileString: (path) => {
79 assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json");
80 return JSON.stringify({ linuxPasswordStore: "auto" });
81 },
82 });
83​
84 assert.deepEqual(options, {
85 isDevelopment: true,
86 linuxWmClass: "t3code-dev",
87 linuxDesktopEntryName: "com.t3tools.T3Code.Development.desktop",
88 passwordStore: "gnome-libsecret",
89 });
90 });
91​
92 it("keeps implicit development state under ~/.t3/dev when T3CODE_HOME is unset", () => {
93 const preference = resolveEarlyLinuxPasswordStorePreference({
94 env: {
95 VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
96 },
97 homeDirectory: "/home/user",
98 joinPath,
99 readFileString: (path) => {
100 assert.equal(path, "/home/user/.t3/dev/desktop-settings.json");
101 return JSON.stringify({ linuxPasswordStore: "kwallet" });
102 },
103 });
104​
105 assert.equal(preference, "kwallet");
106 });
107​
108 it("treats whitespace-only T3CODE_HOME as unconfigured in development", () => {
109 const preference = resolveEarlyLinuxPasswordStorePreference({
110 env: {
111 T3CODE_HOME: " ",
112 VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
113 },
114 homeDirectory: "/home/user",
115 joinPath,
116 readFileString: (path) => {
117 assert.equal(path, "/home/user/.t3/dev/desktop-settings.json");
118 return JSON.stringify({ linuxPasswordStore: "gnome-libsecret" });
119 },
120 });
121​
122 assert.equal(preference, "gnome-libsecret");
123 });
124​
125 describe("resolveLinuxDisableFeaturesSwitch", () => {
126 const hyprland = { XDG_CURRENT_DESKTOP: "Hyprland", XDG_SESSION_TYPE: "wayland" };
127 const releaseCommits: Record<string, string> = {
128 "0.48.0": "5ee35f914f921e5696030698e74fb5566a804768",
129 "0.48.1": "29e2e59fdbab8ed2cc23a20e3c6043d5decb5cdc",
130 "0.49.0": "9958d297641b5c84dcff93f9039d80a5ad37ab00",
131 "0.50.0": "c4a4c341568944bd4fb9cd503558b2de602c0213",
132 "0.50.1": "4e242d086e20b32951fdc0ebcbfb4d41b5be8dcc",
133 };
134 const hyprctlVersion =
135 (version: string, overrides: Record<string, unknown> = {}) =>
136 () =>
137 JSON.stringify({
138 commit: releaseCommits[version] ?? "0123456789abcdef0123456789abcdef01234567",
139 version,
140 dirty: false,
141 tag: `v${version}`,
142 flags: [],
143 ...overrides,
144 });
145 const brokenHyprland = {
146 env: hyprland,
147 ozonePlatform: "wayland",
148 enableFeatures: null,
149 disableFeatures: null,
150 readHyprctlVersionJson: hyprctlVersion("0.48.1"),
151 };
152​
153 it.each(["0.48.0", "0.48.1", "0.49.0", "0.50.0", "0.50.1"])(
154 "disables the color manager on Hyprland %s",
155 (version) => {
156 assert.equal(
157 resolveLinuxDisableFeaturesSwitch({
158 ...brokenHyprland,
159 readHyprctlVersionJson: hyprctlVersion(version),
160 }),
161 "WaylandWpColorManagerV1",
162 );
163 },
164 );
165​
166 it.each([
167 { label: "case-insensitive desktop tokens", env: { XDG_CURRENT_DESKTOP: "foo:HYPRLAND" } },
168 {
169 label: "XDG_SESSION_DESKTOP when XDG_CURRENT_DESKTOP is unset",
170 env: { XDG_SESSION_DESKTOP: "hyprland" },
171 },
172 ])("detects Hyprland via $label", ({ env }) => {
173 assert.equal(
174 resolveLinuxDisableFeaturesSwitch({ ...brokenHyprland, env }),
175 "WaylandWpColorManagerV1",
176 );
177 });
178​
179 it("keeps existing disabled features", () => {
180 assert.equal(
181 resolveLinuxDisableFeaturesSwitch({
182 ...brokenHyprland,
183 disableFeatures: "Vulkan,WaylandWpColorManagerV1Extra",
184 }),
185 "Vulkan,WaylandWpColorManagerV1Extra,WaylandWpColorManagerV1",
186 );
187 });
188​
189 it.each([
190 { label: "Hyprland 0.47.2", readHyprctlVersionJson: hyprctlVersion("0.47.2") },
191 { label: "Hyprland 0.51.0", readHyprctlVersionJson: hyprctlVersion("0.51.0") },
192 { label: "Hyprland 0.56.2", readHyprctlVersionJson: hyprctlVersion("0.56.2") },
193 { label: "an unrecognized version", readHyprctlVersionJson: hyprctlVersion("1.0.0") },
194 {
195 label: "a malformed version",
196 readHyprctlVersionJson: hyprctlVersion("0.48.not-a-version"),
197 },
198 { label: "a two-part version", readHyprctlVersionJson: hyprctlVersion("0.48") },
199 { label: "a prerelease version", readHyprctlVersionJson: hyprctlVersion("0.49.0-rc1") },
200 {
201 label: "a development build after an affected release",
202 readHyprctlVersionJson: hyprctlVersion("0.50.1", { tag: "v0.50.1-87-g4e8875b5" }),
203 },
204 {
205 label: "a later Nix build reporting an affected release tag",
206 readHyprctlVersionJson: hyprctlVersion("0.50.1", {
207 commit: "4e8875b5e9700c81ca4e169dc7b85bb5b3c8cb7a",
208 }),
209 },
210 {
211 label: "an affected version with another release's commit",
212 readHyprctlVersionJson: hyprctlVersion("0.48.0", { commit: releaseCommits["0.48.1"] }),
213 },
214 { label: "an unknown patch release", readHyprctlVersionJson: hyprctlVersion("0.50.2") },
215 {
216 label: "missing commit metadata",
217 readHyprctlVersionJson: () =>
218 JSON.stringify({ version: "0.48.1", tag: "v0.48.1", dirty: false }),
219 },
220 {
221 label: "a build without git metadata",
222 readHyprctlVersionJson: hyprctlVersion("0.48.1", { tag: "" }),
223 },
224 {
225 label: "a dirty build",
226 readHyprctlVersionJson: hyprctlVersion("0.48.1", { dirty: true }),
227 },
228 {
229 label: "output without build metadata",
230 readHyprctlVersionJson: () => JSON.stringify({ version: "0.48.1" }),
231 },
232 { label: "unparseable hyprctl output", readHyprctlVersionJson: () => "ok" },
233 {
234 label: "a missing hyprctl",
235 readHyprctlVersionJson: () => {
236 throw new Error("spawnSync hyprctl ENOENT");
237 },
238 },
239 ])("preserves color management for $label", (overrides) => {
240 assert.isNull(resolveLinuxDisableFeaturesSwitch({ ...brokenHyprland, ...overrides }));
241 });
242​
243 it.each([
244 {
245 label: "a stale Hyprland signature in KDE",
246 env: { XDG_CURRENT_DESKTOP: "KDE", HYPRLAND_INSTANCE_SIGNATURE: "abc_123" },
247 },
248 {
249 label: "resolved X11 in a Wayland session",
250 ozonePlatform: "x11",
251 env: { ...hyprland, WAYLAND_DISPLAY: "wayland-1" },
252 },
253 { label: "a missing platform", ozonePlatform: null },
254 { label: "an unrelated platform", ozonePlatform: "headless" },
255 { label: "already disabled features", disableFeatures: "Vulkan, WaylandWpColorManagerV1" },
256 { label: "an explicitly enabled feature", enableFeatures: "Vulkan,WaylandWpColorManagerV1" },
257 {
258 label: "a feature enabled with trial parameters",
259 enableFeatures: "*WaylandWpColorManagerV1<Study.Group:mode/strict",
260 },
261 ])("skips the Hyprland probe for $label", (overrides) => {
262 assert.isNull(
263 resolveLinuxDisableFeaturesSwitch({
264 ...brokenHyprland,
265 ...overrides,
266 readHyprctlVersionJson: () => assert.fail("hyprctl should not run"),
267 }),
268 );
269 });
270 });
271});