PABCD Initiative Documentation Hub pabcd_initiative codexclaw cli-jaw

dev-testing

Source: skills/dev-testing/SKILL.md

Testing and QA router: strategy, harness choice, CI gates, TDD, and coverage.

왜 별도 모듈인가
테스트 없는 코드는 '동작하는 것 같다'에 머물고, 리팩토링이나 기능 추가 때 회귀를 잡지 못한다. AI 에이전트는 특히 얕은 해피패스 테스트만 작성하거나 실제 동작을 검증하지 않는 가짜 테스트를 만드는 경향이 있다. 이 스킬은 테스트 피라미드, 하니스 선택, CI 게이트, 커버리지 기준을 체계적으로 제공하여 변경의 위험도에 비례하는 검증을 보장한다.
LLM 단독 사용 시 발생하는 문제

LLM이 만드는 테스트의 가장 흔한 문제는 '동어 반복 테스트(tautology test)'다. expect(true).toBe(true)처럼 항상 통과하는 테스트, 또는 모든 의존성을 mock해서 실제 동작이 아니라 mock의 동작을 검증하는 테스트. LLM은 '테스트가 통과했다'는 신호를 만들도록 학습되었기 때문에, 테스트의 '질'보다 '존재'를 우선시한다.

또한 LLM은 해피 패스만 테스트한다. null 입력, 빈 배열, 경계값, 동시 접근, 네트워크 실패 같은 에지 케이스를 자발적으로 테스트하지 않는다. 이건 학습 데이터에서 해피 패스 테스트가 에지 케이스 테스트보다 압도적으로 많기 때문이다.

이 스킬이 해결하는 실제 문제

에이전트가 만드는 가짜 테스트

에이전트는 '테스트를 작성했습니다'라고 보고하지만, 실제로는 항상 통과하는 tautology 테스트(expect(true).toBe(true))이거나, 실제 동작을 검증하지 않는 mock만 잔뜩 있는 테스트를 만든다. 이 스킬은 테스트가 실제로 검증하는 것이 무엇인지 명시하게 한다.

하니스 선택의 혼란

에이전트가 프로젝트에 이미 Jest가 설정되어 있는데 Vitest를 새로 설치하거나, Playwright가 있는데 Cypress를 추가한다. Harness Selection은 기존 프로젝트의 테스트 인프라를 먼저 감지하고 활용하게 한다.

시각적 회귀의 미탐지

CSS 변경이 특정 뷰포트에서만 레이아웃을 깨뜨리는데, 유닛 테스트로는 잡을 수 없다. Visual QA는 스크린샷 비교로 시각적 회귀를 감지한다. dev-frontend의 visual-verification.md와 연동된다.

Triggers: test, TDD, coverage, CI gate, harness, E2E, visual QA, screenshot

Key Concepts

  • Test Pyramid
  • Harness Selection
  • CI Gate Strategy
  • TDD Workflow
  • Coverage as Risk Signal
  • Visual QA (screenshot verification)

Reference Documents

DocumentDescription
Backend Testing Patterns백엔드 테스트 패턴: 서비스 레이어, DB, API 통합 테스트
CI Pipeline TemplatesCI 파이프라인에서의 테스트 게이트와 캐싱 전략
Edge-First Testing Workflow엣지/서버리스 환경 테스트 패턴과 miniflare
Limited-Oracle / Score-Objective Evaluation
Load & Performance Testing부하 테스트: k6, Artillery, 성능 기준선 설정
ML Model EvaluationML 모델 평가: 메트릭, A/B 테스트, 데이터 드리프트 감지

Sections Overview

SectionSummary
Test Pyramid유닛 > 통합 > E2E 비율과 각 계층의 역할을 정의한다.
Harness Selection프로젝트 스택에 맞는 테스트 프레임워크를 선택한다.
CI Gates커버리지 임계값, 테스트 실패 시 머지 차단 규칙.
TDD WorkflowRed-Green-Refactor 사이클과 적용 시점 판단.
Visual QA스크린샷 비교, 뷰포트별 검증, 시각적 회귀 방지.

Academic References

