Skip to content

Visual Studio Code, rebuilt in Rust

Rust
6.4 KB
Raw Blame

Testing

The port's bar is "the same as VS Code", so most checks compare with upstream: its test cases, its API tests, its pixels. This file says which check proves what and where each runs. ARCHITECTURE.md has the map of the code.

Where tests run

Builds and tests run on the build machine (the Studio), not on a laptop: port/tools/studio 'port/tools/cargo-test <name>'. The tool mirrors the checkout, uncommitted changes included, and runs the command there. A tool that opens a window runs in a GUI lane: port/tools/studio --lane '<command>'. port/tools/linux-build and port/tools/windows-build run a command for the other two systems.

port/tools/cargo-test [-p <crate>] [<filter>...] (default crate app) runs cargo gc test in native/ and prints only compile errors, failed tests and the summary lines. It exits non-zero when cargo fails or when the filter matches no test, where cargo test ... | rg passes on both. Use it on any machine, through port/tools/studio too.

.github/workflows/ci.yml runs on each push to main and each pull request: the repository checks (ledger-check, the tests of port/tools, docs-check, licenses, advisories), clippy's SAFETY check, cargo test --workspace on macOS and Linux, and a smoke run of the dev build on macOS arm64 and Linux x64 (port/tools/linux/smoke: the app starts in a window, git and emmet activate, an edit saves to disk). The Linux test jobs are expected-red until milestone M23 closes its test gaps; Windows (M24) is paused and runs by hand in windows.yml. The checks that need the reference app and a window do not run there.

The workspace has about 4000 tests. The app suite takes about a minute after the build.

The kinds of check

Check Proves Where
Unit tests of a model The logic matches upstream's test cases. #[test] beside the module, in a tests.rs file or a tests module
Workbench tests A feature works through keys, clicks and commands in a window. #[gpui::test] in app/src/workbench
Extension host tests The protocol and the session without a host. port/tools/cargo-test -p exthost
API tests The extension API behaves as in VS Code. port/tools/api-tests, port/tools/extension-tests
Pixel checks A still window looks the same. port/tools/pixel-check
Paired UI runs A state reached by input looks the same. port/tools/ui-pair with step files in port/fixtures/ui-steps
Performance gates Frame times and startup stay in budget. ignored tests and port/tools/bench (performance.md)
Repository checks The ledger, the licenses and the documents agree with the code. port/tools/ledger-check.ts, port/tools/check-licenses, port/tools/docs-check.ts

Each unit row of port/ledger/units names the narrowest check that proves the unit. Run that one first.

Ported unit tests

A ported module ports the tests of its upstream file, under names that say what each case checks. The module header names the upstream test file when the cases come from one. Fixtures that upstream keeps as files are read from the checkout at test time (env!("VSCODE_SRC")), so they are not copied into the repository.

A fix comes with a test that fails without the fix. Show it red once, with the fix reverted, before you trust it.

Workbench tests

A workbench test builds a real Workbench in a GPUI test window and drives it as a user does.

  • #[gpui::test] gives a TestAppContext with a deterministic scheduler and a fake clock. Time moves only when the test advances it, so a debounce of 300 ms costs no real time.
  • Each test file has a small workbench helper that makes the entity: a theme from the checkout, settings in a temp folder, and a app/src/host_sync.rs::HostSync over a plain channel. The test reads that channel to assert what the workbench sent to the extension host, and answers as the host. app/src/workbench/notifications_view/tests.rs is a short example.
  • Input goes through the same paths as in the app: simulate_keystrokes, simulate_click, or execute_command.
  • Assertions read Workbench state, or the bounds of a named element with debug_bounds. An element gets its name from .debug_selector. Assert on a size or a position only when upstream's CSS gives it.
  • run_until_parked runs every task that is ready. A test that ends with a task still pending fails ("parking forbidden").

The skill in .agents/skills/gpui-test has the seed and iteration variables for a flaky test, and how to read a pending task trace.

Do not wait for workbench work with std::thread::sleep or the real clock. Advance the test clock. A test that waits for the real file system or for a child process is the exception.

Do not assert on a full element tree or a screenshot in a unit test. Pixels are the job of port/tools/pixel-check.

Tests that need more than a test window

Some tests are #[ignore] because they need something a normal run does not have. Each says what in its attribute or its doc comment.

  • A real extension host: live_host in app/src/host_sync.rs.
  • A release build and a quiet machine: the performance gates in app/src/syntax.rs and app/src/workbench/scroll_frame_time.rs.
  • Signed packages: the update tests in app/src/update/install/tests.rs, fed by port/tools/update-check.

A test with #[ignore = "test.skip upstream"] mirrors a test that upstream skips.

Comparing with VS Code

  • port/tools/pixel-check captures the reference window and the port's window in the same state and diffs them with the pixeldiff crate. Differences that stay are listed with their cause in port/results.
  • port/tools/ui-pair drives both apps through one step file and saves both screenshots, for states a still frame cannot reach: a drag, an inline editor, a dialog.
  • port/tools/ref-dom, port/tools/ref-hover and port/tools/ref-contextmenu read boxes and computed styles from the reference. Use them to get a size before you write it.
  • port/tools/api-tests writes its result to port/results/api-tests.md.

Before a report or a commit

  1. The narrowest check of the unit you changed.
  2. port/tools/cargo-test -p <crate> for each crate you touched.
  3. bun port/tools/ledger-check.ts and bun port/tools/docs-check.ts.
  4. For unsafe code: the checks of memory-safety.md.
  5. For a hot path: the gate of performance.md, before and after.