fix(app): the worker runs the Python sources shipped with this app, not a folder another install stored

The first-run setup writes voiceWorker.cwd; when it ran from another
install, an updated app kept starting that install's older sources (found
on the game PC: 0.1.1 ran without the screenView tool). Shipped sources
next to the executable now always win. Version 0.1.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-15 22:43:06 +09:00
parent a85ad3e00f
commit f991981776
6 changed files with 35 additions and 12 deletions

View File

@@ -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<PathBuf>, 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<Settings, SettingsError> {
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;