PaperYearRelevance
Test Smells in LLM-Generated Unit Tests
arXiv:2410.10628
2024LLM이 생성한 유닛 테스트의 테스트 스멜(anti-pattern) 분석. 가짜 테스트 문제의 실증.
Do LLMs Generate Test Oracles That Capture the Actual or the Expected Program Behaviour?
arXiv:2410.21136
2024LLM 테스트 오라클이 실제 동작 vs 기대 동작 중 무엇을 검증하는지 분석.
TOGLL: Correct and Strong Test Oracle Generation with LLMs
arXiv:2405.03786
2024LLM으로 정확하고 강력한 테스트 오라클을 생성하는 방법론.
Disrupting Test Development with AI Assistants
arXiv:2411.02328
2024테스트 피라미드 프레임워크로 AI 생성 유닛 테스트의 품질과 분포를 평가.
The Ladder: A Reliable Leaderboard for ML Competitions (Blum & Hardt)
arXiv:1502.04585
2015튜닝 세트에서만 이기는 후보는 과적합. GATE-OVERFIT-01의 근거.
The Reusable Holdout (Dwork et al.)
arXiv:1506.02629
2015홀드아웃 데이터를 재사용하면서 적응적 과적합을 방지하는 방법.

Official Guides

Full Specification

Show full SKILL.md content

Testing & QA

Balance: ~40% Backend/API, ~40% Frontend/E2E (Playwright), ~20% Cross-cutting (CI, Security, TDD, Coverage) -- directional guidance, not a hard ratio.

Scope: test harnesses, fixtures, mock policy, runners, Playwright, CI gates, coverage. Root-cause analysis and debugging playbooks → dev-debugging.

  • Review/test boundary and test adequacy findings: see dev-code-reviewer.
  • CI pipeline ownership and deployment verification: see dev-devops.
  • Data pipeline testing and ETL validation: see dev-data.
  • Design direction context for rendered verification: see dev-uiux-design.
  • Browser QA implementation and rendered UI fixes: see dev-frontend.

This skill activates by change surface when work needs verification depth, regression coverage, or a reproducible test harness.

> C0/C1 work (small local patches): See dev §0.0 Work Classifier + §0.1 Patch Fast-Path before reading references.

> dev is canonical: dev §0.2 Rule Classes, §3 Verification Gate, and §5 Safety Rules apply to all work governed by this skill.

Modular References

FileWhen to ReadWhat It Covers
references/core/crud-test-matrix.mdWhen choosing verification depth for a classified task, or testing a CRUD sliceRisk-tier minimums, per-operation negatives, UI smoke rule
references/edge-first-testing.mdNew unit/service/integration tests for features (skip for regression/contract tests)Edge-first principle, test order by change type, 11-class edge matrix
references/backend-testing.mdBackend/API testingSupertest patterns, DB fixtures, auth mocking
references/ci-pipeline.mdCI configurationGitHub Actions, gates, caching, parallelism
references/load-testing.mdPerformance/load testing, C3+ production readinessk6/Locust, test types, measure→profile→verify, CI gates
references/ml-evaluation.mdML model/LLM evaluation, quality gatesLLM-as-judge, RAGAS, DeepEval, CI eval gate, regression detection. CI eval gates are dataset-versioned + regression-based: pin prompts/models/retrieval config, preserve traces, calibrate judges on golden examples, fail only on meaningful regressions or safety failures

When tests depend on current external API behavior, provider docs, CI service

behavior, test-environment versions, dependency audit evidence, or recorded

mock/fixture sources, read the active search skill and follow its

source-fetch and evidence-status rules.

---

1. Test Strategy

1.1 Models

ModelBest ForEmphasis
Test Pyramidmonoliths, librariesspeed, isolation
Testing Trophymodern web apps, REST backendsconfidence-to-cost
Test Honeycombmicroservices, async systemsboundary verification
LayerDefault ShareTypical Tools
Static analysisbase layertsc, ESLint, mypy, Ruff
Unit~25%Vitest, Jest, pytest
Integration~50%Supertest, httpx, Testcontainers
Contract~10%Pact, OpenAPI validators, Schemathesis
E2E~10%Playwright

1.3 Risk-First Priorities

  1. auth / session / permission boundaries
  2. money movement, quota, credits
  3. data mutation and irreversible actions
  4. file upload / parsing / external webhooks
  5. shared API contracts used by frontend clients
  6. error paths, retries, rollback behavior

1.4 Harness Selector

Manual / exploratory~5%human review
ProblemPrimary HarnessAvoid
pure business ruleunit / service testbrowser test
route + middleware + serializationAPI integration testmocking the route itself
DB query / migration / transactionreal DB integration testfake repository for SQL correctness
frontend consuming backend JSONcontract testmanual-only verification
rendered critical flowPlaywright smokeasserting internal React state

