Repository navigation
Capture a macOS harness window offscreen, without Screen Recording (#506) - #516
Merged
Merged
Conversation
) `shot`, `window` and every pixel assertion were Windows-only: the harness photographs the window from outside with `PrintWindow`. On macOS it cannot. Since #511 a harness window is never on screen, and reading another process's pixels needs Screen Recording permission, which a test must not ask for. So on macOS the app now takes the picture itself. The `capture` verb renders the last drawn frame to an offscreen texture with gpui's `Window::render_to_image`, writes the raw RGBA to <sandbox>/suite/capture/last.rgba, and replies with the path, size, scale, frame and `content_origin`. `uiharness` reads the file and from then on it is an ordinary `Capture`: the origin is computed by the same `screen_rect` that `rect` answers with, so the existing crop — a region's rect minus the capture's origin — lands on the right pixels unchanged, and every border probe runs exactly as on Windows. The pixels travel beside the control channel rather than through it; a full window is megabytes of RGBA. That method only exists behind gpui's test-support, so it needs a build made for it: the new `harness-capture` feature. Two things about it are not obvious and both are load-bearing: - It forwards to `gpui_platform/test-support`, not `gpui/test-support`. The macOS implementation is gated on `gpui_macos`'s own feature, so enabling only gpui's builds cleanly and then answers every capture with "not implemented for this platform". - It is a compile error off macOS. test-support also makes gpui draw every dirty window as it flushes effects, without presenting; on Windows that would let a frame wait be satisfied by a frame that never reached the screen, and `PrintWindow` would photograph the one before it.⚠️ So a macOS pixel case tests a test-support build, whose draw scheduling differs from the shipped app's, and a render of gpui's scene rather than what a compositor showed — the native window buttons are absent, so `window` is content only where `PrintWindow` includes the frame. Never ship the feature. A default build answers `capture` with an error naming the feature, rather than handing back a blank picture. Measured on macOS 27 (M1) against the pinned gpui, through the real runner: the unmodified `sheet-selection.uit` passes all five cases, including its three border assertions (solid teal, dashed teal, solid #2f6fdb) with the thresholds tuned on Windows left untouched. The window server reports the window as never on screen and the frontmost app never changed. The instance exits 0 with nothing on stderr, so leak detection raised nothing at quit. Cost of the feature: binary 21,702,768 -> 22,137,088 bytes (+2%), twelve more crates (proptest and its helpers), 252 s for a clean build into its own target directory. Cargo.lock only gains packages; the gpui pin is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qSpykxfaLiQSDxjsqbQUm
Owner
Author
|
Windows review of 3decb6a:
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #506: pixel capture on macOS. With this,
shot,windowand every pixel assertion work for a macOS harness instance, without Screen Recording permission and without the window ever being on screen. Windows is untouched.Why the app has to take the picture
On Windows the harness photographs the window from outside with
PrintWindow. On macOS it cannot. Since #511 a harness window is never on screen, and reading another process's pixels needs Screen Recording, which a test must not ask for.So on macOS the app takes the picture itself. The new
captureverb renders the last drawn frame to an offscreen texture with gpui'sWindow::render_to_image, writes raw RGBA to<sandbox>/suite/capture/last.rgba, and replies:{"path": "...", "width": 1180, "height": 800, "scale": 1, "frame": 8, "content_origin": {"x": 370, "y": 140}}uiharnessreads the file, and from then on it is an ordinaryCapture.content_originis computed by the samescreen_rectthatrectanswers with, so the existing crop (a region's rect minus the capture's origin) lands on the right pixels unchanged, and every border probe runs exactly as on Windows. A unit test pins that invariant on fractional origins, a Retina scale, and a display left of the main one. The pixels travel beside the control channel rather than through it, because a full window is megabytes of RGBA.Driver::captureis the single seam: macOS calls the verb, and everything else still callscapture_pid.The
harness-capturefeaturerender_to_imageonly exists behind gpui's test-support, so it needs a build made for it:Two details are load-bearing. Both were checked against the pinned gpui (8276687), not GitHub:
gpui_platform/test-support, notgpui/test-support. The macOS implementation is gated ongpui_macos's own feature. Enabling only gpui's builds cleanly and then answers every capture with "render_to_image not implemented for this platform".compile_error!off macOS. test-support also makes gpui draw every dirty window as it flushes effects, without presenting. On Windows that would let a frame wait be satisfied by a frame that never reached the screen, andPrintWindowwould photograph the one before it.A default build answers
capturewith an error naming the feature, not a blank picture:The driver also refuses a blank render, a pixel file whose size does not match the stated dimensions, and a reply missing a field. A blank image reaching a probe would read "no border" and pass.
windowis content only wherePrintWindowincludes the frame.Proof: macOS 27.0, M1, through the real runner
The unmodified
uiharness/cases/sheet-selection.uit, a case that passes on Windows today. Thresholds tuned on Windows were left untouched:All three border assertions pass. During the run the window server reported the window as
onscreen=nil, and the frontmost app never changed (lsappinfo, no permission prompt). The instance exits 0 with an empty stderr, so leak detection raised nothing at quit.The whole window, from a window that was never on screen:
The crops the assertions read:
The images live on the
evidence/issue-506-macos-capturebranch, which holds only these PNGs and is not for merging. Delete it after merge.Cost of the feature
harness-captureThe twelve extra crates are
proptestand its helpers.Cargo.lockonly gains packages: four small crates get a second version alongside the first, and the gpui pin is unchanged. No fork, patch or re-pin. CI is untouched.Checks
New tests: five for the driver's reply parsing and refusals, and three for the app side (capture path inside the sandbox, the crop invariant, and the refusal message).
For review on Windows
cargo build --manifest-path suite/Cargo.toml --features harness-capturemust fail with the macOS-onlycompile_error!. I cannot observe that from a Mac.main, sinceDriver::capturestill callscapture_pidthere.Merging
The user told the reviewing session directly to merge in autopilot after review and green CI ("no, merge by yourself"). The Windows reviewer will merge.
🤖 Generated with Claude Code
https://claude.ai/code/session_018qSpykxfaLiQSDxjsqbQUm