Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: flaky DRM detector tests + clippy fixes in test code

Louis Beaumont2d2e656566ee
diff --git a/crates/screenpipe-engine/src/drm_detector.rs b/crates/screenpipe-engine/src/drm_detector.rs
index 39072e7b8..df0917cbc 100644
--- a/crates/screenpipe-engine/src/drm_detector.rs
+++ b/crates/screenpipe-engine/src/drm_detector.rs
@@ -557,6 +557,11 @@ pub fn poll_drm_clear() -> bool {
#[cfg(test)]
mod tests {
use super::*;
+ use std::sync::Mutex;
+
+ /// Tests that touch the global DRM_CONTENT_PAUSED flag must hold this
+ /// mutex to avoid racing with each other (cargo test runs in parallel).
+ static DRM_FLAG_LOCK: Mutex<()> = Mutex::new(());
#[test]
fn test_is_drm_app_positive() {
@@ -631,6 +636,7 @@ mod tests {
#[test]
fn test_global_flag() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
assert!(!drm_content_paused());
set_drm_paused(true);
@@ -641,6 +647,7 @@ mod tests {
#[test]
fn test_check_and_update_disabled() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(true, Ordering::SeqCst);
let result = check_and_update_drm_state(false, Some("Netflix"), None);
assert!(!result);
@@ -649,6 +656,7 @@ mod tests {
#[test]
fn test_check_and_update_enabled() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result = check_and_update_drm_state(true, Some("Netflix"), None);
assert!(result);
@@ -663,6 +671,7 @@ mod tests {
#[test]
fn test_pre_capture_drm_check_disabled() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result = pre_capture_drm_check(false, Some("Netflix"));
assert!(!result, "should be no-op when setting is off");
@@ -671,6 +680,7 @@ mod tests {
#[test]
fn test_pre_capture_drm_check_native_app() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result = pre_capture_drm_check(true, Some("Netflix"));
assert!(result, "should detect native DRM app");
@@ -681,6 +691,7 @@ mod tests {
#[test]
fn test_pre_capture_drm_check_non_drm_app() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result = pre_capture_drm_check(true, Some("Finder"));
assert!(!result, "should not flag Finder as DRM");
@@ -689,6 +700,7 @@ mod tests {
#[test]
fn test_pre_capture_drm_check_already_paused() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(true, Ordering::SeqCst);
let result = pre_capture_drm_check(true, Some("Finder"));
assert!(result, "should stay paused when already paused");
@@ -858,6 +870,7 @@ mod tests {
#[test]
fn test_check_and_update_drm_state_sets_flag_on_drm_app() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result = check_and_update_drm_state(true, Some("Netflix"), None);
assert!(result, "should return true for DRM app");
@@ -867,6 +880,7 @@ mod tests {
#[test]
fn test_check_and_update_drm_state_sets_flag_on_drm_url() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result =
check_and_update_drm_state(true, Some("Chrome"), Some("https://netflix.com/watch"));
@@ -877,6 +891,7 @@ mod tests {
#[test]
fn test_check_and_update_drm_state_clears_flag_on_non_drm() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(true, Ordering::SeqCst);
let result = check_and_update_drm_state(true, Some("Finder"), Some("https://google.com"));
assert!(!result, "should return false for non-DRM content");
@@ -886,6 +901,7 @@ mod tests {
#[test]
fn test_check_and_update_drm_state_noop_when_disabled() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
let result = check_and_update_drm_state(false, Some("Netflix"), None);
assert!(!result, "should return false when feature is disabled");
@@ -897,6 +913,7 @@ mod tests {
#[test]
fn test_check_and_update_drm_state_clears_flag_when_disabled() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
// If the flag was somehow set and the feature is disabled, it should clear
DRM_CONTENT_PAUSED.store(true, Ordering::SeqCst);
let result = check_and_update_drm_state(false, Some("Netflix"), None);
@@ -909,6 +926,7 @@ mod tests {
#[test]
fn test_check_and_update_drm_state_none_app_preserves_current() {
+ let _lock = DRM_FLAG_LOCK.lock().unwrap();
// When app_name is None (empty string), check_and_update_drm_state
// preserves the current flag rather than clearing it (unknown = keep state).
DRM_CONTENT_PAUSED.store(false, Ordering::SeqCst);
diff --git a/crates/screenpipe-engine/tests/first_frames_test.rs b/crates/screenpipe-engine/tests/first_frames_test.rs
index fc8c5a5d0..4f408ba75 100644
--- a/crates/screenpipe-engine/tests/first_frames_test.rs
+++ b/crates/screenpipe-engine/tests/first_frames_test.rs
@@ -3,7 +3,7 @@ use chrono::{Duration, Utc};
use screenpipe_core::paths;
use std::sync::Arc;
use std::time::Instant;
-use tracing::{debug, error, info, warn};
+use tracing::{error, warn};
use screenpipe_db::DatabaseManager;
use screenpipe_engine::video_utils::extract_frame_from_video;
@@ -264,7 +264,7 @@ async fn test_concurrent_frame_loading() -> Result<()> {
for handle in handles {
match handle.await {
- Ok((frame_id, Ok(Ok(_)))) => {
+ Ok((_frame_id, Ok(Ok(_)))) => {
success += 1;
}
Ok((frame_id, Ok(Err(e)))) => {
@@ -395,7 +395,7 @@ async fn test_video_file_write_status() -> Result<()> {
);
println!("{}", "-".repeat(110));
- for (file_path, latest_frame) in &video_files {
+ for (file_path, _latest_frame) in &video_files {
match tokio::fs::metadata(file_path).await {
Ok(meta) => {
let size_mb = meta.len() as f64 / 1024.0 / 1024.0;
@@ -418,7 +418,7 @@ async fn test_video_file_write_status() -> Result<()> {
);
// Check if file might still be open for writing
- if let Some(mtime) = meta.modified().ok() {
+ if let Ok(mtime) = meta.modified() {
let age = std::time::SystemTime::now()
.duration_since(mtime)
.unwrap_or_default();