1.5 General Rules

  • Write tests for new features, bug fixes, refactors, and behavior changes.
  • Prefer one behavioral concern per test.
  • Use factories / builders for setup; avoid repeated inline blobs.
  • A fast real dependency beats a mock. A mock beats an untested branch.
  • If the failure is mysterious, delegate methodology to dev-debugging, then return here for the regression harness.
  • STRICT (TEST-ANTI-FLAKE-01): A time-based flake is a bug. Do not use sleep-based synchronization, retry-as-fix, or green-on-retry acceptance without a deterministic cause and harness correction.
  • Verification depth follows dev §3 DEV-VERIFY-FLOOR-01; CRUD per-operation negative coverage is owned by references/core/crud-test-matrix.md.

1.6 Property-Based & Mutation Testing (verified 2026-07-02)

rendered artifact (visual correctness)render-grounding loop (dev-pabcd C-RENDER-GROUNDING-01)static parse / tsc alone
TechniqueUse forDefault toolsWhen
Property-basedPure logic, parsers, serializers, state machines, API invariantsfast-check (TS), Hypothesis (Python)DEFAULT for invariant-heavy code
MutationJudging test-suite strength on critical domain logic, validators, security branchesStryker (JS/TS), mutmut (Python)Selective, after stable unit/property tests — not every PR
  • Vitest 4 is the current runner baseline: Browser Mode is stable (visual regression via

toMatchScreenshot, Playwright trace generation, expect.schemaMatching).

---

2. Backend & API Testing

> Deep reference: references/backend-testing.md

2.1 Coverage Map

2.2 Mock Strategy Hierarchy

real deterministic dependency
→ Testcontainers / ephemeral infra
→ recorded responses / thin fake
→ manual stub / fake
→ framework mock as last resort

2.3 Service & API Patterns

Mock dependencies at service boundaries. Use Supertest/httpx for route-level integration tests. Match response envelope shape from backend contracts.

2.4 Database Truth with Testcontainers

Use a real database when verifying migrations, transactions, unique constraints, foreign keys, query translation, and performance-sensitive SQL. Use Testcontainers for real DB truth in correctness-sensitive persistence tests. Start container in beforeAll/fixture setup, capture connection URI.

2.5 Fixture / Seed Synchronization

  • Prefer builders / factories over copied JSON snapshots.
  • Keep shared contract examples in fixtures/contracts/ or equivalent.
  • Seed data should expose stable IDs used by Playwright smoke flows.
  • If frontend mocks drift from backend fixtures, write or update a contract test first.

---

3. Contract Testing

Contract tests protect the frontend↔backend boundary. They sit between API tests and browser tests.

Rule: Playwright proves the experience. Contract tests prove the shared shape.

3.1 Contract-Stable Surface

  • response envelope: success, data, error, meta
  • error taxonomy: HTTP status + machine-readable error.code
  • pagination fields, auth headers, cookie behavior
  • requestId propagation
  • nullability, timestamps, enums, money serialization

3.2 Contract Options

LayerVerifyTypeScript DefaultPython Default
Service layervalidation, orchestration, domain errorsVitestpytest
API layerstatus, envelope, middleware, authSupertesthttpx / ASGITransport
Repository layerSQL / ORM correctnessTestcontainers + real DBTestcontainers + real DB
Background jobsidempotency, retry, dead-letterVitest + fake clockpytest + monkeypatch

3.3 Consumer Contract — TypeScript (Pact / PactV4)

PactV4 (aliased Pact) is the current interface and supports Pact Specification v4;

treat PactV3 as the legacy spec-v3 API. Workflow:

  1. Define interaction: provider state + request + expected response (matchers for flexible matching)
  2. Execute test against Pact mock server
  3. Assert consumer expectations
  4. Pact file auto-writes to pacts/ → publish to broker → provider verifies

See references/backend-testing.md for a full example.

3.4 Schema Verification

Use schema-based API testing (Schemathesis) to verify OpenAPI/GraphQL contract

compliance. (Dredd is legacy/inactive — do not adopt for new projects.)

3.5 Rules

  • Contract tests are strongly recommended for parallel FE/BE, public APIs, and cross-team contracts.
  • E2E success does not replace provider verification.
  • Store golden examples near the contract, not inside one app only.
  • If the shape is intentionally breaking, update the contract first, then all consumers.

---

