From a8682eb4c55c5b9032902ec5ff71ee2a0b52b380 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 19 Oct 2026 05:20:36 +0200 Subject: [PATCH] horizon-server: give the game its folders whole when --dir is relative `horizon-server run --dir srv` (what init prints) started the game in srv/ with --control-socket srv/.horizon/engine.json, which the game resolved inside srv/, so it crashed at every start. spawn now passes absolute paths. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-server/src/engine.rs | 40 +++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/horizon-server/src/engine.rs b/crates/horizon-server/src/engine.rs index aa83693cb..0eb70b3a7 100644 --- a/crates/horizon-server/src/engine.rs +++ b/crates/horizon-server/src/engine.rs @@ -141,14 +141,18 @@ pub fn resources(config: &Config, dir: &Path, program: Option<&Path>) -> Result< /// Starts the engine in the server folder, with its console and log piped to the supervisor and its status /// on the control endpoint. pub fn spawn(program: &Path, resources: &Path, dir: &Path) -> std::io::Result { + // The game runs in the server folder, so a folder given relative to ours (`--dir srv`) would put its + // control endpoint in `srv/srv/.horizon`, which doesn't exist. + let dir = std::path::absolute(dir)?; + let resources = std::path::absolute(resources)?; let mut command = Command::new(program); command .arg("--resources") .arg(resources) .arg("--control-socket") - .arg(control_path(dir)) + .arg(control_path(&dir)) .args(["--dedicated", "--nogui"]) - .current_dir(dir) + .current_dir(&dir) .env("HORIZON_NO_AUDIO", "1") .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -276,6 +280,38 @@ mod tests { ); } + #[cfg(unix)] + #[test] + fn a_relative_folder_reaches_the_game_whole() { + use std::os::unix::fs::PermissionsExt; + // Relative to this process's folder (the crate's, under cargo test), as `--dir srv` gives it. + let root = PathBuf::from(format!("reldir-test-{}", std::process::id())); + let server = root.join("srv"); + std::fs::create_dir_all(server.join(".horizon")).unwrap(); + std::fs::create_dir_all(root.join("res")).unwrap(); + // A game that checks, from its own folder, the folders it was given. + let game = root.join("game"); + std::fs::write( + &game, + "#!/bin/sh\nwhile [ $# -gt 0 ]; do case \"$1\" in --resources) r=$2; shift;; \ + --control-socket) c=$2; shift;; esac; shift; done\n\ + [ -d \"$r\" ] && [ -d \"$(dirname \"$c\")\" ] && [ -f server.toml ]\n", + ) + .unwrap(); + std::fs::set_permissions(&game, std::fs::Permissions::from_mode(0o755)).unwrap(); + std::fs::write(server.join("server.toml"), "").unwrap(); + let status = spawn( + &std::path::absolute(&game).unwrap(), + &root.join("res"), + &server, + ) + .unwrap() + .wait(); + std::fs::remove_dir_all(&root).unwrap(); + let status = status.unwrap(); + assert!(status.success(), "{status}"); + } + #[cfg(unix)] #[test] fn the_check_runs_the_program() {