|
| 1 | +// @effect-diagnostics nodeBuiltinImport:off - tests use POSIX path joining to match the Linux startup boundary. |
| 2 | +import * as NodePath from "node:path"; |
| 3 | +import { assert, describe, it } from "@effect/vitest"; |
| 4 | + |
| 5 | +import { |
| 6 | + resolveEarlyLinuxElectronOptions, |
| 7 | + resolveEarlyLinuxPasswordStorePreference, |
| 8 | +} from "./DesktopEarlyElectronStartup.ts"; |
| 9 | + |
| 10 | +describe("DesktopEarlyElectronStartup", () => { |
| 11 | + const joinPath = NodePath.posix.join; |
| 12 | + |
| 13 | + it("reads the persisted linux password-store preference before Electron is ready", () => { |
| 14 | + const preference = resolveEarlyLinuxPasswordStorePreference({ |
| 15 | + env: { T3CODE_HOME: "/home/user/.t3-test" }, |
| 16 | + homeDirectory: "/home/user", |
| 17 | + joinPath, |
| 18 | + readFileString: (path) => { |
| 19 | + assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json"); |
| 20 | + return JSON.stringify({ linuxPasswordStore: "kwallet6" }); |
| 21 | + }, |
| 22 | + }); |
| 23 | + |
| 24 | + assert.equal(preference, "kwallet6"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("accepts JSONC in the early desktop settings file", () => { |
| 28 | + const preference = resolveEarlyLinuxPasswordStorePreference({ |
| 29 | + env: { T3CODE_HOME: "/home/user/.t3-test" }, |
| 30 | + homeDirectory: "/home/user", |
| 31 | + joinPath, |
| 32 | + readFileString: () => `{ |
| 33 | + // manually edited setting |
| 34 | + "linuxPasswordStore": "gnome-libsecret", |
| 35 | + }`, |
| 36 | + }); |
| 37 | + |
| 38 | + assert.equal(preference, "gnome-libsecret"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("falls back to auto when the early settings document is missing or invalid", () => { |
| 42 | + const preference = resolveEarlyLinuxPasswordStorePreference({ |
| 43 | + env: {}, |
| 44 | + homeDirectory: "/home/user", |
| 45 | + joinPath, |
| 46 | + readFileString: () => { |
| 47 | + throw new Error("missing"); |
| 48 | + }, |
| 49 | + }); |
| 50 | + |
| 51 | + assert.equal(preference, "auto"); |
| 52 | + }); |
| 53 | + |
| 54 | + it("preserves absolute root paths when resolving early settings", () => { |
| 55 | + const preference = resolveEarlyLinuxPasswordStorePreference({ |
| 56 | + env: { T3CODE_HOME: "/" }, |
| 57 | + homeDirectory: "/home/user", |
| 58 | + joinPath, |
| 59 | + readFileString: (path) => { |
| 60 | + assert.equal(path, "/userdata/desktop-settings.json"); |
| 61 | + return JSON.stringify({ linuxPasswordStore: "kwallet6" }); |
| 62 | + }, |
| 63 | + }); |
| 64 | + |
| 65 | + assert.equal(preference, "kwallet6"); |
| 66 | + }); |
| 67 | + |
| 68 | + it("resolves the early linux Electron switches", () => { |
| 69 | + const options = resolveEarlyLinuxElectronOptions({ |
| 70 | + env: { |
| 71 | + T3CODE_HOME: "/home/user/.t3-test", |
| 72 | + XDG_CURRENT_DESKTOP: "niri", |
| 73 | + VITE_DEV_SERVER_URL: "http://127.0.0.1:5173", |
| 74 | + }, |
| 75 | + homeDirectory: "/home/user", |
| 76 | + joinPath, |
| 77 | + readFileString: (path) => { |
| 78 | + assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json"); |
| 79 | + return JSON.stringify({ linuxPasswordStore: "auto" }); |
| 80 | + }, |
| 81 | + }); |
| 82 | + |
| 83 | + assert.deepEqual(options, { |
| 84 | + linuxWmClass: "t3code-dev", |
| 85 | + passwordStore: "gnome-libsecret", |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it("keeps implicit development state under ~/.t3/dev when T3CODE_HOME is unset", () => { |
| 90 | + const preference = resolveEarlyLinuxPasswordStorePreference({ |
| 91 | + env: { |
| 92 | + VITE_DEV_SERVER_URL: "http://127.0.0.1:5173", |
| 93 | + }, |
| 94 | + homeDirectory: "/home/user", |
| 95 | + joinPath, |
| 96 | + readFileString: (path) => { |
| 97 | + assert.equal(path, "/home/user/.t3/dev/desktop-settings.json"); |
| 98 | + return JSON.stringify({ linuxPasswordStore: "kwallet" }); |
| 99 | + }, |
| 100 | + }); |
| 101 | + |
| 102 | + assert.equal(preference, "kwallet"); |
| 103 | + }); |
| 104 | + |
| 105 | + it("treats whitespace-only T3CODE_HOME as unconfigured in development", () => { |
| 106 | + const preference = resolveEarlyLinuxPasswordStorePreference({ |
| 107 | + env: { |
| 108 | + T3CODE_HOME: " ", |
| 109 | + VITE_DEV_SERVER_URL: "http://127.0.0.1:5173", |
| 110 | + }, |
| 111 | + homeDirectory: "/home/user", |
| 112 | + joinPath, |
| 113 | + readFileString: (path) => { |
| 114 | + assert.equal(path, "/home/user/.t3/dev/desktop-settings.json"); |
| 115 | + return JSON.stringify({ linuxPasswordStore: "gnome-libsecret" }); |
| 116 | + }, |
| 117 | + }); |
| 118 | + |
| 119 | + assert.equal(preference, "gnome-libsecret"); |
| 120 | + }); |
| 121 | +}); |
0 commit comments