4. Playwright Browser Testing

Use Playwright after API and contract tests are already trustworthy. Browser tests should validate rendered flows, accessibility-critical interactions, and real integration seams that lower layers cannot prove alone.

Helper Scripts Available:

  • scripts/with_server.py - Manages server lifecycle (supports multiple servers)

Run scripts with --help first — treat as black boxes to avoid context window pollution.

4.1 Decision Tree: Choosing Your Approach

User task → Static HTML? → Read file → find selectors → write Playwright script
         → Dynamic app? → Server running? → No: `python scripts/with_server.py --help`
                                           → Yes: Recon-then-action (navigate → screenshot → selectors → act)

4.2 Example: Using with_server.py

# Single server:
python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py

# Multiple servers:
python scripts/with_server.py \
  --server "cd backend && python server.py" --port 3000 \
  --server "cd frontend && npm run dev" --port 5173 \
  -- python your_automation.py

4.3 Reconnaissance-Then-Action Pattern

  1. Wait for an explicit app-ready signal or locator assertion → 2. Screenshot/inspect DOM → 3. Identify selectors → 4. Execute actions

4.4 Best Practices

  • Use bundled scripts as black boxes — run --help first, invoke directly.
  • Use sync_playwright() for synchronous scripts; always close the browser.
  • Prefer locator-based interactions and web-first assertions: expect(page.get_by_role("button", name="Save")).to_be_visible(), then click() on that locator.
  • Prefer user-facing locators, especially get_by_role() with an accessible name. Use get_by_label(), get_by_placeholder(), or get_by_test_id() when role/name cannot express the target.
  • Avoid networkidle, hard sleeps, and wait_for_timeout() in tests. Wait on observable app-ready signals, locator actions, or expect() assertions.
  • AI-authored tests (DEFAULT): Playwright MCP / Test Agents (planner/generator/healer) are generation-and-repair aids only — final acceptance still requires deterministic locators, web-first assertions, traces, and a human-readable failure artifact.

4.5 Reference Files

  • examples/ - Examples showing common patterns:
    • element_discovery.py - Discovering buttons, links, and inputs on a page
    • static_html_automation.py - Using file:// URLs for local HTML
    • console_logging.py - Capturing console logs during automation

4.6 Browser Testing Rules

  • Run contract tests and API tests first for broken-data bugs.
  • Use Playwright for rendered truth, not as a replacement for service tests.
  • Prefer one smoke flow per critical path over many brittle micro-flows.
  • If a failure looks like data-shape drift, go back to §2 Backend & API Testing or §3 Contract Testing.

---

5. CI Pipeline Integration

> Full workflow templates: references/ci-pipeline.md

5.1 Pipeline Order

quality (lint / typecheck)
→ unit + integration tests
→ contract tests
→ Playwright E2E
→ security scan
→ coverage aggregation + artifacts

5.2 Pipeline Template

Structure CI jobs in dependency chain: quality → backend-tests → contract-tests → e2e

Key configuration:

  • concurrency.cancel-in-progress: true — avoid wasted runs
  • strategy.fail-fast: false — for matrix builds
  • Shard large suites: --shard=${{ matrix.shard }}/N
  • Install Playwright deps: npx playwright install --with-deps chromium

See references/ci-pipeline.md for full GitHub Actions and GitLab CI templates.

5.3 Matrix & Parallelization

StyleBest ForTooling
consumer-driven contractrapidly changing frontend/backend teamsPact
schema-first contractOpenAPI-led backendsOpenAPI validators, Schemathesis
type-level contractTS monoreposshared types / codegen
full-stack smokefinal user confidencePlaywright
npx vitest run --shard=1/4
npx playwright test --shard=1/4 --workers=4
pytest -n auto --dist=loadgroup

5.4 Flaky Test Remediation

DimensionWhen to Use
Node / Python version matrixpackages, SDKs, shared libraries
OS matrixnative modules, CLI behavior
shard matrixlarge suites exceeding CI budget

Protocol: detect → quarantine if blocking → assign owner → reinstate after repeated green runs.

5.5 Rules

  • Do not let Playwright be the only blocking job.
  • Contract tests should run before browser tests.
  • Upload artifacts for failures: coverage, junit, traces, screenshots.
  • Fail the build on broken thresholds, not only test exit codes.

---

6. TDD Enforcement Mode

When ENFORCE_TDD=true is set in project instructions or explicitly requested, this section becomes mandatory.

