Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

docs(agents): run the tests you touched, not the whole suite each step

Etienne Lescotdfbd47e427dd
diff --git a/.harness/docs/git-workflow.md b/.harness/docs/git-workflow.md
index f6ca4fbe6..99fc1ff0d 100644
--- a/.harness/docs/git-workflow.md
+++ b/.harness/docs/git-workflow.md
@@ -21,20 +21,22 @@ Conventions for the Mavis reins when working in this repo.
## CI (`.github/workflows/ci.yml`)
-CI runs on every PR to `main` and every push to `main`:
+CI runs on every PR to `main`, `feat/ai-edition` and `release/**`, and on every push to those:
- `npm run lint` (Biome)
-- `npx tsc --noEmit` (TypeScript)
+- `npx tsc --noEmit` (TypeScript, app code)
+- `npx tsc -p tsconfig.test.json --noEmit` (TypeScript, test files — a separate gate at zero)
- `npm run test` (Vitest unit)
-- `npm run test:browser` (Vitest + Playwright headless)
+- `npm run docs:check`
- `npx vite build` (renderer build smoke)
+- `cargo test` / `cargo check` for the compositor on macOS, Windows and Linux
-All five must be green before merge. Native helper code is NOT covered by CI — manual smoke test is required for `electron/*-helper/` changes; note it in the PR description.
+All must be green before merge. Native helper code is NOT covered by CI — manual smoke test is required for `electron/*-helper/` changes; note it in the PR description.
## Pull request flow
1. Branch from `main`.
2. Implement + add tests in the same package.
-3. Run locally: `npm run lint && npx tsc --noEmit && npm run test`. For browser/e2e-touching changes, also run the relevant suite.
+3. While implementing, run only the affected tests (`npx vitest --run <path>` or `--changed`); `npx tsc --noEmit` and `npm run lint` are the cheap inner-loop checks. Run the full `npm run test` **once**, here, before pushing.
4. Push and open the PR via `gh pr create`. Use `.github/pull_request_template.md`.
5. Wait for the Mavis reviewer (`openscreen-reviewer`) PASS or address the requested changes.
6. Merge once CI is green and review is PASS. PR titles must follow Conventional Commits (enforced by the `semantic-pr` job in `ci.yml`) — this keeps the auto-generated release notes clean.
diff --git a/.harness/reins/openscreen-dev/agent.md b/.harness/reins/openscreen-dev/agent.md
index 4bd9ce150..a44c491a9 100644
--- a/.harness/reins/openscreen-dev/agent.md
+++ b/.harness/reins/openscreen-dev/agent.md
@@ -26,6 +26,8 @@ You are the generalist implementer for the OpenScreen project — a free, open-s
- `npx tsc --noEmit` passes.
- `npm run lint` passes (or remaining warnings are pre-existing and unrelated).
-- `npm run test` passes for any unit tests you added or affected.
+- The tests you added or affected pass — run those files, `npx vitest --run <path>`, not the
+ whole suite. `npm run test` is minutes; run it once at the end if at all, and let CI be the
+ full-suite gate. Never `npm run test:watch` (it never terminates).
- The change is documented in the PR description (what + why + how to test).
- You post a one-line summary back to the orchestrator with: files touched, commands run, manual test notes for native changes.
diff --git a/.harness/reins/openscreen-tester/agent.md b/.harness/reins/openscreen-tester/agent.md
index bd4658ce4..aadbf7bbb 100644
--- a/.harness/reins/openscreen-tester/agent.md
+++ b/.harness/reins/openscreen-tester/agent.md
@@ -9,7 +9,7 @@ You are the test specialist for the OpenScreen project — a free, open-source s
## Scope
-- **Own**: Vitest unit tests (`*.test.ts` / `*.test.tsx`, jsdom), Vitest browser tests (`vitest.browser.config.ts`, Playwright headless), Playwright e2e (`tests/e2e/`).
+- **Own**: Vitest unit tests (`*.test.ts` / `*.test.tsx`), Playwright e2e (`tests/e2e/`).
- **Don't own**: writing production code (hand off to `openscreen-dev`). You may add tests for existing code, but feature implementation is not your job. Final PR quality gate is `openscreen-reviewer`.
## How you work
@@ -17,16 +17,23 @@ You are the test specialist for the OpenScreen project — a free, open-source s
- Read `AGENTS.md` at the repo root for commands and conventions.
- Read `technical-documentation/testing/writing-tests.md` for the project's test style guide.
- Match the style of neighboring `*.test.<ext>` files in the same package — don't invent new patterns.
-- Unit tests: `npm run test` (Vitest, jsdom). Browser tests: `npm run test:browser` (needs `npm run test:browser:install` once). E2E: `npm run test:e2e` (Playwright).
+- Iterate with `npx vitest --run <path>` on the files you are writing. `npm run test` is the
+ whole suite (minutes) — run it once at the end, not between edits. E2E: `npm run test:e2e`.
+- The Vitest environment is `node` by default. A test that needs a DOM opts in with
+ `// @vitest-environment jsdom` on line 1 — add it only when the test actually renders.
- E2E specs in `tests/e2e/windows-native-checklist.spec.ts` are Windows-only — gate with `test.skip` for other platforms rather than deleting.
- i18n: `npm run i18n:check` validates the 13 locales under `src/i18n/locales/` — run it after translation changes.
-- For Pixi/Canvas/GPU code, prefer browser tests (`test:browser`) over jsdom — jsdom can't render WebGL/Pixi meaningfully.
+- jsdom can't render WebGL/Pixi meaningfully and there is no browser-test tier anymore. Real
+ codec/GPU behavior belongs to the Rust suites in `crates/` or to the manual checklist —
+ don't write a jsdom test that pretends to cover it.
+- Anything gated on `process.platform` must pin the platform in the test. CI is Linux-only,
+ so an unpinned Linux-only path is green in CI and red on every Windows and macOS machine.
- Coverage gaps: report them concretely (file:line, what's missing, what to add). Don't write the test for someone else's feature unprompted — flag it.
## Stop when
-- `npm run test` passes.
-- For browser-tested changes: `npm run test:browser` passes.
+- The files you touched pass under `npx vitest --run <path>`, and one final `npm run test` is
+ green (that single full run is the gate — not one per edit).
- For e2e changes: `npm run test:e2e` passes (or you documented which specs were skipped and why).
- `npm run i18n:check` passes if any locale file was touched.
- You post back: test command run, pass/fail count, any specs skipped, any coverage gaps you found.
diff --git a/AGENTS.md b/AGENTS.md
index 5f270ef88..2d8e2d049 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -8,8 +8,7 @@ OpenScreen is a free, open-source screen recorder and video editor (Electron + R
- Start dev: `npm run dev` (Vite dev server; Electron window opens via `vite-plugin-electron`)
- Build: `npm run build` (TypeScript check + Vite build + electron-builder)
- Typecheck: `npx tsc --noEmit` — app code only. CI also runs `npx tsc -p tsconfig.test.json --noEmit` in a separate job ("Typecheck (tests)"), so **run both**: test files are invisible to the root config, and a type error in a `*.test.ts` fails CI while the root check stays green.
-- Test (unit): `npm run test` (Vitest, jsdom env)
-- Test (browser): `npm run test:browser` (Vitest + Playwright, requires `npm run test:browser:install` first)
+- Test (unit): `npx vitest --run <path>` while you work, `npm run test` once at the end — see [Testing instructions](#testing-instructions)
- Test (e2e): `npm run test:e2e` (Playwright)
- Lint: `npm run lint` (Biome 2.4)
- Format: `npm run format` (Biome, tabs, double quotes, 100-col)
@@ -37,11 +36,37 @@ OpenScreen is a free, open-source screen recorder and video editor (Electron + R
## Testing instructions
-- Unit tests live next to source as `*.test.ts` / `*.test.tsx` (Vitest, jsdom).
-- Browser tests use `vitest.browser.config.ts` (Playwright headless) — only run when DOM/Pixi rendering matters.
+### When to run what
+
+The full unit suite is ~1670 tests over 140 files and takes over a minute. Running it after
+every edit is the main way an agent turns a 5-minute task into a 30-minute one, so don't:
+
+- **While you work** — run only what you touched: `npx vitest --run src/lib/foo.test.ts`,
+ or `npx vitest --run src/lib/ai-edition` for a directory. `npm run test:changed` picks
+ the affected files off the working tree, `npx vitest --run --changed main` off the
+ branch diff. A single file is 1–10s against ~80s for everything.
+- **Typecheck and lint freely** — `npx tsc --noEmit` and `npm run lint` are seconds, not
+ minutes. They are the right inner-loop check, not the test suite.
+- **Once, at the end** — `npm run test` before you commit or open the PR. One full run per
+ task, not per edit. If the change is narrow and CI will run anyway, the targeted run plus
+ CI is enough; say so rather than burning the wall-clock twice.
+- **Never** `npm run test:watch` — it does not terminate, and it will hang the session.
+
+### Layout and conventions
+
+- Unit tests live next to source as `*.test.ts` / `*.test.tsx` (Vitest). Config is
+ `vitest.config.ts`; it covers `src/`, `electron/` and `.github/`.
+- **The default environment is `node`.** A test that needs a DOM opts in with
+ `// @vitest-environment jsdom` on line 1 — that is also the fix for `document is not
+ defined`. Don't add it to a test that doesn't need it: jsdom setup dominates this
+ suite's runtime (see the comment in `vitest.config.ts`).
+- Anything platform-conditional (`process.platform`) must pin the platform in the test.
+ CI is Linux-only, so a Linux-only code path left unpinned is green in CI and red on
+ every Windows and macOS machine — `electron/recording/webm-seek-index.test.ts` is the
+ worked example.
- E2E tests are in `tests/e2e/` (Playwright). Some specs are platform-specific (e.g. `windows-native-checklist.spec.ts`).
- Add a test for every new behavior in the same package as the code under test.
-- All tests must pass before opening a PR. CI runs `npm run test` and `npm run test:browser` on every PR.
+- All tests must pass before opening a PR. CI runs `npm run test` on every PR.
## Desktop E2E testing with computer-use
diff --git a/package.json b/package.json
index fcff53ac6..d6e058fa0 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
"build:whisper-binaries": "bash scripts/build-whisper-stt.sh",
"test:whisper-stt": "node scripts/test-whisper-stt.mjs",
"test": "vitest --run",
+ "test:changed": "vitest --run --changed",
"wb": "vitest --run --config vitest.workbench.config.ts",
"wb:l0": "vitest --run --config vitest.workbench.config.ts workbench/l0",
"wb:watch": "vitest --config vitest.workbench.config.ts workbench/l0",
diff --git a/technical-documentation/testing/writing-tests.md b/technical-documentation/testing/writing-tests.md
index 69d1b5dda..2e88886ce 100644
--- a/technical-documentation/testing/writing-tests.md
+++ b/technical-documentation/testing/writing-tests.md
@@ -1,23 +1,52 @@
# Writing Tests
-This project uses Vitest for unit/integration tests and browser tests, plus Playwright for desktop end-to-end coverage. The configs select distinct file sets and execution environments.
+This project uses Vitest for unit/integration tests, plus Playwright for desktop end-to-end coverage.
## Test types at a glance
| Test type | Config | What it is for | Run it |
|---|---|---|---|
-| Unit / jsdom | `vitest.config.ts` | Logic, data transformations, React behavior, and integrations that do not require real browser media/graphics APIs. | `npm run test` or `npm run test:watch` |
-| Browser / Playwright in Vitest | `vitest.browser.config.ts` | Source-level tests in real headless Chromium for Canvas, WebCodecs, MediaRecorder, WebGL, and related APIs. | `npm run test:browser:install`, then `npm run test:browser` |
+| Unit | `vitest.config.ts` | Logic, data transformations, React behavior, and integrations that do not require real browser media/graphics APIs. | `npx vitest --run <path>` while working, `npm run test` once at the end |
| End-to-end / Playwright | `playwright.config.ts` | Full workflows under `tests/e2e`, including Electron/native integration checklists and export flows. | `npm run test:e2e` |
+> There used to be a third tier — "browser tests" in real headless Chromium via
+> `vitest.browser.config.ts` and `npm run test:browser`, for `VideoDecoder`,
+> `MediaRecorder`, `OffscreenCanvas` and WebGL. **It no longer exists**: no config, no
+> script, no `*.browser.test.ts` file, and no CI job. Real-codec and real-GPU behavior is
+> covered instead by the Rust compositor's own `cargo test` suites (`crates/`, run by the
+> three `rust-*-compositor-check` CI jobs) and by the manual checklist below.
+
## Unit tests
**Config:** `vitest.config.ts`
-**Runs in:** jsdom (simulated DOM, no real browser)
-**File pattern:** `src/**/*.test.ts` — anything that does **not** end in `.browser.test.ts`
+**Runs in:** Node by default; jsdom only for files that ask for it
+**File pattern:** `{src,electron,.github}/**/*.test.{ts,tsx}`
**CI command:** `npm run test`
-Use unit tests for pure logic, utility functions, data transformations, and anything that doesn't need real browser APIs (Canvas, WebCodecs, MediaRecorder, etc.).
+Use unit tests for pure logic, utility functions, data transformations, and React behavior.
+
+### Environment: node by default, jsdom on request
+
+Building a jsdom for a test that never touches the DOM was this suite's single largest
+cost — 719s of cumulative environment setup against 89s of actual test time. So
+`vitest.config.ts` sets `environment: "node"`, and the 37 files that genuinely need a DOM
+opt in with a docblock on line 1:
+
+```ts
+// @vitest-environment jsdom
+import { render, screen } from "@testing-library/react";
+```
+
+That is also the fix when a new test dies on `document is not defined` or
+`ReferenceError: window is not defined`. Every `*.test.tsx` needs it; a `*.test.ts` needs
+it only if it renders a component, uses `renderHook`, or reaches for a browser global.
+
+### Platform-conditional code
+
+CI runs on Linux only. A test covering a `process.platform`-gated path must pin the
+platform itself, or it passes vacuously in CI and fails on every Windows and macOS
+machine. `electron/recording/webm-seek-index.test.ts` sets `process.platform` in
+`beforeEach` and restores it in `afterEach` — copy that shape.
### File placement
@@ -61,87 +90,18 @@ import { SUPPORTED_LOCALES } from "@/i18n/config";
### Running locally
-```bash
-npm run test # run once
-npm run test:watch # watch mode
-```
-
----
-
-## Browser tests
-
-**Config:** `vitest.browser.config.ts`
-**Runs in:** real Chromium via Playwright (headless)
-**File pattern:** `src/**/*.browser.test.ts`
-**CI commands:** `npm run test:browser:install` then `npm run test:browser`
-
-Use browser tests when the code under test depends on real browser APIs that jsdom doesn't implement: `VideoDecoder`, `VideoEncoder`, `MediaRecorder`, `OffscreenCanvas`, `WebGL`, etc.
-
-### File placement
-
-Name the file `<subject>.browser.test.ts` and place it next to the source file.
-
-```
-src/lib/exporter/videoExporter.ts
-src/lib/exporter/videoExporter.browser.test.ts
-```
-
-### Loading fixture assets
-
-Static assets (video files, images) live in `tests/fixtures/`. Import them with Vite's `?url` suffix so Vite serves them through the dev server.
-
-```ts
-import sampleVideoUrl from "../../../tests/fixtures/sample.webm?url";
-```
-
-### Example
-
-```ts
-import { describe, expect, it } from "vitest";
-import sampleVideoUrl from "../../../tests/fixtures/sample.webm?url";
-import { VideoExporter } from "./videoExporter";
-
-describe("VideoExporter (real browser)", () => {
- it("exports a valid MP4 blob from a real video", async () => {
- const exporter = new VideoExporter({
- videoUrl: sampleVideoUrl,
- width: 320,
- height: 180,
- frameRate: 15,
- bitrate: 1_000_000,
- wallpaper: "#1a1a2e",
- zoomRegions: [],
- showShadow: false,
- shadowIntensity: 0,
- showBlur: false,
- cropRegion: { x: 0, y: 0, width: 1, height: 1 },
- });
-
- const result = await exporter.export();
-
- expect(result.success, result.error).toBe(true);
- expect(result.blob).toBeInstanceOf(Blob);
- });
-});
-```
-
-### Timeouts
-
-Browser tests have a default timeout of 120 seconds per test and 30 seconds per hook (set in `vitest.browser.config.ts`). Export operations are slow — prefer small fixture dimensions (320×180) and low bitrates to keep tests fast.
-
-### Running locally
-
-First install the browser (one-time):
+The full run is ~1670 tests over 140 files and takes over a minute. Run it once, at the end of a
+task — not after each edit.
```bash
-npm run test:browser:install
+npx vitest --run src/lib/foo.test.ts # one file, while you work (1-10s)
+npx vitest --run src/lib/ai-edition # one directory
+npm run test:changed # only what the working tree touches
+npx vitest --run --changed main # only what the branch diff touches
+npm run test # everything (~80s), once, before committing
```
-Then run the tests:
-
-```bash
-npm run test:browser
-```
+`npm run test:watch` never terminates — don't start it from a script or an agent session.
---
@@ -149,11 +109,11 @@ npm run test:browser
| Situation | Use |
|---|---|
-| Pure function / data transformation | Unit test |
-| i18n key coverage | Unit test |
-| React hook logic (no real browser APIs) | Unit test |
-| `VideoDecoder` / `VideoEncoder` / `MediaRecorder` | Browser test |
-| `OffscreenCanvas` / WebGL / Pixi.js rendering | Browser test |
-| File export producing a real `Blob` | Browser test |
+| Pure function / data transformation | Unit test (node) |
+| i18n key coverage | Unit test (node) |
+| React component or hook behavior | Unit test + `// @vitest-environment jsdom` |
+| `VideoDecoder` / `VideoEncoder` / real codecs | Rust test in `crates/`, or the manual checklist |
+| WebGL / Pixi.js / GPU rendering | Rust test in `crates/`, or the manual checklist |
+| A full export producing a real file | `tests/e2e/`, or the manual checklist |
Automated suites do not exercise every hardware, permission, codec, signing, and packaged-app combination. Use the [manual end-to-end checklist](manual-e2e-checklist.md) for those release and platform checks.