mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-30 18:24:11 +01:00
feat(nightly): wire craft-nightly for self-isolated direct launch (#2751)
* feat(nightly): wire craft-nightly for self-isolated direct launch * fix(nightly): answer bare version queries before profile resolution * test(nightly): cover launcher delimiter, spec, and launch_profile helpers * test(nightly): retain FigCraft startup and persistence coverage * test(nightly): keep previous write-probe files intact
This commit is contained in:
1 parent
f30df4db19
commit
01b2e48034
7 files changed
+405
-942
No files matched your search
Generated
+9
@@ -1605,6 +1605,14 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-nightly"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=9949e08d6f29b6c4462f14af1d5007acac163dbf#9949e08d6f29b6c4462f14af1d5007acac163dbf"
|
||||
dependencies = [
|
||||
"winsafe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
@@ -2771,6 +2779,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"craft-control",
|
||||
"craft-menu",
|
||||
"craft-nightly",
|
||||
"craft-settings",
|
||||
"craft-update",
|
||||
"craft-window",
|
||||
|
||||
@@ -67,6 +67,8 @@ craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "9949e08d6
|
||||
craft-menu = { git = "https://github.com/storytold/craft-libs", rev = "9949e08d6f29b6c4462f14af1d5007acac163dbf" }
|
||||
# Where the settings live: the suite's folder rules, portable mode included (craft-libs).
|
||||
craft-settings = { git = "https://github.com/storytold/craft-libs", rev = "9949e08d6f29b6c4462f14af1d5007acac163dbf" }
|
||||
# Nightly profile isolation, launch protocol, and security fence (craft-libs).
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "9949e08d6f29b6c4462f14af1d5007acac163dbf" }
|
||||
|
||||
# Penpot export container only; JSON values cross this boundary, not shared model types.
|
||||
craft-penpot = { git = "https://github.com/storytold/craft-libs", rev = "9949e08d6f29b6c4462f14af1d5007acac163dbf" }
|
||||
|
||||
@@ -21,6 +21,8 @@ figcraft-text = { workspace = true }
|
||||
craft-window = { workspace = true }
|
||||
# The suite's settings folder: `FIGCRAFT_CONFIG_DIR`, a portable marker, then the platform folder.
|
||||
craft-settings = { workspace = true }
|
||||
# Shared nightly profile isolation, launch protocol, and security fence.
|
||||
craft-nightly = { workspace = true }
|
||||
# The control channel's token and the ArtCraft Launcher's agents switch (src/agents.rs).
|
||||
craft-control = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
|
||||
@@ -1,31 +1,13 @@
|
||||
//! Build-time channel is distinct from a launch selector. A runtime environment cannot promote a stable build.
|
||||
use crate::launch_profile::Profile;
|
||||
use std::ffi::OsString;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum BuildFlavor {
|
||||
Stable,
|
||||
NightlyV1,
|
||||
}
|
||||
pub use craft_nightly::BuildFlavor;
|
||||
|
||||
pub const COMPILED: BuildFlavor = if cfg!(figcraft_nightly_v1) { BuildFlavor::NightlyV1 } else { BuildFlavor::Stable };
|
||||
|
||||
pub fn require_profile(flavor: BuildFlavor, profile: &Profile) -> Result<(), String> {
|
||||
match (flavor, profile.is_nightly()) {
|
||||
(BuildFlavor::NightlyV1, false) => Err("Open FigCraft Nightly from ArtCraft Launcher".into()),
|
||||
(BuildFlavor::Stable, true) => Err("This is a stable FigCraft build; nightly-v1 requires the nightly build".into()),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn needs_native_error(flavor: BuildFlavor, desktop_session: bool) -> bool {
|
||||
desktop_session && flavor == BuildFlavor::NightlyV1
|
||||
}
|
||||
|
||||
pub fn version_query(args: &[OsString]) -> bool {
|
||||
matches!(args, [arg] if arg == "--version" || arg == "-V")
|
||||
}
|
||||
|
||||
pub fn version(flavor: BuildFlavor, stable: &str) -> String {
|
||||
match flavor {
|
||||
BuildFlavor::Stable => stable.to_owned(),
|
||||
@@ -35,7 +17,8 @@ pub fn version(flavor: BuildFlavor, stable: &str) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::{BuildFlavor, needs_native_error, version};
|
||||
|
||||
#[test]
|
||||
fn only_a_nightly_desktop_refusal_requests_a_native_dialog() {
|
||||
assert!(needs_native_error(BuildFlavor::NightlyV1, true));
|
||||
@@ -45,26 +28,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nightly_build_without_a_profile_is_refused_before_startup() {
|
||||
let started = std::cell::Cell::new(false);
|
||||
let result = require_profile(BuildFlavor::NightlyV1, &Profile::Stable).map(|()| started.set(true));
|
||||
assert!(result.unwrap_err().contains("ArtCraft Launcher"));
|
||||
assert!(!started.get());
|
||||
}
|
||||
#[test]
|
||||
fn stable_and_nightly_flavors_accept_only_their_own_profile() {
|
||||
let nightly = Profile::NightlyV1(std::path::PathBuf::from("already validated root"));
|
||||
assert!(require_profile(BuildFlavor::Stable, &Profile::Stable).is_ok());
|
||||
assert!(require_profile(BuildFlavor::Stable, &nightly).is_err());
|
||||
assert!(require_profile(BuildFlavor::NightlyV1, &nightly).is_ok());
|
||||
}
|
||||
#[test]
|
||||
fn nightly_version_query_is_unambiguous_and_never_reinterprets_file_arguments() {
|
||||
fn nightly_version_string_is_distinct_from_stable() {
|
||||
assert_eq!(version(BuildFlavor::Stable, "0.18.1"), "0.18.1");
|
||||
assert_eq!(version(BuildFlavor::NightlyV1, "0.18.1"), "0.18.1 (nightly-v1)");
|
||||
assert!(version_query(&["--version".into()]));
|
||||
assert!(version_query(&["-V".into()]));
|
||||
assert!(!version_query(&["--".into(), "--version".into()]));
|
||||
assert!(!version_query(&[]));
|
||||
}
|
||||
}
|
||||
@@ -1,215 +1,131 @@
|
||||
//! Launcher-owned nightly-v1 bootstrap. Selected before logging, updates, fonts or saved state.
|
||||
//! Stable launches retain their original arguments and directory policy. No environment mutation.
|
||||
//! Nightly-v1 profile bootstrap backed by `craft-nightly`. Selected before logging, updates,
|
||||
//! fonts or saved state. Direct launches of a nightly build self-isolate into
|
||||
//! `craft_nightly::canonical_profile_root("figcraft")`; explicit `--launch-profile nightly-v1
|
||||
//! --profile-root <dir>` overrides it. Stable launches retain their original arguments and
|
||||
//! directory policy.
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
pub const VERSION: &str = "nightly-v1";
|
||||
use craft_nightly::StartupOptions;
|
||||
pub use craft_nightly::{Launch, Profile, ProfileError};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Profile {
|
||||
Stable,
|
||||
NightlyV1(PathBuf),
|
||||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn is_nightly(&self) -> bool {
|
||||
matches!(self, Self::NightlyV1(_))
|
||||
}
|
||||
|
||||
pub fn root(&self) -> Option<&Path> {
|
||||
match self {
|
||||
Self::Stable => None,
|
||||
Self::NightlyV1(root) => Some(root),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Launch {
|
||||
pub profile: Profile,
|
||||
pub args: Vec<OsString>,
|
||||
}
|
||||
|
||||
static PROFILE: OnceLock<Profile> = OnceLock::new();
|
||||
static STABLE: Profile = Profile::Stable;
|
||||
|
||||
pub fn current() -> &'static Profile {
|
||||
PROFILE.get().unwrap_or(&Profile::Stable)
|
||||
craft_nightly::current().unwrap_or(&STABLE)
|
||||
}
|
||||
|
||||
pub fn install(profile: Profile) -> Result<(), String> {
|
||||
PROFILE.set(profile).map_err(|_| "the launch profile was already selected".into())
|
||||
}
|
||||
|
||||
/// Recognize only the agreed literal selector/root pair before `--`. Everything after it is
|
||||
/// a file, even when it looks like a profile flag. No filesystem or startup hook runs here.
|
||||
///
|
||||
/// Every other flag is refused for a nightly launch, which is how Nightly stays away from the
|
||||
/// control channel and the automation roots the stable app can be started with.
|
||||
pub fn parse(args: Vec<OsString>) -> Result<Launch, String> {
|
||||
let mut selector = None;
|
||||
let mut root = None;
|
||||
let mut other = Vec::new();
|
||||
let mut files = Vec::new();
|
||||
let mut iter = args.iter();
|
||||
let mut delimiter = false;
|
||||
while let Some(arg) = iter.next() {
|
||||
if arg == "--" {
|
||||
delimiter = true;
|
||||
files.extend(iter.cloned());
|
||||
break;
|
||||
}
|
||||
if arg == "--launch-profile" || arg == "--profile-root" {
|
||||
let slot = if arg == "--launch-profile" { &mut selector } else { &mut root };
|
||||
if slot.is_some() {
|
||||
return Err("the profile selector and root must each occur exactly once".into());
|
||||
}
|
||||
let value = iter.next().filter(|v| !v.is_empty()).ok_or("the profile selector/root needs a value")?;
|
||||
if value.to_string_lossy().starts_with("--") {
|
||||
return Err("the profile selector/root needs a value".into());
|
||||
}
|
||||
*slot = Some(value.clone());
|
||||
} else if arg.to_string_lossy().starts_with("--launch-profile=") || arg.to_string_lossy().starts_with("--profile-root=") {
|
||||
return Err("the nightly protocol requires separate literal selector/root argument tokens".into());
|
||||
} else {
|
||||
other.push(arg.clone());
|
||||
}
|
||||
}
|
||||
match (selector, root) {
|
||||
(None, None) => Ok(Launch { profile: Profile::Stable, args }),
|
||||
(Some(version), Some(root)) if version == VERSION => {
|
||||
if !delimiter || !other.is_empty() {
|
||||
return Err("nightly-v1 accepts only its selector/root followed by -- and file names".into());
|
||||
}
|
||||
let root = PathBuf::from(root);
|
||||
if !root.is_absolute() || root.components().any(|c| matches!(c, Component::ParentDir)) {
|
||||
return Err("the nightly profile root must be absolute and contain no parent traversal".into());
|
||||
}
|
||||
Ok(Launch { profile: Profile::NightlyV1(root), args: std::iter::once(OsString::from("--")).chain(files).collect() })
|
||||
}
|
||||
(Some(_), Some(_)) => Err("unsupported launch profile (expected nightly-v1)".into()),
|
||||
_ => Err("--launch-profile and --profile-root must be supplied together".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Launcher's version check: the selector/root pair followed by exactly `--version` (or `-V`),
|
||||
/// answered like a plain version query. Only [`parse`]'s lexical checks apply; the root is never
|
||||
/// validated or touched, and `-- --version` stays a file name.
|
||||
pub fn version_query(args: &[OsString]) -> bool {
|
||||
let Some((last, pair)) = args.split_last() else { return false };
|
||||
if last != "--version" && last != "-V" {
|
||||
return false;
|
||||
}
|
||||
let lexical = pair.iter().cloned().chain(std::iter::once(OsString::from("--"))).collect();
|
||||
matches!(parse(lexical), Ok(Launch { profile: Profile::NightlyV1(_), args }) if args.len() == 1)
|
||||
}
|
||||
|
||||
/// Validation finishes before the caller's first startup effect. Stable never calls the nightly
|
||||
/// root validator, so its old portable/config resolution stays unchanged.
|
||||
pub fn prepare(mut launch: Launch, validate: impl FnOnce(&Path) -> Result<PathBuf, String>) -> Result<Launch, String> {
|
||||
if let Profile::NightlyV1(root) = &launch.profile {
|
||||
launch.profile = Profile::NightlyV1(validate(root)?);
|
||||
}
|
||||
Ok(launch)
|
||||
}
|
||||
|
||||
/// Resolve the selected private root before the caller's first startup effect.
|
||||
pub fn validate_root(root: &Path, env: impl Fn(&str) -> Option<OsString>, exe: Option<&Path>) -> Result<PathBuf, String> {
|
||||
crate::profile_root::validate(root, env, exe, crate::profile_root::ensure_writable)
|
||||
pub fn prepare(flavor: crate::build_flavor::BuildFlavor, args: impl IntoIterator<Item = OsString>) -> Result<Launch, ProfileError> {
|
||||
let spec = crate::profile_root::spec();
|
||||
craft_nightly::prepare_launch(flavor, &spec, args, &StartupOptions::new())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::cell::Cell;
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use craft_nightly::{NIGHTLY_V1_CONTRACT, StartupOptions, canonical_profile_root, parse_startup};
|
||||
|
||||
use super::{Profile, ProfileError, current, prepare};
|
||||
use crate::build_flavor::BuildFlavor;
|
||||
use crate::profile_root;
|
||||
|
||||
fn args(values: &[&str]) -> Vec<OsString> {
|
||||
values.iter().map(OsString::from).collect()
|
||||
}
|
||||
|
||||
fn absolute() -> &'static str {
|
||||
if cfg!(windows) { r"C:\NightlyData\profiles\figcraft" } else { "/nightly-data/profiles/figcraft" }
|
||||
}
|
||||
fn nightly() -> Vec<OsString> {
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--"])
|
||||
|
||||
#[test]
|
||||
fn direct_nightly_launch_self_isolates_to_canonical_profile_root_and_preserves_args() {
|
||||
let spec = profile_root::spec_with(|_| None);
|
||||
let expected = canonical_profile_root(profile_root::APP_ID).unwrap();
|
||||
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, args(&["a.figcraft", "b.figcraft"]), &StartupOptions::new()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::NightlyV1(expected));
|
||||
assert!(launch.profile.is_nightly());
|
||||
assert_eq!(launch.passthrough_args, args(&["a.figcraft", "b.figcraft"]));
|
||||
assert!(!launch.is_version_query());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_arguments_and_directory_policy_are_unchanged() {
|
||||
for argv in [args(&[]), args(&["--control", "8765", "a.figcraft"]), args(&["--", "--launch-profile", "file.figcraft"])] {
|
||||
let launch = prepare(parse(argv.clone()).unwrap(), |_| panic!("stable must never validate a nightly root")).unwrap();
|
||||
assert_eq!(launch, Launch { profile: Profile::Stable, args: argv });
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_version_and_root_are_parsed_without_reinterpreting_file_names() {
|
||||
let mut argv = nightly();
|
||||
argv.extend(args(&["--profile-root", "image with spaces.figcraft"]));
|
||||
let launch = parse(argv).unwrap();
|
||||
fn explicit_nightly_flags_override_canonical_root_and_preserve_file_names() {
|
||||
let spec = profile_root::spec_with(|_| None);
|
||||
let argv =
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--", "--profile-root", "image with spaces.figcraft"]);
|
||||
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::new()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::NightlyV1(PathBuf::from(absolute())));
|
||||
assert_eq!(launch.args, args(&["--", "--profile-root", "image with spaces.figcraft"]));
|
||||
assert_eq!(launch.passthrough_args, args(&["--profile-root", "image with spaces.figcraft"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_duplicate_unknown_and_conflicting_profile_arguments_are_refused() {
|
||||
fn stable_build_keeps_arguments_and_refuses_nightly_flags() {
|
||||
let spec = profile_root::spec_with(|_| None);
|
||||
for argv in [args(&[]), args(&["--control", "8765", "a.figcraft"]), args(&["--", "--launch-profile", "file.figcraft"])] {
|
||||
let launch = parse_startup(BuildFlavor::Stable, &spec, argv.clone(), &StartupOptions::new()).unwrap();
|
||||
assert_eq!(launch.profile, Profile::Stable);
|
||||
assert_eq!(launch.passthrough_args, argv);
|
||||
}
|
||||
let nightly = args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"]);
|
||||
assert!(matches!(parse_startup(BuildFlavor::Stable, &spec, nightly, &StartupOptions::new()), Err(ProfileError::NightlyFlagsInStableBuild)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_duplicate_unsupported_and_misplaced_profile_flags_are_refused() {
|
||||
let spec = profile_root::spec_with(|_| None);
|
||||
for argv in [
|
||||
args(&["--launch-profile", VERSION]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT]),
|
||||
args(&["--profile-root", absolute()]),
|
||||
args(&["--launch-profile", "future-v2", "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", VERSION, "--launch-profile", VERSION, "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", "relative", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", "", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--control", "8765", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--automation-write-root", "/tmp", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute()]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--profile-root", absolute(), "--"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", "", "--"]),
|
||||
args(&["a.figcraft", "--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute()]),
|
||||
] {
|
||||
assert!(parse(argv).is_err());
|
||||
assert!(parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::new()).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_launcher_version_check_is_a_version_query_only_in_its_exact_form() {
|
||||
let pair = &["--launch-profile", VERSION, "--profile-root", absolute()];
|
||||
let reversed = &["--profile-root", absolute(), "--launch-profile", VERSION];
|
||||
for flag in ["--version", "-V"] {
|
||||
for form in [pair, reversed] {
|
||||
let mut argv = args(form);
|
||||
argv.push(flag.into());
|
||||
assert!(version_query(&argv), "{argv:?}");
|
||||
}
|
||||
}
|
||||
fn version_queries_are_recognized_for_direct_and_launcher_invocations() {
|
||||
let spec = profile_root::spec_with(|_| None);
|
||||
for argv in [
|
||||
args(&["--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--", "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--version", "--"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--control", "8765", "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--version", "--version"]),
|
||||
args(&["--version", "--launch-profile", VERSION, "--profile-root", absolute()]),
|
||||
args(&["--launch-profile", "future-v2", "--profile-root", absolute(), "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", "relative", "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--version"]),
|
||||
args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--help"]),
|
||||
args(&["-V"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--version"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "-V"]),
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--", "--version"]),
|
||||
args(&["--profile-root", absolute(), "--launch-profile", NIGHTLY_V1_CONTRACT, "--version"]),
|
||||
] {
|
||||
assert!(!version_query(&argv), "{argv:?}");
|
||||
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv.clone(), &StartupOptions::new()).unwrap();
|
||||
assert!(launch.is_version_query(), "{argv:?}");
|
||||
}
|
||||
for argv in [args(&[]), args(&["--", "--version"]), args(&["a.figcraft"])] {
|
||||
let launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv.clone(), &StartupOptions::new()).unwrap();
|
||||
assert!(!launch.is_version_query(), "{argv:?}");
|
||||
}
|
||||
// Outside the query the strict protocol still refuses the version flag.
|
||||
assert!(parse(args(&["--launch-profile", VERSION, "--profile-root", absolute(), "--version"])).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_root_validation_never_reaches_startup_or_falls_back_to_stable() {
|
||||
let reached = Cell::new(false);
|
||||
let result = prepare(parse(nightly()).unwrap(), |_| Err("read-only or unsafe profile".into())).map(|_| reached.set(true));
|
||||
assert!(result.is_err());
|
||||
assert!(!reached.get());
|
||||
fn ordinary_file_arguments_do_not_turn_a_launcher_invocation_into_a_version_query() {
|
||||
let spec = profile_root::spec_with(|_| None);
|
||||
for tail in [&["--version", "drawing.figcraft"][..], &["--", "drawing.figcraft", "notes.figcraft"][..], &["--version", "--"][..]] {
|
||||
let mut argv = args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute()]);
|
||||
argv.extend(args(tail));
|
||||
let parsed = parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::new()).unwrap();
|
||||
assert!(!parsed.is_version_query());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn successful_root_validation_keeps_the_persistent_root_not_the_binary_tag() {
|
||||
let checked = PathBuf::from(absolute()).join("checked");
|
||||
let launch = prepare(parse(nightly()).unwrap(), |_| Ok(checked.clone())).unwrap();
|
||||
assert_eq!(launch.profile.root(), Some(checked.as_path()));
|
||||
assert!(launch.profile.is_nightly());
|
||||
fn current_defaults_to_stable_and_prepare_handles_version_query_without_installing() {
|
||||
assert_eq!(current(), &Profile::Stable);
|
||||
let version = prepare(BuildFlavor::NightlyV1, args(&["--version"])).unwrap();
|
||||
assert!(version.is_version_query());
|
||||
assert_eq!(current(), &Profile::Stable);
|
||||
let rejected = prepare(BuildFlavor::Stable, args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"]));
|
||||
assert!(matches!(rejected, Err(ProfileError::NightlyFlagsInStableBuild)));
|
||||
}
|
||||
}
|
||||
+59
-17
@@ -236,34 +236,50 @@ fn report_launch_profile_error(error: &str) -> ! {
|
||||
std::process::exit(2)
|
||||
}
|
||||
|
||||
/// Whether `argv` begins with explicit `--launch-profile`/`--profile-root` flags followed
|
||||
/// immediately by `--` (which `craft-nightly` strips from `passthrough_args`).
|
||||
fn has_launcher_delimiter(argv: &[std::ffi::OsString]) -> bool {
|
||||
let mut i = 0;
|
||||
let mut saw_flag = false;
|
||||
while let Some(arg) = argv.get(i).and_then(|a| a.to_str()) {
|
||||
if arg == craft_nightly::LAUNCH_PROFILE_FLAG || arg == craft_nightly::PROFILE_ROOT_FLAG {
|
||||
saw_flag = true;
|
||||
i += 2;
|
||||
} else if arg.starts_with("--launch-profile=") || arg.starts_with("--profile-root=") {
|
||||
saw_flag = true;
|
||||
i += 1;
|
||||
} else {
|
||||
return saw_flag && arg == "--";
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Select the immutable launch profile before any startup service or side effect, and answer the
|
||||
/// version query first: `None` means the query did (there is nothing left to start).
|
||||
///
|
||||
/// Stable keeps its arguments and its directory policy untouched; only a Nightly build answers the
|
||||
/// Launcher's `--launch-profile nightly-v1 --profile-root <dir> --version` form.
|
||||
/// Stable keeps its arguments and its directory policy untouched; a Nightly build self-isolates
|
||||
/// into `craft_nightly::canonical_profile_root("figcraft")` on direct launch or uses the
|
||||
/// Launcher's `--launch-profile nightly-v1 --profile-root <dir>` override.
|
||||
fn prepare_launch() -> Option<Vec<std::ffi::OsString>> {
|
||||
let argv: Vec<_> = std::env::args_os().skip(1).collect();
|
||||
let nightly_build = build_flavor::COMPILED == build_flavor::BuildFlavor::NightlyV1;
|
||||
if nightly_build && (build_flavor::version_query(&argv) || launch_profile::version_query(&argv)) {
|
||||
// A bare version query must not resolve HOME or LOCALAPPDATA.
|
||||
if nightly_build && matches!(argv.as_slice(), [arg] if arg == "--version" || arg == "-V") {
|
||||
use std::io::Write as _;
|
||||
let _ = writeln!(std::io::stdout(), "FigCraft {}", build_flavor::version(build_flavor::COMPILED, env!("FIGCRAFT_BUILT_VERSION")));
|
||||
return None;
|
||||
}
|
||||
let launcher_delimited = nightly_build && has_launcher_delimiter(&argv);
|
||||
let early = launch_profile::prepare(build_flavor::COMPILED, argv).unwrap_or_else(|error| report_launch_profile_error(&error.to_string()));
|
||||
if nightly_build && early.is_version_query() {
|
||||
// Before root validation, logging, the update helper, fonts or any window: a runner reads
|
||||
// this line and the process ends. Nothing else may be printed here.
|
||||
use std::io::Write as _;
|
||||
let _ = writeln!(std::io::stdout(), "FigCraft {}", build_flavor::version(build_flavor::COMPILED, env!("FIGCRAFT_BUILT_VERSION")));
|
||||
return None;
|
||||
}
|
||||
let early = launch_profile::parse(argv)
|
||||
.and_then(|launch| {
|
||||
build_flavor::require_profile(build_flavor::COMPILED, &launch.profile)?;
|
||||
initialize_nightly_identity()?;
|
||||
Ok(launch)
|
||||
})
|
||||
.and_then(|launch| {
|
||||
launch_profile::prepare(launch, |root| {
|
||||
launch_profile::validate_root(root, |key| std::env::var_os(key), std::env::current_exe().ok().as_deref())
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|error| report_launch_profile_error(&error));
|
||||
if let Err(error) = launch_profile::install(early.profile) {
|
||||
if let Err(error) = initialize_nightly_identity() {
|
||||
report_launch_profile_error(&error);
|
||||
}
|
||||
if let Some(root) = launch_profile::current().root() {
|
||||
@@ -273,7 +289,12 @@ fn prepare_launch() -> Option<Vec<std::ffi::OsString>> {
|
||||
// fonts inside its own profile instead.
|
||||
figcraft_engine::fonts::download::use_store_dir(root.join("Fonts"));
|
||||
}
|
||||
Some(early.args)
|
||||
let args = if launcher_delimited {
|
||||
std::iter::once(std::ffi::OsString::from("--")).chain(early.passthrough_args).collect()
|
||||
} else {
|
||||
early.passthrough_args
|
||||
};
|
||||
Some(args)
|
||||
}
|
||||
|
||||
fn open_startup_files(app: &mut FigApp, files: &[String]) {
|
||||
@@ -699,3 +720,24 @@ mod refusal_dialog_tests {
|
||||
assert!(!refusal_dialog(BuildFlavor::Stable, true, false), "only a nightly refusal explains itself in a box");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod launcher_delimiter_tests {
|
||||
use std::ffi::OsString;
|
||||
|
||||
use super::has_launcher_delimiter;
|
||||
|
||||
fn args(values: &[&str]) -> Vec<OsString> {
|
||||
values.iter().map(OsString::from).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recognizes_delimiter_immediately_after_nightly_header_flags() {
|
||||
assert!(has_launcher_delimiter(&args(&["--launch-profile", "nightly-v1", "--profile-root", "/tmp/p", "--", "a.figcraft"])));
|
||||
assert!(has_launcher_delimiter(&args(&["--launch-profile=nightly-v1", "--profile-root=/tmp/p", "--"])));
|
||||
assert!(!has_launcher_delimiter(&args(&["--launch-profile", "nightly-v1", "--profile-root", "/tmp/p", "a.figcraft", "--", "b.figcraft"])));
|
||||
assert!(!has_launcher_delimiter(&args(&["--launch-profile", "nightly-v1", "--profile-root", "/tmp/p"])));
|
||||
assert!(!has_launcher_delimiter(&args(&["--", "a.figcraft"])));
|
||||
assert!(!has_launcher_delimiter(&args(&[])));
|
||||
}
|
||||
}
|
||||
+243
-716
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user