6.1 RED → GREEN → REFACTOR

  1. RED — write the failing test first and verify it fails for the right reason.
  2. GREEN — write the minimum implementation to pass.
  3. REFACTOR — clean up after green, then rerun the affected suite.

6.2 Self-Audit Checklist

SymptomFirst Fix
passes locally, fails in CIdeterministic seeds, containerized deps, explicit waits
order-dependent failurereset shared state in fixtures
green on retry onlyremove wall-clock / random assumptions
screenshot noisestable CI image, mask dynamic regions

6.3 Vertical Tracer-Bullet TDD

Prefer one behavior test → minimal implementation → next behavior. Slice by something

a user, caller, or consuming module can observe, not by horizontal layers such as "DB",

"API", then "UI". Assert through public interfaces and durable contracts. Retire shallow

scaffolding tests when a stronger interface or acceptance test covers the same promise.

6.4 Default Style

CheckPass Criteria
Test written before implementation?test file added / updated before or with code
Failure observed before fix?red state was actually executed
Behavior-focused assertions?checks outputs, side effects, contracts
Regression locked in?failing case is now protected by a persistent test

Default to Hybrid: mock external systems, keep internal collaboration real unless it becomes too slow or unstable.

6.5 Boundary with dev-debugging

  • dev-testing owns the regression harness and enforcement loop.
  • dev-debugging owns root-cause methodology once a failure is mysterious or multi-layered.
  • After dev-debugging isolates the cause, come back here to lock it in with tests.

---

6.6 AI-Assisted Development Regressions

When an AI writes and reviews its own code, it carries the same assumptions into both steps. Automated tests break this feedback loop.

Common AI Regression Patterns

StyleBest For
London / mockistorchestration-heavy boundaries
Chicago / classicistdomain logic and transforms
Hybridmost production code
PatternDescriptionTest Strategy
Sandbox/production mismatchFix applied to one code path, not bothAssert same response shape in both modes
SELECT clause omissionNew field in response but missing from DB queryAssert all required fields are present and defined
Error state leakageError set but stale data not clearedAssert state cleanup on error transitions
Missing rollbackOptimistic UI update without recovery on failureAssert state restoration after simulated API error

Regression Naming Convention

Name regression tests with BUG-R{N} convention. Assert all required fields with a loop.

Sandbox-Mode API Testing

When the project supports a sandbox/mock mode, use it for fast DB-free regression testing:

  • Force sandbox mode in test setup: process.env.SANDBOX_MODE = 'true'
  • Assert sandbox responses match the same contract as production responses.
  • Treat sandbox/production parity as a high-priority regression target.
  • In sandbox/spike mode, write tests for bugs found — coverage grows organically. For production refactors, see §1.5 (tests required for behavior changes).

---

6.7 Test-Induced Production Defense Detection

Rule: Do not add production defensive code solely to satisfy unrealistic tests. A production guard is allowed only when the invalid state can occur at a real boundary or represents an explicit domain rule.

Production change smellLikely test problemRequired action
Internal if (!x) return added after unit test failsTest fixture omitted required fieldFix fixture factory or test boundary validation
Required field made optional to satisfy testTest is using invalid domain objectRestore required type and update test data
Catch-all added so test passesTest expects silence instead of failureAssert typed error or user-visible failure
Production default added for impossible stateTest bypassed constructor/parserUse real constructor/parser in test
Private helper exported only for testTest is coupled to implementationTest public behavior or move helper to test support
Sleep/retry added only for test flakeTest lacks deterministic synchronizationWait on observable condition or fake clock
NODE_ENV === "test" branch addedTest-only production behaviorRemove branch; improve test harness

Required questions before adding a guard:

  1. Is the input from an untrusted boundary? → If yes, validate at that boundary
  2. Can this state happen in production? → If no, fix the test
  3. What contract allows this value? → Cite schema/type/domain rule
  4. Would this hide a real bug? → If yes, fail fast instead

Banned patterns: process.env.NODE_ENV === "test" branches, silent fallbacks for impossible internal state, making required types optional for mocks, exporting internals only for tests.

Allowed guards: Boundary validation (process/network/user/file boundary), backward compatibility (documented old schema), security checks, domain invariants, observed production bug regressions, external dependency adapters.

---

7. Accessibility Testing

Component Level

  • jest-axe / vitest-axe: run axe-core on rendered components
  •   import { axe, toHaveNoViolations } from 'jest-axe'
      expect.extend(toHaveNoViolations)
      expect(await axe(container)).toHaveNoViolations()

