Skip to content

Let TestAppContext render with a real text system, renderer and scale - #11

Open
francois-unity wants to merge 1 commit into
unity/a11y-automationfrom
unity/HUB-8114-configurable-test-platform
Open

francois-unity wants to merge 1 commit into
unity/a11y-automationfrom
unity/HUB-8114-configurable-test-platform

Conversation

@francois-unity

@francois-unity francois-unity commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Adds TestAppContext::with_platform, which takes a text system, an asset source, a headless renderer factory and a scale factor, so a TestAppContext window renders to pixels through Window::render_to_image the way the app draws it. build, and with it #[gpui::test], keeps the stub text system, no renderer, no assets and a scale of 2.

Why: the native Unity Hub’s visual regression suite renders seeded scenes from its headless harness, which is built on TestAppContext and VisualTestContext (HUB-8114, for HUB-8065). build hardcodes TestPlatform::new: the stub TestTextSystem paints no glyphs, there is no renderer, and the empty AssetRegistry drops svg() icons. TestWindow::scale_factor is the constant 2. HeadlessAppContext has that configuration but isn’t a TestAppContext; it stays as it is.

  • TestPlatform keeps a scale factor (2 by default) and hands it to each TestWindow, whose scale_factor() reads it, resizes included.
  • gpui_platform::current_headless_renderer() returns WGPU’s headless renderer on Linux, FreeBSD and Windows under test-support, through an optional gpui_wgpu dependency that Linux already builds for its windows. Like Metal’s without a device, it panics without a GPU adapter; lavapipe or WARP is enough. Under bench-support alone it still returns None there.
  • CI runs the new rendering test on all three platforms.

How to test

  • cargo +1.98.1 test -p gpui-ce --lib -- app::test_context: three new tests. With a recording renderer, a with_platform window at scale 1.5 reports that scale, renders and reads back 300×150 for 200×100, keeps the scale through a resize, and loads its assets. build still gives scale 2, no glyph sprites and no assets, and render_to_image refuses. A zero scale panics.
  • GPUI_RUN_RENDERING_TESTS=1 cargo +1.98.1 test -p gpui_ce_platform --features test-support --test test_app_context_render: IBM Plex through Parley with current_headless_renderer() at scales 1 and 1.5, checking glyph sprites, the image size, the background colour and the ink. Green with Metal on macOS; CI runs it with WGPU on Linux and Windows.
  • cargo +1.98.1 test -p gpui-ce --features test-support, -p gpui_ce_elements -p gpui_ce_parley -p gpui_ce_macos -p gpui_ce_platform, parley_render and workspace clippy with -D warnings are green on macOS. A Linux-target cargo clippy -p gpui-ce -p gpui_ce_platform --all-targets -- -D warnings, with and without test-support, is clean.
  • --features bench-support alone stops on two errors already at the base (bench_context.rs:536, debug_overlay.rs:220), so its None branch is checked by reading.
  • As on Keep a paragraph’s closing whitespace on its last row and in its width #7, clippy, msrv, test-linux and test-windows stop on the base’s bindgen build-script error (Declare gpui_media’s bindgen build dependency on every host #6 fixes it), and typos on the base’s wdth (Let typos accept the renamed Noto Sans font file #10 fixes it).
  • Unity Hub pins this commit on top of HUB-8070’s pin, unity/HUB-8070-hub-pin-2 (Read a Linux window’s frame back with render-to-image #9’s two commits over unity/HUB-8048-hub-pin-3), as unity/HUB-8114-hub-pin-2 (d12157734f) in Unity-Technologies/unity-hub#16239. The cherry-pick is clean, and the same tests and clippy runs are green there, with render-to-image on as well.

@francois-unity francois-unity self-assigned this Oct 7, 2026
@francois-unity
francois-unity marked this pull request as ready for review October 8, 2026 14:19
TestAppContext::build hardcodes its platform: the stub TestTextSystem,
which paints no glyphs, no headless renderer, an empty asset registry,
and windows whose scale factor is the constant 2. A test can open a
window and read its scene, but not render it to pixels the way an app
draws it. HeadlessAppContext can, but it isn’t a TestAppContext, so
code written against TestAppContext and VisualTestContext can’t use it.

TestAppContext::with_platform takes a text system, an asset source, a
headless renderer factory and a scale factor. TestPlatform keeps the
scale factor and hands it to each TestWindow, which reports it from
scale_factor(), so Window::render_to_image returns an image of the
window’s size times that factor. build, and with it #[gpui::test],
keeps the stub text system, no renderer, no assets and a scale of 2.

gpui_platform::current_headless_renderer now returns WGPU’s headless
renderer on Linux, FreeBSD and Windows under test-support, through an
optional gpui_wgpu dependency that Linux already builds for its
windows. Under bench-support alone it still returns None there.

Unit tests drive the new constructor with a recording renderer. A
rendering test in gpui_platform renders IBM Plex through Parley with
the platform’s headless renderer at two scales, and CI runs it on all
three platforms.
@chris-addison
chris-addison force-pushed the unity/HUB-8114-configurable-test-platform branch from a40b259 to 9daafb9 Compare October 12, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant