{
  "uid": "cogitave.learn.testing-and-quality.the-testing-standard",
  "kind": "moduleUnit",
  "href": "/modules/testing-and-quality/the-testing-standard/",
  "title": "The testing standard",
  "summary": "",
  "type": null,
  "products": [],
  "roles": [],
  "levels": [],
  "subjects": [],
  "headings": [
    "Test shape follows the layer",
    "Required types, by surface",
    "Coverage is a floor and a trend, never a goal",
    "Mutation testing is the real adequacy gate",
    "A flaky test is quarantined, not tolerated"
  ],
  "source": "The [Testing & Quality Standard](../../../../standards/docs/standards/testing-quality.md)\nis policy: it says *what* is required, and it opens with three non-negotiable\nprinciples. A behavior change is incomplete without a test **and** a doc change;\n**a flaky test is a bug**, never \"just retry\"; and **determinism is a property of\nthe suite** - same input, same result, on any machine, in any order.\n\n## Test shape follows the layer\n\nCogitave does not mandate one shape across the stack; the shape follows the\nfailure modes of the layer.\n\n- **Backend / hot path (Rust, Go) - a pyramid.** Roughly unit ~70%, integration\n  ~20%, end-to-end ~10%, as an order-of-magnitude guide, not a quota.\n- **Frontend / edge (TypeScript) - a trophy.** The integration tier (component +\n  interaction, real DOM, mocked network) catches the most regressions per unit of\n  maintenance, so emphasis runs integration > unit ~= e2e > static.\n\n> [!IMPORTANT]\n> The rule that overrides the ratios: **test at the lowest tier that can observe\n> the behavior.** A bug provable by a unit test must not require an e2e test.\n> Ratios are a smell detector, never a target - do not write tests to hit a\n> percentage.\n\n## Required types, by surface\n\nNot every type applies to every repo. Unit tests are **always** mandatory.\nIntegration is mandatory once a repo crosses a real boundary (DB, network, FFI,\ntransport), because adapters lie and types do not catch wire drift. Property-based\ntests are required on core logic (parsers, encoders, query planners, auth checks);\nfuzz tests on untrusted-input attack surfaces such as `yuva`, `namzu`, and\nprotocol decoders; contract tests on any boundary with an independent consumer;\nand evals on any agent-behavior change.\n\n## Coverage is a floor and a trend, never a goal\n\nHigh line coverage with weak assertions is theater. The thresholds are per-file\n70%, per-package 80%, and repo 90% target / 85% hard floor - but the **blocking\ngate is patch (diff) coverage: 90% of changed lines**. That is what makes the gate\nfair on legacy code and strict on new code, plus a no-regression ratchet on the\nrepo total. Watch the documented pitfalls: coverage is not correctness, coverage\nfarming (tests that touch lines without asserting) is review-rejectable, and\nexclusions must be checked-in, commented ignore rules - never a silent CI flag.\n\n## Mutation testing is the real adequacy gate\n\nFor modules flagged `tier: critical` (hot paths, auth, Core logic), line coverage\nis necessary but not sufficient. Mutation testing perturbs the code - flips a `<`,\ndrops a `+ 1` - and asserts the suite **fails**; a surviving mutant is an untested\nassertion. The threshold is **>= 80% of mutants killed** on the critical set\nbefore merge.\n\n## A flaky test is quarantined, not tolerated\n\nWhen CI detects a test that passes and fails on the same commit, it is\n**quarantined immediately** - it still runs and reports but does not block merge -\nand a defect is filed with an owner and a default **7-day deadline**. Past the\ndeadline, the quarantine blocks the owning team's merges. Blanket retries may\n*detect* flakiness; they may never be the *remedy*.\n",
  "partOf": "cogitave.learn.testing-and-quality",
  "durationInMinutes": 7,
  "quiz": null
}