Page Level

  • Playwright a11y assertions:
  •   import AxeBuilder from '@axe-core/playwright'
      const results = await new AxeBuilder({ page }).analyze()
      expect(results.violations).toEqual([])

CI Pipeline

  • Gate order (verified 2026-07-02): component axe (jest-axe/vitest-axe) → page axe

(@axe-core/playwright) → keyboard/focus/manual checks. **Blocking gate = zero

serious/critical axe violations + targeted manual checks.**

  • Lighthouse a11y score (≥90) is an advisory route-level smoke signal, NOT the blocking

gate — Lighthouse itself separates automated scoring from required manual checks.

  • Pa11y: page-level scanning for WCAG AA violations
  • Run a11y tests on EVERY page route, not just the homepage

Observability Verification

Verify trace propagation in integration tests. Assert that spans appear for critical paths. Check structured log format matches the schema in dev-backend/references/core/observability.md.

---

8. Security Testing

→ Delegated: threat modeling and secure design policy belong to dev-security.

This section covers the automated test hooks and CI gates that enforce those rules.

8.1 Minimum Security Stack

fast local checks
→ Semgrep / CodeQL gate
→ dependency audit
→ auth / validation regression tests

8.2 Dependency Scanning Commands

npm audit --audit-level=high
pip-audit --strict --desc

8.3 Semgrep Gate

The returntocorp/semgrep-action wrapper is deprecated (stated by the repo itself) —

run Semgrep natively in CI:

semgrep:
  runs-on: ubuntu-latest
  container: semgrep/semgrep
  steps:
    - uses: actions/checkout@v4
    - run: semgrep ci --config p/default --config p/javascript --config p/typescript --config p/python

(Open-source alternative engine: Opengrep, the LGPL-2.1 community fork — see

dev-security/references/static-analysis.md.)

8.4 Security Regressions

Test missing auth (expect 401) and verify error.code matches contract for every auth-protected endpoint.

8.5 Rules

  • dependency audit in CI
  • Semgrep or equivalent SAST
  • auth / permission regression tests
  • validation tests for malicious or malformed input
  • a blocking rule for high / critical dependency findings

---

9. Coverage & Quality Gates

9.1 Suggested Thresholds

These are project/risk-based, not universal minimums. Adjust for your context.

9.2 Outcome Metrics

MetricSuggested FloorIdeal
Line coverage70%85%+
Branch coverage60%80%+
Function coverage80%90%+
Diff coverage80%90%+

9.3 Coverage Workflow

  1. generate coverage reports
  2.    npm test -- --coverage
       npx vitest run --coverage
       pytest --cov --cov-report=xml
  3. review by priority: auth, payment, mutations, upload, contracts first
  4. write targeted tests for the gaps
  5. publish artifacts and fail the merge when thresholds drop

9.4 Quality Gate Checklist

  • [ ] focused unit / service tests
  • [ ] API integration tests for changed routes
  • [ ] contract tests for shared payload changes
  • [ ] Playwright smoke for critical rendered journeys
  • [ ] security scan / dependency scan
  • [ ] coverage thresholds and diff coverage
  • [ ] CI artifacts uploaded for failure analysis

9.5 Limited-Oracle / Score-Objective Evaluation

Use these rules when the true evaluator is scarce or costly and local checks are only

proxies. PABCD loop response to repeated candidate deaths is owned by dev-pabcd §10

Optimization-Loop Meta-Rules.

  • STRICT (GATE-ORACLE-VALIDITY-01): When the true evaluator/oracle is rate-limited

(limited submissions, paid runs) and local metrics are proxies, evaluator validity is a

prerequisite gate. Before trusting the proxy for accept/reject, quantify historical

divergence: cases where the proxy said better/equal but the oracle said worse. A proxy

with known optimistic bias must not be the sole acceptance evidence.

  • DEFAULT (GATE-PREFIX-HORIZON-01): Replay-based evidence (recorded logs, scripted

opponents) is prefix-valid only; it stops being valid when the candidate diverges from

the recorded trajectory. Candidates that diverge early need live adversarial evaluation

through a modeled opponent/environment, not replays. State the divergence turn/point

when citing replay evidence.

  • DEFAULT (GATE-INVARIANT-EV-01): Every hard invariant in an acceptance gate (a metric

that must not regress) needs an expected-value justification: protected value versus the

