mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 05:22:58 -05:00
* feat(nightly): wire craft-nightly for self-isolated direct launch * fix(nightly): answer plain version before resolving profile root * test(nightly): retain exact version and saved profile coverage
157 lines
7.0 KiB
Rust
157 lines
7.0 KiB
Rust
//! Nightly-v1 bootstrap backed by [`craft_nightly`]. Selected before logging, updates, fonts or
|
|
//! saved state. Stable launches retain their original arguments and directory policy; direct
|
|
//! nightly launches self-isolate into [`craft_nightly::canonical_profile_root`], while ArtCraft
|
|
//! Launcher can supply `--launch-profile nightly-v1 --profile-root <abs> -- [args…]`.
|
|
|
|
use std::ffi::OsString;
|
|
|
|
pub use craft_nightly::NIGHTLY_V1_CONTRACT as VERSION;
|
|
use craft_nightly::{BuildFlavor, Launch, Profile, ProfileError, StartupOptions};
|
|
|
|
static STABLE: Profile = Profile::Stable;
|
|
|
|
pub fn current() -> &'static Profile {
|
|
craft_nightly::current().unwrap_or(&STABLE)
|
|
}
|
|
|
|
pub fn prepare_launch(flavor: BuildFlavor, args: impl IntoIterator<Item = OsString>) -> Result<Launch, ProfileError> {
|
|
let spec = crate::profile_root::app_profile_spec();
|
|
craft_nightly::prepare_launch(flavor, &spec, args, &StartupOptions::default())
|
|
}
|
|
|
|
/// The arguments a child of this process starts with: a nightly launch hands its profile on, so the
|
|
/// child opens the same private profile, and `--` keeps a file whose name starts with '-' a file.
|
|
/// Stable's child arguments are unchanged. Only `single_instance` starts a child, and macOS does
|
|
/// not build it.
|
|
#[cfg(not(target_os = "macos"))]
|
|
pub fn child_args(files: &[String]) -> Vec<OsString> {
|
|
child_args_for(current(), files)
|
|
}
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
fn child_args_for(profile: &Profile, files: &[String]) -> Vec<OsString> {
|
|
let delimited: Vec<OsString> = std::iter::once(OsString::from("--")).chain(files.iter().map(OsString::from)).collect();
|
|
match profile {
|
|
Profile::Stable => delimited,
|
|
Profile::NightlyV1(root) => craft_nightly::launch_arguments(root, &delimited),
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use std::ffi::OsString;
|
|
use std::path::PathBuf;
|
|
|
|
use craft_nightly::{BuildFlavor, Profile, ProfileError, StartupOptions, canonical_profile_root, parse_startup};
|
|
|
|
use super::VERSION;
|
|
#[cfg(not(target_os = "macos"))]
|
|
use super::child_args_for;
|
|
use crate::profile_root::app_profile_spec;
|
|
|
|
fn args(values: &[&str]) -> Vec<OsString> {
|
|
values.iter().map(OsString::from).collect()
|
|
}
|
|
|
|
fn absolute() -> &'static str {
|
|
if cfg!(windows) { r"C:\NightlyData\profiles\vectorcraft" } else { "/nightly-data/profiles/vectorcraft" }
|
|
}
|
|
|
|
#[test]
|
|
fn stable_arguments_are_unchanged_and_nightly_flags_are_refused() {
|
|
let spec = app_profile_spec();
|
|
for argv in [args(&[]), args(&["--new-instance", "a.svg"]), args(&["--", "--launch-profile", "file.svg"])] {
|
|
let launch = parse_startup(BuildFlavor::Stable, &spec, argv.clone(), &StartupOptions::default()).unwrap();
|
|
assert_eq!(launch.profile, Profile::Stable);
|
|
assert_eq!(launch.passthrough_args, argv);
|
|
}
|
|
|
|
let nightly_flags = args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--"]);
|
|
let err = parse_startup(BuildFlavor::Stable, &spec, nightly_flags, &StartupOptions::default()).unwrap_err();
|
|
assert!(matches!(err, ProfileError::NightlyFlagsInStableBuild));
|
|
}
|
|
|
|
#[test]
|
|
fn nightly_direct_launch_self_isolates_into_canonical_profile_root() {
|
|
let spec = app_profile_spec();
|
|
let expected_root = canonical_profile_root("vectorcraft").unwrap();
|
|
|
|
let empty = parse_startup(BuildFlavor::NightlyV1, &spec, Vec::new(), &StartupOptions::default()).unwrap();
|
|
assert_eq!(empty.profile, Profile::NightlyV1(expected_root.clone()));
|
|
assert!(empty.passthrough_args.is_empty());
|
|
|
|
let with_args = parse_startup(BuildFlavor::NightlyV1, &spec, args(&["--safe-mode", "art.svg"]), &StartupOptions::default()).unwrap();
|
|
assert_eq!(with_args.profile, Profile::NightlyV1(expected_root));
|
|
assert_eq!(with_args.passthrough_args, args(&["--safe-mode", "art.svg"]));
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_launcher_arguments_preserve_profile_root_and_user_args() {
|
|
let spec = app_profile_spec();
|
|
let argv = args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--", "--profile-root", "art with spaces.svg"]);
|
|
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::default()).unwrap();
|
|
assert_eq!(launch.profile, Profile::NightlyV1(PathBuf::from(absolute())));
|
|
assert_eq!(launch.passthrough_args, args(&["--profile-root", "art with spaces.svg"]));
|
|
}
|
|
|
|
#[test]
|
|
fn version_queries_are_recognized_plain_and_via_launcher() {
|
|
let spec = app_profile_spec();
|
|
for flag in ["--version", "-V"] {
|
|
for argv in [
|
|
args(&[flag]),
|
|
args(&["--launch-profile", VERSION, "--profile-root", absolute(), flag]),
|
|
args(&["--profile-root", absolute(), "--launch-profile", VERSION, flag]),
|
|
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--", flag]),
|
|
] {
|
|
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv.clone(), &StartupOptions::default()).unwrap();
|
|
assert!(launch.is_version_query(), "{argv:?}");
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn version_and_document_arguments_are_not_a_version_only_query() {
|
|
let spec = app_profile_spec();
|
|
for flag in ["--version", "-V"] {
|
|
for argv in [
|
|
args(&[flag, "art with spaces.svg"]),
|
|
args(&["--launch-profile", VERSION, "--profile-root", absolute(), flag, "art with spaces.svg"]),
|
|
args(&["--profile-root", absolute(), "--launch-profile", VERSION, flag, "art with spaces.svg"]),
|
|
] {
|
|
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::default()).unwrap();
|
|
assert!(!launch.is_version_query());
|
|
assert_eq!(launch.passthrough_args, args(&[flag, "art with spaces.svg"]));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
#[test]
|
|
fn a_stable_child_gets_the_file_delimiter_only() {
|
|
let child = child_args_for(&Profile::Stable, &["a file.svg".to_string(), "--looks-like-a-flag".to_string()]);
|
|
assert_eq!(child, args(&["--", "a file.svg", "--looks-like-a-flag"]));
|
|
}
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
#[test]
|
|
fn a_nightly_child_inherits_the_selected_profile() {
|
|
let spec = app_profile_spec();
|
|
let root = PathBuf::from(absolute());
|
|
let child = child_args_for(&Profile::NightlyV1(root.clone()), &["art.svg".to_string()]);
|
|
let expected = vec![
|
|
OsString::from("--launch-profile"),
|
|
OsString::from(VERSION),
|
|
OsString::from("--profile-root"),
|
|
root.into_os_string(),
|
|
OsString::from("--"),
|
|
OsString::from("--"),
|
|
OsString::from("art.svg"),
|
|
];
|
|
assert_eq!(child, expected);
|
|
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, child, &StartupOptions::default()).unwrap();
|
|
assert!(launch.profile.is_nightly());
|
|
assert_eq!(launch.passthrough_args, args(&["--", "art.svg"]));
|
|
}
|
|
}
|