diff --git a/src/core/processor/face.rs b/src/core/processor/face.rs index 0488a293..3f249423 100644 --- a/src/core/processor/face.rs +++ b/src/core/processor/face.rs @@ -410,8 +410,9 @@ async fn run_face_with_config( let json_str = std::fs::read_to_string(output_path) .context("Failed to read Swift FACE output")?; - let result: FaceResult = serde_json::from_str(&json_str) + let mut result: FaceResult = serde_json::from_str(&json_str) .context("Failed to parse Swift FACE output")?; + result.compute_status(); return Ok(Some(result)); } @@ -432,8 +433,9 @@ async fn run_face_with_config( let json_str = std::fs::read_to_string(output_path) .context("Failed to read Python FACE output")?; - let result: FaceResult = serde_json::from_str(&json_str) + let mut result: FaceResult = serde_json::from_str(&json_str) .context("Failed to parse Python FACE output")?; + result.compute_status(); return Ok(Some(result)); } @@ -525,6 +527,29 @@ mod tests { assert!(result.frames[0].faces[0].attributes.is_some()); } + #[test] + fn test_compute_status_recalculates_total_faces() { + let json = r#"{ + "fps": 30.0, + "frame_count": 2, + "frames": [ + {"frame": 0, "timestamp": 0.0, "faces": [ + {"confidence": 0.9, "bbox": {"x": 1, "y": 2, "width": 3, "height": 4}} + ]}, + {"frame": 1, "timestamp": 0.03, "faces": [ + {"confidence": 0.8, "bbox": {"x": 5, "y": 6, "width": 7, "height": 8}}, + {"confidence": 0.7, "bbox": {"x": 9, "y": 10, "width": 11, "height": 12}} + ]} + ] + }"#; + let mut result: FaceResult = serde_json::from_str(json).unwrap(); + assert_eq!(result.total_faces, 0, "json has no total_faces field"); + assert!(result.status.is_none(), "json has no status field"); + result.compute_status(); + assert_eq!(result.total_faces, 3); + assert_eq!(result.status.unwrap(), FaceStatus::HasFaces); + } + #[test] fn test_face_result_empty_frames() { let result = FaceResult {