PM: merge H6 isolated data directory for dev and live-check instances
Some checks are pending
ci / ci (macos-15) (push) Waiting to run
ci / ci (ubuntu-24.04) (push) Waiting to run
ci / ci (windows-2025) (push) Waiting to run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-25 13:04:34 +01:00
commit f6ea0b708c
10 changed files with 418 additions and 29 deletions

View file

@ -14,7 +14,8 @@
//! that ACL. A file whose listener does not answer, or answers without
//! accepting the token, is stale: the next app start replaces it.
//!
//! The directory is [`dir`]: `LUTRA_RENDEZVOUS_DIR` if set, otherwise
//! The directory is [`dir`]: `LUTRA_RENDEZVOUS_DIR` if set, otherwise the
//! isolated data directory `LUTRA_DATA_DIR` if set, otherwise
//! [`default_data_dir`], which matches Tauri's `app_data_dir()` for the
//! identifier [`APP_IDENTIFIER`].
@ -32,6 +33,13 @@ pub const FILE_NAME: &str = "instance.json";
/// takes part in the single instance only when it is set.
pub const DIR_ENV: &str = "LUTRA_RENDEZVOUS_DIR";
/// Environment variable that moves a desktop instance's whole data
/// directory (settings, recovery journal, rendezvous file, webview data)
/// away from the user's, like the desktop's `--data-dir PATH`. Such an
/// instance is isolated: it never forwards to or registers as the user's
/// main instance. The CLI looks for the rendezvous file there too.
pub const DATA_DIR_ENV: &str = "LUTRA_DATA_DIR";
/// The Tauri app identifier, the last part of the data directory.
pub const APP_IDENTIFIER: &str = "dev.lutra.desktop";
@ -79,12 +87,17 @@ impl std::fmt::Display for ReadError {
impl std::error::Error for ReadError {}
/// The rendezvous directory: `LUTRA_RENDEZVOUS_DIR` if set and not empty,
/// otherwise [`default_data_dir`].
/// otherwise `LUTRA_DATA_DIR` if set and not empty (made absolute against
/// the current directory), otherwise [`default_data_dir`].
pub fn dir() -> Option<PathBuf> {
match std::env::var_os(DIR_ENV) {
Some(value) if !value.is_empty() => Some(PathBuf::from(value)),
_ => default_data_dir(),
}
let set = |name: &str| {
std::env::var_os(name)
.filter(|value| !value.is_empty())
.map(PathBuf::from)
};
set(DIR_ENV)
.or_else(|| set(DATA_DIR_ENV).map(|p| std::path::absolute(&p).unwrap_or(p)))
.or_else(default_data_dir)
}
/// The app data directory as Tauri computes it for [`APP_IDENTIFIER`]:

View file

@ -101,6 +101,10 @@ pub struct Toolchain {
config: Option<Config>,
/// The project root the last job saw.
root: Option<PathBuf>,
/// Where the managed tools live (`tools/phpactor/<version>/`) when that
/// is not the engine's data directory; see
/// [`crate::Engine::share_tools_from`].
tools_dir: Option<PathBuf>,
}
impl Toolchain {
@ -114,6 +118,12 @@ impl Toolchain {
pub fn allow_downloads(&mut self, source: Source) {
self.source = Some(source);
}
/// Keeps the managed tools in `dir` instead of the engine's data
/// directory.
pub fn set_tools_dir(&mut self, dir: PathBuf) {
self.tools_dir = Some(dir);
}
}
/// The settings and directories a job runs with.
@ -125,7 +135,8 @@ struct Config {
phpactor_path: String,
/// `phpactor.autoDownload`.
auto_download: bool,
/// The engine's data directory.
/// The directory holding the managed tools: the toolchain's tools
/// directory if set, else the engine's data directory.
data_dir: Option<PathBuf>,
}
@ -236,7 +247,11 @@ fn config(state: &State) -> Config {
.get("phpactor.autoDownload")
.and_then(|v| v.as_bool())
.unwrap_or(true),
data_dir: state.config.as_ref().map(|c| c.data_dir.clone()),
data_dir: state
.toolchain
.tools_dir
.clone()
.or_else(|| state.config.as_ref().map(|c| c.data_dir.clone())),
}
}
@ -883,4 +898,32 @@ mod tests {
Mode::Auto(PathBuf::from("p"))
);
}
#[test]
fn a_shared_tools_dir_is_used_instead_of_the_data_dir() {
let dir = tempfile::tempdir().unwrap();
let shared = dir.path().join("user-data");
let body = b"shared phar".to_vec();
let path = phpactor::managed_path(&shared, "1.0.0");
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, &body).unwrap();
let mut engine = engine(dir.path());
engine.share_tools_from(shared.clone());
engine.allow_downloads_from(Source {
url: "http://127.0.0.1:9/never".into(),
version: "1.0.0".into(),
sha256: Hash::of_bytes(&body),
https_only: false,
});
engine.execute("toolchain.status", Value::Null).unwrap();
let events = pump_until(&mut engine, |ev| {
last_status(ev).is_some_and(|s| s.phpactor.state == PhpactorState::Ready)
});
let status = last_status(&events).unwrap();
assert_eq!(
status.phpactor.path.as_deref(),
Some(path.display().to_string().as_str())
);
assert!(!dir.path().join("data").join("tools").exists());
}
}

View file

@ -242,6 +242,15 @@ impl Engine {
self.state.toolchain.allow_downloads(source);
}
/// Looks for (and downloads) the managed tools such as the Phpactor
/// PHAR under `dir` instead of the data directory of the engine's
/// [`EngineConfig`]. An isolated desktop instance (`--data-dir`,
/// `--control`) passes the user's normal data directory, so it shares
/// the SHA-256-checked cache instead of downloading its own copy.
pub fn share_tools_from(&mut self, dir: PathBuf) {
self.state.toolchain.set_tools_dir(dir);
}
/// Makes the engine run `launch` as the project's language server
/// instead of Phpactor from the toolchain; `None` goes back to the
/// toolchain. For tests (the fake server) and hosts with their own