Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(cli): report export-preview as always-JSON; pin duration tests
sloemodzncc386114afed
diff --git a/apps/cli/src/guide.rs b/apps/cli/src/guide.rsindex 92e4cdcb7..2e8899be7 100644--- a/apps/cli/src/guide.rs+++ b/apps/cli/src/guide.rs@@ -206,7 +206,7 @@ fn build() -> Guide {cmd("export-preview","Render a still frame from a .cap project at a given timestamp. JSON emits jpeg_base64 plus frame metadata.",- OutputMode::SingleJson,+ OutputMode::AlwaysJson,&[],),cmd(diff --git a/apps/cli/tests/cli.rs b/apps/cli/tests/cli.rsindex 69243786b..bf837ceb6 100644--- a/apps/cli/tests/cli.rs+++ b/apps/cli/tests/cli.rs@@ -237,6 +237,67 @@ fn project_inspect_missing_fails() {assert!(stderr(&output).to_lowercase().contains("failed to load"));}+#[test]+fn project_commands_report_duration_for_readable_media() {+ let dir = tempfile::tempdir().unwrap();+ let project = dir.path().join("recording.cap");+ write_test_media(&project.join("content/display.mp4"));+ write_single_segment_meta(&project);++ for command in ["validate", "inspect"] {+ let output = run(&[+ "project",+ command,+ project.to_str().unwrap(),+ "--format",+ "json",+ ]);+ assert!(+ output.status.success(),+ "{command} stderr: {}",+ stderr(&output)+ );+ let json = parse_json(&output);+ let duration = json["durationSeconds"]+ .as_f64()+ .unwrap_or_else(|| panic!("{command} did not report durationSeconds: {json}"));+ assert!(+ (duration - 1.0).abs() < 0.25,+ "{command} reported unexpected duration {duration}"+ );+ }+}++#[test]+fn project_commands_omit_duration_for_unreadable_media() {+ let dir = tempfile::tempdir().unwrap();+ let project = dir.path().join("recording.cap");+ let content = project.join("content");+ std::fs::create_dir_all(&content).unwrap();+ std::fs::write(content.join("display.mp4"), b"fake").unwrap();+ write_single_segment_meta(&project);++ for command in ["validate", "inspect"] {+ let output = run(&[+ "project",+ command,+ project.to_str().unwrap(),+ "--format",+ "json",+ ]);+ assert!(+ output.status.success(),+ "{command} stderr: {}",+ stderr(&output)+ );+ let json = parse_json(&output);+ assert!(+ json.get("durationSeconds").is_none(),+ "{command} reported a duration for unreadable media: {json}"+ );+ }+}+#[test]fn project_validate_missing_meta_reports_invalid() {let dir = tempfile::tempdir().unwrap();@@ -1258,6 +1319,59 @@ fn auth_login_defaults_to_the_creator_profile() {assert!(stdout(&output).contains("[default: creator]"));}+fn write_test_media(path: &Path) {+ use ffmpeg::format::Pixel;+ ffmpeg::init().unwrap();+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();+ let mut output = ffmpeg::format::output(path).unwrap();+ let codec = ffmpeg::encoder::find(ffmpeg::codec::Id::MPEG4).unwrap();+ let mut encoder = ffmpeg::codec::Context::new_with_codec(codec)+ .encoder()+ .video()+ .unwrap();+ encoder.set_width(32);+ encoder.set_height(32);+ encoder.set_format(Pixel::YUV420P);+ encoder.set_time_base((1, 30));+ encoder.set_frame_rate(Some((30, 1)));+ encoder.set_flags(ffmpeg::codec::Flags::GLOBAL_HEADER);+ let mut encoder = encoder.open_as(codec).unwrap();+ output.add_stream(codec).unwrap().set_parameters(&encoder);+ output.write_header().unwrap();+ let output_time_base = output.stream(0).unwrap().time_base();+ {+ let mut drain = |encoder: &mut ffmpeg::encoder::video::Encoder, finished: bool| loop {+ let mut packet = ffmpeg::Packet::empty();+ match encoder.receive_packet(&mut packet) {+ Ok(()) => {+ packet.set_stream(0);+ packet.rescale_ts((1, 30), output_time_base);+ packet.write_interleaved(&mut output).unwrap();+ }+ Err(ffmpeg::Error::Other { errno })+ if !finished && errno == ffmpeg::ffi::EAGAIN =>+ {+ break;+ }+ Err(ffmpeg::Error::Eof) if finished => break,+ Err(error) => panic!("test media encoding failed: {error}"),+ }+ };+ for index in 0..30 {+ let mut frame = ffmpeg::frame::Video::new(Pixel::YUV420P, 32, 32);+ frame.data_mut(0).fill(32 + index as u8);+ frame.data_mut(1).fill(128);+ frame.data_mut(2).fill(128);+ frame.set_pts(Some(index));+ encoder.send_frame(&frame).unwrap();+ drain(&mut encoder, false);+ }+ encoder.send_eof().unwrap();+ drain(&mut encoder, true);+ }+ output.write_trailer().unwrap();+}+fn write_single_segment_meta(project: &Path) {std::fs::create_dir_all(project).unwrap();let meta = serde_json::json!({