The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(testing): add testing strategy guide
Steven Enamakelb7e24b3e1b41
diff --git a/gitbooks/developing/testing-strategy.md b/gitbooks/developing/testing-strategy.mdindex 7fb7a255b8..11444341cf 100644--- a/gitbooks/developing/testing-strategy.md+++ b/gitbooks/developing/testing-strategy.md@@ -1,11 +1,11 @@----description: How OpenHuman tests its product - Vitest, cargo test, WDIO E2E. Where each test goes.+description: How OpenHuman tests its product with Vitest, cargo test and WDIO E2E, and where each kind of test goes.icon: vial----# Testing Strategy+# Testing strategy-How OpenHuman tests its product. Source of truth for "where does my test go?". Companion to [`TEST-COVERAGE-MATRIX.md`](https://github.com/tinyhumansai/openhuman/blob/main/docs/TEST-COVERAGE-MATRIX.md).+This page answers "where does my test go?". It is the companion to [`TEST-COVERAGE-MATRIX.md`](https://github.com/tinyhumansai/openhuman/blob/main/docs/TEST-COVERAGE-MATRIX.md).---@@ -13,15 +13,15 @@ How OpenHuman tests its product. Source of truth for "where does my test go?". C| Layer | Where it lives | What it tests | Driver || -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |-| **Rust unit** | Sibling `<module>_tests.rs` files beside the module under `crates/openhuman-core/src/<domain>/`, or a `tests/` subdir under a domain (e.g. `crates/openhuman-core/src/channels/tests/`); inline `#[cfg(test)] mod` blocks and files named `tests.rs`/`test.rs` fail `pnpm rust:layout` | Pure domain logic, schemas, RPC handler shape, in-memory state machines | `cargo test` |-| **Rust integration** | `tests/*.rs` at repo root, each an explicit `[[test]]` target in `crates/openhuman-cli/Cargo.toml` (`autotests = false`); `tests/raw_coverage/*.rs` is globbed by `build.rs` into the single `raw_coverage_all` target | Full domain wiring with real Tokio runtime, mock external services, JSON-RPC end-to-end (`tests/json_rpc_e2e.rs`), domain × domain interactions | `pnpm test:rust` (which calls `bash scripts/test-rust-with-mock.sh`) |-| **Vitest unit** | Co-located as `*.test.ts(x)` next to source under `app/src/**`, or under `app/src/**/__tests__/` | React components, hooks, store slices, pure utilities, service-layer adapters | `pnpm test` (root) or `pnpm --filter openhuman-app test:unit` |-| **WDIO E2E** | `app/test/e2e/specs/*.spec.ts` | Full desktop flow: UI → Tauri → in-process core → JSON-RPC; user-visible behaviour | All platforms: Linux CI drives the Wry-based debug build (macOS/Windows desktop E2E is disabled until a native driver lands, #5485). See [E2E Testing](e2e-testing.md). |-| **Manual smoke** | [`docs/RELEASE-MANUAL-SMOKE.md`](https://github.com/tinyhumansai/openhuman/blob/main/docs/RELEASE-MANUAL-SMOKE.md) | OS-level surfaces drivers cannot assert: TCC permission prompts, Gatekeeper, code signing, DMG install, OS-native toasts | Human at release-cut; the completed sign-off block is pasted as a GitHub commit comment on the `v<version>-staging` tagged commit QA validated. There is no release PR in the promotion flow, see [Release Policy](release-policy.md) |+| Rust unit | Sibling `<module>_tests.rs` files beside the module under `crates/openhuman-core/src/<domain>/`, or a `tests/` subdir under a domain (e.g. `crates/openhuman-core/src/channels/tests/`); inline `#[cfg(test)] mod` blocks and files named `tests.rs`/`test.rs` fail `pnpm rust:layout` | Pure domain logic, schemas, RPC handler shape, in-memory state machines | `cargo test` |+| Rust integration | `tests/*.rs` at repo root, each an explicit `[[test]]` target in `crates/openhuman-cli/Cargo.toml` (`autotests = false`); `tests/raw_coverage/*.rs` is globbed by `build.rs` into the single `raw_coverage_all` target | Full domain wiring with real Tokio runtime, mock external services, JSON-RPC end-to-end (`tests/json_rpc_e2e.rs`), domain × domain interactions | `pnpm test:rust` (which calls `bash scripts/test-rust-with-mock.sh`) |+| Vitest unit | Co-located as `*.test.ts(x)` next to source under `app/src/**`, or under `app/src/**/__tests__/` | React components, hooks, store slices, pure utilities, service-layer adapters | `pnpm test` (root) or `pnpm --filter openhuman-app test:unit` |+| WDIO E2E | `app/test/e2e/specs/*.spec.ts` | Full desktop flow: UI → Tauri → in-process core → JSON-RPC; user-visible behavior | All platforms: Linux CI drives the Wry-based debug build (macOS and Windows desktop E2E is disabled until a native driver exists). See [E2E testing](e2e-testing.md). |+| Manual smoke | [`docs/RELEASE-MANUAL-SMOKE.md`](https://github.com/tinyhumansai/openhuman/blob/main/docs/RELEASE-MANUAL-SMOKE.md) | OS-level surfaces drivers cannot assert: TCC permission prompts, Gatekeeper, code signing, DMG install, OS-native toasts | Human at release-cut; the completed sign-off block is pasted as a GitHub commit comment on the `v<version>-staging` tagged commit QA validated. The promotion flow has no release PR. See [Release policy](release-policy.md) |----## Decision tree - where does my test go?+## Where does my test go?```textIs the change behind the JSON-RPC boundary (in `crates/openhuman-core/src/`, `crates/openhuman-rpc/`, or `crates/openhuman-embed/`)?@@ -37,13 +37,13 @@ Is the change behind the JSON-RPC boundary (in `crates/openhuman-core/src/`, `cr└─ YES → Manual smoke checklist```-If a change touches more than one of these, write a test in **each** layer it touches. Don't substitute one for another.+If a change touches more than one layer, write a test in each layer it touches. Do not substitute one for another.---## Failure-path requirement-Every feature leaf in the coverage matrix must have **at least one failure / edge** assertion in addition to the happy path. Examples:+Every feature in the coverage matrix needs at least one failure or edge assertion as well as the happy path. Examples:- File-write tool: happy = wrote bytes; failure = path-restriction denial.- OAuth flow: happy = token issued; edge = expired refresh token recovery.@@ -55,47 +55,47 @@ A spec that asserts only the happy path is incomplete.## Mock policy-- **No real network in unit / integration / E2E.** Use the shared mock backend (`scripts/mock-api-core.mjs`, `scripts/mock-api-server.mjs`, `app/test/e2e/mock-server.ts`).+- Use no real network in unit, integration or E2E tests. Use the shared mock backend (`scripts/mock-api-core.mjs`, `scripts/mock-api-server.mjs`, `app/test/e2e/mock-server.ts`).- Admin endpoints for tests: `GET /__admin/health`, `POST /__admin/reset`, `POST /__admin/behavior`, `GET /__admin/requests`.-- **External services** (Telegram, Slack, Gmail, Notion, Ollama, OpenAI, etc.) are stubbed at the mock backend level; tests assert the request shape via `getRequestLog()`.+- External services (Telegram, Slack, Gmail, Notion, Ollama, OpenAI and others) are stubbed at the mock backend level; tests assert the request shape via `getRequestLog()`.- The only acceptable exception is a documented release-cut manual smoke step.---## Determinism rules-- No wall-clock waits, use `waitForApp`, `waitForAppReady`, `waitForWebView` helpers, or explicit element-readiness predicates.-- No shared filesystem state, every E2E spec runs inside an isolated `OPENHUMAN_WORKSPACE` (created/cleaned by `app/scripts/e2e-run-spec.sh`).-- No order-dependent specs, each spec must pass when run alone.+- No wall-clock waits. Use the `waitForApp`, `waitForAppReady` and `waitForWebView` helpers, or explicit element-readiness checks.+- No shared filesystem state. Every E2E spec runs in an isolated `OPENHUMAN_WORKSPACE`, created and cleaned by `app/scripts/e2e-run-spec.sh`.+- No order-dependent specs. Each spec must pass when run alone.- No reliance on absolute coordinates or animation timing.-- Prefer synthesizing keyboard input via `browser.execute(...)` over `browser.keys()` (see `command-palette.spec.ts` for the pattern).+- Prefer synthesizing keyboard input with `browser.execute(...)` over `browser.keys()`. See `command-palette.spec.ts` for the pattern.---## What the existing harness gives you-- **Mock backend bootstrapping**: `startMockServer` / `stopMockServer` in `app/test/e2e/mock-server.ts`.-- **Auth shortcut**: `triggerAuthDeepLink` / `triggerAuthDeepLinkBypass` in `helpers/deep-link-helpers.ts` skips real OAuth.-- **Element helpers**: `clickNativeButton`, `waitForWebView`, `clickToggle` in `helpers/element-helpers.ts`, use these instead of raw `XCUIElementType*` selectors.-- **Shared flows**: `completeOnboardingIfVisible`, `navigateViaHash`, `navigateToSkills`, `walkOnboarding` in `helpers/shared-flows.ts`.-- **Core RPC from spec**: `callOpenhumanRpc` in `helpers/core-rpc.ts`, drives the embedded core directly when a UI step would be brittle.-- **Platform guards**: `isTauriDriver` and `supportsExecuteScript` in `helpers/platform.ts`. Desktop E2E runs the debug binary under Xvfb through `tauri-driver` on Linux; the Appium Chromium-driver backend went away with CEF, and macOS and Windows have no automated desktop session yet.-- **Artifact capture on failure**: `captureFailureArtifacts` runs from `wdio.conf.ts`, screenshots + DOM dumps land under `app/test/e2e/artifacts/`.+- Mock backend: `startMockServer` and `stopMockServer` in `app/test/e2e/mock-server.ts`.+- Auth shortcut: `triggerAuthDeepLink` and `triggerAuthDeepLinkBypass` in `helpers/deep-link-helpers.ts` skip real OAuth.+- Element helpers: `clickNativeButton`, `waitForWebView` and `clickToggle` in `helpers/element-helpers.ts`. Use these instead of raw `XCUIElementType*` selectors.+- Shared flows: `completeOnboardingIfVisible`, `navigateViaHash`, `navigateToSkills` and `walkOnboarding` in `helpers/shared-flows.ts`.+- Core RPC from a spec: `callOpenhumanRpc` in `helpers/core-rpc.ts` drives the embedded core directly when a UI step would be brittle.+- Platform guards: `isTauriDriver` and `supportsExecuteScript` in `helpers/platform.ts`. Desktop E2E runs the debug binary under Xvfb through `tauri-driver` on Linux. macOS and Windows have no automated desktop session yet.+- Artifact capture on failure: `captureFailureArtifacts` runs from `wdio.conf.ts`, and screenshots and DOM dumps land under `app/test/e2e/artifacts/`.----## Naming + structure conventions+## Naming and structure- WDIO specs: `<feature-area>-flow.spec.ts` for end-to-end product flows; `<feature>.spec.ts` for narrower surfaces.- Vitest co-location: prefer `Component.tsx` + `Component.test.tsx` siblings; use `__tests__/` only when grouping multiple related tests.- Rust integration tests: snake_case file matching the surface, `<feature>_e2e.rs` for JSON-RPC-driven flows, `<feature>_integration.rs` for cross-domain.-- Each `describe` / `mod tests` block maps to a feature-list ID range, link the matrix row in a comment if the mapping is non-obvious.+- Each `describe` block maps to a feature-list ID range. Link the matrix row in a comment if the mapping is not obvious.---## Pre-merge gates-Run before opening a PR. CI runs the same set, but local runs are faster:+Run these before opening a PR. CI runs the same set, but local runs are faster:```bash# Rust core@@ -116,25 +116,25 @@ pnpm test # vitest, via the app workspace# Rust integration with mock backendpnpm test:rust-# E2E (slow - run when behaviour changes user-visibly)+# E2E (slow, run when behavior changes visibly to users)pnpm --filter openhuman-app test:e2e:buildbash app/scripts/e2e-run-spec.sh test/e2e/specs/<your-spec>.spec.ts <id>```----## Not driver-automatable - manual smoke required+## Manual smoke checks-Some surfaces cannot be driven by WDIO / Appium because they cross OS-level trust boundaries or hardware paths. The complete checklist + sign-off block lives in [`docs/RELEASE-MANUAL-SMOKE.md`](https://github.com/tinyhumansai/openhuman/blob/main/docs/RELEASE-MANUAL-SMOKE.md), that file is the source of truth for what must be verified per release. Examples of what it covers:+WDIO and Appium cannot drive some surfaces, because they cross OS-level trust boundaries or hardware paths. [`docs/RELEASE-MANUAL-SMOKE.md`](https://github.com/tinyhumansai/openhuman/blob/main/docs/RELEASE-MANUAL-SMOKE.md) holds the full checklist and sign-off block. It is the source of truth for what to verify per release. It covers items such as:- macOS TCC permission prompts (Accessibility, Input Monitoring, Microphone)- Gatekeeper signature validation on first launch- Code-sign integrity (`codesign --verify --deep --strict`)-- DMG install / drag-to-Applications flow-- Auto-update download + relaunch-- OS-native notification toasts on Linux (no display server visible to the driver beyond Xvfb)+- DMG install and drag-to-Applications flow+- Auto-update download and relaunch+- OS-native notification toasts on Linux (the driver sees no display server beyond Xvfb)-If a feature has no automated coverage AND is not on the manual smoke list, treat it as untested, open a coverage gap.+If a feature has no automated coverage and is not on the manual smoke list, treat it as untested and open a coverage gap.---@@ -142,67 +142,42 @@ If a feature has no automated coverage AND is not on the manual smoke list, treaEvery feature leaf in the [coverage matrix](https://github.com/tinyhumansai/openhuman/blob/main/docs/TEST-COVERAGE-MATRIX.md) maps to:-1. A test path or paths, **or**+1. One or more test paths, or2. A justified `🚫` with a manual-smoke entry.-When you add / remove / rename a feature, **update the matrix row in the same PR**. CI will guard this contract once #965 lands.+When you add, remove or rename a feature, update its matrix row in the same PR.---## A red Rust suite locally is usually not a defect-Most local Rust failures in this repo are environmental, and the environments-fail in ways that look exactly like product defects. Work down this list before-concluding anything. Each step is one command, and every one of them has caught-a wrong conclusion that was already on its way into an issue.--**Every prerequisite below carries the failure you get without it.** A step with-its failure attached is self-auditing: anyone can check in thirty seconds-whether it is still true, and a stale one announces itself. A bare list of steps-cannot be audited at all, which is how it rots into folklore. *If you cannot-produce the failure for an item, it does not belong here.*--**A note that tells you the cause is not evidence of the cause.** A line in a-doc or a memory saying "these fail locally, it is provisioning" is a-*pre-supplied conclusion*. It terminates the investigation before it starts,-which is worse than no note at all: one such note sent a worker looking for a-provisioning gap when the real cause was a product defect-(`agent definition \`harness\` was not found`, openhuman#6487). Use the steps,-not the folklore.+Most local Rust failures here come from the environment, and they look exactly like product bugs. Work down this list before you conclude anything. Each step is one command. Each carries the failure you see without it, so you can check in thirty seconds whether it still holds.++Do not trust a note that tells you the cause. A line saying "these fail locally, it is provisioning" ends the investigation before it starts. Once it sent a worker hunting for a provisioning gap when the real cause was a product defect (`agent definition \`harness\` was not found`). Use the steps, not folklore.### 1. Did anything compile?-`cargo` exits **101** for at least three states that are identical from the-shell: nothing compiled, a test asserted false, or the process aborted.+`cargo` exits 101 in at least three cases that look identical from the shell: nothing compiled, a test asserted false, or the process aborted.```bashgrep -c "^test result" run.log # 0 = nothing ran```-Zero `test result` lines means the question is *compilation or abort*, never-"which test failed". Then read the **first** error line:+Zero `test result` lines means the problem is compilation or an abort, not a failing test. Read the first error line:-- `failed to load source for dependency <x>` / `No such file or directory` →- a submodule is not checked out.-- `fatal runtime error: stack overflow` with `signal: 6, SIGABRT` and no- `test result` line at all → the process aborted; see step 3.+- `failed to load source for dependency <x>` or `No such file or directory` means a submodule is not checked out.+- `fatal runtime error: stack overflow` with `signal: 6, SIGABRT` and no `test result` line means the process aborted. See step 3.-### 2. Are the submodules actually there, at every depth?+### 2. Are the submodules there, at every depth?-Some crates depend on submodules **nested inside other submodules**.-`openhuman-tinyhumans` is the clearest case: it needs `vendor/tinyhumans-sdk`-(top level) **and** `vendor/tinyagents/vendor/tinytools` (nested). A plain-`git submodule update --init` fetches the first and silently not the second, so-the obvious command leaves you with a compile failure that reads as a test-failure.+Some crates depend on submodules nested inside other submodules. `openhuman-tinyhumans` is the clearest case. It needs `vendor/tinyhumans-sdk` (top level) and `vendor/tinyagents/vendor/tinytools` (nested). A plain `git submodule update --init` fetches the first and silently skips the second, so you get a compile failure that reads like a test failure.```bashgit submodule update --initgit -C vendor/tinyagents submodule update --init --recursive```-*Falsified:* deinitialising `vendor/tinyagents/vendor/tinytools` and re-running-`cargo test -p openhuman-tinyhumans` gives, with **no** `test result` line:+Without the nested module, `cargo test -p openhuman-tinyhumans` fails with no `test result` line:```texterror: failed to get `tinytools` as a dependency of package `openhuman-cli v0.63.31`@@ -210,11 +185,7 @@ error: failed to get `tinytools` as a dependency of package `openhuman-cli v0.63No such file or directory (os error 2)```-**Check content, never status.** `git submodule status` prints `-` only for-*unregistered* modules, and registration happens **before** checkout, so a-mid-flight init reads as ready while every working tree is still empty.-Observed mid-`update --init`: **13 `+`, 3 ` `, zero `-`** while `du -sh vendor`-was **120K** and `ls vendor/tinychannels` was empty.+Check content, not status. `git submodule status` prints `-` only for unregistered modules, and registration happens before checkout. A half-finished init can therefore look ready while every working tree is empty. Seen mid-init: 13 `+`, 3 blank, zero `-`, while `du -sh vendor` said 120K and `ls vendor/tinychannels` was empty.```bashdu -sh vendor # 120K = empty; a real checkout is GBs@@ -223,74 +194,33 @@ ls vendor/<module> | wc -l # 0 = empty, whatever status says### 3. Is your feature set the one CI uses?-`cargo test -p openhuman --lib` on default features is a **materially smaller-product** than CI builds, and the difference changes test *outcomes*, not just-which tests exist.--The mechanism is worth understanding because it is invisible in the output: a-feature flag can gate the *registration* of a tool, a test's expected side is a-static allowlist while its actual side is computed by **introspecting the built-binary**, and so the flag silently moves the actual. Nothing is stubbed, nothing-is skipped, and the failure names a product concept,-*"agents that carry tools but whose prompt names none of them,"* with no-mention of a feature anywhere.--*Falsified, from the two runs side by side:* on `0f1ecc9d2`, `openhuman --lib`-fails **5** tests on default and **3** under CI's set; the two that differ are-pure profile artefacts-(`every_prompt_names_at_least_one_tool_it_can_call` needs `runtime-node`,-`the_withheld_block_renders_for_a_renamed_session_with_a_filter` needs-`documents`). Reproduce CI exactly before asserting anything:+`cargo test -p openhuman --lib` on default features builds a smaller product than CI does, and the difference changes test outcomes, not just which tests exist. A feature flag can gate a tool's registration. A test can compare a static allowlist with what it finds by inspecting the built binary. The flag then moves the result silently, and the failure names a product concept, such as "agents that carry tools but whose prompt names none of them", with no mention of a feature.++In one comparison, `openhuman --lib` failed 5 tests on default features and 3 under CI's set. The two that differed were profile artifacts: `every_prompt_names_at_least_one_tool_it_can_call` needs `runtime-node`, and `the_withheld_block_renders_for_a_renamed_session_with_a_filter` needs `documents`. Reproduce CI exactly before you assert anything:```bashRUST_MIN_STACK=67108864 cargo test -p openhuman --lib \--features "$(bash scripts/ci/product-features.sh)"```-Tracked as openhuman#6512; per-profile detail in openhuman#6486.--**`RUST_MIN_STACK` is per-suite, not universal.**--*Falsified for `openhuman-tinyhumans`:* removing it and re-running still gives-`183 passed; 0 failed`. It is **not** a requirement there.--*Reported for `openhuman --lib`:* `web_chat` aborts with-`fatal runtime error: stack overflow` without it, which is why the CI lane-exports it. Not reproduced here: treat that as the reason the CI command above-carries it, and re-verify before relying on it elsewhere.+`RUST_MIN_STACK` is per suite, not universal. Removing it from `openhuman-tinyhumans` still gives `183 passed; 0 failed`, so that crate does not need it. For `openhuman --lib`, `web_chat` is reported to abort with `fatal runtime error: stack overflow` without it, which is why the CI lane exports it. That abort has not been reproduced locally, so re-verify before relying on it elsewhere.-Two crates, one variable, opposite answers. That is the argument against a-single blanket recipe: do not add a prerequisite by reflex. One that is not-needed teaches contributors the docs are unreliable, and it is precisely how the-misleading note above came to exist: someone's defensively-accumulated setup,-written down as necessity, never falsified.+Two crates, one variable, opposite answers. Do not add a prerequisite by reflex. An unneeded one teaches contributors that the docs are unreliable.### 4. Only now suspect a defect, and make the silence speak-If it compiled, the submodules are present and the feature set matches CI, then-a failure may be real. The trap at this stage is a layer that *correctly*-discards detail: a sanitizer, a scrubber, a redactor. The symptom is a generic-message where a specific one was produced.+If it compiled, the submodules are present and the feature set matches CI, a failure may be real. The trap at this stage is a layer that correctly discards detail, such as a sanitizer, scrubber or redactor. The symptom is a generic message where a specific one was produced.-Patch the discarding line to print what it drops, run once, and read the-underlying error. On openhuman#6487 a sanitized-`hosted agent invocation was rejected by policy` was hiding-`Validation("agent definition \`harness\` was not found")`, which named the-defect outright. **Reading seven links of a chain correctly is not the same as-watching it fire.**+Patch the discarding line to print what it drops, run once, and read the underlying error. In one case a sanitized `hosted agent invocation was rejected by policy` hid `Validation("agent definition \`harness\` was not found")`, which named the defect outright.### Why this order-The cheap checks are first because a wrong answer early is invisible later: a-suite that never compiled reports the same exit code as one that failed, and a-plausible-but-wrong explanation gets *confirmed* rather than tested, because-confirming it succeeds. Knowing that features matter is not enough: the rule is-not applied at the moment of asserting. Running CI's literal command is.+The cheap checks come first because a wrong answer early is invisible later. A suite that never compiled reports the same exit code as one that failed, and a plausible but wrong explanation gets confirmed instead of tested. Running CI's literal command is the surest way to avoid that.---## When in doubt-- Push the test as low in the layer stack as possible (Rust unit > Rust integration > Vitest > WDIO). Lower layers are faster, more deterministic, and cheaper to run.-- WDIO is for behaviours that genuinely cross UI ⇄ Tauri ⇄ embedded core ⇄ JSON-RPC. Don't drive a unit-testable concern through WDIO just because the UI exists.+- Put the test as low in the stack as you can (Rust unit, then Rust integration, then Vitest, then WDIO). Lower layers are faster, more deterministic and cheaper.+- Use WDIO only for behavior that really crosses UI, Tauri, the embedded core and JSON-RPC. Do not drive a unit-testable concern through WDIO just because the UI exists.- A failing happy path is a regression. A missing failure-path test is a gap. Both are bugs.