diff --git a/crates/fastled-cli/src/viewer.rs b/crates/fastled-cli/src/viewer.rs index 7e439def..89a5ae9f 100644 --- a/crates/fastled-cli/src/viewer.rs +++ b/crates/fastled-cli/src/viewer.rs @@ -346,7 +346,18 @@ fn spawn_hidden_viewer(binary: &Path, url: &str) -> Result { /// viewer/WebView2 process tree is torn down too. /// /// Returns a process handle whose lifetime controls the viewer lifetime. +/// +/// Fails loudly when `url` is not an http(s) URL. The viewer must always be +/// pointed at the embedded HTTP server (which serves the loading page and +/// reloads on build completion); pointing it at a directory or `fastled://` +/// path regresses to a dead "Not Found" page (issues #151/#160). pub fn launch_tauri_viewer(url: &str) -> Result { + if !url.starts_with("http://") && !url.starts_with("https://") { + anyhow::bail!( + "viewer must be launched with an http(s) URL pointing at the FastLED server, got: {url}" + ); + } + let binary = find_tauri_viewer().context("fastled binary not found; cannot launch Tauri viewer")?; @@ -520,6 +531,24 @@ mod tests { assert_eq!(args, vec!["--internal-viewer", "http://127.0.0.1:8089"]); } + #[test] + fn test_launch_tauri_viewer_rejects_directory_path() { + // Regression gate for #151/#160: the viewer must never be pointed at + // a filesystem path; it must load the FastLED HTTP server URL. + match launch_tauri_viewer("examples/TwinkleFox/fastled_js") { + Ok(_) => panic!("directory path must be rejected"), + Err(err) => assert!(err.to_string().contains("http(s) URL"), "got: {err}"), + } + } + + #[test] + fn test_launch_tauri_viewer_rejects_fastled_protocol() { + match launch_tauri_viewer("fastled://localhost/index.html") { + Ok(_) => panic!("fastled:// protocol must be rejected"), + Err(err) => assert!(err.to_string().contains("http(s) URL"), "got: {err}"), + } + } + #[test] #[cfg(windows)] fn test_viewer_uses_hidden_process_creation_flags() {