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 Retina capture dimensions and refresh live macOS display configurations

Louis Beaumont77001166c629
diff --git a/Cargo.lock b/Cargo.lock
index 77dfa490f..d950ee006 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8618,7 +8618,7 @@ dependencies = [
[[package]]
name = "sck-rs"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/sck-rs?rev=60610e8c970af1ea9d47e274c1a48182e1da5bd1#60610e8c970af1ea9d47e274c1a48182e1da5bd1"
+source = "git+https://github.com/screenpipe/sck-rs?rev=62d79abed212015eb9beaa03138002807f61f59a#62d79abed212015eb9beaa03138002807f61f59a"
dependencies = [
"cidre 0.16.1 (git+https://github.com/yury/cidre.git?rev=9c20f5ee5abaad4598843a33e13d6e48822d1f30)",
"image",
@@ -9034,6 +9034,7 @@ dependencies = [
"uuid",
"windows 0.58.0",
"wiremock",
+ "xcap",
"zbus",
]
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index cda6c7a05..b1ae8b8b8 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -11204,7 +11204,7 @@ dependencies = [
[[package]]
name = "sck-rs"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/sck-rs?rev=60610e8c970af1ea9d47e274c1a48182e1da5bd1#60610e8c970af1ea9d47e274c1a48182e1da5bd1"
+source = "git+https://github.com/screenpipe/sck-rs?rev=62d79abed212015eb9beaa03138002807f61f59a#62d79abed212015eb9beaa03138002807f61f59a"
dependencies = [
"cidre 0.16.1 (git+https://github.com/yury/cidre.git?rev=9c20f5ee5abaad4598843a33e13d6e48822d1f30)",
"image 0.25.10",
diff --git a/crates/screenpipe-engine/Cargo.toml b/crates/screenpipe-engine/Cargo.toml
index 9d88523b4..b2cbfa76e 100644
--- a/crates/screenpipe-engine/Cargo.toml
+++ b/crates/screenpipe-engine/Cargo.toml
@@ -208,6 +208,10 @@ jemalloc = ["tikv-jemallocator"]
name = "screenpipe"
path = "src/bin/screenpipe-engine.rs"
+[[test]]
+name = "native_multi_monitor"
+harness = false
+
[[bench]]
name = "hot_frame_cache"
harness = false
@@ -244,3 +248,6 @@ tracing-oslog = { workspace = true }
# screenpipe-redact is wired into the engine binary (image-PII
# reconciliation worker, screenpipe-engine.rs:1571).
ignored = []
+
+[target.'cfg(target_os = "macos")'.dev-dependencies]
+xcap = { workspace = true }
diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
index 13e888532..669d220e3 100644
--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
@@ -292,21 +292,35 @@ fn restart_after_database_fault() -> anyhow::Result<()> {
}
}
-#[tokio::main]
-#[tracing::instrument]
-async fn main() -> anyhow::Result<()> {
- // ACP re-enters the same signed binary in private subprocess modes. Handle
- // those before clap sees the private arguments or the recorder initializes.
- if let Some(exit_code) = screenpipe_core::agents::acp::run_hidden_mode_without_observer().await
+fn main() -> anyhow::Result<()> {
+ #[cfg(feature = "heap-prof")]
+ let _profiler = dhat::Profiler::new_heap();
+
+ let runtime = tokio::runtime::Runtime::new()?;
+ // Private ACP modes must run before public CLI parsing or AppKit startup.
+ if let Some(exit_code) =
+ runtime.block_on(screenpipe_core::agents::acp::run_hidden_mode_without_observer())
{
std::process::exit(exit_code);
}
+ let matches = Cli::command().get_matches();
+ let record_arg_sources = RecordArgSources::from_cli_matches(&matches);
+ let cli = Cli::from_arg_matches(&matches)?;
+ #[cfg(target_os = "macos")]
+ let native_capture = matches!(
+ cli.command,
+ Command::Record(_) | Command::Vision { .. } | Command::Doctor
+ );
+ let command = move || runtime.block_on(run(cli, record_arg_sources));
+ #[cfg(target_os = "macos")]
+ if native_capture {
+ return screenpipe_engine::macos_run_loop::run(command)?;
+ }
+ command()
+}
- // dhat heap profiler — must be the first thing in main.
- // Writes dhat-heap.json on drop (Ctrl+C / graceful exit).
- #[cfg(feature = "heap-prof")]
- let _profiler = dhat::Profiler::new_heap();
-
+#[tracing::instrument(skip_all)]
+async fn run(cli: Cli, record_arg_sources: RecordArgSources) -> anyhow::Result<()> {
#[cfg(windows)]
if let Ok(parent) = env::var("SCREENPIPE_DB_RESTART_PARENT") {
env::remove_var("SCREENPIPE_DB_RESTART_PARENT");
@@ -323,10 +337,6 @@ async fn main() -> anyhow::Result<()> {
screenpipe_engine::fd_limit::set_fd_limit();
debug!("starting screenpipe server");
- let matches = Cli::command().get_matches();
- let record_arg_sources = RecordArgSources::from_cli_matches(&matches);
- let cli = Cli::from_arg_matches(&matches)?;
-
// Dispatch subcommands — non-recording commands return early
let record_args = match cli.command {
Command::Status {
diff --git a/crates/screenpipe-engine/src/lib.rs b/crates/screenpipe-engine/src/lib.rs
index a397bc2a2..00c4c6e50 100644
--- a/crates/screenpipe-engine/src/lib.rs
+++ b/crates/screenpipe-engine/src/lib.rs
@@ -134,5 +134,5 @@ pub use ui_recorder::{start_ui_recording, UiRecorderConfig, UiRecorderHandle};
pub use video::{video_quality_to_crf, video_quality_to_jpeg_q, video_quality_to_preset};
pub mod search_only;
-#[cfg(all(test, target_os = "macos"))]
-mod multi_monitor_vm_test;
+#[cfg(target_os = "macos")]
+pub mod macos_run_loop;
diff --git a/crates/screenpipe-engine/src/macos_run_loop.rs b/crates/screenpipe-engine/src/macos_run_loop.rs
new file mode 100644
index 000000000..d5c607cbf
--- /dev/null
+++ b/crates/screenpipe-engine/src/macos_run_loop.rs
@@ -0,0 +1,82 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+//! Main-thread AppKit lifecycle for standalone capture hosts. Tauri owns its own.
+use cidre::{arc, cf, objc};
+use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
+use std::sync::mpsc;
+
+#[link(name = "AppKit", kind = "framework")]
+extern "C" {
+ fn NSApplicationLoad() -> bool;
+}
+
+// CoreFoundation explicitly permits signaling a run-loop source from another
+// thread. Its context contains no data and the owned reference keeps it alive.
+struct CompletionSource(arc::R<cf::RunLoopSrc>);
+unsafe impl Send for CompletionSource {}
+impl CompletionSource {
+ fn signal(&self) {
+ self.0.signal();
+ cf::RunLoop::main().wakeup();
+ }
+}
+extern "C-unwind" fn completion_ready(_: *mut std::ffi::c_void) {}
+
+/// Run a standalone capture command while servicing display notifications.
+/// Call only from the process main thread, before starting native capture.
+/// The worker owns its runtime so shutdown completes while AppKit is still live.
+pub fn run<T: Send + 'static>(work: impl FnOnce() -> T + Send + 'static) -> anyhow::Result<T> {
+ anyhow::ensure!(
+ unsafe { libc::pthread_main_np() } != 0,
+ "AppKit requires the main thread"
+ );
+ anyhow::ensure!(
+ objc::ar_pool(|| unsafe { NSApplicationLoad() }),
+ "AppKit initialization failed"
+ );
+ let mut context = cf::RunLoopSrcCtx::<std::ffi::c_void> {
+ perform: Some(completion_ready),
+ ..Default::default()
+ };
+ let source = cf::RunLoopSrc::with_ctx(0, &mut context)
+ .ok_or_else(|| anyhow::anyhow!("could not create command completion source"))?;
+ let mode = cf::RunLoopMode::default();
+ let main_loop = cf::RunLoop::main();
+ main_loop.add_src(&source, mode);
+ let completion = CompletionSource(source.clone());
+ let (send, receive) = mpsc::sync_channel(1);
+ let worker = std::thread::Builder::new()
+ .name("capture-command".into())
+ .spawn(move || {
+ let result = catch_unwind(AssertUnwindSafe(work));
+ let _ = send.send(result);
+ completion.signal();
+ });
+ let result = match worker {
+ Ok(worker) => {
+ let result = loop {
+ match receive.try_recv() {
+ Ok(result) => break Ok(result),
+ Err(mpsc::TryRecvError::Disconnected) => {
+ break Err(anyhow::anyhow!("capture worker disconnected"))
+ }
+ Err(mpsc::TryRecvError::Empty) => {}
+ }
+ // The registered completion source prevents an empty-loop spin.
+ // A signaled source also survives completion before this call.
+ objc::ar_pool(|| {
+ cf::RunLoop::run_in_mode(mode, 3600.0, true);
+ });
+ };
+ let _ = worker.join();
+ result
+ }
+ Err(error) => Err(error.into()),
+ };
+ main_loop.remove_src(&source, mode);
+ source.invalidate();
+ match result? {
+ Ok(value) => Ok(value),
+ Err(panic) => resume_unwind(panic),
+ }
+}
diff --git a/crates/screenpipe-engine/src/multi_monitor_vm_test.rs b/crates/screenpipe-engine/src/multi_monitor_vm_test.rs
deleted file mode 100644
index d18bbc24f..000000000
--- a/crates/screenpipe-engine/src/multi_monitor_vm_test.rs
+++ /dev/null
@@ -1,426 +0,0 @@
-// screenpipe — AI that knows everything you've seen, said, or heard
-// https://screenpipe.com
-//! Opt-in native acceptance in a disposable macOS guest. No mocked topology.
-use crate::focus_aware_controller::FocusAwareController;
-use crate::focus_tracker::{new_tracker, FocusTracker};
-use screenpipe_screen::monitor::{list_monitors, SafeMonitor};
-use serde_json::Value;
-use std::io::{BufRead, BufReader, Write};
-use std::process::{Child, ChildStdin, Command, Stdio};
-use std::sync::{mpsc, Arc};
-use std::time::{Duration, Instant};
-struct Fixture {
- child: Child,
- input: ChildStdin,
- output: mpsc::Receiver<String>,
- reader: Option<std::thread::JoinHandle<()>>,
-}
-impl Fixture {
- fn start() -> (Self, Value) {
- assert_eq!(
- std::env::var("SCREENPIPE_ISOLATED_VM_TEST").as_deref(),
- Ok("1")
- );
- let mut child = Command::new(std::env::var("SCREENPIPE_DISPLAY_FIXTURE").unwrap())
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .spawn()
- .unwrap();
- let input = child.stdin.take().unwrap();
- let stdout = child.stdout.take().unwrap();
- let (sender, output) = mpsc::channel();
- let reader = std::thread::spawn(move || {
- for line in BufReader::new(stdout).lines() {
- match line {
- Ok(line) => {
- if sender.send(line).is_err() {
- break;
- }
- }
- Err(_) => break,
- }
- }
- });
- let mut fixture = Self {
- child,
- input,
- output,
- reader: Some(reader),
- };
- let initial = fixture.read();
- (fixture, initial)
- }
- fn read(&mut self) -> Value {
- let line = self
- .output
- .recv_timeout(Duration::from_secs(15))
- .expect("native display fixture failed to answer within 15 seconds");
- let v = serde_json::from_str(&line).unwrap();
- eprintln!("native topology: {line}");
- v
- }
- fn command(&mut self, command: &str) -> Value {
- writeln!(self.input, "{command}").unwrap();
- self.input.flush().unwrap();
- self.read()
- }
-}
-impl Drop for Fixture {
- fn drop(&mut self) {
- let _ = writeln!(self.input, "quit");
- let _ = self.input.flush();
- let _ = self.child.kill();
- let _ = self.child.wait();
- if let Some(reader) = self.reader.take() {
- let _ = reader.join();
- }
- }
-}
-async fn wait_mapping(
- controller: &FocusAwareController,
- monitors: &[SafeMonitor],
- expected: Option<u32>,
-) {
- let deadline = Instant::now() + Duration::from_secs(12);
- loop {
- let focused: Vec<_> = monitors
- .iter()
- .filter(|m| controller.hosts_focus_for_monitor(m))
- .map(|m| m.id())
- .collect();
- if focused == expected.into_iter().collect::<Vec<_>>() {
- return;
- }
- assert!(
- Instant::now() < deadline,
- "controller mapping expected {expected:?}, got {focused:?}"
- );
- tokio::time::sleep(Duration::from_millis(100)).await;
- }
-}
-fn verify_capture_marker(image: &image::DynamicImage, native: &Value) {
- // The helper paints a 200-point square at (+20,+20) on each display.
- // Sample its center in backing pixels, away from the cursor at (+100,+100).
- let x = (120. * image.width() as f64 / native["w"].as_f64().unwrap()) as u32;
- let y = (120. * image.height() as f64 / native["h"].as_f64().unwrap()) as u32;
- assert!(x < image.width() && y < image.height());
- let rgb = image.to_rgb8();
- let [red, green, blue] = rgb.get_pixel(x, y).0;
- let primary = native["main"].as_i64() == Some(1);
- let (dominant, other) = if primary { (red, blue) } else { (blue, red) };
- assert!(
- dominant > 150
- && dominant.saturating_sub(other) > 80
- && dominant.saturating_sub(green) > 80,
- "wrong display content: id={} primary={primary} pixel=({red},{green},{blue}) at ({x},{y})",
- native["id"]
- );
-}
-async fn wait_focus(tracker: &Arc<dyn FocusTracker>, expected: Option<u32>) {
- let deadline = Instant::now() + Duration::from_secs(12);
- loop {
- if tracker.current().map(|m| m.id) == expected {
- return;
- }
- assert!(
- Instant::now() < deadline,
- "focus expected {expected:?}, got {:?}",
- tracker.current()
- );
- tokio::time::sleep(Duration::from_millis(100)).await;
- }
-}
-async fn verify_displays(native: &Value) -> Vec<SafeMonitor> {
- let monitors = list_monitors().await;
- let displays = native["displays"].as_array().unwrap();
- assert_eq!(
- monitors.len(),
- displays.len(),
- "capture backend must see actual CG displays"
- );
- for d in displays {
- let m = monitors
- .iter()
- .find(|m| m.id() as u64 == d["id"].as_u64().unwrap())
- .expect("missing native display");
- eprintln!(
- "capture topology id={} origin=({}, {}) dimensions={}x{} sck={}",
- m.id(),
- m.x(),
- m.y(),
- m.width(),
- m.height(),
- m.uses_sck_backend()
- );
- assert_eq!(m.x() as i64, d["x"].as_i64().unwrap());
- assert_eq!(m.y() as i64, d["y"].as_i64().unwrap());
- assert_eq!(
- m.width() as i64,
- d["w"].as_i64().unwrap(),
- "focus bounds must use display points"
- );
- assert_eq!(
- m.height() as i64,
- d["h"].as_i64().unwrap(),
- "focus bounds must use display points"
- );
- }
- monitors
-}
-#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
-#[ignore = "requires isolated logged-in Mac VM and native display fixture"]
-async fn native_multi_monitor_focus_capture_gap_and_hotplug() {
- let (mut fixture, initial) = Fixture::start();
- assert_eq!(
- initial["displays"].as_array().unwrap().len(),
- 2,
- "requires one base and one virtual display"
- );
- let primary = initial["displays"]
- .as_array()
- .unwrap()
- .iter()
- .find(|d| d["main"].as_i64() == Some(1))
- .unwrap()
- .clone();
- let primary_id = primary["id"].as_u64().unwrap() as u32;
- let width = primary["w"].as_i64().unwrap();
- verify_displays(&initial).await;
- let tracker = new_tracker();
- let controller = FocusAwareController::new(tracker.clone());
- for (label, x, y) in [
- ("right", width, 0),
- ("left", -1280, 0),
- ("above", 0, -720),
- ("offset", width, 400),
- ] {
- eprintln!("CASE {label}");
- let native = fixture.command(&format!("layout {x} {y}"));
- let requested = native["displays"]
- .as_array()
- .unwrap()
- .iter()
- .find(|d| d["id"] == native["extra"])
- .unwrap();
- assert_eq!(
- requested["x"].as_i64(),
- Some(x),
- "requested layout was not applied"
- );
- assert_eq!(
- requested["y"].as_i64(),
- Some(y),
- "requested layout was not applied"
- );
- assert_eq!(
- requested["mirror"].as_u64(),
- Some(0),
- "extended displays required"
- );
- let monitors = verify_displays(&native).await;
- for d in native["displays"].as_array().unwrap() {
- let px = d["x"].as_f64().unwrap() + 100.;
- let py = d["y"].as_f64().unwrap() + 100.;
- let actual = fixture.command(&format!("warp {px} {py}"));
- assert_eq!(actual["cursor_x"].as_f64().unwrap(), px);
- assert_eq!(actual["cursor_y"].as_f64().unwrap(), py);
- let id = d["id"].as_u64().unwrap() as u32;
- wait_focus(&tracker, Some(id)).await;
- wait_mapping(&controller, &monitors, Some(id)).await;
- assert!(!controller.resolution_degraded());
- for m in &monitors {
- assert_eq!(controller.hosts_focus_for_monitor(m), m.id() == id);
- }
- let m = monitors.iter().find(|m| m.id() == id).unwrap();
- let frame = tokio::time::timeout(Duration::from_secs(20), m.capture_image())
- .await
- .unwrap()
- .unwrap();
- assert!(frame.width() > 0 && frame.height() > 0);
- verify_capture_marker(&frame, d);
- if let Ok(dir) = std::env::var("SCREENPIPE_VM_EVIDENCE_DIR") {
- std::fs::create_dir_all(&dir).unwrap();
- frame.save(format!("{dir}/{label}-{id}.png")).unwrap();
- }
- eprintln!(
- "CAPTURE {label} display={id} actual={}x{}",
- frame.width(),
- frame.height()
- );
- }
- }
- // An offset layout leaves a real rectangle outside every display. Confirm
- // where the OS cursor actually lands, rather than injecting tracker state.
- let gap = fixture.command(&format!("warp {} 200", width + 50));
- let gap_monitors = verify_displays(&gap).await;
- let actual_x = gap["cursor_x"].as_f64().unwrap();
- let actual_y = gap["cursor_y"].as_f64().unwrap();
- let literal_gap_supported = actual_x == (width + 50) as f64 && actual_y == 200.;
- eprintln!(
- "LITERAL_GAP requested=({},200) actual=({actual_x},{actual_y}) clamped={}",
- width + 50,
- !literal_gap_supported
- );
- if literal_gap_supported {
- wait_focus(&tracker, None).await;
- wait_mapping(&controller, &gap_monitors, None).await;
- assert!(!controller.resolution_degraded());
- tokio::time::sleep(Duration::from_secs(31)).await;
- assert!(controller.resolution_degraded());
- assert!(gap_monitors
- .iter()
- .all(|m| !controller.hosts_focus_for_monitor(m)));
- eprintln!("LITERAL_GAP: native off-display cursor held; grace degraded as expected");
- } else {
- let landing = gap["displays"]
- .as_array()
- .unwrap()
- .iter()
- .find(|d| {
- let x = d["x"].as_f64().unwrap();
- let y = d["y"].as_f64().unwrap();
- actual_x >= x
- && actual_x < x + d["w"].as_f64().unwrap()
- && actual_y >= y
- && actual_y < y + d["h"].as_f64().unwrap()
- })
- .expect("clamped cursor must land on an actual display");
- let landing_id = landing["id"].as_u64().unwrap() as u32;
- wait_focus(&tracker, Some(landing_id)).await;
- wait_mapping(&controller, &gap_monitors, Some(landing_id)).await;
- assert!(!controller.resolution_degraded());
- eprintln!("LITERAL_GAP UNSUPPORTED: macOS clamped the cursor onto a real display; no literal-gap reproduction or pass claimed");
- }
- fixture.command("warp 100 100");
- wait_focus(&tracker, Some(primary_id)).await;
- wait_mapping(&controller, &gap_monitors, Some(primary_id)).await;
- assert!(!controller.resolution_degraded());
- eprintln!("PRIMARY: cursor and attribution resolved on primary");
- // This intentionally omits the monitor watcher's fresh discovery while
- // rearranging real displays. It tests native resolution against stale
- // cached geometry, not a mocked tracker or the customer's literal gap.
- eprintln!("STALE_TOPOLOGY: withholding watcher discovery; native displays/cursor, not literal-gap/customer reproduction");
- let stale_native = fixture.command("layout -1280 0");
- let stale_extra_id = stale_native["extra"].as_u64().unwrap() as u32;
- let stale_extra = stale_native["displays"]
- .as_array()
- .unwrap()
- .iter()
- .find(|d| d["id"].as_u64() == Some(stale_extra_id as u64))
- .unwrap();
- assert_eq!(stale_extra["x"].as_i64(), Some(-1280));
- assert_eq!(stale_extra["y"].as_i64(), Some(0));
- assert_eq!(stale_extra["mirror"].as_u64(), Some(0));
- let stale_cursor = fixture.command("warp -1180 100");
- assert_eq!(stale_cursor["cursor_x"].as_f64(), Some(-1180.));
- assert_eq!(stale_cursor["cursor_y"].as_f64(), Some(100.));
- // Do not call list_monitors/verify_displays until after the grace check.
- wait_focus(&tracker, None).await;
- wait_mapping(&controller, &gap_monitors, None).await;
- assert!(!controller.resolution_degraded());
- tokio::time::sleep(Duration::from_secs(31)).await;
- assert!(
- controller.resolution_degraded(),
- "stale cached topology must degrade after grace"
- );
- assert!(gap_monitors
- .iter()
- .all(|m| !controller.hosts_focus_for_monitor(m)));
- let fresh_monitors = verify_displays(&stale_cursor).await;
- wait_focus(&tracker, Some(stale_extra_id)).await;
- wait_mapping(&controller, &fresh_monitors, Some(stale_extra_id)).await;
- assert!(!controller.resolution_degraded());
- let unchanged_cursor = fixture.command("report");
- assert_eq!(unchanged_cursor["cursor_x"].as_f64(), Some(-1180.));
- assert_eq!(unchanged_cursor["cursor_y"].as_f64(), Some(100.));
- eprintln!("STALE_TOPOLOGY PASS: native unresolved grace and attribution recovery after fresh discovery, without moving cursor");
- let restored = fixture.command(&format!("layout {width} 400"));
- let restored_extra = restored["displays"]
- .as_array()
- .unwrap()
- .iter()
- .find(|d| d["id"] == restored["extra"])
- .unwrap();
- assert_eq!(restored_extra["x"].as_i64(), Some(width));
- assert_eq!(restored_extra["y"].as_i64(), Some(400));
- let gap_monitors = verify_displays(&restored).await;
- // Remove the display that actually holds focus; removing an already-idle
- // display cannot expose stale focused identities after hot-unplug.
- let extra_before_remove = gap["extra"].as_u64().unwrap() as u32;
- fixture.command(&format!("warp {} 500", width + 100));
- wait_focus(&tracker, Some(extra_before_remove)).await;
- wait_mapping(&controller, &gap_monitors, Some(extra_before_remove)).await;
- let removed = fixture.command("remove");
- let remaining = verify_displays(&removed).await;
- assert_eq!(remaining.len(), 1);
- assert_eq!(remaining[0].id(), primary_id);
- // Explicitly return the pointer to the remaining display. The test makes
- // no promise that macOS automatically relocates a warped off-screen cursor.
- fixture.command("warp 100 100");
- wait_focus(&tracker, Some(primary_id)).await;
- wait_mapping(&controller, &remaining, Some(primary_id)).await;
- assert!(!controller.resolution_degraded());
- let recovered_frame =
- tokio::time::timeout(Duration::from_secs(20), remaining[0].capture_image())
- .await
- .unwrap()
- .unwrap();
- let remaining_native = &removed["displays"].as_array().unwrap()[0];
- verify_capture_marker(&recovered_frame, remaining_native);
- eprintln!("HOT_UNPLUG: focused secondary removed; primary focus and red capture recovered");
- let retina = fixture.command("add-retina");
- assert_eq!(verify_displays(&retina).await.len(), 2);
- let positioned = fixture.command(&format!("layout {width} 0"));
- let monitors = verify_displays(&positioned).await;
- let extra = positioned["extra"].as_u64().unwrap() as u32;
- let native_retina = positioned["displays"]
- .as_array()
- .unwrap()
- .iter()
- .find(|d| d["id"].as_u64() == Some(extra as u64))
- .unwrap();
- assert_eq!(native_retina["x"].as_i64(), Some(width));
- assert_eq!(native_retina["y"].as_i64(), Some(0));
- assert_eq!(
- native_retina["pixels_w"].as_u64().unwrap(),
- native_retina["w"].as_u64().unwrap() * 2,
- "retina must be actual 2x backing scale"
- );
- fixture.command(&format!("warp {} 100", width + 100));
- wait_focus(&tracker, Some(extra)).await;
- wait_mapping(&controller, &monitors, Some(extra)).await;
- let m = monitors.iter().find(|m| m.id() == extra).unwrap();
- let image = tokio::time::timeout(Duration::from_secs(20), m.capture_image())
- .await
- .unwrap()
- .unwrap();
- assert_eq!(
- image.width() as u64,
- native_retina["pixels_w"].as_u64().unwrap()
- );
- assert_eq!(
- image.height() as u64,
- native_retina["pixels_h"].as_u64().unwrap()
- );
- verify_capture_marker(&image, native_retina);
- eprintln!("HIDPI_CAPTURE {}x{}", image.width(), image.height());
- assert!(!controller.resolution_degraded());
- controller.shutdown();
- tracker.stop();
- // Drop reaps the helper process. Independently verify its virtual display
- // disappeared through the production enumeration path, creating no helper.
- drop(fixture);
- let cleanup_deadline = Instant::now() + Duration::from_secs(12);
- loop {
- let remaining = list_monitors().await;
- if remaining.len() == 1 && remaining[0].id() == primary_id {
- break;
- }
- assert!(
- Instant::now() < cleanup_deadline,
- "fixture display survived helper cleanup"
- );
- tokio::time::sleep(Duration::from_millis(100)).await;
- }
- eprintln!("PASS multi-monitor layouts, captures, stale-topology grace/recovery, hotplug and Retina; literal_gap={}", if literal_gap_supported { "native gap exercised" } else { "UNSUPPORTED (OS clamped cursor), not reproduced" });
-}
diff --git a/crates/screenpipe-engine/src/vision_manager/manager.rs b/crates/screenpipe-engine/src/vision_manager/manager.rs
index 8c217cd64..7199cab0d 100644
--- a/crates/screenpipe-engine/src/vision_manager/manager.rs
+++ b/crates/screenpipe-engine/src/vision_manager/manager.rs
@@ -118,12 +118,10 @@ pub struct VisionManager {
status: Arc<RwLock<VisionManagerStatus>>,
/// Map of monitor_id -> JoinHandle
recording_tasks: Arc<DashMap<u32, JoinHandle<()>>>,
- /// macOS capture backend used by each active monitor task. A fallback
- /// CoreGraphics handle and a recovered ScreenCaptureKit handle share the
- /// same display ID, so the watcher needs this separate generation signal
- /// to upgrade the running task after SCK recovers.
+ /// Configuration held by each macOS task. Same-ID scale/layout changes and
+ /// recovery from fallback both require replacing that immutable handle.
#[cfg(target_os = "macos")]
- monitor_sck_backends: Arc<DashMap<u32, bool>>,
+ monitor_configurations: Arc<DashMap<u32, screenpipe_screen::monitor::CaptureConfiguration>>,
/// Per-monitor pipeline heartbeat. Aggregate metrics remain in `config` for
/// `/health`; these independent clocks are exclusively the recovery source
/// so partial multi-display stalls are observable.
@@ -238,7 +236,7 @@ impl VisionManager {
status: Arc::new(RwLock::new(VisionManagerStatus::Stopped)),
recording_tasks: Arc::new(DashMap::new()),
#[cfg(target_os = "macos")]
- monitor_sck_backends: Arc::new(DashMap::new()),
+ monitor_configurations: Arc::new(DashMap::new()),
monitor_liveness: Arc::new(DashMap::new()),
hd_recording_tasks: Arc::new(DashMap::new()),
trigger_tx,
@@ -582,7 +580,7 @@ impl VisionManager {
);
#[cfg(target_os = "macos")]
- let uses_sck_backend = monitor.uses_sck_backend();
+ let configuration = monitor.capture_configuration();
let liveness = Arc::new(PipelineMetrics::new());
let handle = self
.start_event_driven_monitor(monitor_id, monitor, liveness.clone())
@@ -590,8 +588,8 @@ impl VisionManager {
self.monitor_liveness.insert(monitor_id, liveness);
#[cfg(target_os = "macos")]
- self.monitor_sck_backends
- .insert(monitor_id, uses_sck_backend);
+ self.monitor_configurations
+ .insert(monitor_id, configuration);
self.recording_tasks.insert(monitor_id, handle);
Ok(())
@@ -800,7 +798,7 @@ impl VisionManager {
pub async fn stop_monitor(&self, monitor_id: u32) -> Result<()> {
self.monitor_liveness.remove(&monitor_id);
#[cfg(target_os = "macos")]
- self.monitor_sck_backends.remove(&monitor_id);
+ self.monitor_configurations.remove(&monitor_id);
// Stop the HD recorder first. Aborting drops its ffmpeg stdin, which
// sends EOF so ffmpeg finalizes the .mp4 (moov atom) on its own.
if let Some((_, hd_handle)) = self.hd_recording_tasks.remove(&monitor_id) {
@@ -851,7 +849,7 @@ impl VisionManager {
for id in &dead {
self.monitor_liveness.remove(id);
#[cfg(target_os = "macos")]
- self.monitor_sck_backends.remove(id);
+ self.monitor_configurations.remove(id);
if let Some((_, handle)) = self.recording_tasks.remove(id) {
// Await to clean up the JoinHandle and capture exit reason
match handle.await {
@@ -880,12 +878,20 @@ impl VisionManager {
.collect()
}
- /// Return the capture backend generation held by an active macOS monitor.
+ /// Compare fresh topology with the immutable handle held by the task.
#[cfg(target_os = "macos")]
- pub(crate) fn active_monitor_uses_sck(&self, monitor_id: u32) -> Option<bool> {
- self.monitor_sck_backends
- .get(&monitor_id)
- .map(|entry| *entry.value())
+ pub(crate) fn active_monitor_needs_refresh(
+ &self,
+ monitor: &screenpipe_screen::monitor::SafeMonitor,
+ ) -> bool {
+ self.monitor_configurations
+ .get(&monitor.id())
+ .map(|active| {
+ monitor
+ .capture_configuration()
+ .should_replace(*active.value())
+ })
+ .unwrap_or(false)
}
/// Independent liveness for each active capture loop. Never derive this
diff --git a/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs b/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs
index 3bb59e330..70d167a4b 100644
--- a/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs
+++ b/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs
@@ -1108,23 +1108,19 @@ pub async fn start_monitor_watcher(
}
}
- // A bounded SCK failure can start a monitor on the privacy-safe
- // CoreGraphics fallback. Once a fresh enumeration returns an SCK
- // handle, display IDs alone cannot reveal that the active task is
- // still holding the fallback generation. Upgrade it immediately;
- // otherwise excluded-window capture keeps failing closed forever.
+ // Reconcile immutable capture handles even when display IDs remain
+ // unchanged: Retina scale/layout changes and recovered SCK handles
+ // must replace the generation used by screenshots and HD recording.
#[cfg(target_os = "macos")]
for monitor in &current_monitors {
- if monitor.uses_sck_backend()
- && vision_manager.active_monitor_uses_sck(monitor.id()) == Some(false)
- {
+ if vision_manager.active_monitor_needs_refresh(monitor) {
info!(
- "ScreenCaptureKit recovered for monitor {}; replacing temporary CoreGraphics fallback",
+ "Capture configuration changed for monitor {}; refreshing recording task",
monitor.id()
);
if let Err(e) = vision_manager.stop_monitor(monitor.id()).await {
warn!(
- "failed to stop CoreGraphics fallback for monitor {}: {:?}",
+ "failed to stop stale capture configuration for monitor {}: {:?}",
monitor.id(),
e
);
@@ -1132,7 +1128,7 @@ pub async fn start_monitor_watcher(
}
if let Err(e) = vision_manager.start_monitor_handle(monitor.clone()).await {
warn!(
- "failed to upgrade monitor {} back to ScreenCaptureKit: {:?}",
+ "failed to refresh capture configuration for monitor {}: {:?}",
monitor.id(),
e
);
diff --git a/crates/screenpipe-engine/tests/native_multi_monitor.rs b/crates/screenpipe-engine/tests/native_multi_monitor.rs
new file mode 100644
index 000000000..13c57834b
--- /dev/null
+++ b/crates/screenpipe-engine/tests/native_multi_monitor.rs
@@ -0,0 +1,573 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+//! Opt-in native acceptance in a disposable macOS guest. No mocked topology.
+#[cfg(target_os = "macos")]
+mod native {
+ use screenpipe_engine::focus_aware_controller::FocusAwareController;
+ use screenpipe_engine::focus_tracker::{new_tracker, FocusTracker};
+ use screenpipe_screen::monitor::{list_monitors, SafeMonitor};
+ use serde_json::Value;
+ use std::io::{BufRead, BufReader, Write};
+ use std::process::{Child, ChildStdin, Command, Stdio};
+ use std::sync::{mpsc, Arc};
+ use std::time::{Duration, Instant};
+ struct Fixture {
+ child: Child,
+ input: ChildStdin,
+ output: mpsc::Receiver<String>,
+ reader: Option<std::thread::JoinHandle<()>>,
+ }
+ impl Fixture {
+ fn start() -> (Self, Value) {
+ assert_eq!(
+ std::env::var("SCREENPIPE_ISOLATED_VM_TEST").as_deref(),
+ Ok("1")
+ );
+ let mut child = Command::new(std::env::var("SCREENPIPE_DISPLAY_FIXTURE").unwrap())
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()
+ .unwrap();
+ let input = child.stdin.take().unwrap();
+ let stdout = child.stdout.take().unwrap();
+ let (sender, output) = mpsc::channel();
+ let reader = std::thread::spawn(move || {
+ for line in BufReader::new(stdout).lines() {
+ match line {
+ Ok(line) => {
+ if sender.send(line).is_err() {
+ break;
+ }
+ }
+ Err(_) => break,
+ }
+ }
+ });
+ let mut fixture = Self {
+ child,
+ input,
+ output,
+ reader: Some(reader),
+ };
+ let initial = fixture.read();
+ (fixture, initial)
+ }
+ fn read(&mut self) -> Value {
+ let line = self
+ .output
+ .recv_timeout(Duration::from_secs(15))
+ .expect("native display fixture failed to answer within 15 seconds");
+ let v = serde_json::from_str(&line).unwrap();
+ eprintln!("native topology: {line}");
+ v
+ }
+ fn command(&mut self, command: &str) -> Value {
+ writeln!(self.input, "{command}").unwrap();
+ self.input.flush().unwrap();
+ self.read()
+ }
+ }
+ impl Drop for Fixture {
+ fn drop(&mut self) {
+ let _ = writeln!(self.input, "quit");
+ let _ = self.input.flush();
+ let _ = self.child.kill();
+ let _ = self.child.wait();
+ if let Some(reader) = self.reader.take() {
+ let _ = reader.join();
+ }
+ }
+ }
+ async fn wait_mapping(
+ controller: &FocusAwareController,
+ monitors: &[SafeMonitor],
+ expected: Option<u32>,
+ ) {
+ let deadline = Instant::now() + Duration::from_secs(12);
+ loop {
+ let focused: Vec<_> = monitors
+ .iter()
+ .filter(|m| controller.hosts_focus_for_monitor(m))
+ .map(|m| m.id())
+ .collect();
+ if focused == expected.into_iter().collect::<Vec<_>>() {
+ return;
+ }
+ assert!(
+ Instant::now() < deadline,
+ "controller mapping expected {expected:?}, got {focused:?}"
+ );
+ tokio::time::sleep(Duration::from_millis(100)).await;
+ }
+ }
+ fn verify_capture_marker(image: &image::DynamicImage, native: &Value) {
+ // The helper paints a 200-point square at (+20,+20) on each display.
+ // Sample its center in backing pixels, away from the cursor at (+100,+100).
+ let x = (120. * image.width() as f64 / native["w"].as_f64().unwrap()) as u32;
+ let y = (120. * image.height() as f64 / native["h"].as_f64().unwrap()) as u32;
+ assert!(x < image.width() && y < image.height());
+ let rgb = image.to_rgb8();
+ let [red, green, blue] = rgb.get_pixel(x, y).0;
+ let primary = native["main"].as_i64() == Some(1);
+ let (dominant, other) = if primary { (red, blue) } else { (blue, red) };
+ assert!(
+ dominant > 150
+ && dominant.saturating_sub(other) > 80
+ && dominant.saturating_sub(green) > 80,
+ "wrong display content: id={} primary={primary} pixel=({red},{green},{blue}) at ({x},{y})",
+ native["id"]
+ );
+ }
+ async fn wait_focus(tracker: &Arc<dyn FocusTracker>, expected: Option<u32>) {
+ let deadline = Instant::now() + Duration::from_secs(12);
+ loop {
+ if tracker.current().map(|m| m.id) == expected {
+ return;
+ }
+ assert!(
+ Instant::now() < deadline,
+ "focus expected {expected:?}, got {:?}",
+ tracker.current()
+ );
+ tokio::time::sleep(Duration::from_millis(100)).await;
+ }
+ }
+ async fn verify_displays(native: &Value) -> Vec<SafeMonitor> {
+ let monitors = list_monitors().await;
+ let displays = native["displays"].as_array().unwrap();
+ assert_eq!(
+ monitors.len(),
+ displays.len(),
+ "capture backend must see actual CG displays"
+ );
+ for d in displays {
+ let m = monitors
+ .iter()
+ .find(|m| m.id() as u64 == d["id"].as_u64().unwrap())
+ .expect("missing native display");
+ eprintln!(
+ "capture topology id={} origin=({}, {}) dimensions={}x{} sck={}",
+ m.id(),
+ m.x(),
+ m.y(),
+ m.width(),
+ m.height(),
+ m.uses_sck_backend()
+ );
+ assert!(
+ m.uses_sck_backend(),
+ "native acceptance must not silently use the legacy fallback"
+ );
+ assert_eq!(m.x() as i64, d["x"].as_i64().unwrap());
+ assert_eq!(m.y() as i64, d["y"].as_i64().unwrap());
+ assert_eq!(
+ m.width() as i64,
+ d["w"].as_i64().unwrap(),
+ "focus bounds must use display points"
+ );
+ assert_eq!(
+ m.height() as i64,
+ d["h"].as_i64().unwrap(),
+ "focus bounds must use display points"
+ );
+ }
+ monitors
+ }
+ async fn native_multi_monitor_focus_capture_gap_and_hotplug() {
+ let (mut fixture, initial) = Fixture::start();
+ assert_eq!(
+ initial["displays"].as_array().unwrap().len(),
+ 2,
+ "requires one base and one virtual display"
+ );
+ let primary = initial["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| d["main"].as_i64() == Some(1))
+ .unwrap()
+ .clone();
+ let primary_id = primary["id"].as_u64().unwrap() as u32;
+ let width = primary["w"].as_i64().unwrap();
+ verify_displays(&initial).await;
+ let tracker = new_tracker();
+ let controller = FocusAwareController::new(tracker.clone());
+ for (label, x, y) in [
+ ("right", width, 0),
+ ("left", -1280, 0),
+ ("above", 0, -720),
+ ("offset", width, 400),
+ ] {
+ eprintln!("CASE {label}");
+ let native = fixture.command(&format!("layout {x} {y}"));
+ let requested = native["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| d["id"] == native["extra"])
+ .unwrap();
+ assert_eq!(
+ requested["x"].as_i64(),
+ Some(x),
+ "requested layout was not applied"
+ );
+ assert_eq!(
+ requested["y"].as_i64(),
+ Some(y),
+ "requested layout was not applied"
+ );
+ assert_eq!(
+ requested["mirror"].as_u64(),
+ Some(0),
+ "extended displays required"
+ );
+ let monitors = verify_displays(&native).await;
+ for d in native["displays"].as_array().unwrap() {
+ let px = d["x"].as_f64().unwrap() + 100.;
+ let py = d["y"].as_f64().unwrap() + 100.;
+ let actual = fixture.command(&format!("warp {px} {py}"));
+ assert_eq!(actual["cursor_x"].as_f64().unwrap(), px);
+ assert_eq!(actual["cursor_y"].as_f64().unwrap(), py);
+ let id = d["id"].as_u64().unwrap() as u32;
+ wait_focus(&tracker, Some(id)).await;
+ wait_mapping(&controller, &monitors, Some(id)).await;
+ assert!(!controller.resolution_degraded());
+ for m in &monitors {
+ assert_eq!(controller.hosts_focus_for_monitor(m), m.id() == id);
+ }
+ let m = monitors.iter().find(|m| m.id() == id).unwrap();
+ let frame = tokio::time::timeout(Duration::from_secs(20), m.capture_image())
+ .await
+ .unwrap()
+ .unwrap();
+ assert!(frame.width() > 0 && frame.height() > 0);
+ verify_capture_marker(&frame, d);
+ if let Ok(dir) = std::env::var("SCREENPIPE_VM_EVIDENCE_DIR") {
+ std::fs::create_dir_all(&dir).unwrap();
+ frame.save(format!("{dir}/{label}-{id}.png")).unwrap();
+ }
+ eprintln!(
+ "CAPTURE {label} display={id} actual={}x{}",
+ frame.width(),
+ frame.height()
+ );
+ }
+ }
+ // An offset layout leaves a real rectangle outside every display. Confirm
+ // where the OS cursor actually lands, rather than injecting tracker state.
+ let gap = fixture.command(&format!("warp {} 200", width + 50));
+ let gap_monitors = verify_displays(&gap).await;
+ let actual_x = gap["cursor_x"].as_f64().unwrap();
+ let actual_y = gap["cursor_y"].as_f64().unwrap();
+ let literal_gap_supported = actual_x == (width + 50) as f64 && actual_y == 200.;
+ eprintln!(
+ "LITERAL_GAP requested=({},200) actual=({actual_x},{actual_y}) clamped={}",
+ width + 50,
+ !literal_gap_supported
+ );
+ if literal_gap_supported {
+ wait_focus(&tracker, None).await;
+ wait_mapping(&controller, &gap_monitors, None).await;
+ assert!(!controller.resolution_degraded());
+ tokio::time::sleep(Duration::from_secs(31)).await;
+ assert!(controller.resolution_degraded());
+ assert!(gap_monitors
+ .iter()
+ .all(|m| !controller.hosts_focus_for_monitor(m)));
+ eprintln!("LITERAL_GAP: native off-display cursor held; grace degraded as expected");
+ } else {
+ let landing = gap["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| {
+ let x = d["x"].as_f64().unwrap();
+ let y = d["y"].as_f64().unwrap();
+ actual_x >= x
+ && actual_x < x + d["w"].as_f64().unwrap()
+ && actual_y >= y
+ && actual_y < y + d["h"].as_f64().unwrap()
+ })
+ .expect("clamped cursor must land on an actual display");
+ let landing_id = landing["id"].as_u64().unwrap() as u32;
+ wait_focus(&tracker, Some(landing_id)).await;
+ wait_mapping(&controller, &gap_monitors, Some(landing_id)).await;
+ assert!(!controller.resolution_degraded());
+ eprintln!("LITERAL_GAP UNSUPPORTED: macOS clamped the cursor onto a real display; no literal-gap reproduction or pass claimed");
+ }
+ fixture.command("warp 100 100");
+ wait_focus(&tracker, Some(primary_id)).await;
+ wait_mapping(&controller, &gap_monitors, Some(primary_id)).await;
+ assert!(!controller.resolution_degraded());
+ eprintln!("PRIMARY: cursor and attribution resolved on primary");
+ // This intentionally omits the monitor watcher's fresh discovery while
+ // rearranging real displays. It tests native resolution against stale
+ // cached geometry, not a mocked tracker or the customer's literal gap.
+ eprintln!("STALE_TOPOLOGY: withholding watcher discovery; native displays/cursor, not literal-gap/customer reproduction");
+ let stale_native = fixture.command("layout -1280 0");
+ let stale_extra_id = stale_native["extra"].as_u64().unwrap() as u32;
+ let stale_extra = stale_native["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| d["id"].as_u64() == Some(stale_extra_id as u64))
+ .unwrap();
+ assert_eq!(stale_extra["x"].as_i64(), Some(-1280));
+ assert_eq!(stale_extra["y"].as_i64(), Some(0));
+ assert_eq!(stale_extra["mirror"].as_u64(), Some(0));
+ let stale_cursor = fixture.command("warp -1180 100");
+ assert_eq!(stale_cursor["cursor_x"].as_f64(), Some(-1180.));
+ assert_eq!(stale_cursor["cursor_y"].as_f64(), Some(100.));
+ // Do not call list_monitors/verify_displays until after the grace check.
+ wait_focus(&tracker, None).await;
+ wait_mapping(&controller, &gap_monitors, None).await;
+ assert!(!controller.resolution_degraded());
+ tokio::time::sleep(Duration::from_secs(31)).await;
+ assert!(
+ controller.resolution_degraded(),
+ "stale cached topology must degrade after grace"
+ );
+ assert!(gap_monitors
+ .iter()
+ .all(|m| !controller.hosts_focus_for_monitor(m)));
+ let fresh_monitors = verify_displays(&stale_cursor).await;
+ wait_focus(&tracker, Some(stale_extra_id)).await;
+ wait_mapping(&controller, &fresh_monitors, Some(stale_extra_id)).await;
+ assert!(!controller.resolution_degraded());
+ let unchanged_cursor = fixture.command("report");
+ assert_eq!(unchanged_cursor["cursor_x"].as_f64(), Some(-1180.));
+ assert_eq!(unchanged_cursor["cursor_y"].as_f64(), Some(100.));
+ eprintln!("STALE_TOPOLOGY PASS: native unresolved grace and attribution recovery after fresh discovery, without moving cursor");
+ let restored = fixture.command(&format!("layout {width} 400"));
+ let restored_extra = restored["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| d["id"] == restored["extra"])
+ .unwrap();
+ assert_eq!(restored_extra["x"].as_i64(), Some(width));
+ assert_eq!(restored_extra["y"].as_i64(), Some(400));
+ let gap_monitors = verify_displays(&restored).await;
+ // Remove the display that actually holds focus; removing an already-idle
+ // display cannot expose stale focused identities after hot-unplug.
+ let extra_before_remove = gap["extra"].as_u64().unwrap() as u32;
+ fixture.command(&format!("warp {} 500", width + 100));
+ wait_focus(&tracker, Some(extra_before_remove)).await;
+ wait_mapping(&controller, &gap_monitors, Some(extra_before_remove)).await;
+ let removed = fixture.command("remove");
+ let remaining = verify_displays(&removed).await;
+ assert_eq!(remaining.len(), 1);
+ assert_eq!(remaining[0].id(), primary_id);
+ // Explicitly return the pointer to the remaining display. The test makes
+ // no promise that macOS automatically relocates a warped off-screen cursor.
+ fixture.command("warp 100 100");
+ wait_focus(&tracker, Some(primary_id)).await;
+ wait_mapping(&controller, &remaining, Some(primary_id)).await;
+ assert!(!controller.resolution_degraded());
+ let recovered_frame =
+ tokio::time::timeout(Duration::from_secs(20), remaining[0].capture_image())
+ .await
+ .unwrap()
+ .unwrap();
+ let remaining_native = &removed["displays"].as_array().unwrap()[0];
+ verify_capture_marker(&recovered_frame, remaining_native);
+ eprintln!("HOT_UNPLUG: focused secondary removed; primary focus and red capture recovered");
+ let retina = fixture.command("add-retina");
+ assert_eq!(verify_displays(&retina).await.len(), 2);
+ let positioned = fixture.command(&format!("layout {width} 0"));
+ let monitors = verify_displays(&positioned).await;
+ let extra = positioned["extra"].as_u64().unwrap() as u32;
+ let native_retina = positioned["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| d["id"].as_u64() == Some(extra as u64))
+ .unwrap();
+ assert_eq!(native_retina["x"].as_i64(), Some(width));
+ assert_eq!(native_retina["y"].as_i64(), Some(0));
+ assert_eq!(
+ native_retina["pixels_w"].as_u64().unwrap(),
+ native_retina["w"].as_u64().unwrap() * 2,
+ "retina must be actual 2x backing scale"
+ );
+ fixture.command(&format!("warp {} 100", width + 100));
+ wait_focus(&tracker, Some(extra)).await;
+ wait_mapping(&controller, &monitors, Some(extra)).await;
+ let m = monitors.iter().find(|m| m.id() == extra).unwrap();
+ let image = tokio::time::timeout(Duration::from_secs(20), m.capture_image())
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(
+ image.width() as u64,
+ native_retina["pixels_w"].as_u64().unwrap()
+ );
+ assert_eq!(
+ image.height() as u64,
+ native_retina["pixels_h"].as_u64().unwrap()
+ );
+ verify_capture_marker(&image, native_retina);
+ eprintln!("HIDPI_CAPTURE {}x{}", image.width(), image.height());
+ if let Ok(dir) = std::env::var("SCREENPIPE_VM_EVIDENCE_DIR") {
+ image.save(format!("{dir}/retina-native.png")).unwrap();
+ }
+ // Changing capture size must recreate the stream and preserve full content.
+ struct RestoreCaptureWidth;
+ impl Drop for RestoreCaptureWidth {
+ fn drop(&mut self) {
+ screenpipe_screen::monitor::set_sck_capture_max_width(0);
+ }
+ }
+ let _restore_capture_width = RestoreCaptureWidth;
+ for cap in [1280, 1920, 0] {
+ screenpipe_screen::monitor::set_sck_capture_max_width(cap);
+ let frame = tokio::time::timeout(Duration::from_secs(20), m.capture_image())
+ .await
+ .unwrap()
+ .unwrap();
+ let expected_width = if cap == 0 { 2560 } else { cap };
+ assert_eq!(
+ (frame.width(), frame.height()),
+ (expected_width, expected_width * 9 / 16)
+ );
+ verify_capture_marker(&frame, native_retina);
+ eprintln!("RETINA_CAP {cap}: {}x{}", frame.width(), frame.height());
+ }
+ // HD recording uses pixels before its own 1920 cap, independently of focus.
+ let hd_monitor = m.clone();
+ let mut hd = tokio::task::spawn_blocking(move || hd_monitor.start_hd_capture(2, &[], 0))
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!((hd.width, hd.height), (1920, 1080));
+ let hd_frame = tokio::time::timeout(Duration::from_secs(20), hd.frames.recv())
+ .await
+ .unwrap()
+ .expect("HD stream produced no frame");
+ assert_eq!(hd_frame.dimensions(), (1920, 1080));
+ verify_capture_marker(&image::DynamicImage::ImageRgba8(hd_frame), native_retina);
+ drop(hd);
+ eprintln!("RETINA_HD: actual 1920x1080 frame, correct blue display content");
+ // A 2x raster must not double the logical rectangle used for focus.
+ for (x, expected) in [
+ (width - 1, primary_id),
+ (width, extra),
+ (width + 1279, extra),
+ ] {
+ let actual = fixture.command(&format!("warp {x} 100"));
+ assert_eq!(actual["cursor_x"].as_f64(), Some(x as f64));
+ wait_focus(&tracker, Some(expected)).await;
+ wait_mapping(&controller, &monitors, Some(expected)).await;
+ }
+ eprintln!("RETINA_BOUNDARIES: exactly one focused display at mixed-DPI edges");
+ for (command, scale) in [("mode-standard", 1), ("mode-retina", 2)] {
+ let changed = fixture.command(command);
+ assert_eq!(
+ changed["extra"].as_u64(),
+ Some(extra as u64),
+ "mode change must retain display ID"
+ );
+ let monitors = verify_displays(&changed).await;
+ let native = changed["displays"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|d| d["id"].as_u64() == Some(extra as u64))
+ .unwrap();
+ assert_eq!(native["pixels_w"].as_u64(), Some(1280 * scale));
+ let current = monitors.iter().find(|m| m.id() == extra).unwrap();
+ let frame = tokio::time::timeout(Duration::from_secs(20), current.capture_image())
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(
+ (frame.width(), frame.height()),
+ (1280 * scale as u32, 720 * scale as u32)
+ );
+ verify_capture_marker(&frame, native);
+ eprintln!(
+ "SAME_ID_MODE {command}: display={extra}, {}x{}",
+ frame.width(),
+ frame.height()
+ );
+ }
+ // Force the actual CoreGraphics backend directly, without wedging a
+ // callback or permitting fallback to hide failures in the SCK cases.
+ let fallback = SafeMonitor::from_xcap(
+ xcap::Monitor::all()
+ .unwrap()
+ .into_iter()
+ .find(|m| m.id().ok() == Some(extra))
+ .unwrap(),
+ );
+ assert!(!fallback.uses_sck_backend());
+ for (cap, expected_width) in [(1280, 1280), (1920, 1920), (0, 2560)] {
+ screenpipe_screen::monitor::set_sck_capture_max_width(cap);
+ let frame = tokio::time::timeout(Duration::from_secs(20), fallback.capture_image())
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(
+ (frame.width(), frame.height()),
+ (expected_width, expected_width * 9 / 16)
+ );
+ verify_capture_marker(&frame, native_retina);
+ eprintln!("RETINA_CG_CAP {cap}: {}x{}", frame.width(), frame.height());
+ }
+ assert!(!controller.resolution_degraded());
+ controller.shutdown();
+ tracker.stop();
+ // Drop reaps the helper process. Independently verify its virtual display
+ // disappeared through the production enumeration path, creating no helper.
+ drop(fixture);
+ let cleanup_deadline = Instant::now() + Duration::from_secs(12);
+ loop {
+ let remaining = list_monitors().await;
+ if remaining.len() == 1 && remaining[0].id() == primary_id {
+ break;
+ }
+ assert!(
+ Instant::now() < cleanup_deadline,
+ "fixture display survived helper cleanup"
+ );
+ tokio::time::sleep(Duration::from_millis(100)).await;
+ }
+ eprintln!("PASS multi-monitor layouts, captures, stale-topology grace/recovery, hotplug and Retina; literal_gap={}", if literal_gap_supported { "native gap exercised" } else { "UNSUPPORTED (OS clamped cursor), not reproduced" });
+ }
+
+ #[cfg(target_os = "macos")]
+ pub fn run() -> anyhow::Result<()> {
+ if std::env::var("SCREENPIPE_ISOLATED_VM_TEST").as_deref() != Ok("1") {
+ println!(
+ "SKIP: requires SCREENPIPE_ISOLATED_VM_TEST=1 in a disposable logged-in Mac VM"
+ );
+ return Ok(());
+ }
+ // Exercise completion-before-loop, returned errors and panic propagation.
+ assert_eq!(screenpipe_engine::macos_run_loop::run(|| 7)?, 7);
+ let error = screenpipe_engine::macos_run_loop::run(|| Err::<(), _>("expected error"))?;
+ assert_eq!(error, Err("expected error"));
+ assert!(std::panic::catch_unwind(|| {
+ let _ = screenpipe_engine::macos_run_loop::run(|| panic!("expected lifecycle panic"));
+ })
+ .is_err());
+ screenpipe_engine::macos_run_loop::run(|| {
+ tokio::runtime::Builder::new_multi_thread()
+ .worker_threads(4)
+ .enable_all()
+ .build()
+ .unwrap()
+ .block_on(native_multi_monitor_focus_capture_gap_and_hotplug());
+ })?;
+ println!("PASS: native multi-monitor acceptance and main-loop shutdown");
+ Ok(())
+ }
+}
+#[cfg(target_os = "macos")]
+fn main() -> anyhow::Result<()> {
+ native::run()
+}
+#[cfg(not(target_os = "macos"))]
+fn main() {
+ println!("SKIP: macOS-only native acceptance");
+}
diff --git a/crates/screenpipe-screen/Cargo.toml b/crates/screenpipe-screen/Cargo.toml
index 93f10e402..11758456f 100644
--- a/crates/screenpipe-screen/Cargo.toml
+++ b/crates/screenpipe-screen/Cargo.toml
@@ -83,7 +83,7 @@ harness = false
# macOS: sck-rs for 12.3+ (ScreenCaptureKit), xcap as fallback for older versions
[target.'cfg(target_os = "macos")'.dependencies]
-sck-rs = { git = "https://github.com/screenpipe/sck-rs", rev = "60610e8c970af1ea9d47e274c1a48182e1da5bd1" }
+sck-rs = { git = "https://github.com/screenpipe/sck-rs", rev = "62d79abed212015eb9beaa03138002807f61f59a" }
xcap = { workspace = true }
libc = { workspace = true }
cidre = { git = "https://github.com/yury/cidre.git", rev = "8481f3f0dc7dd39bb5be80d9424bfac0cad3801a", features = ["vn", "cv", "cg", "app"] }
diff --git a/crates/screenpipe-screen/src/monitor.rs b/crates/screenpipe-screen/src/monitor.rs
index 1c0985354..117ef2b30 100644
--- a/crates/screenpipe-screen/src/monitor.rs
+++ b/crates/screenpipe-screen/src/monitor.rs
@@ -31,7 +31,8 @@ pub use macos::{
cached_monitor_status, e2e_arm_sck_lookup_hang_fault, get_capture_backend, get_default_monitor,
get_monitor_by_id, invalidate_monitor_lookup_cache, is_screen_capture_supported, list_monitors,
list_monitors_cached, list_monitors_detailed, macos_version,
- secs_since_capture_backend_fallback, set_sck_capture_max_width, HdCapture,
+ secs_since_capture_backend_fallback, set_sck_capture_max_width, CaptureConfiguration,
+ HdCapture,
};
/// Seconds since capture last fell back off its primary backend, if ever.
diff --git a/crates/screenpipe-screen/src/monitor/macos.rs b/crates/screenpipe-screen/src/monitor/macos.rs
index 1bde908c3..71ff7afcc 100644
--- a/crates/screenpipe-screen/src/monitor/macos.rs
+++ b/crates/screenpipe-screen/src/monitor/macos.rs
@@ -252,13 +252,53 @@ fn core_graphics_fallback_allowed(excluded_window_ids: &[u32]) -> bool {
excluded_window_ids.is_empty()
}
+// CoreGraphics returns native pixels. Apply the same explicit width budget
+// as SCK without resizing (or allocating another raster) when already within it.
+fn cap_fallback_image(image: DynamicImage, max_width: u32) -> DynamicImage {
+ if max_width == 0 || image.width() <= max_width {
+ image
+ } else {
+ image.resize(max_width, u32::MAX, image::imageops::FilterType::Triangle)
+ }
+}
+
+/// Immutable geometry of a capture task, compared only during topology scans.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct CaptureConfiguration {
+ logical: (i32, i32, u32, u32),
+ backing: (u32, u32),
+ primary: bool,
+ sck: bool,
+}
+impl CaptureConfiguration {
+ /// Refresh on recovered SCK or geometry/scale changes; a transient discovery
+ /// fallback must not downgrade an otherwise working SCK task.
+ pub fn should_replace(self, active: Self) -> bool {
+ self.sck && self != active
+ }
+}
+
impl SafeMonitor {
+ pub fn capture_configuration(&self) -> CaptureConfiguration {
+ CaptureConfiguration {
+ logical: (self.x(), self.y(), self.width(), self.height()),
+ backing: self
+ .cached_sck
+ .as_ref()
+ .map(|m| (m.raw_width(), m.raw_height()))
+ .unwrap_or((self.width(), self.height())),
+ primary: self.is_primary(),
+ sck: self.use_sck,
+ }
+ }
+
// macOS: Create from sck-rs monitor
pub fn from_sck(monitor: SckMonitor) -> Self {
let monitor_id = monitor.id();
let monitor_data = Arc::new(MonitorData {
- width: monitor.width().unwrap_or(0),
- height: monitor.height().unwrap_or(0),
+ // Focus bounds share the cursor's logical coordinate space.
+ width: monitor.logical_width(),
+ height: monitor.logical_height(),
x: monitor.x(),
y: monitor.y(),
name: monitor.name().to_string(),
@@ -369,7 +409,12 @@ impl SafeMonitor {
}
monitor
.capture_image()
- .map(DynamicImage::ImageRgba8)
+ .map(|image| {
+ cap_fallback_image(
+ DynamicImage::ImageRgba8(image),
+ sck_capture_max_width(),
+ )
+ })
.map_err(|e| e.to_string())
})
.map_err(anyhow::Error::msg)
@@ -1089,9 +1134,14 @@ impl SafeMonitor {
excluded_window_ids: &[u32],
snapshot_max_width: u32,
) -> Result<HdCapture> {
+ // Focus geometry is in points; encode sizing starts from backing pixels.
+ let (native_width, native_height) = self.cached_sck.as_ref().map_or(
+ (self.monitor_data.width, self.monitor_data.height),
+ |monitor| (monitor.raw_width(), monitor.raw_height()),
+ );
let (width, height) = hd_scaled_dims(
- self.monitor_data.width,
- self.monitor_data.height,
+ native_width,
+ native_height,
hd_capture_max_width(snapshot_max_width),
);
let (stream, frames) =
@@ -1147,6 +1197,47 @@ mod tests {
.block_on(list_monitors_cached())
}
+ #[test]
+ fn fallback_respects_width_budget_without_upscaling() {
+ for (cap, expected) in [
+ (0, (256, 144)),
+ (128, (128, 72)),
+ (192, (192, 108)),
+ (512, (256, 144)),
+ ] {
+ let image = cap_fallback_image(DynamicImage::new_rgba8(256, 144), cap);
+ assert_eq!((image.width(), image.height()), expected);
+ }
+ }
+
+ #[test]
+ fn capture_task_refreshes_for_scale_layout_and_backend_recovery() {
+ let standard = CaptureConfiguration {
+ logical: (0, 0, 1280, 720),
+ backing: (1280, 720),
+ primary: false,
+ sck: true,
+ };
+ let retina = CaptureConfiguration {
+ backing: (2560, 1440),
+ ..standard
+ };
+ let fallback = CaptureConfiguration {
+ sck: false,
+ ..standard
+ };
+ assert!(retina.should_replace(standard));
+ assert!(standard.should_replace(retina));
+ assert!(standard.should_replace(fallback));
+ assert!(!fallback.should_replace(standard));
+ assert!(!standard.should_replace(standard));
+ assert!(CaptureConfiguration {
+ logical: (-1280, 0, 1280, 720),
+ ..standard
+ }
+ .should_replace(standard));
+ }
+
#[test]
fn status_polling_never_discovers_monitors_on_a_cold_or_invalidated_cache() {
let _guard = lock_lookup_cache_tests();
diff --git a/docs/COVERAGE.md b/docs/COVERAGE.md
index d4cb345ed..199b2ea34 100644
--- a/docs/COVERAGE.md
+++ b/docs/COVERAGE.md
@@ -37,16 +37,16 @@ results and `cargo llvm-cov` data on top when judging release confidence.
### Core Engine
- Mapped suites: 37
-- Mapped Rust files: 401
-- Active test blocks: 3894
-- Ignored/manual test blocks: 186
-- Weighted coverage points: 3208.0
+- Mapped Rust files: 400
+- Active test blocks: 3896
+- Ignored/manual test blocks: 185
+- Weighted coverage points: 3209.0
| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| windows | 33 | 3731 | 168 | 3135.0 | 21 | 11 | 100% |
-| macos | 32 | 3774 | 147 | 3130.3 | 22 | 11 | 100% |
-| linux | 29 | 3309 | 142 | 2753.3 | 20 | 11 | 100% |
+| windows | 33 | 3733 | 167 | 3136.0 | 21 | 11 | 100% |
+| macos | 32 | 3776 | 146 | 3131.3 | 22 | 11 | 100% |
+| linux | 29 | 3311 | 142 | 2754.3 | 20 | 11 | 100% |
## Refresh
diff --git a/docs/coverage/CORE.md b/docs/coverage/CORE.md
index 15c0075b9..286730f8f 100644
--- a/docs/coverage/CORE.md
+++ b/docs/coverage/CORE.md
@@ -8,11 +8,11 @@ confidence, and criticality.
- Manifest: `docs/coverage/core-engine-map.json`
- Tracked crates: screenpipe-engine, screenpipe-db, screenpipe-sqlite-coordinator, screenpipe-audio, screenpipe-screen, screenpipe-a11y, screenpipe-fs
- Mapped suites: 37
-- Mapped Rust files: 401
-- Active test blocks: 3894
-- Ignored/manual test blocks: 186
-- Declared test blocks: 4080
-- Weighted coverage points: 3208.0
+- Mapped Rust files: 400
+- Active test blocks: 3896
+- Ignored/manual test blocks: 185
+- Declared test blocks: 4081
+- Weighted coverage points: 3209.0
Confidence weights: strong=1.0, partial=0.7, conditional=0.4, smoke=0.3.
Criticality weights: high=1.0, medium=0.7, low=0.4.
@@ -23,19 +23,19 @@ are explicitly enabled in a runtime lane.
| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| windows | 33 | 3731 | 168 | 3135.0 | 21 | 11 | 100% |
-| macos | 32 | 3774 | 147 | 3130.3 | 22 | 11 | 100% |
-| linux | 29 | 3309 | 142 | 2753.3 | 20 | 11 | 100% |
+| windows | 33 | 3733 | 167 | 3136.0 | 21 | 11 | 100% |
+| macos | 32 | 3776 | 146 | 3131.3 | 22 | 11 | 100% |
+| linux | 29 | 3311 | 142 | 2754.3 | 20 | 11 | 100% |
## Crate Summary
| Crate | Suites | Integration files | Source unit files | Active tests | Ignored tests | Weighted points | Flows |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| screenpipe-engine | 12 | 22 | 132 | 1863 | 54 | 1434.8 | 10 |
+| screenpipe-engine | 12 | 22 | 131 | 1863 | 53 | 1434.8 | 10 |
| screenpipe-db | 5 | 69 | 28 | 629 | 32 | 599.4 | 9 |
| screenpipe-sqlite-coordinator | 1 | 0 | 3 | 27 | 0 | 27.0 | 2 |
| screenpipe-audio | 8 | 29 | 53 | 695 | 53 | 606.9 | 5 |
-| screenpipe-screen | 6 | 9 | 19 | 276 | 9 | 245.4 | 4 |
+| screenpipe-screen | 6 | 9 | 19 | 278 | 9 | 246.4 | 4 |
| screenpipe-a11y | 4 | 2 | 34 | 401 | 38 | 291.5 | 3 |
| screenpipe-fs | 1 | 0 | 1 | 3 | 0 | 3.0 | 3 |
@@ -68,11 +68,11 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| configuration | 2 suites / 153 active / 3 ignored / 138.7 pts | 2 suites / 153 active / 3 ignored / 138.7 pts | 2 suites / 153 active / 3 ignored / 138.7 pts |
| database | 7 suites / 585 active / 28 ignored / 555.4 pts | 7 suites / 585 active / 28 ignored / 555.4 pts | 7 suites / 585 active / 28 ignored / 555.4 pts |
| db-search | 2 suites / 120 active / 9 ignored / 120.0 pts | 2 suites / 120 active / 9 ignored / 120.0 pts | 2 suites / 120 active / 9 ignored / 120.0 pts |
-| engine-lifecycle | 6 suites / 270 active / 2 ignored / 242.0 pts | 6 suites / 270 active / 2 ignored / 242.0 pts | 6 suites / 266 active / 9 ignored / 241.1 pts |
+| engine-lifecycle | 6 suites / 270 active / 1 ignored / 242.0 pts | 6 suites / 270 active / 1 ignored / 242.0 pts | 6 suites / 266 active / 9 ignored / 241.1 pts |
| local-api | 3 suites / 485 active / 12 ignored / 343.4 pts | 3 suites / 485 active / 12 ignored / 343.4 pts | 3 suites / 485 active / 12 ignored / 343.4 pts |
| meeting | 6 suites / 1757 active / 32 ignored / 1437.2 pts | 6 suites / 1757 active / 32 ignored / 1437.2 pts | 4 suites / 1403 active / 28 ignored / 1106.9 pts |
| ocr | 4 suites / 141 active / 7 ignored / 130.8 pts | 4 suites / 134 active / 7 ignored / 128.6 pts | 3 suites / 125 active / 6 ignored / 119.6 pts |
-| os-integration | 1 suites / 6 active / 1 ignored / 1.7 pts | 1 suites / 6 active / 1 ignored / 1.7 pts | - |
+| os-integration | 1 suites / 6 active / 0 ignored / 1.7 pts | 1 suites / 6 active / 0 ignored / 1.7 pts | - |
| performance | 13 suites / 1686 active / 83 ignored / 1488.5 pts | 14 suites / 1811 active / 91 ignored / 1538.5 pts | 13 suites / 1686 active / 83 ignored / 1488.5 pts |
| pipes | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts |
| privacy | 5 suites / 1013 active / 42 ignored / 816.8 pts | 5 suites / 1069 active / 21 ignored / 818.5 pts | 5 suites / 971 active / 14 ignored / 781.7 pts |
@@ -83,7 +83,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| timeline | 4 suites / 1244 active / 48 ignored / 1021.1 pts | 4 suites / 1244 active / 48 ignored / 1021.1 pts | 4 suites / 1244 active / 48 ignored / 1021.1 pts |
| transcription | 7 suites / 896 active / 53 ignored / 700.8 pts | 6 suites / 890 active / 53 ignored / 696.6 pts | 6 suites / 890 active / 53 ignored / 696.6 pts |
| ui-events | 4 suites / 828 active / 34 ignored / 627.7 pts | 3 suites / 759 active / 5 ignored / 579.4 pts | 3 suites / 759 active / 5 ignored / 579.4 pts |
-| vision-capture | 6 suites / 577 active / 32 ignored / 454.3 pts | 6 suites / 570 active / 32 ignored / 452.1 pts | 5 suites / 561 active / 31 ignored / 443.1 pts |
+| vision-capture | 6 suites / 579 active / 32 ignored / 455.3 pts | 6 suites / 572 active / 32 ignored / 453.1 pts | 5 suites / 563 active / 31 ignored / 444.1 pts |
## Critical Flow Matrix
@@ -140,7 +140,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| engine-capture-timeline | screenpipe-engine | windows, macos, linux | vision-capture, timeline, storage, performance | capture-ocr-pipeline, timeline-streaming, performance-liveness | high | partial | mixed | 25 | 307 | 26 | Covers capture trigger logic, frame/audio linking, hot cache, timeline refresh regressions, fragmented MP4 extraction, and HD-mode control. Several real-data tests are intentionally ignored by default. |
| engine-config-lifecycle | screenpipe-engine | windows, macos, linux | configuration, engine-lifecycle, performance | settings-to-engine-config, engine-health-lifecycle, performance-liveness | high | strong | mixed | 13 | 125 | 1 | Fast logic coverage for the config bridge, health-endpoint identity, tray health debounce, sleep/power policies, and queue backpressure. |
| engine-db-recovery-cli | screenpipe-engine | windows, macos, linux | database, engine-lifecycle | engine-health-lifecycle, performance-liveness | high | strong | unit | 1 | 33 | 0 | Exact DB/WAL/SHM working-copy preservation, rollback on archive failure, and restart repair for crashes during the multi-file generation swap. |
-| engine-focus-os | screenpipe-engine | windows, macos | engine-lifecycle, os-integration | engine-health-lifecycle, performance-liveness | medium | conditional | unit | 4 | 6 | 1 | Platform focus-tracker parsing/helpers. These files are cfg-gated and only execute on their target OS. |
+| engine-focus-os | screenpipe-engine | windows, macos | engine-lifecycle, os-integration | engine-health-lifecycle, performance-liveness | medium | conditional | unit | 3 | 6 | 0 | Platform focus-tracker parsing/helpers. These files are cfg-gated and only execute on their target OS. The separately invoked harness=false tests/native_multi_monitor.rs acceptance is documented in scripts/native-test-fixtures/macos/README.md and is not counted as an automatic Rust test block. |
| engine-linux-keep-awake | screenpipe-engine | linux | engine-lifecycle | engine-health-lifecycle | high | conditional | mixed | 1 | 2 | 8 | Existing isolated-process missing/stalled bus regressions plus ignored live logind inhibitor tests. Live tests require logind and explicit execution. |
| engine-local-api-search-integration | screenpipe-engine | windows, macos, linux | local-api, db-search | local-api-search | high | strong | integration | 1 | 13 | 5 | Active /search route test builds an audio-disabled router, seeds captured-screen-shaped OCR data into an in-memory DB, and asserts the HTTP response and pagination. |
| engine-meeting-privacy-sync | screenpipe-engine | windows, macos, linux | meeting, privacy, ui-events, pipes, sync | meeting-live-notes, privacy-and-redaction, accessibility-ui-events, performance-liveness | medium | strong | unit | 33 | 551 | 3 | Unit-heavy coverage for privacy filter policy, capture exclusions, UI recorder safety, pipes/live-view/structured-output helpers, sync helpers, and CLI parsing. Meeting detection moved to the engine-meeting-watcher suite. |
@@ -153,7 +153,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| screen-capture-windowing | screenpipe-screen | windows, macos, linux | vision-capture, timeline, performance, privacy | capture-ocr-pipeline, timeline-streaming, privacy-and-redaction, performance-liveness | high | strong | mixed | 14 | 193 | 0 | Window filtering, empty-window regressions, retry policy, URL timing, monitor cache, OCR cache, snapshots, and image comparison. |
| screen-custom-ocr | screenpipe-screen | windows, macos, linux | ocr | capture-ocr-pipeline | medium | conditional | manual | 1 | 0 | 2 | Custom OCR tests are ignored by default and only contribute when explicitly run. |
| screen-macos-ocr | screenpipe-screen | macos | ocr, vision-capture | capture-ocr-pipeline | high | strong | mixed | 2 | 9 | 1 | Apple Vision OCR source/unit coverage and fixture OCR assertions. |
-| screen-monitor-platform | screenpipe-screen | windows, macos, linux | vision-capture | capture-ocr-pipeline | medium | partial | unit | 5 | 40 | 5 | Per-OS monitor enumeration (Windows, macOS, Wayland/portal on Linux) and the persistent Windows.Graphics.Capture session. Each file is cfg-gated and only executes on its target OS. |
+| screen-monitor-platform | screenpipe-screen | windows, macos, linux | vision-capture | capture-ocr-pipeline | medium | partial | unit | 5 | 42 | 5 | Per-OS monitor enumeration (Windows, macOS, Wayland/portal on Linux) and the persistent Windows.Graphics.Capture session. Each file is cfg-gated and only executes on its target OS. |
| screen-windows-ocr | screenpipe-screen | windows | ocr, vision-capture | capture-ocr-pipeline | high | partial | integration | 3 | 16 | 1 | Windows OCR fixture and STA-pool regression tests, portable bounded-worker tests, plus an ignored continuous-capture probe that requires a live desktop. Native OCR tests require an installed English recognizer. |
| sqlite-coordinator-durable-quarantine | screenpipe-sqlite-coordinator | windows, macos, linux | database, engine-lifecycle | engine-health-lifecycle, performance-liveness | high | strong | unit | 3 | 27 | 0 | Process-wide single-writer gates and manager ownership, SQLite runtime pinning, pending incident markers, fresh integrity verification, confirmed-damage quarantine, file-identity guarded admission, and crash-journal recovery. |
@@ -437,7 +437,6 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| engine-meeting-watcher | screenpipe-engine | src/meeting_watcher/ui_scan/macos.rs | source | 2 | 2 | 4 |
| engine-meeting-watcher | screenpipe-engine | src/meeting_watcher/ui_scan/tests.rs | source | 137 | 0 | 137 |
| engine-meeting-watcher | screenpipe-engine | src/meeting_watcher/ui_scan/windows.rs | source | 0 | 1 | 1 |
-| engine-focus-os | screenpipe-engine | src/multi_monitor_vm_test.rs | source | 0 | 1 | 1 |
| engine-config-lifecycle | screenpipe-engine | src/permission_monitor.rs | source | 1 | 0 | 1 |
| engine-telemetry-observability | screenpipe-engine | src/piggyback_telemetry.rs | source | 1 | 0 | 1 |
| engine-workflows | screenpipe-engine | src/pipe_permissions_middleware.rs | source | 6 | 0 | 6 |
@@ -541,7 +540,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| screen-capture-windowing | screenpipe-screen | src/monitor.rs | source | 5 | 0 | 5 |
| screen-monitor-platform | screenpipe-screen | src/monitor/linux_portal.rs | source | 5 | 0 | 5 |
| screen-monitor-platform | screenpipe-screen | src/monitor/linux_wayland.rs | source | 5 | 0 | 5 |
-| screen-monitor-platform | screenpipe-screen | src/monitor/macos.rs | source | 20 | 2 | 22 |
+| screen-monitor-platform | screenpipe-screen | src/monitor/macos.rs | source | 22 | 2 | 24 |
| screen-monitor-platform | screenpipe-screen | src/monitor/windows.rs | source | 2 | 1 | 3 |
| screen-capture-windowing | screenpipe-screen | src/ocr_cache.rs | source | 15 | 0 | 15 |
| screen-windows-ocr | screenpipe-screen | src/ocr_worker.rs | source | 3 | 0 | 3 |
diff --git a/docs/coverage/core-engine-map.json b/docs/coverage/core-engine-map.json
index 5d4c4c307..56f90cb2c 100644
--- a/docs/coverage/core-engine-map.json
+++ b/docs/coverage/core-engine-map.json
@@ -431,7 +431,6 @@
"crate": "screenpipe-engine",
"files": [
"src/focus_tracker/darwin.rs",
- "src/multi_monitor_vm_test.rs",
"src/focus_tracker/windows.rs",
"src/process_priority.rs"
],
@@ -450,7 +449,7 @@
"criticality": "medium",
"confidence": "conditional",
"kind": "unit",
- "notes": "Platform focus-tracker parsing/helpers. These files are cfg-gated and only execute on their target OS."
+ "notes": "Platform focus-tracker parsing/helpers. These files are cfg-gated and only execute on their target OS. The separately invoked harness=false tests/native_multi_monitor.rs acceptance is documented in scripts/native-test-fixtures/macos/README.md and is not counted as an automatic Rust test block."
},
{
"id": "engine-meeting-privacy-sync",
diff --git a/packages/sdk/Cargo.lock b/packages/sdk/Cargo.lock
index cb729b730..631df09cd 100644
--- a/packages/sdk/Cargo.lock
+++ b/packages/sdk/Cargo.lock
@@ -6814,7 +6814,7 @@ dependencies = [
[[package]]
name = "sck-rs"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/sck-rs?rev=60610e8c970af1ea9d47e274c1a48182e1da5bd1#60610e8c970af1ea9d47e274c1a48182e1da5bd1"
+source = "git+https://github.com/screenpipe/sck-rs?rev=62d79abed212015eb9beaa03138002807f61f59a#62d79abed212015eb9beaa03138002807f61f59a"
dependencies = [
"cidre 0.16.1 (git+https://github.com/yury/cidre.git?rev=9c20f5ee5abaad4598843a33e13d6e48822d1f30)",
"image",
diff --git a/packages/sdk/examples/tauri-app/src-tauri/Cargo.lock b/packages/sdk/examples/tauri-app/src-tauri/Cargo.lock
index fef390ed1..4efe8af37 100644
--- a/packages/sdk/examples/tauri-app/src-tauri/Cargo.lock
+++ b/packages/sdk/examples/tauri-app/src-tauri/Cargo.lock
@@ -6940,7 +6940,7 @@ dependencies = [
[[package]]
name = "sck-rs"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/sck-rs?rev=60610e8c970af1ea9d47e274c1a48182e1da5bd1#60610e8c970af1ea9d47e274c1a48182e1da5bd1"
+source = "git+https://github.com/screenpipe/sck-rs?rev=62d79abed212015eb9beaa03138002807f61f59a#62d79abed212015eb9beaa03138002807f61f59a"
dependencies = [
"cidre 0.16.1 (git+https://github.com/yury/cidre.git?rev=9c20f5ee5abaad4598843a33e13d6e48822d1f30)",
"image",
diff --git a/scripts/native-test-fixtures/macos/README.md b/scripts/native-test-fixtures/macos/README.md
index de7508340..e445d5147 100644
--- a/scripts/native-test-fixtures/macos/README.md
+++ b/scripts/native-test-fixtures/macos/README.md
@@ -14,7 +14,7 @@ clang++ -fobjc-arc -framework Cocoa -framework CoreGraphics \
-framework ApplicationServices -mmacosx-version-min=15.0 \
scripts/native-test-fixtures/macos/display-fixture.mm \
-o display-fixture
-cargo test -p screenpipe-engine --lib --no-run
+cargo test -p screenpipe-engine --test native_multi_monitor --no-run
cargo test -p screenpipe-a11y --lib --no-run
```
@@ -26,13 +26,20 @@ using the disposable VM's test-permission setup. No host permission changes.
SCREENPIPE_ISOLATED_VM_TEST=1 \
SCREENPIPE_DISPLAY_FIXTURE=/absolute/path/display-fixture \
SCREENPIPE_VM_EVIDENCE_DIR=/absolute/path/frames \
-./engine-tests --ignored native_multi_monitor_focus_capture_gap_and_hotplug --nocapture
+./native_multi_monitor
```
+The manual executable uses the production standalone main-thread AppKit loop,
+including immediate completion, error and panic cleanup checks. It skips without
+the explicit VM opt-in and is not a new CI job.
+
The engine test asserts actual display geometry (right, negative-left, above,
offset), cursor positions, production tracker/controller attribution, distinct
red/blue capture content, stale-topology grace/recovery, focused-secondary removal,
-Retina backing scale and display cleanup. It reports an OS-clamped literal
+Retina backing scale, native-resolution pixels, 1280/1920 capture caps, actual
+1920x1080 HD frames, native CoreGraphics fallback width caps, mixed-DPI focus boundaries, same-ID 1x/2x mode changes,
+and display cleanup. The helper accepts `mode-standard` and `mode-retina` to
+change backing scale without replacing the display. It reports an OS-clamped literal
cursor-gap attempt as unsupported, never as a passing gap reproduction. The
stale-topology case rearranges the actual display while intentionally withholding
discovery, waits through the real grace, and verifies recovery after fresh
@@ -62,3 +69,17 @@ Stop and reap the fixture process and verify only the base display remains.
Destroy the disposable guest and task-owned tunnels after collecting evidence.
These tests do not establish physical cable/dock behavior, persisted-frame app
attribution, packaged UI warnings or the customer's exact hardware incident.
+
+For the actual standalone recorder, use a fresh output directory and the same VM
+permissions. This verifies the automatic monitor watcher, persisted snapshots at
+1x/2x, the live health response, SQLite integrity and SIGINT shutdown:
+
+```sh
+SCREENPIPE_ISOLATED_VM_TEST=1 python3 recorder-acceptance.py \
+ --engine /absolute/path/screenpipe --fixture /absolute/path/display-fixture \
+ --output /absolute/path/new-cli-evidence
+```
+
+The recorder disables audio and telemetry. This is a screen-capture test; it does
+not validate audio, ffmpeg encoding or packaged desktop UI. Its database is read
+only after the recorder exits, respecting the process-exclusive macOS VFS.
diff --git a/scripts/native-test-fixtures/macos/display-fixture.mm b/scripts/native-test-fixtures/macos/display-fixture.mm
index 77e314376..47f86e3d0 100644
--- a/scripts/native-test-fixtures/macos/display-fixture.mm
+++ b/scripts/native-test-fixtures/macos/display-fixture.mm
@@ -86,7 +86,23 @@
// BSD-3-Clause: https://chromium.googlesource.com/chromium/src/+/HEAD/LICENSE
static CGVirtualDisplay *extra;
static NSMutableDictionary<NSNumber *, NSWindow *> *markers;
-static unsigned serial = 20261017;
+static unsigned serial;
+// Close the marker before unplug: WindowServer otherwise relocates the blue
+// window onto the primary, contaminating its real capture during teardown.
+static void removeDisplay(void) {
+ if (extra) {
+ NSNumber *key = @(extra.displayID);
+ [markers[key] close];
+ [markers removeObjectForKey:key];
+ extra = nil;
+ }
+}
+static void setMode(BOOL retina) {
+ CGVirtualDisplaySettings *settings = [CGVirtualDisplaySettings new];
+ settings.hiDPI = retina;
+ settings.modes = @[[[CGVirtualDisplayMode alloc] initWithWidth:1280 height:720 refreshRate:60]];
+ if (![extra applySettings:settings]) exit(3);
+}
static void addDisplay(BOOL retina) {
CGVirtualDisplayDescriptor *d = [CGVirtualDisplayDescriptor new];
d.name = @"Screenpipe disposable acceptance display";
@@ -98,13 +114,10 @@ static void addDisplay(BOOL retina) {
d.queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0);
extra = [[CGVirtualDisplay alloc] initWithDescriptor:d];
if (!extra) { fprintf(stderr,"virtual display creation failed\n"); exit(2); }
- CGVirtualDisplaySettings *settings = [CGVirtualDisplaySettings new];
- settings.hiDPI = retina;
- settings.modes = @[[[CGVirtualDisplayMode alloc] initWithWidth:1280 height:720 refreshRate:60]];
- if (![extra applySettings:settings]) exit(3);
+ setMode(retina);
}
static void settle(void) {
- NSDate *end=[NSDate dateWithTimeIntervalSinceNow:0.6];
+ NSDate *end=[NSDate dateWithTimeIntervalSinceNow:2.0];
while ([end timeIntervalSinceNow]>0) [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
}
static void report(void) {
@@ -126,7 +139,7 @@ static void report(void) {
}
[marker setFrame:NSMakeRect(r.origin.x+20,mainHeight-r.origin.y-220,200,200) display:YES];[marker orderFrontRegardless];
CGDisplayModeRef mode=CGDisplayCopyDisplayMode(ids[i]);
- [items addObject:@{@"id":@(ids[i]),@"x":@(r.origin.x),@"y":@(r.origin.y),@"w":@(r.size.width),@"h":@(r.size.height),@"pixels_w":@(CGDisplayModeGetPixelWidth(mode)),@"pixels_h":@(CGDisplayModeGetPixelHeight(mode)),@"main":@(CGDisplayIsMain(ids[i])),@"mirror":@(CGDisplayMirrorsDisplay(ids[i]))}];
+ [items addObject:@{@"id":@(ids[i]),@"x":@(r.origin.x),@"y":@(r.origin.y),@"w":@(r.size.width),@"h":@(r.size.height),@"mode_w":@(CGDisplayModeGetWidth(mode)),@"mode_h":@(CGDisplayModeGetHeight(mode)),@"pixels_w":@(CGDisplayModeGetPixelWidth(mode)),@"pixels_h":@(CGDisplayModeGetPixelHeight(mode)),@"main":@(CGDisplayIsMain(ids[i])),@"mirror":@(CGDisplayMirrorsDisplay(ids[i]))}];
CGDisplayModeRelease(mode);
}
for(NSNumber *key in [markers.allKeys copy]) if(![live containsObject:key]) { [markers[key] close];[markers removeObjectForKey:key]; }
@@ -152,6 +165,7 @@ static int placeWindow(pid_t pid,double x,double y) {
int main(int argc,char **argv) { @autoreleasepool {
const char *opt=getenv("SCREENPIPE_ISOLATED_VM_TEST");
if (!opt || strcmp(opt,"1")!=0) return 10;
+ serial = arc4random_uniform(UINT32_MAX - 100) + 1;
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
if(argc==2 && strcmp(argv[1],"--list-only")==0) {
@@ -172,11 +186,13 @@ int main(int argc,char **argv) { @autoreleasepool {
} else if(sscanf(line,"warp %lf %lf",&x,&y)==2) {
CGError e=CGWarpMouseCursorPosition(CGPointMake(x,y));
if(e) fprintf(stderr,"warp error %d\n",e);
- } else if(strncmp(line,"remove",6)==0) { extra=nil;
- } else if(strncmp(line,"add-retina",10)==0) { extra=nil;settle();addDisplay(YES);
- } else if(strncmp(line,"add",3)==0) { extra=nil;settle();addDisplay(NO);
+ } else if(strncmp(line,"mode-retina",11)==0) { setMode(YES);
+ } else if(strncmp(line,"mode-standard",13)==0) { setMode(NO);
+ } else if(strncmp(line,"remove",6)==0) { removeDisplay();
+ } else if(strncmp(line,"add-retina",10)==0) { removeDisplay();settle();addDisplay(YES);
+ } else if(strncmp(line,"add",3)==0) { removeDisplay();settle();addDisplay(NO);
} else if(strncmp(line,"quit",4)==0) { break; }
settle();report();
}}
- free(line);extra=nil;return 0;
+ free(line);removeDisplay();return 0;
}}
diff --git a/scripts/native-test-fixtures/macos/recorder-acceptance.py b/scripts/native-test-fixtures/macos/recorder-acceptance.py
new file mode 100644
index 000000000..861fdfd50
--- /dev/null
+++ b/scripts/native-test-fixtures/macos/recorder-acceptance.py
@@ -0,0 +1,164 @@
+#!/usr/bin/env python3
+# screenpipe — AI that knows everything you've seen, said, or heard
+# https://screenpipe.com
+"""Verify real CLI capture, automatic topology refresh, persistence and shutdown.
+
+Run only in a disposable logged-in macOS VM with capture permissions already set.
+The output directory must be new. No permission or account configuration is changed.
+"""
+import argparse
+import json
+import os
+from pathlib import Path
+import select
+import signal
+import sqlite3
+import subprocess
+import time
+import urllib.request
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--engine", required=True)
+ parser.add_argument("--fixture", required=True)
+ parser.add_argument("--output", type=Path, required=True)
+ parser.add_argument("--port", type=int, default=3049)
+ args = parser.parse_args()
+ if os.environ.get("SCREENPIPE_ISOLATED_VM_TEST") != "1":
+ parser.error("requires SCREENPIPE_ISOLATED_VM_TEST=1 in a disposable VM")
+ output = args.output.resolve()
+ output.mkdir(parents=True, exist_ok=False)
+ data = output / "recorder-data"
+ data.mkdir()
+ env = dict(os.environ, RUST_LOG="screenpipe_engine=info,screenpipe_screen=debug,sck_rs=debug")
+ fixture = recorder = None
+ snapshots = []
+ with (output / "recorder.log").open("w") as log:
+ try:
+ fixture = subprocess.Popen(
+ [args.fixture], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ text=True, env=env,
+ )
+
+ def topology(command=None):
+ if command:
+ fixture.stdin.write(command + "\n")
+ fixture.stdin.flush()
+ assert select.select([fixture.stdout], [], [], 15)[0], "fixture timed out"
+ value = json.loads(fixture.stdout.readline())
+ print("TOPOLOGY", command, json.dumps(value), flush=True)
+ return value
+
+ initial = topology()
+ command = [
+ args.engine, "record", "--disable-audio", "--disable-telemetry",
+ "--data-dir", str(data), "--port", str(args.port),
+ "--video-quality", "max", "--capture-max-width", "0",
+ "--use-pii-removal=false", "--idle-capture-interval-ms", "1000",
+ "--recording-detail", "more_detail",
+ ]
+ recorder = subprocess.Popen(command, stdout=log, stderr=subprocess.STDOUT, env=env)
+ print("CLI_PID", recorder.pid, "ARGS", command, flush=True)
+
+ def boundary():
+ return int(time.time() * 1000)
+
+ def wait_frame(label, display, dimensions, after):
+ # The recorder uses an exclusive SQLite VFS. Inspect its fsynced
+ # images while live, then verify all DB references after shutdown.
+ deadline = time.monotonic() + 100
+ seen = set()
+ while time.monotonic() < deadline:
+ assert recorder.poll() is None, f"recorder exited {recorder.returncode}"
+ candidates = sorted(
+ (path for path in data.rglob(f"*_m{display}.jpg")
+ if int(path.name.split("_")[0]) > after), reverse=True,
+ )[:12]
+ for path in candidates:
+ if path in seen:
+ continue
+ # Only remember a candidate once the writer closed it.
+ probe = subprocess.run(
+ ["/usr/bin/sips", "-g", "pixelWidth", "-g", "pixelHeight", str(path)],
+ text=True, capture_output=True, timeout=10,
+ )
+ if probe.returncode:
+ continue
+ seen.add(path)
+ actual = tuple(int(line.split(":")[1]) for line in probe.stdout.splitlines()
+ if "pixelWidth:" in line or "pixelHeight:" in line)
+ print("FRAME", label, str(path), actual, flush=True)
+ if actual == dimensions:
+ snapshots.append({"phase": label, "path": str(path), "dimensions": actual})
+ print("PASS", label, flush=True)
+ return
+ time.sleep(1)
+ raise AssertionError(f"no {dimensions} frame for {label}")
+
+ primary = next(d for d in initial["displays"] if d["main"])
+ width = int(primary["w"])
+ topology(f"layout {width} 0")
+ topology(f"warp {width + 100} 100")
+ wait_frame("initial-1x", initial["extra"], (1280, 720), 0)
+ after = boundary()
+ topology("remove")
+ topology("warp 100 100")
+ wait_frame("hot-unplug-primary", primary["id"], (width, int(primary["h"])), after)
+ after = boundary()
+ retina = topology("add-retina")
+ secondary = retina["extra"]
+ topology(f"layout {width} 0")
+ topology(f"warp {width + 100} 100")
+ wait_frame("hot-add-retina", secondary, (2560, 1440), after)
+ for mode, size in [("mode-standard", (1280, 720)), ("mode-retina", (2560, 1440))]:
+ after = boundary()
+ changed = topology(mode)
+ assert changed["extra"] == secondary, "mode switch replaced display ID"
+ topology(f"warp {width + 100} 100")
+ wait_frame(mode, secondary, size, after)
+ with urllib.request.urlopen(f"http://127.0.0.1:{args.port}/health", timeout=10) as response:
+ health = json.load(response)
+ assert health["frame_status"] == "ok", health
+ print("HEALTH", health["status"], health["frame_status"], flush=True)
+ recorder.send_signal(signal.SIGINT)
+ code = recorder.wait(timeout=40)
+ assert code == 0, f"unclean recorder shutdown: {code}"
+ print("CLI_EXIT", code, flush=True)
+ # New installs use a versioned hybrid index; existing installs may
+ # still use the legacy db.sqlite. Follow the active descriptor.
+ descriptor = data / "storage.json"
+ database = data / "db.sqlite"
+ if descriptor.exists():
+ database = (data / json.loads(descriptor.read_text())["index"]).resolve()
+ assert data in database.parents, "index escaped fixture data directory"
+ wal = Path(str(database) + "-wal")
+ assert not wal.exists() or wal.stat().st_size == 0, "shutdown left uncheckpointed WAL"
+ # With the process gone and no WAL, immutable avoids macOS SQLite
+ # trying to create shared-memory sidecars through a read-only handle.
+ with sqlite3.connect(f"file:{database}?mode=ro&immutable=1", uri=True) as db:
+ assert db.execute("pragma integrity_check").fetchone()[0] == "ok"
+ for snapshot in snapshots:
+ count = db.execute("select count(*) from frames where snapshot_path=?",
+ (snapshot["path"],)).fetchone()[0]
+ assert count > 0, f"snapshot lacks durable frame row: {snapshot}"
+ rows = db.execute("select count(*) from frames").fetchone()[0]
+ result = {"status": "passed", "snapshots": snapshots, "durable_rows": rows,
+ "integrity": "ok", "exit_code": code, "health": health["status"]}
+ (output / "result.json").write_text(json.dumps(result, indent=2) + "\n")
+ print("PASS actual CLI record, automatic hotplug/scale refresh, five durable phase snapshots, integrity and SIGINT", flush=True)
+ finally:
+ if recorder and recorder.poll() is None:
+ recorder.send_signal(signal.SIGINT)
+ try:
+ recorder.wait(timeout=15)
+ except subprocess.TimeoutExpired:
+ recorder.kill()
+ recorder.wait()
+ if fixture and fixture.poll() is None:
+ fixture.kill()
+ fixture.wait()
+
+
+if __name__ == "__main__":
+ main()