candidate-space it vetoes. If a hard invariant vetoes 3+ consecutive candidates that

target strictly larger gains, downgrade it to a soft cost and re-justify or remove.

Grounding: observed in a 14-discard optimization plateau where a prefix-only replay gate

and a hard draw-protection invariant locked a 3.5/8 score.

---

10. Pre-Flight Test Checklist

10.1 Change-Type Routing

  • [ ] pure business logic change → add / update unit or service tests
  • [ ] API or middleware change → add / update API integration tests
  • [ ] shared frontend↔backend payload change → add / update contract tests
  • [ ] rendered user flow change → add / update Playwright smoke coverage
  • [ ] auth / upload / billing / external integration change → add security or edge-case regression coverage

10.2 Harness Readiness

  • [ ] fixtures are deterministic and reusable
  • [ ] real dependencies are used where correctness matters
  • [ ] Testcontainers are used for DB truth, not mocked SQL
  • [ ] external APIs are mocked or recorded intentionally, not accidentally called live
  • [ ] ENFORCE_TDD requirements were followed if enabled

10.3 Contract & Data Integrity

  • [ ] response envelope remains stable or contract was updated first
  • [ ] error codes are asserted, not only HTTP status
  • [ ] requestId, pagination, and nullability are verified where relevant
  • [ ] frontend fixtures do not drift from backend examples

10.4 CI & Reporting

  • [ ] relevant CI jobs exist and are actually executed
  • [ ] sharding / matrix choices match project size
  • [ ] flaky failures were investigated instead of blindly retried
  • [ ] coverage / junit / trace artifacts are available on failure

10.5 Final Rule (risk-tier)

Verification intensity follows the work class (dev §0.0 / references/core/crud-test-matrix.md):

for C2 UI work, one focused smoke (manual click-through or one Playwright run) plus targeted

checks IS a complete story; for C3/C4 or release-sensitive work, a single smoke is not enough —

run the affected suites and required negatives. Manual/Playwright smoke is a risk-tier rule,

not a universal blocker.

unit / service
→ API integration
→ contract verification
→ Playwright smoke
→ CI gate + coverage + security scan

Patch Integrity Gate (TEST-PATCH-INTEGRITY-01, DEFAULT)

Source: sol research (SWE-bench containerized evaluation, addyosmani/agent-skills).

An agent that obtains green by weakening tests has not fixed the bug. Before

claiming implementation complete:

  1. Baseline: record which tests fail and their failure signatures BEFORE any

production code change.

  1. Implement: write the fix/feature.
  2. Re-run originals: execute the ORIGINAL test suite (not the modified version)

against the patched source. All baseline failures must now pass.

  1. Classify test changes: every test/config change is required (new test for

new behavior), suspicious (deleted assertion, lowered threshold, added skip,

reduced coverage exclusion), or unrelated.

  1. Justify suspicious changes: each suspicious change needs a stated reason.

"The test was wrong" is valid only with evidence of the original test's incorrectness.

Red flags that trigger escalation:

  • Deleted assertions without replacement
  • Snapshot updates without visual/behavioral verification
  • Coverage exclusions added in the same PR as the fix
  • @skip or .skip() added to failing tests
  • Threshold reductions (e.g., coverage 80% → 60%)
  • Type assertion suppressions (as any, @ts-ignore) in test files

TDD Evidence Contract (TEST-TDD-EVIDENCE-01, DEFAULT)

When TDD is claimed, durable evidence must show:

  • RED: failing test name + failure message (before production code)
  • GREEN: same test passing (after production code)
  • REFACTOR: full affected suite passing (after cleanup)

A TDD claim without RED evidence is not TDD.

---

Acceptance-Row Reachability (TEST-ROW-REACHABLE-01, DEFAULT)

Every row of an acceptance-criteria table must have a constructible precondition.

Before writing a row, ask: is there a call path that reaches this state? Does an

earlier guard consume this condition first, so the branch under test is never entered?

Does an operation that produces this value actually exist?

An unreachable row is decoration, not verification — the implementer tries to write

that test, cannot, and quietly drops it. This applies C-ACTIVATION-GROUNDING-01's

requirement (every conditional path names its activation scenario) to each row of the

acceptance table, not just to the plan's prose.

Common unreachable shapes:

  • The row asserts a rejection that an earlier, broader rule already rejects — the

