From e1b22258bc080970bba3135f4e970023e2786d44 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sun, 8 Nov 2026 13:42:03 +0100 Subject: [PATCH] test(engine): cover explicit WAV stems and reusable scratch directories Address the review by clearing stale test scratch directories before setup and exercising an explicit supported WAV format through the real command, including decoded output format, frames and audio. --- crates/engine/src/cmd/file/tests.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/engine/src/cmd/file/tests.rs b/crates/engine/src/cmd/file/tests.rs index 35c821d8..a2b709b2 100644 --- a/crates/engine/src/cmd/file/tests.rs +++ b/crates/engine/src/cmd/file/tests.rs @@ -121,6 +121,7 @@ fn import_audio_honours_new_tracks() { #[test] fn bounce_stems_rejects_unsupported_formats_before_writing() { let dir = std::env::temp_dir().join(format!("sc-stems-unsupported-format-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir(&dir).unwrap(); let stems = dir.join("stems"); let mut e = Engine::default(); @@ -138,6 +139,7 @@ fn bounce_stems_rejects_unsupported_formats_before_writing() { #[test] fn bounce_stems_rejects_non_string_formats_before_writing() { let dir = std::env::temp_dir().join(format!("sc-stems-format-type-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir(&dir).unwrap(); let mut e = Engine::default(); e.execute("track.new", &json!({"count": 1, "name": "Tone", "format": "mono"})).unwrap(); @@ -158,6 +160,29 @@ fn bounce_stems_rejects_non_string_formats_before_writing() { } } +#[test] +fn bounce_stems_accepts_explicit_wav_format() { + let dir = std::env::temp_dir().join(format!("sc-stems-explicit-wav-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir(&dir).unwrap(); + let mut e = Engine::default(); + let wav = tone_wav(&dir, "tone.wav"); + e.execute("file.import_audio", &json!({"path": wav})).unwrap(); + let stems = dir.join("stems"); + let result = e.execute("file.bounce_stems", &json!({"dir": stems, "format": "wav", "start": 0, "end": 32, "dither": false})).unwrap(); + let files = result["files"].as_array().unwrap(); + assert_eq!(files.len(), 1); + let path = std::path::Path::new(files[0].as_str().unwrap()); + assert_eq!(path.parent(), Some(stems.as_path())); + assert_eq!(path.extension().and_then(|extension| extension.to_str()), Some("wav")); + let (info, audio) = soundcraft_audio_io::decode(&std::fs::read(path).unwrap(), None).unwrap(); + assert_eq!(info.format, soundcraft_audio_io::FileFormat::Wav); + assert_eq!(audio.frames(), 32); + assert_eq!(audio.num_channels(), e.session().main_format().channels()); + assert!(audio.channels.iter().flatten().any(|sample| sample.abs() > 0.01)); + std::fs::remove_dir_all(&dir).unwrap(); +} + #[test] fn bounce_refuses_formats_it_cannot_write() { let mut e = Engine::default();