diff --git a/app/Cargo.lock b/app/Cargo.lock index 3e0ec7a..3bc4e8b 100644 --- a/app/Cargo.lock +++ b/app/Cargo.lock @@ -1484,7 +1484,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" [[package]] name = "jarvis-app" -version = "0.1.1" +version = "0.1.2" dependencies = [ "async-trait", "base64 0.22.1", diff --git a/app/Cargo.toml b/app/Cargo.toml index 1c3f533..17f1c95 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jarvis-app" -version = "0.1.1" +version = "0.1.2" edition = "2021" rust-version = "1.85" description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels" diff --git a/app/shell/Cargo.lock b/app/shell/Cargo.lock index b1b7c9a..c5061f9 100644 --- a/app/shell/Cargo.lock +++ b/app/shell/Cargo.lock @@ -2380,7 +2380,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" [[package]] name = "jarvis-app" -version = "0.1.1" +version = "0.1.2" dependencies = [ "async-trait", "base64 0.22.1", @@ -2408,7 +2408,7 @@ dependencies = [ [[package]] name = "jarvis-shell" -version = "0.1.1" +version = "0.1.2" dependencies = [ "jarvis-app", "serde_json", diff --git a/app/shell/Cargo.toml b/app/shell/Cargo.toml index efdd34a..7d6673b 100644 --- a/app/shell/Cargo.toml +++ b/app/shell/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jarvis-shell" -version = "0.1.1" +version = "0.1.2" edition = "2021" rust-version = "1.85" description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)" diff --git a/app/src/admin.spec.md b/app/src/admin.spec.md index 6523e84..7322d9a 100644 --- a/app/src/admin.spec.md +++ b/app/src/admin.spec.md @@ -762,9 +762,11 @@ both to a release with that tag. The repository's other releases (v1's `v1.x`) a quits anyway. Quitting another way (the system shutting down) runs the same shutdown. - `app/shell/package.sh ` builds it on Linux (`x86_64-pc-windows-gnu`, mingw-w64) and lays out `Jarvis/`: `jarvis.exe`, `WebView2Loader.dll`, `python-src/` (the `voice_worker` and - `jarvis` packages, no caches or specs) and `display-driver/` (the virtual monitor's driver). The worker's default sources are `python-src` next to the - executable when it is there, else the repository's `src/`; the install reads its requirement - files from the same place. The folder also runs as it is. + `jarvis` packages, no caches or specs) and `display-driver/` (the virtual monitor's driver). The worker's sources are `python-src` next to the + executable when it is there, also over a `voiceWorker.cwd` the settings keep (another install's + first-run setup may have written its own folder there, and an update must never run those older + sources); without shipped sources `voiceWorker.cwd`, else the repository's `src/`. The install + reads its requirement files from the same place. The folder also runs as it is. ## Installer (`app/shell/installer.nsi`, `app/shell/installer.sh`) diff --git a/app/src/settings.rs b/app/src/settings.rs index 6224c57..c9533f2 100644 --- a/app/src/settings.rs +++ b/app/src/settings.rs @@ -288,6 +288,14 @@ pub fn worker_cwd_for(exe: Option<&Path>) -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("src") } +/// The worker's Python sources: the ones shipped next to the app's executable always win, so an +/// update or a second install never runs the older sources a `voiceWorker.cwd` written by another +/// install points at; without shipped sources the stored folder, else the default. +pub fn worker_cwd(stored: Option, exe: Option<&Path>) -> PathBuf { + let shipped = exe.and_then(Path::parent).map(|d| d.join("python-src")).filter(|p| p.join("voice_worker").is_dir()); + shipped.or(stored).unwrap_or_else(|| worker_cwd_for(exe)) +} + impl Settings { /// The voice worker's arguments: `voiceWorker.args`, plus the voice speed when it speaks /// (`--melo-python`) and the arguments do not set one themselves. @@ -575,11 +583,11 @@ pub fn parse_settings(raw: &Value) -> Result { chat_channels, voice_worker: WorkerSettings { python: get_str(worker, "python", "voiceWorker", &d.voice_worker.python)?, - cwd: match worker.and_then(|m| m.get("cwd")) { - None => d.voice_worker.cwd.clone(), - Some(Value::String(s)) => PathBuf::from(s), + cwd: worker_cwd(match worker.and_then(|m| m.get("cwd")) { + None => None, + Some(Value::String(s)) => Some(PathBuf::from(s)), Some(_) => return err("voiceWorker.cwd must be a string"), - }, + }, std::env::current_exe().ok().as_deref()), args: get_str_list(worker, "args", "voiceWorker", &d.voice_worker.args)?, }, call, @@ -855,6 +863,19 @@ mod tests { assert_eq!(worker_cwd_for(None), Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("src")); } + #[test] + fn a_worker_folder_stored_by_another_install_never_beats_the_sources_shipped_with_this_app() { + // The first-run setup of one install wrote its folder; this app (installed elsewhere, or + // updated) must still run its own sources, never the other install's older ones. + let dir = crate::datadir::temp_dir("pysrc-stored"); + let exe = dir.join("jarvis.exe"); + let other = PathBuf::from("C:/old-install/python-src"); + assert_eq!(worker_cwd(Some(other.clone()), Some(&exe)), other, "nothing shipped: the stored folder"); + std::fs::create_dir_all(dir.join("python-src").join("voice_worker")).unwrap(); + assert_eq!(worker_cwd(Some(other), Some(&exe)), dir.join("python-src")); + assert_eq!(worker_cwd(None, Some(&exe)), dir.join("python-src")); + } + const ID: &str = "123456789012345678"; const IDN: u64 = 123456789012345678;