specific guard is never exercised, so the test passes even if that guard is absent.

  • The row needs a state the public API cannot produce (no operation creates it).
  • The row asserts on a call-site argument the function never receives.
  • Two rows in the same table are mutually exclusive on the same tree (for example

"the gate reports a failure here" together with "the gate exits 0 overall").

Test Oracle Integrity (DEFAULT)

Three narrow contracts that stop false-green. No gate enforces any of them; the

reviewer is the only check.

TEST-PROMPT-SEAM-01. Do not assert on prose. A test may read a document only when

it extracts a value and compares it against a value from another source. Asserting

that a phrase exists in a file is a violation no matter how many files you read or

what the test's header says it is for.

  • Forbidden: assert.match(readFileSync(".../SKILL.md"), /prefer rg first/i) — one

source, phrase existence, breaks on harmless rewording, proves no behavior.

  • Allowed: parse the frontmatter description, pull a token out of it, and assert that

token appears in the runtime constant it is supposed to mirror — two sources, values

compared, breaks only when they genuinely disagree.

  • Outside this rule's scope, and allowed: asserting on non-prose values — version pins,

license names, runtime output, CLI stdout, file existence.

The rule was written after two such tests were deleted rather than repaired, and

the reason repair failed is the reusable part. Three designs were tried: a structured

metadata field in each document compared between them (nothing at runtime reads such a

field, so it becomes a third source of truth that passes whenever both copies are wrong

together); promoting the prose to a behavioral test (the behavior was already covered,

so this duplicated coverage while appearing to offset the deletion); and promoting a

doctrine statement the same way (no runtime branch implements it, so there is nothing to

compare against).

What that costs is stated plainly rather than hidden: the affected doctrine has **no

automated consistency check and is a human-review item. When prose has no

counterpart in code, a test that reads it can only check that the words are still

there.** Deleting it removes a false green; inventing a second document to compare it

against removes nothing and adds a lie.

TEST-ORACLE-INDEPENDENCE-01. Never derive the expected value from the code under

test.

  • Forbidden: assert.equal(fn(x), fn(x)); building the expectation with a helper the

code under test also uses; refreshing a snapshot from current output and calling that

verification.

  • Allowed: hardcode the expectation in the fixture, or compute it by an independent

route — a second implementation, a hand-worked example, an external spec.

TEST-PRECEDENCE-FIXTURE-01. When testing override / default / fallback, the three

values must all differ — otherwise the test cannot tell which path ran.

  • Forbidden: override "x", default "x", fallback "x" — every branch passes.
  • Allowed: override "from-flag", default "from-config", fallback "builtin", with

each case asserting the specific one.

A regression test should FAIL when the defect is reintroduced. Confirm it once by

mutation — break it, watch it go red, restore it, watch it go green. A regression test

that has never been seen red is an assertion about the test, not about the defect.

CI Green Discipline (TEST-CI-GREEN-01, STRICT)

The latest HEAD is the source of truth for whether CI is green.

  1. Inspect before editing. Read the failing job's log and its artifacts. A failure

you have not read is a failure you are guessing about.

  1. Make the minimal correct fix for that failure.
  2. Re-watch the latest HEAD, not the run you were looking at when you started.

Never blind-retry a failed job, and never push another change without new failure

evidence. Both produce the same illusion — activity that looks like progress while the

failure is unexamined. Re-running to measure a failure RATE is a different act and is

allowed; see references/ci-pipeline.md §5.2.

Exploratory QA Tier (TEST-CU-QA-01, DEFAULT)

Deterministic browser test suites and exploratory QA are different tools for different

jobs, and the split is worth stating because collapsing it wastes both:

  • Deterministic suites own regression guarding. They are the thing you keep.
  • Exploratory QA through whatever browser or screen-control capability the runtime

offers owns immediate proof that a surface built right now actually works.

Protocol: inspect → act → re-inspect. When DOM inspection is unavailable, fall back

to screenshots and read the image back — a screenshot produced but never read is

not an observation.

Evidence names the flow, the states traversed, the result, and the artifacts. **Promote

any flow that must stay guarded into a deterministic test**; exploratory proof does not

accumulate, so a flow left only in QA is a flow that will regress unnoticed.

The tool ladder for this tier is QA-TOOL-LADDER-01 in dev — start at the runtime's

embedded browser and escalate only with a stated reason.

MetricTarget
Defect detection rate> 80%
Mean time to detect< 1 CI run
Test signal-to-noise> 95%
Contract drift ratenear 0