Conrad Irwin 95cd535a5f gpui: Make test-support safe to enable in every build (#65043)
Projects that depend on GPUI rebuild it, and everything above it,
whenever they switch between running their app and running their tests:
`cargo test` turns on `test-support` through dev-dependencies, and
`cargo build` doesn't. Turning `test-support` on in every build would
remove that split, but today the feature changes runtime behavior, so it
can't ship in a production binary. This PR makes it additive where it
mattered.

- **Leak detection is opt-in.** `gpui/test-support` no longer turns on
`leak-detection`, which takes the entity map's write lock on every
handle create and drop. It's now enabled by the `leak-detection` feature
(as `zed/track-project-leak` already does) or by setting
`GPUI_LEAK_DETECTION=1` when building. Without it:
  - `leak_detector_snapshot()` and `assert_no_new_leaks()` are no-ops;
- `WeakEntity::assert_released()` still panics when the entity is alive,
but can't list the live handles.
- **`util::paths::home_dir()`** returns the fixed fake path
(`/Users/zed`) only in `util`'s own tests, not whenever
`util/test-support` is on. No test outside `util` depended on the fake
path.
- **`is_test()` on GPUI contexts.** `App::is_test`, `AsyncApp::is_test`
and `BackgroundExecutor::is_test` (in gpui and scheduler) report whether
the executor is a `TestScheduler`, in every build. Code that must behave
differently under tests should use these instead of `cfg(feature =
"test-support")`, so compiling the feature into an app doesn't change
its behavior. For code with no executor, such as expensive invariant
checks, `scheduler::test_scheduler_created()` reports whether the
process has created a `TestScheduler`, which test harnesses do before
the test body runs.
- **Metal `framebuffer_only(false)`** (needed for offscreen capture) now
only applies in debug builds, so optimized builds that compile
`test-support` keep the faster presentation path.

**Open question:** CI doesn't set `GPUI_LEAK_DETECTION`, so with this
change leak checks outside gpui's own unit tests are skipped in CI. If
we go ahead, the test jobs should set it. I've left that out until we
agree on the approach.

This PR is mainly to see what CI says about crates whose tests read
`home_dir()` (`project`, `worktree`, `workspace`, …), which now see the
real home directory.

Release Notes:

- [GPUI] Made the `test-support` feature safe to enable in production
builds: leak detection is now opt-in via the `leak-detection` feature or
`GPUI_LEAK_DETECTION`, and `App::is_test` reports whether code runs
under the test scheduler
2026-10-01 16:33:50 +00:00
…
…
…
…
…
…
…
…
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Languages
Rust 95.5%
JSON-with-Comments 2.3%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.3%