Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: avoid full video decoding after clean Instant stops

Richie McIlroyc871d2fffefd
diff --git a/apps/cli/src/record.rs b/apps/cli/src/record.rs
index 92aa09977..d02934146 100644
--- a/apps/cli/src/record.rs
+++ b/apps/cli/src/record.rs
@@ -986,8 +986,10 @@ async fn finalize_after_stop_trigger<T>(
finalized
}
-async fn finalize_completed(completed: CompletedRecording) -> Result<CompletedRecording, String> {
- match &completed {
+async fn finalize_completed(
+ mut completed: CompletedRecording,
+) -> Result<CompletedRecording, String> {
+ match &mut completed {
CompletedRecording::Studio(recording) => {
let project_path = recording.project_path.clone();
tokio::task::spawn_blocking(move || {
@@ -998,7 +1000,7 @@ async fn finalize_completed(completed: CompletedRecording) -> Result<CompletedRe
.map_err(|e| format!("Failed to finalize recording: {e}"))?;
}
CompletedRecording::Instant(recording) => {
- finalize_instant_output(recording.project_path.clone()).await?;
+ finalize_instant_output(recording).await?;
persist_instant_recording_meta(recording)?;
}
}
@@ -1006,7 +1008,11 @@ async fn finalize_completed(completed: CompletedRecording) -> Result<CompletedRe
Ok(completed)
}
-async fn finalize_instant_output(project_path: PathBuf) -> Result<(), String> {
+async fn finalize_instant_output(
+ recording: &mut instant_recording::CompletedRecording,
+) -> Result<(), String> {
+ let completion = recording.clean_completion.take();
+ let project_path = recording.project_path.clone();
let output_path = project_path.join("content/output.mp4");
let audio_dir = project_path.join("content/audio");
if std::fs::metadata(&output_path)
@@ -1018,12 +1024,20 @@ async fn finalize_instant_output(project_path: PathBuf) -> Result<(), String> {
}
let display_dir = project_path.join("content/display");
- tokio::task::spawn_blocking(move || {
- cap_recording::recovery::RecoveryManager::finalize_instant_output(
+ tokio::task::spawn_blocking(move || match completion {
+ Some(completion) => {
+ cap_recording::recovery::RecoveryManager::finalize_completed_instant_output(
+ &display_dir,
+ &audio_dir,
+ &output_path,
+ completion,
+ )
+ }
+ None => cap_recording::recovery::RecoveryManager::finalize_instant_output(
&display_dir,
&audio_dir,
&output_path,
- )
+ ),
})
.await
.map_err(|e| format!("instant recording finalize task failed: {e}"))?
diff --git a/apps/cli/src/selftest/instant.rs b/apps/cli/src/selftest/instant.rs
index 539cd15ac..36e6bf3a7 100644
--- a/apps/cli/src/selftest/instant.rs
+++ b/apps/cli/src/selftest/instant.rs
@@ -63,8 +63,9 @@ pub async fn start_recording(
/// `content/output.mp4`, then persist the meta so the `.cap` is a real
/// recording rather than a directory of fragments.
pub async fn finalize(
- recording: &instant_recording::CompletedRecording,
+ recording: &mut instant_recording::CompletedRecording,
) -> Result<PathBuf, String> {
+ let completion = recording.clean_completion.take();
let project_path = recording.project_path.clone();
let output = output_path(&project_path);
let audio_dir = project_path.join("content/audio");
@@ -77,8 +78,14 @@ pub async fn finalize(
if !already_muxed {
let display_dir = project_path.join("content/display");
let output = output.clone();
- tokio::task::spawn_blocking(move || {
- RecoveryManager::finalize_instant_output(&display_dir, &audio_dir, &output)
+ tokio::task::spawn_blocking(move || match completion {
+ Some(completion) => RecoveryManager::finalize_completed_instant_output(
+ &display_dir,
+ &audio_dir,
+ &output,
+ completion,
+ ),
+ None => RecoveryManager::finalize_instant_output(&display_dir, &audio_dir, &output),
})
.await
.map_err(|e| format!("instant finalize task join error: {e}"))?
diff --git a/apps/cli/src/selftest/mod.rs b/apps/cli/src/selftest/mod.rs
index 2c03de44b..b9b531a6c 100644
--- a/apps/cli/src/selftest/mod.rs
+++ b/apps/cli/src/selftest/mod.rs
@@ -756,14 +756,14 @@ async fn run_instant_leg(
reporter.stage("remuxing", Some("instant"));
reporter.log("[instant 2/3] Finalizing recording...");
- let completed = handle
+ let mut completed = handle
.stop()
.await
.map_err(|e| LegFailure::Failed(format!("failed to stop instant recording: {e}")))?;
let project_path = completed.project_path.clone();
temp.track(project_path.clone());
- let output = instant::finalize(&completed)
+ let output = instant::finalize(&mut completed)
.await
.map_err(LegFailure::Failed)?;
diff --git a/apps/desktop-gpui/src/recording.rs b/apps/desktop-gpui/src/recording.rs
index 7a7c9a868..2dcae99a7 100644
--- a/apps/desktop-gpui/src/recording.rs
+++ b/apps/desktop-gpui/src/recording.rs
@@ -913,7 +913,7 @@ impl ActiveRecording {
if let Err(error) = &metadata_result {
tracing::warn!(%error, "Could not mark the instant recording as stopped");
}
- let completed = stopped?;
+ let mut completed = stopped?;
metadata_result?;
let project_path = completed.project_path.clone();
let upload = instant_upload
@@ -924,16 +924,25 @@ impl ActiveRecording {
let display_dir = project_path.join("content/display");
let audio_dir = project_path.join("content/audio");
let output_path = project_path.join("content/output.mp4");
+ let completion = completed.clean_completion.take();
if display_dir.is_dir() {
let muxed = output_path.clone();
let project_path = project_path.clone();
tokio::task::spawn_blocking(move || {
ensure_finalization_storage(&project_path)?;
- cap_recording::recovery::RecoveryManager::finalize_instant_output(
- &display_dir,
- &audio_dir,
- &muxed,
- )
+ match completion {
+ Some(completion) => cap_recording::recovery::RecoveryManager::finalize_completed_instant_output(
+ &display_dir,
+ &audio_dir,
+ &muxed,
+ completion,
+ ),
+ None => cap_recording::recovery::RecoveryManager::finalize_instant_output(
+ &display_dir,
+ &audio_dir,
+ &muxed,
+ ),
+ }
.map_err(anyhow::Error::from)
})
.await
@@ -2938,6 +2947,7 @@ mod tests {
sample_rate: Some(48_000),
},
health: cap_recording::RecordingHealth::Healthy,
+ clean_completion: None,
};
let video = cap_project::VideoUploadInfo {
id: "test".into(),
diff --git a/crates/recording/src/instant_recording.rs b/crates/recording/src/instant_recording.rs
index d7fc34971..f617332d2 100644
--- a/crates/recording/src/instant_recording.rs
+++ b/crates/recording/src/instant_recording.rs
@@ -35,6 +35,9 @@ use std::{
};
use tracing::*;
+mod completion;
+pub use completion::CleanInstantRecording;
+
#[cfg(target_os = "linux")]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
/// Joined covers this attempt's capture/output work, not shared preview feeds or physical device shutdown.
@@ -489,12 +492,15 @@ impl Message<Stop> for Actor {
}
}
- let segments_dir =
+ let (segments_dir, completion_audio) =
replace_with::replace_with_or_abort_and_return(&mut self.state, |state| {
let result = match &state {
ActorState::Recording { pipeline, .. }
- | ActorState::Paused { pipeline, .. } => pipeline.segments_dir.clone(),
- ActorState::Stopped => self.output_dir.clone(),
+ | ActorState::Paused { pipeline, .. } => (
+ pipeline.segments_dir.clone(),
+ Some(pipeline.audio.is_some()),
+ ),
+ ActorState::Stopped => (self.output_dir.clone(), None),
};
(result, state)
});
@@ -534,6 +540,13 @@ impl Message<Stop> for Actor {
}
};
+ // Only successfully finished segmented mux workers certify this output, not device shutdown.
+ let clean_completion = completion_audio
+ .filter(|_| has_segments && segments_dir == self.recording_dir.join("content/display"))
+ .map(|expected_audio| {
+ CleanInstantRecording::new(self.recording_dir.clone(), expected_audio)
+ });
+
Ok(CompletedRecording {
project_path: self.recording_dir.clone(),
meta: InstantRecordingMeta::Complete {
@@ -542,6 +555,7 @@ impl Message<Stop> for Actor {
},
display_source: self.capture_target.clone(),
health,
+ clean_completion,
})
}
}
@@ -633,6 +647,7 @@ pub struct CompletedRecording {
pub display_source: ScreenCaptureTarget,
pub meta: InstantRecordingMeta,
pub health: crate::RecordingHealth,
+ pub clean_completion: Option<CleanInstantRecording>,
}
struct ScreenPipelineInput {
diff --git a/crates/recording/src/instant_recording/completion.rs b/crates/recording/src/instant_recording/completion.rs
new file mode 100644
index 000000000..2f6ea8468
--- /dev/null
+++ b/crates/recording/src/instant_recording/completion.rs
@@ -0,0 +1,340 @@
+use std::path::PathBuf;
+
+#[derive(Debug)]
+pub struct CleanInstantRecording {
+ project_path: PathBuf,
+ expected_audio: bool,
+}
+
+impl CleanInstantRecording {
+ pub(super) fn new(project_path: PathBuf, expected_audio: bool) -> Self {
+ Self {
+ project_path,
+ expected_audio,
+ }
+ }
+
+ pub(crate) fn into_parts(self) -> (PathBuf, bool) {
+ (self.project_path, self.expected_audio)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::super::{Actor, ActorState, Cancel, Pause, Pipeline, Stop, current_time_f64};
+ use super::CleanInstantRecording;
+ use crate::{
+ output_pipeline::{
+ AudioFrame, AudioMuxer, ChannelAudioSource, ChannelAudioSourceConfig,
+ ChannelVideoSource, ChannelVideoSourceConfig, Muxer, OutputPipeline, TaskPool,
+ VideoFrame, VideoMuxer,
+ },
+ recovery::RecoveryManager,
+ sources::screen_capture::ScreenCaptureTarget,
+ };
+ use cap_media_info::{AudioInfo, VideoInfo};
+ use cap_timestamp::{Timestamp, Timestamps};
+ use kameo::{Actor as _, prelude::ActorRef};
+ use std::{
+ ffi::OsString,
+ fs,
+ path::{Path, PathBuf},
+ sync::{Arc, atomic::AtomicBool},
+ time::Duration,
+ };
+
+ #[derive(Clone, Copy)]
+ struct Frame(Timestamp);
+
+ impl VideoFrame for Frame {
+ fn timestamp(&self) -> Timestamp {
+ self.0
+ }
+ }
+
+ struct TestMuxer(bool);
+
+ impl Muxer for TestMuxer {
+ type Config = bool;
+
+ async fn setup(
+ fail: bool,
+ _: PathBuf,
+ _: Option<VideoInfo>,
+ _: Option<AudioInfo>,
+ _: Arc<AtomicBool>,
+ _: &mut TaskPool,
+ ) -> anyhow::Result<Self> {
+ Ok(Self(fail))
+ }
+
+ fn finish(&mut self, _: Duration) -> anyhow::Result<anyhow::Result<()>> {
+ Ok(if self.0 {
+ Err(anyhow::anyhow!("output finalization failed"))
+ } else {
+ Ok(())
+ })
+ }
+ }
+
+ impl VideoMuxer for TestMuxer {
+ type VideoFrame = Frame;
+
+ fn send_video_frame(&mut self, _: Frame, _: Duration) -> anyhow::Result<()> {
+ Ok(())
+ }
+ }
+
+ impl AudioMuxer for TestMuxer {
+ fn send_audio_frame(&mut self, _: AudioFrame, _: Duration) -> anyhow::Result<()> {
+ Ok(())
+ }
+ }
+
+ #[derive(Clone, Copy)]
+ enum OutputFiles {
+ Segmented,
+ Progressive,
+ InitOnly,
+ Missing,
+ }
+
+ struct Fixture {
+ actor: ActorRef<Actor>,
+ video_cancel: tokio_util::sync::CancellationToken,
+ video_sender: Option<flume::Sender<Frame>>,
+ audio_sender: Option<futures::channel::mpsc::Sender<AudioFrame>>,
+ }
+
+ impl Fixture {
+ async fn close_sources_after_stop(&mut self) {
+ self.video_cancel.cancelled().await;
+ drop(self.video_sender.take());
+ drop(self.audio_sender.take());
+ }
+ }
+
+ async fn fixture(project: &Path, output: OutputFiles, with_audio: bool, fail: bool) -> Fixture {
+ #[cfg(target_os = "linux")]
+ let lifetime = super::super::InstantLifetimeOwner::new();
+ let timestamps = Timestamps::now();
+ let video_info = VideoInfo::from_raw(cap_media_info::RawVideoFormat::Bgra, 4, 4, 30);
+ let progressive = matches!(output, OutputFiles::Progressive);
+ let segments_dir = project.join(if progressive {
+ "content"
+ } else {
+ "content/display"
+ });
+ fs::create_dir_all(&segments_dir).unwrap();
+ match output {
+ OutputFiles::Segmented => {
+ fs::write(segments_dir.join("init.mp4"), b"init").unwrap();
+ fs::write(segments_dir.join("segment-1.m4s"), b"segment").unwrap();
+ }
+ OutputFiles::Progressive => {
+ fs::write(segments_dir.join("output.mp4"), b"progressive").unwrap();
+ }
+ OutputFiles::InitOnly => {
+ fs::write(segments_dir.join("init.mp4"), b"init").unwrap();
+ }
+ OutputFiles::Missing => {}
+ }
+ let (video_sender, video_receiver) = flume::bounded(4);
+ let build = OutputPipeline::builder(segments_dir.clone())
+ .with_video::<ChannelVideoSource<Frame>>(ChannelVideoSourceConfig::new(
+ video_info,
+ video_receiver,
+ ))
+ .with_timestamps(timestamps)
+ .build::<TestMuxer>(fail);
+ #[cfg(target_os = "linux")]
+ let build = lifetime.lifecycle.0.scope.run(build);
+ let video = build.await.unwrap();
+ video_sender
+ .send(Frame(Timestamp::Instant(timestamps.instant())))
+ .unwrap();
+ let mut audio_sender = None;
+ let audio = if with_audio {
+ let info = AudioInfo::new_raw(
+ cap_media_info::Sample::F32(cap_media_info::Type::Packed),
+ 48_000,
+ 2,
+ );
+ let (mut sender, receiver) = futures::channel::mpsc::channel(4);
+ let build = OutputPipeline::builder(project.join("content/audio"))
+ .with_audio_source::<ChannelAudioSource>(ChannelAudioSourceConfig::new(
+ info, receiver,
+ ))
+ .with_timestamps(timestamps)
+ .build::<TestMuxer>(false);
+ #[cfg(target_os = "linux")]
+ let build = lifetime.lifecycle.0.scope.run(build);
+ let audio = build.await.unwrap();
+ sender
+ .try_send(AudioFrame::new(
+ info.empty_frame(960),
+ Timestamp::Instant(timestamps.instant()),
+ ))
+ .unwrap();
+ audio_sender = Some(sender);
+ Some(audio)
+ } else {
+ None
+ };
+ let video_cancel = video.cancel_token();
+ let actor = Actor::spawn(Actor {
+ recording_dir: project.to_path_buf(),
+ output_dir: segments_dir.clone(),
+ capture_target: if progressive {
+ ScreenCaptureTarget::CameraOnly
+ } else {
+ ScreenCaptureTarget::Display {
+ id: "0".parse().unwrap(),
+ }
+ },
+ video_info,
+ state: ActorState::Recording {
+ pipeline: Pipeline {
+ video,
+ audio,
+ video_info,
+ segments_dir,
+ segment_rx: None,
+ },
+ segment_start_time: current_time_f64(),
+ },
+ total_pause_duration: Duration::ZERO,
+ pause_started_at: None,
+ terminal_stop_error: None,
+ #[cfg(target_os = "linux")]
+ lifetime,
+ });
+ Fixture {
+ actor,
+ video_cancel,
+ video_sender: Some(video_sender),
+ audio_sender,
+ }
+ }
+
+ async fn stop(fixture: &mut Fixture) -> anyhow::Result<super::super::CompletedRecording> {
+ let actor = fixture.actor.clone();
+ tokio::time::timeout(Duration::from_secs(2), async {
+ tokio::join!(actor.ask(Stop), fixture.close_sources_after_stop()).0
+ })
+ .await
+ .unwrap()
+ .map_err(anyhow::Error::from)
+ }
+
+ async fn finish(fixture: Fixture) {
+ fixture.actor.kill();
+ tokio::time::timeout(Duration::from_secs(2), fixture.actor.wait_for_stop())
+ .await
+ .unwrap();
+ }
+
+ #[tokio::test]
+ async fn live_and_paused_segmented_outputs_issue_one_matching_completion() {
+ for (paused, with_audio) in [(false, false), (false, true), (true, false), (true, true)] {
+ let directory = tempfile::tempdir().unwrap();
+ let mut fixture =
+ fixture(directory.path(), OutputFiles::Segmented, with_audio, false).await;
+ if paused {
+ fixture.actor.ask(Pause).await.unwrap();
+ }
+ let mut completed = stop(&mut fixture).await.unwrap();
+ let token = completed.clean_completion.take().unwrap();
+ assert_eq!(
+ token.into_parts(),
+ (directory.path().to_path_buf(), with_audio)
+ );
+ assert!(stop(&mut fixture).await.unwrap().clean_completion.is_none());
+ finish(fixture).await;
+ }
+ }
+
+ #[tokio::test]
+ async fn cancelled_output_does_not_issue_completion() {
+ let directory = tempfile::tempdir().unwrap();
+ let mut fixture = fixture(directory.path(), OutputFiles::Segmented, true, false).await;
+ let actor = fixture.actor.clone();
+ tokio::time::timeout(Duration::from_secs(2), async {
+ tokio::join!(actor.ask(Cancel), fixture.close_sources_after_stop()).0
+ })
+ .await
+ .unwrap()
+ .unwrap();
+ assert!(stop(&mut fixture).await.unwrap().clean_completion.is_none());
+ finish(fixture).await;
+ }
+
+ #[tokio::test]
+ async fn progressive_and_incomplete_outputs_do_not_issue_completion() {
+ for output in [
+ OutputFiles::Progressive,
+ OutputFiles::InitOnly,
+ OutputFiles::Missing,
+ ] {
+ let directory = tempfile::tempdir().unwrap();
+ let mut fixture = fixture(directory.path(), output, false, false).await;
+ assert!(stop(&mut fixture).await.unwrap().clean_completion.is_none());
+ finish(fixture).await;
+ }
+ }
+
+ #[tokio::test]
+ async fn failed_finalization_never_issues_completion() {
+ let directory = tempfile::tempdir().unwrap();
+ let mut fixture = fixture(directory.path(), OutputFiles::Segmented, true, true).await;
+ for _ in 0..2 {
+ assert!(
+ stop(&mut fixture)
+ .await
+ .unwrap_err()
+ .to_string()
+ .contains("output finalization failed")
+ );
+ }
+ finish(fixture).await;
+ }
+
+ fn entries(path: &Path) -> Vec<OsString> {
+ let mut entries = fs::read_dir(path)
+ .unwrap()
+ .map(|entry| entry.unwrap().file_name())
+ .collect::<Vec<_>>();
+ entries.sort();
+ entries
+ }
+
+ #[test]
+ fn completion_for_another_project_does_not_touch_either_project() {
+ let directory = tempfile::tempdir().unwrap();
+ let recorded = directory.path().join("recorded.cap");
+ let other = directory.path().join("other.cap");
+ for project in [&recorded, &other] {
+ fs::create_dir_all(project.join("content")).unwrap();
+ fs::write(project.join("content/original.m4s"), b"original bytes").unwrap();
+ }
+ let completion = CleanInstantRecording::new(recorded.clone(), true);
+ let result = RecoveryManager::finalize_completed_instant_output(
+ &other.join("content/display"),
+ &other.join("content/audio"),
+ &other.join("content/output.mp4"),
+ completion,
+ );
+ assert!(result.is_err());
+ for project in [&recorded, &other] {
+ assert_eq!(entries(project), vec![OsString::from("content")]);
+ assert_eq!(
+ entries(&project.join("content")),
+ vec![OsString::from("original.m4s")]
+ );
+ assert_eq!(
+ fs::read(project.join("content/original.m4s")).unwrap(),
+ b"original bytes"
+ );
+ }
+ }
+}
diff --git a/crates/recording/src/recovery.rs b/crates/recording/src/recovery.rs
index e121a2f07..49e6842b1 100644
--- a/crates/recording/src/recovery.rs
+++ b/crates/recording/src/recovery.rs
@@ -1408,6 +1408,29 @@ impl RecoveryManager {
display_dir: &Path,
audio_dir: &Path,
output: &Path,
+ ) -> Result<PathBuf, RecoveryError> {
+ Self::finalize_instant_output_with_completion(display_dir, audio_dir, output, None)
+ }
+
+ pub fn finalize_completed_instant_output(
+ display_dir: &Path,
+ audio_dir: &Path,
+ output: &Path,
+ completion: crate::instant_recording::CleanInstantRecording,
+ ) -> Result<PathBuf, RecoveryError> {
+ Self::finalize_instant_output_with_completion(
+ display_dir,
+ audio_dir,
+ output,
+ Some(completion.into_parts()),
+ )
+ }
+
+ fn finalize_instant_output_with_completion(
+ display_dir: &Path,
+ audio_dir: &Path,
+ output: &Path,
+ completion: Option<(PathBuf, bool)>,
) -> Result<PathBuf, RecoveryError> {
let content = output
.parent()
@@ -1425,10 +1448,33 @@ impl RecoveryManager {
"Instant tracks must be in project content".into(),
));
}
+ let (video_validation, completed_audio) = match completion {
+ Some((completed_project, expected_audio)) => {
+ if completed_project != project {
+ return Err(RecoveryError::Validation(
+ "Instant completion belongs to another recording".into(),
+ ));
+ }
+ if display_dir != content.join("display")
+ || audio_dir != content.join("audio")
+ || output != content.join("output.mp4")
+ {
+ return Err(RecoveryError::Validation(
+ "Instant completion must use the recorded track and output paths".into(),
+ ));
+ }
+ (VideoValidation::Bounded, expected_audio)
+ }
+ None => (VideoValidation::Full, false),
+ };
+ let staging_durability = match video_validation {
+ VideoValidation::Full => RecoveryCopyDurability::Durable,
+ VideoValidation::Bounded => RecoveryCopyDurability::Deferred,
+ };
Self::require_no_track_failure(project)?;
let _lock = RecoveryLock::acquire(project)?;
let before = recovery_snapshot(project)?;
- let mut expected_audio = audio_dir.try_exists()?;
+ let mut expected_audio = completed_audio || audio_dir.try_exists()?;
if project.join("recording-meta.json").try_exists()? {
let meta = RecordingMeta::load_for_project(project)
.map_err(|error| RecoveryError::Validation(error.to_string()))?;
@@ -1456,7 +1502,7 @@ impl RecoveryManager {
create_private_recovery_dir(&workspace)?;
let staged = workspace.join("content");
let result = (|| {
- copy_recovery_input(content, &staged)?;
+ copy_recovery_input_with_durability(content, &staged, staging_durability)?;
validate_recovery_manifests(&staged)?;
let display = staged.join(
display_dir
@@ -1489,10 +1535,10 @@ impl RecoveryManager {
&video.fragments,
video.init_segment.as_deref(),
&workspace,
- VideoValidation::Full,
+ video_validation,
)?;
Self::finalize_instant_staged(&display, &audio, &final_output)?;
- validate_recovered_track(&final_output, ffmpeg::media::Type::Video)?;
+ validate_recovery_track(&final_output, ffmpeg::media::Type::Video, video_validation)?;
if expected_audio {
validate_recovered_track(&final_output, ffmpeg::media::Type::Audio)?;
}
@@ -3086,6 +3132,67 @@ mod tests {
}
}
+ #[test]
+ fn completed_instant_audio_requirement_preserves_inputs_when_audio_is_missing() {
+ let directory = tempdir().unwrap();
+ let project = directory.path();
+ let display = project.join("content/display");
+ fs::create_dir_all(&display).unwrap();
+ fs::write(display.join("init.mp4"), b"original video init").unwrap();
+ let output = project.join("content/output.mp4");
+ fs::write(&output, b"original output").unwrap();
+ let before = super::recovery_snapshot(project).unwrap();
+
+ let error = RecoveryManager::finalize_instant_output_with_completion(
+ &display,
+ &project.join("content/audio"),
+ &output,
+ Some((project.to_path_buf(), true)),
+ )
+ .unwrap_err();
+
+ assert!(error.to_string().contains("Missing required Instant audio"));
+ assert_eq!(super::recovery_snapshot(project).unwrap(), before);
+ assert!(fs::read_dir(project).unwrap().all(|entry| {
+ !entry
+ .unwrap()
+ .file_name()
+ .to_string_lossy()
+ .starts_with(".recovery-")
+ }));
+ }
+
+ #[test]
+ fn completed_instant_rejects_other_paths_in_the_same_project_without_mutation() {
+ let directory = tempdir().unwrap();
+ let project = directory.path();
+ let content = project.join("content");
+ fs::create_dir(&content).unwrap();
+ fs::write(content.join("original.mp4"), b"original output").unwrap();
+ let before = super::recovery_snapshot(project).unwrap();
+
+ for (display, audio, output) in [
+ ("other", "audio", "output.mp4"),
+ ("display", "other", "output.mp4"),
+ ("display", "audio", "original.mp4"),
+ ] {
+ let error = RecoveryManager::finalize_instant_output_with_completion(
+ &content.join(display),
+ &content.join(audio),
+ &content.join(output),
+ Some((project.to_path_buf(), false)),
+ )
+ .unwrap_err();
+ assert!(
+ error
+ .to_string()
+ .contains("must use the recorded track and output paths")
+ );
+ assert_eq!(super::recovery_snapshot(project).unwrap(), before);
+ assert_eq!(fs::read_dir(project).unwrap().count(), 1);
+ }
+ }
+
fn complete_m4s_fragment() -> Vec<u8> {
let mut fragment = Vec::new();
for name in [b"moof", b"mdat"] {