Repository navigation
Description
Context
Checked at aadbe7e; main at 6160fe6 has the same internal/platform/macos/testsurface.go and internal/platform/apple/decor.go.
On the macOS target, testSurface.Screenshot draws the surface's view with bitmapImageRepForCachingDisplayInRect: and cacheDisplayInRect:toBitmapImageRep: (internal/platform/macos/testsurface.go:434-456), and docs/architecture/testing.md:47 lists cacheDisplayInRect: as the macOS screenshot. That AppKit path redraws the view hierarchy into a bitmap; it does not capture what Core Animation composites for the window. Much of what NSGo's Apple backend draws lives only in the layer tree, so the image differs from the window in ways a test cannot tell from a real regression. A probe test on macOS showed:
- Shadows are missing entirely.
layoutShadowsgives each shadow aCALayerwithshadowColor,shadowOpacity,shadowRadiusandshadowOffset(internal/platform/apple/decor.go:489,:531-536). None of them show, including a spread shadow with zero blur, so halos and focus rings drawn as shadows vanish too. - Per-corner radii ignore
maskedCorners.setCornerssets onecornerRadiusand limits it withmaskedCorners(internal/platform/apple/decor.go:330-340). In the image every corner is rounded, so a list whose first row rounds only its top corners and its last row only its bottom ones looks like separate cards. - Corners are not antialiased. 6-8 pt circles come out as rounded squares and 36 pt circles have jagged edges.
- Core Animation keyframes are not captured. A pulse or a looping animation shows its model (resting) value, not the frame on screen.
- Layer filters draw differently. A glow made with
CALayer.filtersfromlayoutFilters(internal/platform/apple/decor.go:801-835) came out hard-edged. - A backdrop blur draws as flat grey, not the blurred content behind it (the
NSVisualEffectViewfromsetBackdrop,internal/platform/macos/material.go:153). - No caret in a focused field.
#184 is about target tests checking the model instead of the backend; #119 gave tests the image (App.CapturePNG / App.Capture on main, nsgotest/target.go:440-461). This issue is about the macOS image not being what the window shows, which matters more now that tests can compare its pixels.
Why it matters
Screenshot galleries are how an app checks its look across themes on a real backend: shadows, rounded groups, status dots, focus halos, frosted bars and pulsing indicators are exactly the parts a model check cannot see. With the current capture they are absent or wrong in every macOS screenshot, so a gallery cannot verify them, and an app that compares against design mockups chases differences that are not on screen (or rewrites a shadow as a bitmap just to make it show up in the test). The other targets do not have the same gap to the same degree: the web uses Page.captureScreenshot of the composited page.
Proposal
Capture the composited window rather than redraw the view:
- Prefer a window capture of the test app's own window:
CGWindowListCreateImagewith the window's number andkCGWindowImageBoundsIgnoreFraming | kCGWindowImageBestResolution(deprecated since macOS 14 but still callable), or ScreenCaptureKit'sSCScreenshotManageron macOS 14 and later. Either one sees shadows, masks, filters, backdrops, the presentation layer of running animations and the caret. Crop to the surface's view frame so the image keeps today's bounds. - If a capture method needs the Screen Recording permission on the test machine, fall back to
cacheDisplayInRect:without it and say so once in the test output, so a run never silently compares the wrong pixels. - Until then, list in
docs/architecture/testing.mdwhat the macOS screenshot leaves out.
Acceptance
- On
nsgo test -target macos, a view with aBoxShadow(blurred, and spread with zero blur), a view rounded on two corners only, a 6 pt round dot, and a focused input show the shadow, the two square corners, an antialiased dot and the caret inCapture. - A view under a looping keyframe animation is captured at its on-screen frame.
- A backdrop-blurred view shows the content behind it.
-
testing.mdsays how the macOS screenshot is taken and what, if anything, it still leaves out.
Activity
houko commentedon Nov 15, 2026
One more difference for the list: the PNG carries the window's colour space, not sRGB.
ScreenshottakesbitmapImageRepForCachingDisplayInRect:and writes it withrepresentationUsingType:properties:(internal/platform/macos/testsurface.go:439-450at aadbe7e), so on a Mac with a P3 display the file is tagged Display P3 (sips -g profileprintsprofile: Display P3) and its pixel values are P3 values. A colour the app sets as sRGB#2B7766reads back as about#417567.That makes screenshots differ by the machine that took them, and any comparison that reads raw pixel values (golden images, colour checks, diffing against a reference rendered elsewhere) sees colours that look desaturated even though the app draws them correctly. Converting the bitmap to sRGB before encoding (
bitmapImageRepByConvertingToColorSpace:renderingIntent:withNSColorSpace.sRGBColorSpace), or rendering into an sRGB bitmap in the first place, would make screenshots reproducible across displays.houko commentedon Nov 16, 2026
Another difference in these screenshots: a fill drawn with the layer's
cornerRadius(internal/platform/apple/decor.go:406,setCorners) comes out with a visibly smaller radius than set, while a stroke with the same radius drawn as aCAShapeLayerpath (decor.go:733,strokeShape) comes out right.A 28pt-high filled button with corner radius 7 measures about 4.5pt of rounding in the screenshot, without antialiasing; an outlined control next to it with the same radius shows the full 7pt, antialiased. Where a control has both a fill and a stroke, the fill's corners poke out past the stroke. In a real window Core Animation draws both at 7pt, so this is the capture path again, not the app.
houko commentedon Nov 16, 2026
Another case this blocks: Kando (github.com/yldm-tech/kando) has a library test that should check the hero card's shadow spreads past its sides by reading the captured pixels on
-target macos. WithApp.Capture()the pixels around any view withStyle.Shadowsare the plain page colour; a minimal check (a white page, a dark 200x80 view withShadows: {Offset Y 12, Blur 32, RGBA(0, 0.5)}) shows no shadow at all. The test stays a layout check until captures include layer shadows.test: point the hero shadow check at nsgo-dev/nsgo#311
test: render the screenshot scenes under nsgo test -target (#131)
houko commentedon Nov 20, 2026
Implemented in PR #1005.
The macOS screenshot path now converts both WindowServer composites and the AppKit fallback bitmap to sRGB before PNG encoding, keeping pixel comparisons stable on Display P3 machines. Existing composited capture still preserves Core Animation effects when WindowServer provides the image, and the fallback remains logged once when the window is unavailable.
Validation:
go tool nsgo check -target macos -jobs 1passed for macOS arm64 and x86_64.go tool nsgo test -target macos -run '^TestMountIgnoresCommandsForMissingViews$' ./internal/platform/macospassed.