From 7cce4ce1733e8995acb4d3529beea313a4f6ab71 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:27:50 +0100 Subject: [PATCH] test: resolve nightly launches in the socket tests without installing the profile cargo test runs the pdfcraft binary's unit tests in one process. The single-instance socket tests called launch_profile::prepare, which installs the nightly profile in craft_nightly's process-wide OnceLock, so tests that ran after them saw a nightly launch: the window icon test compared the nightly icon with the stable one, and stable_defaults_and_nightly_version_line found is_nightly() true. The FreeBSD workflow runs plain cargo test and failed this way. The socket tests now parse and validate the launch the same way, without installing it. --- apps/pdfcraft/src/launch_profile.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/pdfcraft/src/launch_profile.rs b/apps/pdfcraft/src/launch_profile.rs index 21f6e039cf..fd1df09247 100644 --- a/apps/pdfcraft/src/launch_profile.rs +++ b/apps/pdfcraft/src/launch_profile.rs @@ -67,6 +67,19 @@ mod tests { args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"]) } + /// What [`super::prepare`] returns for `argv`, without installing the profile process-wide. + /// `cargo test` runs every unit test of the binary in one process, and an installed nightly + /// profile would make the stable icon, app id and title tests that run after it see nightly. + #[cfg(any(windows, all(unix, not(target_os = "macos"))))] + fn prepare_without_installing(argv: Vec) -> Result { + let spec = profile_root::spec(); + let mut launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::new())?; + if let Profile::NightlyV1(root) = &launch.profile { + launch.profile = Profile::NightlyV1(craft_nightly::validate_and_prepare_root(root, &spec)?); + } + Ok(launch) + } + #[test] fn stable_arguments_and_directory_policy_are_unchanged() { let spec = profile_root::spec(); @@ -158,14 +171,14 @@ mod tests { let listener = UnixListener::bind(&sock_path).unwrap(); // Live listener socket already present inside /single-instance/. - let live_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap(); + let live_launch = prepare_without_installing(launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap(); assert_eq!(live_launch.profile, Profile::NightlyV1(expected_root.clone())); assert_eq!(live_launch.passthrough_args, args(&["doc.pdf"])); // Leftover/stale socket remaining after the previous instance exits. drop(listener); assert!(std::fs::symlink_metadata(&sock_path).is_ok(), "stale socket remains on disk"); - let stale_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap(); + let stale_launch = prepare_without_installing(launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap(); assert_eq!(stale_launch.profile, Profile::NightlyV1(expected_root)); assert_eq!(stale_launch.passthrough_args, args(&["after-exit.pdf"])); } @@ -183,14 +196,14 @@ mod tests { let listener = uds_windows::UnixListener::bind(&sock_path).unwrap(); // Live AF_UNIX listener socket already present inside \single-instance\. - let live_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap(); + let live_launch = prepare_without_installing(launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap(); assert_eq!(live_launch.profile, Profile::NightlyV1(expected_root.clone())); assert_eq!(live_launch.passthrough_args, args(&["doc.pdf"])); // Leftover/stale socket remaining after the previous instance exits. drop(listener); assert!(std::fs::symlink_metadata(&sock_path).is_ok(), "stale socket remains on disk"); - let stale_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap(); + let stale_launch = prepare_without_installing(launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap(); assert_eq!(stale_launch.profile, Profile::NightlyV1(expected_root)); assert_eq!(stale_launch.passthrough_args, args(&["after-exit.pdf"])); }