Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,8 @@ the Python module reports must be the same file. Consequences:
- **Do not set `VAPOURSYNTH_EXTRA_PLUGIN_PATH` on macOS/Linux** — R78 autoloads
`vapoursynth/plugins` itself, and setting it too double-loads every plugin.
**Windows still needs the variable** (its plugins live in `vs-plugins`, not
the autoload directory).
the autoload directory). `vspipe_environment_test` (Rust) runs vspipe under
the worker's environment and fails on any "already loaded" line (task #61).

No source-indexing plugin is bundled — sources are read as raw frames piped
from ffmpeg (`templates/pipe_source.py`); BestSource was removed in 2026-08-07
Expand Down
3 changes: 2 additions & 1 deletion app/lib/services/tool_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ToolLocator {
String? get workerPath => _workerPath;

/// Environment variables for spawning worker/tool processes.
/// Includes PYTHONHOME, PYTHONPATH, VAPOURSYNTH_EXTRA_PLUGIN_PATH, PATH, etc.
/// Includes PYTHONHOME, PYTHONPATH, PATH, etc. (VAPOURSYNTH_EXTRA_PLUGIN_PATH
/// on Windows only: R78 autoloads the plugins on macOS/Linux, task #61).
///
/// The temp variables are applied per call rather than baked into the cached
/// map, so changing the temp directory in Settings takes effect immediately.
Expand Down
7 changes: 7 additions & 0 deletions docs/ENGINEERING_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,13 @@ so `import vapoursynth` resolves there. Four consequences:
both, every plugin loads twice and warns `Plugin ... already loaded`. Windows
still needs the variable: its plugins are in `vs-plugins`, which is not the
autoload directory.
*2026-11-17, task #61:* the worker kept setting it anyway until now — the
macOS and Linux blocks of `build_environment` were left over from the R78
move, which only added the Windows-only insert. Every vspipe run printed 35
(macOS x64) / 37 (arm64) duplicate-load warnings with the identical plugin
set loaded, and a preview's vspipe failure was reported as the first of them
(task #56 F9). `worker/tests/vspipe_environment_test.rs` runs vspipe under
`build_environment()` and fails on any `already loaded` line.

`_has_implicit_config()` returns true **only on Windows** (where `python.exe`
sits next to the package), which is why the Windows bundle needs none of this and
Expand Down
43 changes: 24 additions & 19 deletions worker/src/dependency_locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,10 @@ impl DependencyLocator {
// which is <libdir>/plugins relative to libvapoursynth, so R78
// autoloads them and setting this as well would load every plugin
// twice ("Plugin ... already loaded"). Windows keeps it: its plugins
// live in vs-plugins, which is not the autoload directory.
// live in vs-plugins, which is not the autoload directory. Task #61:
// the macOS/Linux blocks below set it too until 2026-11, burying real
// vspipe errors under 35+ warnings; tests/vspipe_environment_test.rs
// fails on a duplicate load.
#[cfg(target_os = "windows")]
env.insert(
"VAPOURSYNTH_EXTRA_PLUGIN_PATH".to_string(),
Expand Down Expand Up @@ -1036,17 +1039,6 @@ impl DependencyLocator {
format!("{}:{}:{}", vs_lib_path.to_string_lossy(), python_lib_path.to_string_lossy(), existing_dyld)
};
env.insert("DYLD_LIBRARY_PATH".to_string(), new_dyld);

// Point vspipe-bin at the bundled plugins. R74 removed the config
// file mechanism (UserPluginDir / AutoloadUserPluginDir /
// VAPOURSYNTH_CONF_PATH) in favour of this variable, which also
// retires the per-process conf file we used to write: there is no
// longer a shared file for concurrent runs to race on.
let plugins_dir = vs_lib_path.join("plugins");
env.insert(
"VAPOURSYNTH_EXTRA_PLUGIN_PATH".to_string(),
plugins_dir.to_string_lossy().to_string(),
);
}

#[cfg(target_os = "linux")]
Expand All @@ -1073,13 +1065,6 @@ impl DependencyLocator {
)
};
env.insert("LD_LIBRARY_PATH".to_string(), new_ld);

// Bundled plugin path (same as macOS)
let plugins_dir = vs_lib_path.join("plugins");
env.insert(
"VAPOURSYNTH_EXTRA_PLUGIN_PATH".to_string(),
plugins_dir.to_string_lossy().to_string(),
);
}

env
Expand Down Expand Up @@ -1112,6 +1097,26 @@ mod tests {
assert_eq!(locator.platform_suffix(), "windows-x64");
}

/// Task #61: R78 autoloads `<deps>/vapoursynth/plugins` on macOS and
/// Linux, so the variable must only be set on Windows (`vs-plugins`).
#[test]
fn extra_plugin_path_is_set_on_windows_only() {
let base = std::env::temp_dir()
.join(format!("vapourbox_env_test_{}", std::process::id()));
let locator = DependencyLocator {
base_path: base.clone(),
platform: DependencyLocator::detect_platform(),
};
let env = locator.build_environment();
let var = env.get("VAPOURSYNTH_EXTRA_PLUGIN_PATH");
if cfg!(windows) {
assert!(var.is_some_and(|v| v.ends_with("vs-plugins")), "{var:?}");
} else {
assert_eq!(var, None, "R78 autoloads the plugins; setting this loads each twice");
}
let _ = std::fs::remove_dir_all(&base);
}

#[test]
fn frame_count_takes_the_first_line() {
assert_eq!(super::first_count("125\n125\n"), Some(125));
Expand Down
6 changes: 5 additions & 1 deletion worker/src/pipeline_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ impl PipelineExecutor {
);
self.reporter.send_log(
LogLevel::Debug,
&format!("VAPOURSYNTH_EXTRA_PLUGIN_PATH: {:?}", env.get("VAPOURSYNTH_EXTRA_PLUGIN_PATH")),
&format!(
"VapourSynth plugins: {:?} ({})",
self.deps.vapoursynth_plugin_path(),
if cfg!(windows) { "VAPOURSYNTH_EXTRA_PLUGIN_PATH" } else { "autoloaded" }
),
);

// Determine input pixel format for the decoder. Formats pipe_source
Expand Down
68 changes: 68 additions & 0 deletions worker/tests/vspipe_environment_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! vspipe under the worker's own environment loads every plugin once (task #61).
//!
//! On macOS and Linux R78 autoloads `<deps>/vapoursynth/plugins` (it is
//! `<libdir>/plugins`), so `DependencyLocator::build_environment` must not also
//! set `VAPOURSYNTH_EXTRA_PLUGIN_PATH` there: with both, each plugin loads twice
//! and vspipe's stderr starts with 35+ "Plugin … already loaded" warnings, which
//! buried real errors (task #56 F9). Windows sets the variable, for
//! `vs-plugins`, which is not the autoload directory; it must load once too.
//!
//! Run with: cargo test --test vspipe_environment_test -- --nocapture

use std::process::Command;

use vapourbox_worker::dependency_locator::DependencyLocator;

/// Namespaces every platform's bundle carries (the full list is
/// `app/test/vapoursynth_integration_test.dart`'s); proof the plugins still
/// load without the variable.
const EXPECTED: &[&str] = &["std", "resize", "mv", "fmtc", "znedi3", "misc"];

#[test]
fn vspipe_loads_each_plugin_once() {
let deps = DependencyLocator::new().expect("locate dependencies");
let vspipe = deps.vspipe_path().expect("locate vspipe");
let env = deps.build_environment();

let script = std::env::temp_dir()
.join(format!("vapourbox_vspipe_env_{}.vpy", std::process::id()));
std::fs::write(
&script,
"import sys\n\
import vapoursynth as vs\n\
core = vs.core\n\
core.std.BlankClip(length=1).set_output()\n\
print('NAMESPACES ' + ' '.join(sorted(p.namespace for p in core.plugins())), file=sys.stderr)\n",
)
.expect("write script");

let out = Command::new(&vspipe)
.args(["-i", script.to_str().unwrap(), "-"])
.envs(&env)
.output()
.expect("run vspipe");
let _ = std::fs::remove_file(&script);
let stderr = String::from_utf8_lossy(&out.stderr);

assert!(out.status.success(), "vspipe -i failed ({}):\n{stderr}", out.status);

let duplicates: Vec<&str> = stderr.lines().filter(|l| l.contains("already loaded")).collect();
assert!(
duplicates.is_empty(),
"{} plugin(s) loaded twice under build_environment() \
(VAPOURSYNTH_EXTRA_PLUGIN_PATH = {:?}):\n{}",
duplicates.len(),
env.get("VAPOURSYNTH_EXTRA_PLUGIN_PATH"),
duplicates.join("\n")
);

let namespaces: Vec<&str> = stderr
.lines()
.find_map(|l| l.strip_prefix("NAMESPACES "))
.unwrap_or_else(|| panic!("script printed no namespaces:\n{stderr}"))
.split_whitespace()
.collect();
for ns in EXPECTED {
assert!(namespaces.contains(ns), "plugin namespace '{ns}' not loaded: {namespaces:?}");
}
}
Loading