Browse documentation

Technical documentation / Reference

Risk-based testing

Tests protect contracts and risks, not raw counts. P0 blocks release; P1 protects important behavior; P2 samples boundaries and failure modes.

Decision rubric

Keep a test when it uses the lowest useful layer, asserts an observable contract, models a realistic regression, has one unique canonical owner, is deterministic, and has a justified runtime cost. Move or rewrite it when any check fails.

Tiers: P0 covers release-blocking data, safety, and protocol invariants; P1 covers important user-facing behavior and failure handling; P2 covers representative boundaries and unusual inputs; diagnostic tests measure performance without claiming correctness.

Applied inventory

Sampled areaRiskClassificationCanonical ownerDecision
Picker helperClamp/scroll arguments could be ignoredmisleadingsrc/tui/state/tests/pickers.rsrewrite; keep helper and state coverage distinct
Modal secret testFixture had no secret; preview redaction could regress unnoticedtautologicalsrc/tui/sessions/commands.rs testrewrite; canonical preview redaction owner
Title waitsBusy yield and speed ceilings are scheduler-dependenttiming-sensitivesrc/agent/tests/titles_herdr.rsrewrite with completion channels and bounded deadlock guard
Filesystem cacheDirectory mtime and zero elapsed are platform/timing racestiming-sensitivesrc/tools/fs_cache.rsrewrite with private keys and aged entries
CLI hook cleanupImmediate marker absence does not prove descendant cleanuptautologicaltests/cli_smoke.rsrewrite with PID publication and ESRCH
ast-grep timeout30-second test is costly and obscures timeout contracttiming-sensitivesrc/tools/ast_grep.rsrewrite with test-only short context timeout; production remains 30s
Auth concurrency duplicateSame duplicate contract existed in facade and auth moduleduplicate contractsrc/config/auth.rsconsolidate; retain lower-level canonical test
Settings unknown fieldsParser rejection and facade wiring are distinct risksunique contractssrc/config/settings.rs, src/config/mod.rskeep both; distinct owners
Resume/continue integrationResume identity and continue selection are separate CLI contractsunique contractstests/cli_smoke.rskeep both
Responsiveness timing gateDraw latency is a performance diagnostic, not a general correctness claimbenchmark/diagnosticTUI render testskeep as explicit timing gate
SSE partitionsChunk boundaries must not change complete events or metadataP2 boundarysrc/mcp/sse.rskeep oracle comparison including finish()
Append durabilityWrite, flush, sync, and rollback failures affect durable stateP0 fault injectionsrc/sessions/write.rskeep one table-driven stage matrix plus distinct happy path
Unicode editorGrapheme-safe mutation must preserve valid UTF-8 cursor boundariesP2 boundarysrc/tui/prompt_editor/tests.rsrepresentative mutation coverage is now kept; broader operations are follow-up

P2 claims are limited to these representative samples; they do not claim exhaustive platform, Unicode, PTY, or fault-matrix coverage.

Direct helper redaction assertions live under src/output/redaction.rs, and session duplicate coverage lives in src/sessions/write.rs. The metadata failure case explicitly asserts SessionAppendOutcome::DurableJsonlMetadataUpdateFailed while checking readable JSONL and the metadata path's directory boundary.

Local checks

Run focused checks while working, then the full suite before merging:

cargo test --locked --lib agent::
cargo test --locked --lib providers::
cargo test --locked --lib tools::
cargo test --locked --lib tui::
cargo test --locked --lib mcp::
cargo test --locked --lib config::
cargo test --locked --lib sessions::
cargo test --locked --lib context::
cargo test --locked --bin magi-code
cargo test --locked --test foundation
cargo test --locked --test cli_smoke
cargo test --locked --doc
cargo test --locked --quiet

CI checks public Rust API compatibility with cargo semver-checks against the pull request's base branch. New public exports need an intended external use, covered by tests/foundation.rs or equivalent evidence.

Test health and CI

cargo test --quiet is the canonical full-suite command. CI runs root library, binary, foundation, CLI smoke, and doctest partitions in named failure-isolated steps. Each step appends one TSV row with status, duration, run id, attempt, and SHA; the combined per-attempt artifact is named test-health-${{ github.run_attempt }}, so failed workflow reruns remain available for flake comparison. Artifacts across run history expose these fields for later analysis, but the workflow does not create an automatic historical graph. A flake means fail then pass on an explicit workflow rerun; there are no automatic retries.

Maintenance rules

Keep unique P0/P1 contracts and representative P2 boundaries. Rewrite misleading tests, consolidate obvious duplicates, use bounded deterministic signals instead of sleeps/yields, and label diagnostics honestly.

Edit this page on GitHub ↗