@@ -5,6 +5,7 @@ import { assert, describe, it } from "@effect/vitest";
55import {
66 resolveEarlyLinuxElectronOptions ,
77 resolveEarlyLinuxPasswordStorePreference ,
8+ resolveLinuxDisableFeaturesSwitch ,
89} from "./DesktopEarlyElectronStartup.ts" ;
910
1011describe ( "DesktopEarlyElectronStartup" , ( ) => {
@@ -120,4 +121,152 @@ describe("DesktopEarlyElectronStartup", () => {
120121
121122 assert . equal ( preference , "gnome-libsecret" ) ;
122123 } ) ;
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+ // Shape of `hyprctl version -j` from a release tarball, trimmed to the fields we read.
135+ const hyprctlVersion =
136+ ( version : string , overrides : Record < string , unknown > = { } ) =>
137+ ( ) =>
138+ JSON . stringify ( {
139+ commit : releaseCommits [ version ] ?? "0123456789abcdef0123456789abcdef01234567" ,
140+ version,
141+ dirty : false ,
142+ tag : `v${ version } ` ,
143+ flags : [ ] ,
144+ ...overrides ,
145+ } ) ;
146+ const brokenHyprland = {
147+ env : hyprland ,
148+ ozonePlatform : "wayland" ,
149+ enableFeatures : null ,
150+ disableFeatures : null ,
151+ readHyprctlVersionJson : hyprctlVersion ( "0.48.1" ) ,
152+ } ;
153+
154+ it . each ( [ "0.48.0" , "0.48.1" , "0.49.0" , "0.50.0" , "0.50.1" ] ) (
155+ "disables the color manager on Hyprland %s" ,
156+ ( version ) => {
157+ assert . equal (
158+ resolveLinuxDisableFeaturesSwitch ( {
159+ ...brokenHyprland ,
160+ readHyprctlVersionJson : hyprctlVersion ( version ) ,
161+ } ) ,
162+ "WaylandWpColorManagerV1" ,
163+ ) ;
164+ } ,
165+ ) ;
166+
167+ it . each ( [
168+ { label : "case-insensitive desktop tokens" , env : { XDG_CURRENT_DESKTOP : "foo:HYPRLAND" } } ,
169+ {
170+ label : "XDG_SESSION_DESKTOP when XDG_CURRENT_DESKTOP is unset" ,
171+ env : { XDG_SESSION_DESKTOP : "hyprland" } ,
172+ } ,
173+ ] ) ( "detects Hyprland via $label" , ( { env } ) => {
174+ assert . equal (
175+ resolveLinuxDisableFeaturesSwitch ( { ...brokenHyprland , env } ) ,
176+ "WaylandWpColorManagerV1" ,
177+ ) ;
178+ } ) ;
179+
180+ it ( "keeps existing disabled features" , ( ) => {
181+ assert . equal (
182+ resolveLinuxDisableFeaturesSwitch ( {
183+ ...brokenHyprland ,
184+ disableFeatures : "Vulkan,WaylandWpColorManagerV1Extra" ,
185+ } ) ,
186+ "Vulkan,WaylandWpColorManagerV1Extra,WaylandWpColorManagerV1" ,
187+ ) ;
188+ } ) ;
189+
190+ it . each ( [
191+ { label : "Hyprland 0.47.2" , readHyprctlVersionJson : hyprctlVersion ( "0.47.2" ) } ,
192+ { label : "Hyprland 0.51.0" , readHyprctlVersionJson : hyprctlVersion ( "0.51.0" ) } ,
193+ { label : "Hyprland 0.56.2" , readHyprctlVersionJson : hyprctlVersion ( "0.56.2" ) } ,
194+ { label : "an unrecognized version" , readHyprctlVersionJson : hyprctlVersion ( "1.0.0" ) } ,
195+ {
196+ label : "a malformed version" ,
197+ readHyprctlVersionJson : hyprctlVersion ( "0.48.not-a-version" ) ,
198+ } ,
199+ { label : "a two-part version" , readHyprctlVersionJson : hyprctlVersion ( "0.48" ) } ,
200+ { label : "a prerelease version" , readHyprctlVersionJson : hyprctlVersion ( "0.49.0-rc1" ) } ,
201+ {
202+ label : "a development build after an affected release" ,
203+ readHyprctlVersionJson : hyprctlVersion ( "0.50.1" , { tag : "v0.50.1-87-g4e8875b5" } ) ,
204+ } ,
205+ {
206+ label : "a later Nix build reporting an affected release tag" ,
207+ readHyprctlVersionJson : hyprctlVersion ( "0.50.1" , {
208+ commit : "4e8875b5e9700c81ca4e169dc7b85bb5b3c8cb7a" ,
209+ } ) ,
210+ } ,
211+ {
212+ label : "an affected version with another release's commit" ,
213+ readHyprctlVersionJson : hyprctlVersion ( "0.48.0" , { commit : releaseCommits [ "0.48.1" ] } ) ,
214+ } ,
215+ { label : "an unknown patch release" , readHyprctlVersionJson : hyprctlVersion ( "0.50.2" ) } ,
216+ {
217+ label : "missing commit metadata" ,
218+ readHyprctlVersionJson : ( ) =>
219+ JSON . stringify ( { version : "0.48.1" , tag : "v0.48.1" , dirty : false } ) ,
220+ } ,
221+ {
222+ label : "a build without git metadata" ,
223+ readHyprctlVersionJson : hyprctlVersion ( "0.48.1" , { tag : "" } ) ,
224+ } ,
225+ {
226+ label : "a dirty build" ,
227+ readHyprctlVersionJson : hyprctlVersion ( "0.48.1" , { dirty : true } ) ,
228+ } ,
229+ {
230+ label : "output without build metadata" ,
231+ readHyprctlVersionJson : ( ) => JSON . stringify ( { version : "0.48.1" } ) ,
232+ } ,
233+ { label : "unparseable hyprctl output" , readHyprctlVersionJson : ( ) => "ok" } ,
234+ {
235+ label : "a missing hyprctl" ,
236+ readHyprctlVersionJson : ( ) => {
237+ throw new Error ( "spawnSync hyprctl ENOENT" ) ;
238+ } ,
239+ } ,
240+ ] ) ( "preserves color management for $label" , ( overrides ) => {
241+ assert . isNull ( resolveLinuxDisableFeaturesSwitch ( { ...brokenHyprland , ...overrides } ) ) ;
242+ } ) ;
243+
244+ it . each ( [
245+ {
246+ label : "a stale Hyprland signature in KDE" ,
247+ env : { XDG_CURRENT_DESKTOP : "KDE" , HYPRLAND_INSTANCE_SIGNATURE : "abc_123" } ,
248+ } ,
249+ {
250+ label : "resolved X11 in a Wayland session" ,
251+ ozonePlatform : "x11" ,
252+ env : { ...hyprland , WAYLAND_DISPLAY : "wayland-1" } ,
253+ } ,
254+ { label : "a missing platform" , ozonePlatform : null } ,
255+ { label : "an unrelated platform" , ozonePlatform : "headless" } ,
256+ { label : "already disabled features" , disableFeatures : "Vulkan, WaylandWpColorManagerV1" } ,
257+ { label : "an explicitly enabled feature" , enableFeatures : "Vulkan,WaylandWpColorManagerV1" } ,
258+ {
259+ label : "a feature enabled with trial parameters" ,
260+ enableFeatures : "*WaylandWpColorManagerV1<Study.Group:mode/strict" ,
261+ } ,
262+ ] ) ( "skips the Hyprland probe for $label" , ( overrides ) => {
263+ assert . isNull (
264+ resolveLinuxDisableFeaturesSwitch ( {
265+ ...brokenHyprland ,
266+ ...overrides ,
267+ readHyprctlVersionJson : ( ) => assert . fail ( "hyprctl should not run" ) ,
268+ } ) ,
269+ ) ;
270+ } ) ;
271+ } ) ;
123272} ) ;
0 commit comments