test(gates): testing law, nextest tiers without retries, cargo x e2e and coverage, CI push and nightly jobs, plan DFOG846Z
6f5ecb2e2a968fe56f558644b0556a9c0fc83b5b
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 8398eaec9342
There are many coding harnesses - but this one is fast
6f5ecb2e2a968fe56f558644b0556a9c0fc83b5b
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+405 / −218 text lines
+5 / −0 text lines
new file mode 100644+11 / −0 text lines
new file mode 100644+10 / −0 text lines
+10 / −16 text lines
# Source of truth: .system/specs/SMH-SPEC-SPEC0001-smith-specification/index.md.# Every commit: unit, property, snapshot, and bound tests.default-filter = 'not binary(/^e2e_/)'+19 / −0 text lines
- Every `cargo x` command accepts argument passthrough; `-p` scoping overrides workspace defaults. Lockfile-wide commands (`audit`, `bootstrap`, `ci`) reject scope explicitly.## Testing- Every file with test code names the spec it proves (`SMH-SPEC-…`) in its header; `cargo x arch` rejects test code without one.- No retries; a flaky test is a bug. Tests never sleep or poll to wait for the system under test; time, cancellation, and readiness are injected or synchronized. Fixtures may pace input; every wait carries a deadline.- Regression first: a bug fix lands with the test that failed before it; a refactor starts with a test that pins the behavior it must keep; a security finding lands with the test that encodes the boundary.- Kinds, each where it is strong: - end to end, core: the real binary through cli, eval, and rpc; real files, real sockets, scripted provider; every user-visible workflow has one; the acceptance gate for correctness. - end to end, frontends: every `smith-ui` consumer owns a harness fit to its technology (tui: PTY driver with screen snapshots and terminal-state checks; mcp: a real MCP client over stdio; web: a browser driver); the intent vocabulary is the contract and degradation per the intent law is asserted, not assumed; the acceptance gate for usability. - unit and behavior: core crates; one owner per spec sentence; mock `StreamFn`; isolated dirs. - property: pure functions with algebraic laws (encode and decode, canonicalization, span and index math, masking); `proptest` with checked-in regression files. - snapshot: rendered frames, RPC lines, traces, help text; `insta`, reviewed diffs, redacted ids and times. - conformance kits: providers, plugin guests, frontends; fixtures in, vocabulary out. - golden corpus: checked-in sessions; replay and trace byte-identical; regenerated only with a frame-version bump. - bounds: allocation counts and type sizes; exact pins; tighten only. - mutation: all first-party crates nightly; missed mutants become issues. - coverage: `cargo-llvm-cov` over every tier; reported per push as a diff, never a percentage gate; uncovered spec sentences are the backlog.- Tiers: `cargo x test` (unit, property, snapshot, bounds; every commit) → `cargo x e2e` (binary; every push) → `cargo x coverage` (report) → nightly (`mutants`, golden regeneration check).- A dev dependency earns its place by a test that uses it.new file mode 100644+57 / −0 text lines
---id: SMH-PLAN-DFOG846Ztype: plantitle: "Testing Methodology"spec: SMH-SPEC-SPEC0001status: approveddepends_on: [SMH-PLAN-CORE0002]---# Testing Methodology## Entry- RULES `## Testing` names the kinds, the tiers, and the regression-first law.- 191 tests, ≈ 4 s, nextest process-per-test; conformance kit for providers; allocation bounds pinned.- Findings behind the plan: retries masked timing races; 26 of 30 test-bearing files cite no spec; mutation scope covered two crates and missed seven boundary comparisons in `config.rs`; `insta`, `proptest`, `expectrl`, `assert_fs`, `tokio` were declared and unused; `smith_core::trace::replay` had no corpus.## Decisions- End to end is the acceptance gate: core e2e drives the built binary through cli, eval, and rpc; each frontend owns a harness fit to its technology.- Retries are zero everywhere; waits are injected or synchronized with deadlines.- Every test file cites its spec; `cargo x arch` enforces it.- Property, snapshot, golden, bounds, mutation, coverage each have one home and one command; nothing is wired twice.- Fuzzing is deferred until its nightly-toolchain footprint is understood; decoders of untrusted bytes are listed as future targets.## Order1. Law and wiring: RULES `## Testing`; nextest tiers (`default` excludes `e2e_*`, `e2e` selects them, `mutants` unchanged, all `retries = 0`); `cargo x e2e`, `cargo x coverage` (`cargo-llvm-cov`, lcov artifact, summary); CI: push runs `ci` and `e2e`; nightly runs `mutants` and `coverage`.2. Core e2e in `smith-cli/tests/e2e_*.rs`: eval mock turn, eval `--json`, rpc over stdin/stdout (ping, prompt, abort, wait, malformed line, shutdown), auth round trip, session file survives a second run and replays its trace.3. Spec-reference gate in `cargo x arch`; headers on every test-bearing file.4. Sleep audit: rpc poll loops become settle signals with deadlines; remaining sites reviewed one by one.5. Property tests: frame encode and decode, `canonical_json` idempotence and order independence, `Span` arithmetic, `EntryContent` and `EntryContentRef` byte equality, secret mask and unmask; regression files checked in.6. Snapshots with `insta`: `eval --json`, rpc line sequences, `build_trace`, `--help`; ids and timestamps redacted.7. Golden corpus: `smith-core/tests/golden/*.smh` plus `*.trace.json`; byte-identical replay; `SMITH_GOLDEN=regenerate` with a frame-version bump only.8. Mutation: scope every first-party crate; fix the seven `config.rs` misses; nightly job.9. Coverage: `cargo llvm-cov nextest` across tiers; lcov artifact and summary in the CI log; no threshold.10. Research: supersede RSCH0013 with the measured state; remove dev dependencies no test uses; fix the criterion bench.11. Frontend e2e stubs: one harness skeleton per `smith-ui` consumer, filled when the frontend lands (tui first, PTY via `expectrl`).## Interfaces- `xtask`: `e2e`, `coverage`; `arch` gains the spec-reference check.- `.config/nextest.toml`: profiles `default`, `e2e`, `mutants`.- `.ci/`: `check.kdl` (push), `e2e.kdl` (push), `nightly.kdl` (schedule).- `smith-cli/tests/e2e_*.rs`: the core e2e suite.- `smith-core/tests/golden/`: the replay corpus.## Risks- e2e tests spawn the binary; cold builds dominate CI time; `cargo x e2e` shares the target dir with `ci`.- Snapshot review needs discipline: a blind `INSTA_UPDATE=always` turns the gate into noise; snapshots are reviewed in the diff.- Golden regeneration is a deliberate, versioned act; an accidental regen hides a determinism break.- Coverage numbers vary with e2e process boundaries; the report is a map, not a score.## Exit- Every step green under `cargo x check`, `cargo x e2e`, `cargo x arch`; CI jobs observed running on the public repository.deleted file mode 100644+0 / −101 text lines
//! End-to-end credential store behavior through the `smith auth` CLI.use assert_cmd::Command;use std::path::PathBuf;fn scratch(name: &str) -> PathBuf { std::env::temp_dir().join(format!("smith-auth-test-{name}-{}", std::process::id()))}fn smith(name: &str) -> Command { let mut command = Command::cargo_bin("smith").unwrap(); command .env("XDG_DATA_HOME", scratch(name)) .env_remove("ANTHROPIC_API_KEY") .env_remove("OPENAI_API_KEY") .env_remove("GEMINI_API_KEY"); command}#[test]fn add_list_remove_round_trips_with_user_only_permissions() { let mut add = smith("roundtrip"); add.args(["auth", "add", "--provider", "anthropic"]) .write_stdin("sk-test-secret\n") .assert() .success() .stdout("anthropic: stored\n"); let mut list = smith("roundtrip"); list.args(["auth", "list"]) .assert() .success() .stdout("anthropic: store\n"); let mut check = smith("roundtrip"); check .args(["auth", "check", "--provider", "anthropic"]) .assert() .success() .stdout("anthropic: store\n"); let mut remove = smith("roundtrip"); remove .args(["auth", "remove", "--provider", "anthropic"]) .assert() .success() .stdout("anthropic: removed\n"); let mut gone = smith("roundtrip"); gone.args(["auth", "check", "--provider", "anthropic"]) .assert() .failure() .stderr(predicates::str::contains( "no credential for anthropic (tried store, env ANTHROPIC_API_KEY)", )); let mut empty = smith("roundtrip"); empty .args(["auth", "remove", "--provider", "anthropic"]) .assert() .failure() .stderr(predicates::str::contains( "no stored credential for anthropic", ));}#[test]fn stored_secret_never_prints_and_permissions_are_user_only() { let mut add = smith("hygiene"); add.args(["auth", "add", "--provider", "openai"]) .write_stdin("sk-super-secret-value\n") .assert() .success(); let secret_file = scratch("hygiene").join("smith/auth/openai"); #[cfg(unix)] { use std::os::unix::fs::PermissionsExt; let mode = std::fs::metadata(&secret_file) .unwrap() .permissions() .mode(); assert_eq!(mode & 0o777, 0o600); } let mut list = smith("hygiene"); list.args(["auth", "list"]) .assert() .stdout("openai: store\n");}#[test]fn check_reports_environment_source() { let mut check = smith("envsource"); check .args(["auth", "check", "--provider", "google"]) .env("GEMINI_API_KEY", "sk-env") .assert() .success() .stdout("google: env:GEMINI_API_KEY\n");}new file mode 100644+101 / −0 text lines
//! End-to-end credential store behavior through the `smith auth` CLI.use assert_cmd::Command;use std::path::PathBuf;fn scratch(name: &str) -> PathBuf { std::env::temp_dir().join(format!("smith-auth-test-{name}-{}", std::process::id()))}fn smith(name: &str) -> Command { let mut command = Command::cargo_bin("smith").unwrap(); command .env("XDG_DATA_HOME", scratch(name)) .env_remove("ANTHROPIC_API_KEY") .env_remove("OPENAI_API_KEY") .env_remove("GEMINI_API_KEY"); command}#[test]fn add_list_remove_round_trips_with_user_only_permissions() { let mut add = smith("roundtrip"); add.args(["auth", "add", "--provider", "anthropic"]) .write_stdin("sk-test-secret\n") .assert() .success() .stdout("anthropic: stored\n"); let mut list = smith("roundtrip"); list.args(["auth", "list"]) .assert() .success() .stdout("anthropic: store\n"); let mut check = smith("roundtrip"); check .args(["auth", "check", "--provider", "anthropic"]) .assert() .success() .stdout("anthropic: store\n"); let mut remove = smith("roundtrip"); remove .args(["auth", "remove", "--provider", "anthropic"]) .assert() .success() .stdout("anthropic: removed\n"); let mut gone = smith("roundtrip"); gone.args(["auth", "check", "--provider", "anthropic"]) .assert() .failure() .stderr(predicates::str::contains( "no credential for anthropic (tried store, env ANTHROPIC_API_KEY)", )); let mut empty = smith("roundtrip"); empty .args(["auth", "remove", "--provider", "anthropic"]) .assert() .failure() .stderr(predicates::str::contains( "no stored credential for anthropic", ));}#[test]fn stored_secret_never_prints_and_permissions_are_user_only() { let mut add = smith("hygiene"); add.args(["auth", "add", "--provider", "openai"]) .write_stdin("sk-super-secret-value\n") .assert() .success(); let secret_file = scratch("hygiene").join("smith/auth/openai"); #[cfg(unix)] { use std::os::unix::fs::PermissionsExt; let mode = std::fs::metadata(&secret_file) .unwrap() .permissions() .mode(); assert_eq!(mode & 0o777, 0o600); } let mut list = smith("hygiene"); list.args(["auth", "list"]) .assert() .stdout("openai: store\n");}#[test]fn check_reports_environment_source() { let mut check = smith("envsource"); check .args(["auth", "check", "--provider", "google"]) .env("GEMINI_API_KEY", "sk-env") .assert() .success() .stdout("google: env:GEMINI_API_KEY\n");}new file mode 100644+99 / −0 text lines
//! Provider selection and provenance behavior through the `smith` CLI.//! CLI tests assert on outcomes.use assert_cmd::Command;use predicates::prelude::PredicateBooleanExt;fn smith(name: &str) -> Command { let mut command = Command::cargo_bin("smith").unwrap(); command .env( "XDG_DATA_HOME", std::env::temp_dir().join(format!("smith-sel-test-{name}-{}", std::process::id())), ) .env_remove("SMITH_PROVIDER") .env_remove("SMITH_MODEL") .env_remove("SMITH_BASE_URL") .env_remove("ANTHROPIC_API_KEY") .env_remove("OPENAI_API_KEY") .env_remove("GEMINI_API_KEY"); command}#[test]fn eval_without_provider_fails_naming_the_selection_surfaces() { smith("noprovider") .args(["eval", "hi"]) .assert() .failure() .stderr(predicates::str::contains( "no provider selected (tried --provider/SMITH_PROVIDER)", ));}#[test]fn eval_missing_credential_names_store_and_env_without_leaking_secrets() { let assert = smith("nocreds") .args([ "eval", "--provider", "anthropic", "--model", "claude-sonnet-4-5", "hi", ]) .env("ANTHROPIC_API_KEY", "") .assert() .failure(); assert .stderr(predicates::str::contains( "no credential for anthropic (tried store, env ANTHROPIC_API_KEY)", )) .stderr(predicates::str::contains("sk-").not());}#[test]fn command_line_overrides_environment_and_reports_provenance() { smith("provenance") .args([ "eval", "--provider", "anthropic", "--model", "claude-sonnet-4-5", "hi", ]) .env("SMITH_PROVIDER", "google") .env("SMITH_MODEL", "gemini-3-pro") .env_remove("ANTHROPIC_API_KEY") .assert() .failure() .stderr(predicates::str::contains( "provider=anthropic(cli) model=claude-sonnet-4-5(cli)", )) .stderr(predicates::str::contains("provider=google").not());}#[test]fn environment_selection_reports_env_provenance() { smith("envprov") .args(["eval", "hi"]) .env("SMITH_PROVIDER", "google") .env("SMITH_MODEL", "gemini-3-pro") .assert() .failure() .stderr(predicates::str::contains( "provider=google(env) model=gemini-3-pro(env)", ));}#[test]fn mock_eval_still_runs_without_selection() { smith("mock") .args(["eval", "--mock", "hi"]) .assert() .success() .stdout("mock provider: no model configured\n");}deleted file mode 100644+0 / −99 text lines
//! Provider selection and provenance behavior through the `smith` CLI.//! CLI tests assert on outcomes.use assert_cmd::Command;use predicates::prelude::PredicateBooleanExt;fn smith(name: &str) -> Command { let mut command = Command::cargo_bin("smith").unwrap(); command .env( "XDG_DATA_HOME", std::env::temp_dir().join(format!("smith-sel-test-{name}-{}", std::process::id())), ) .env_remove("SMITH_PROVIDER") .env_remove("SMITH_MODEL") .env_remove("SMITH_BASE_URL") .env_remove("ANTHROPIC_API_KEY") .env_remove("OPENAI_API_KEY") .env_remove("GEMINI_API_KEY"); command}#[test]fn eval_without_provider_fails_naming_the_selection_surfaces() { smith("noprovider") .args(["eval", "hi"]) .assert() .failure() .stderr(predicates::str::contains( "no provider selected (tried --provider/SMITH_PROVIDER)", ));}#[test]fn eval_missing_credential_names_store_and_env_without_leaking_secrets() { let assert = smith("nocreds") .args([ "eval", "--provider", "anthropic", "--model", "claude-sonnet-4-5", "hi", ]) .env("ANTHROPIC_API_KEY", "") .assert() .failure(); assert .stderr(predicates::str::contains( "no credential for anthropic (tried store, env ANTHROPIC_API_KEY)", )) .stderr(predicates::str::contains("sk-").not());}#[test]fn command_line_overrides_environment_and_reports_provenance() { smith("provenance") .args([ "eval", "--provider", "anthropic", "--model", "claude-sonnet-4-5", "hi", ]) .env("SMITH_PROVIDER", "google") .env("SMITH_MODEL", "gemini-3-pro") .env_remove("ANTHROPIC_API_KEY") .assert() .failure() .stderr(predicates::str::contains( "provider=anthropic(cli) model=claude-sonnet-4-5(cli)", )) .stderr(predicates::str::contains("provider=google").not());}#[test]fn environment_selection_reports_env_provenance() { smith("envprov") .args(["eval", "hi"]) .env("SMITH_PROVIDER", "google") .env("SMITH_MODEL", "gemini-3-pro") .assert() .failure() .stderr(predicates::str::contains( "provider=google(env) model=gemini-3-pro(env)", ));}#[test]fn mock_eval_still_runs_without_selection() { smith("mock") .args(["eval", "--mock", "hi"]) .assert() .success() .stdout("mock provider: no model configured\n");}+93 / −2 text lines
"usage: cargo x <check|lint|fmt|test|doc|arch|mutants [args...]|audit|ci|release|bootstrap>\n", "usage: cargo x <check|lint|fmt|test|e2e|coverage|doc|arch|mutants [args...]|audit|ci|release|bootstrap>\n",const LLVM_COV_VERSION: &str = "0.9.1";/// End-to-end tier: the built binary through cli, eval, and rpc; test/// binaries named `e2e_*`, selected by the `e2e` nextest profile.fn cargo_e2e(extra: &[OsString]) -> ExitCode { let args = scoped( &[ "--locked", "--workspace", "--all-features", "--profile", "e2e", ], extra, ); nextest_run_os(&args)}/// Coverage report over every tier; informational, never a percentage gate./// Both tiers accumulate into one profile set, then `target/coverage/lcov.info`/// and the per-file summary are produced from it.fn cargo_coverage(extra: &[OsString]) -> ExitCode { let installed = install_llvm_cov(&[]); if installed != ExitCode::SUCCESS { return installed; } if std::fs::create_dir_all(target_dir().join("coverage")).is_err() { return fail("cannot create target/coverage\n"); } let tiers: [&[&str]; 2] = [&[], &["--profile", "e2e"]]; let base = [ "llvm-cov", "nextest", "--no-report", "--locked", "--workspace", "--all-features", ]; let clean = run_os( "cargo", &["llvm-cov", "clean", "--workspace"].map(OsString::from), ); if clean != ExitCode::SUCCESS { return clean; } for tier in tiers { let mut args: Vec<&str> = base.to_vec(); args.extend_from_slice(tier); // A tier with no matching tests is a report, not a failure. args.push("--no-tests=warn"); let ran = run_os("cargo", &scoped(&args, extra)); if ran != ExitCode::SUCCESS { return ran; } } let lcov = [ "llvm-cov", "report", "--lcov", "--output-path", "target/coverage/lcov.info", ]; let wrote = run_os("cargo", &lcov.map(OsString::from)); if wrote != ExitCode::SUCCESS { return wrote; } run_os( "cargo", &["llvm-cov", "report", "--summary-only"].map(OsString::from), )} install_llvm_cov,fn install_llvm_cov(_extra: &[OsString]) -> ExitCode { let tool = tool_present_bin("cargo-llvm-cov", LLVM_COV_VERSION, || { cargo(&[ "binstall", "--no-confirm", &format!("cargo-llvm-cov@{LLVM_COV_VERSION}"), ]) }); if tool != ExitCode::SUCCESS { return tool; } run_os( "rustup", &["component", "add", "llvm-tools"].map(OsString::from), )}