Ai agents validation and qa

From rjmurillo/ai-agents · View interactive version

Ai agents validation and qa is an AI agent skill from the GitHub repository rjmurillo/ai-agents. What counts as evidence in ai-agents, how to produce it, and the contract for authoring CI workflows, composite actions, validation scripts, and CI ratchet baselines. Covers TESTING-RIGOR pos+neg+edge, test layout, coverage proof, runtime-contract tests, ADR-034 QA skips, and CI script rules (refere

How to use this skill

Skill file

ai-agents Validation and QA

<!-- vendor-portability: contributor-facing knowledge pack for the rjmurillo/ai-agents repo itself; intentionally references upstream paths because its audience is repo contributors, not plugin consumers. Declared paths: .agents/governance/FAILURE-MODES.md, .agents/governance/TESTING-ANTI-PATTERNS.md, .agents/governance/TESTING-RIGOR.md, .agents/governance/test-location-standards.md, .project-toolkit/architecture/ADR-, .project-toolkit/architecture/ADR-034-investigation-session-qa-exemption.md, .project-toolkit/retrospective, scripts/modules/investigation_allowlist.py, scripts/validate_session_json.py, scripts/validation/pre_pr.py -->

This repo runs verification-based governance: a claim is true when a gate, test, or command output says it is, not when an agent asserts it. This skill defines the evidence bar for code changes, where tests live and how they are collected, the anti-pattern canon (each entry paid for by a real incident), and the QA gate semantics at session end.

Audience: a zero-context contributor (human or model) about to write, run, or skip tests in this repository.

Triggers

Before authoring or editing a CI workflow, composite action, validation script, or CI ratchet baseline file, read ci-scripts.

Scope Boundaries

| You want | Use instead |

|----------|-------------|

| Triage a red CI check or blocked push (other than editing a CI script or ratchet baseline) | ai-agents-debugging-playbook |

| Measure drift, budgets, telemetry, coverage trends | ai-agents-diagnostics-toolkit |

| Probe an external tool's runtime behavior empirically | ai-agents-empirical-probe-toolkit |

| Understand which gates a change class triggers | ai-agents-change-control |

| Decide whether two pieces of evidence are independent, or whether a named check ran | evidence-provenance |

| Session-log mechanics beyond the QA row | .claude/rules/session-logs.md |

Process

Phase 1: Internalize the evidence bar

.agents/governance/TESTING-RIGOR.md is BLOCKING for code changes (its own Status line, TESTING-RIGOR.md:5). The bar, per function you add or change:

| Requirement | Concretely |

|-------------|-----------|

| Positive test | Valid input produces the expected output |

| Negative test | Invalid input produces the language's idiomatic error, asserted |

| Edge tests | Whitespace, empty, None, wrong type |

| Every error branch | Each raise / error-return path exercised |

| Every conditional branch | Including branches that only change user-facing strings |

| Mocked I/O | No live subprocess, API, or file dependencies in unit tests |

| CLI contract | argv-failure exits, exit codes, stdout vs --output tested |

| Coverage proof | 100% block coverage on changed files (see Phase 4) |

Origin story: in one PR, the original 20 unit tests gave 24% block coverage; adding negative, edge, and branch tests raised it to 100% and caught real defects the happy-path tests missed (whitespace handling on verdict matching, conditional OTHER-hint emission, type validation). That review created TESTING-RIGOR.md (TESTING-RIGOR.md:3-16). The rule exists because bots (Copilot, CodeRabbit, Gemini) reliably catch what happy-path tests skip, at roughly 10x the cost of writing the tests up front (TESTING-RIGOR.md:97).

Coverage targets by risk tier (AGENTS.md Standards; TESTING-ANTI-PATTERNS.md:165-172): 100% security-critical, 80% business logic, 60-70% docs/glue. "Security-critical" includes secret handling, input validation, command execution, path sanitization, auth checks.

Quality trumps quantity: .agents/governance/TESTING-ANTI-PATTERNS.md bans coverage theater (assertion-free tests), brittle mocks for impossible scenarios, unit-tests-as-only-testing, quantity over quality, and testing entirely after the fact. A test that never failed during development may not be testing anything (TESTING-ANTI-PATTERNS.md:91).

Phase 2: Know where tests live and how they are collected

pytest collects only testpaths = ["tests"] (pyproject.toml [tool.pytest.ini_options].testpaths). Everything else runs explicitly.

| Location | Collected by default | What lives there | Run it |

|----------|---------------------|------------------|--------|

| tests/ | Yes | Root suite: scripts, hooks (tests/hooks/), build scripts (tests/build_scripts/), workflows, harness-specific suites (tests/claude_mem/, tests/claude/skills/) | uv run pytest tests/ -x |

| tests/skills/NAME/ | Yes | Structure and behavior tests for a skill; kept outside customer installs | uv run pytest tests/skills/NAME/ -x |

Skill tests live under tests/skills/NAME/ so customer installs contain

runtime assets only. Never colocate a tests/ directory inside a skill;

the pre-commit colocated-test guard blocks new ones.

Useful invocations (the --collect-only form re-run 2026-10-31):

uv run pytest tests/ -x                                    # full default suite, stop on first failure
uv run pytest tests/test_ai_review.py -x                   # one file
uv run pytest tests/ -m unit                               # by marker
uv run pytest tests/skills/NAME/ --collect-only -q         # prove new skill tests are collected
uv run pytest tests/skills/prose-self-check/ -q            # one skill's suite

Markers (pyproject.toml [tool.pytest.ini_options].markers): unit, integration, safe_push_transport, security, smoke, claude, copilot, codex, grok, pi, hermes, muse, cursor, windows_path. safe_push_transport means the test touches a non-local transport and is excluded from pre-push. smoke means real-CLI tests needing auth/credits or an installed CLI, run on pull requests by plugin-cli-smoke.yml (except grok, hermes, and muse, which no CI leg selects: run them locally with RUN_CLI_E2E=1; muse also needs a Muse login); the smoke gate asserts they were not skipped. claude, copilot, and codex name the CLI a real-CLI test needs; each CLI smoke leg selects smoke and <cli>. windows_path means the test exercises Windows path handling and must run on a Windows runner. Always uv run pytest, never bare pytest or python3 -m pytest outside the venv: PyYAML and friends live in the uv venv (see ai-agents-build-and-env).

Stale doc warning: .agents/governance/test-location-standards.md still describes a Pester/*.Tests.ps1 layout. Zero *.Tests.ps1 files exist (checked 2026-10-31; ADR-042 Python migration; run pester-count to re-measure). Trust the table above and pyproject.toml, not that file.

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-validation-and-qa/scripts/test_layout.py --repo . pester; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-validation-and-qa/scripts/test_layout.py --repo . skill-tests NAME; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

pester counts *.Tests.ps1 files and exits 1 only when this warning is dead prose (count is 0 and the governance doc no longer mentions Pester). skill-tests lists the files uv run pytest tests/skills/NAME --collect-only -q collects (write --no-pytest after NAME, inside the locator, for a test_*.py walk) and exits 1 when none. Neither says whether the tests pass or cover the code.

Phase 3: Write tests that count

Beyond pos+neg+edge, this repo demands five specific disciplines:

1. Isolation from the real repo. The root conftest.py (repo root, fixture _guard_real_repo_head, helper _check_head_change) fails any test that moves the REAL repo HEAD: every git mutation must run in a tmp_path repo with cwd= that repo. Supporting fixtures in tests/conftest.py: GIT_CONFIG_COUNT injection neutralizes host commit.gpgsign so tmp-repo commits work in signing environments (fixture _isolate_git_config_for_test_git in tests/conftest.py), and AI_AGENTS_PROJECT_REPO=1 defaults identity for guards that check the origin remote (fixture _default_project_repo in tests/conftest.py). Consumer-repo simulation tests override that env var to "0".

2. Runtime-contract tests for generated artifacts (FM-11). A generated artifact that has never been executed is not done (FAILURE-MODES.md:29, index row 11; the plugin-root incident wedged every plugin customer for 33 days). The **Ship a runtime-contract test.** item in the repo-local ai-agents-generation-and-release skill's references/rule-generated-artifacts.md points here; this section owns it:

The artifact MUST have a test that executes

it under the verified contract: set the cwd the host sets (for a plugin hook,

a directory that is NOT the plugin root), set the env vars the host exports,

run the command, and assert the intended effect (the script is found and

runs). Include a negative control that proves the test fails when the artifact

is wrong (a bare relative path must fail the same harness). See

tests/build_scripts/test_generate_hooks_runtime_contract.py.

See test_negative_control_bare_relative_path_fails and test_anchor_is_load_bearing_when_no_plugin_root_var_set.

3. Negative controls beat self-reference. A test that string-matches the generator's own output passes when the generator is consistently wrong. The first plugin-root fix shipped exactly this (retro 2026-06-02-pr-2205-customer-wedge-incident.md:49,83) and it hid two more defects. Every contract test needs a case where the wrong artifact fails.

4. Threshold detectors need calibration. Any threshold-based signal (rework count, thread count, file count) must be replayed against roughly the last 5 real merged PRs and shown to fire correctly before shipping. The recursive-failure PR's M4 warning shipped with threshold 6 in a repo whose PRs maxed at 4 file edits: it could never fire (retro 2026-05-10-pr-1989-recursive-failure.md:151-157). A detector that cannot fire on recent real work is not calibrated.

5. Guards run on their own branch. A PR shipping a pre-push or pre-commit guard must show that guard running against its own branch, terminal output in the PR description (retro 2026-05-10-pr-1989-recursive-failure.md:131-137; M5 was never applied to the PR that shipped it).

Phase 4: Prove coverage

100% block coverage on changed files, with only defensive-unreachable exclusions (# pragma: no cover) plus written justification (TESTING-RIGOR.md:54).

uv run pytest tests/test_ai_review.py tests/test_verdict.py tests/test_quality_gate.py --cov --cov-branch --cov-report=
coverage report --include=scripts/ai_review_common/verdict.py --fail-under=100

.github/workflows/pytest.yml pins two modules this way: step Pin ai_review_common.verdict coverage collection (REQ-008-07) with its Enforce ... at 100% step (lines 512-522), and the REQ-009 pair after it. Two traps, both fossilized in comments there:

| Trap | Rule | Evidence |

|------|------|----------|

| File-set sensitivity | Collect with EVERY test file that exercises the module. After a test-file split, test_ai_review.py alone reported 63% and tripped the gate | pytest.yml:508 |

| Coverage target form | Collect with bare --cov --cov-branch, then isolate the module with coverage report --include=<path> --fail-under=100. A module-name --cov=<name> target fails when the module is a file-path target not importable by name | pytest.yml:524 |

Related discipline, FM-10: there is "no neutral default for a missing signal" (FAILURE-MODES.md:391). The neutral default is UNKNOWN, not PASS (extract_verdict on no-match, merge_verdicts on empty; get_verdict fails safe to CRITICAL_FAIL). The verdict-parser PR still took 3 fix rounds to make UNKNOWN blocking everywhere it flowed: the workflow verdict list, the action parser allowlist, and the action exit-code mapping. When testing parsers or gates, always include the missing-signal case and assert it raises or blocks, never that it silently passes.

Phase 5: QA evidence semantics

QA validation remains required for feature code. Session-log presence does not

affect that gate. Skip classes are defined by ADR-034 and

.project-toolkit/architecture/ADR-034-investigation-session-qa-exemption.md:

| Evidence string | When valid | Staged files limited to |

|-----------------|-----------|------------------------|

| SKIPPED: docs-only | Strictly editorial doc edits: no code, config, tests, workflows, or code blocks changed | Documentation files |

| SKIPPED: investigation-only | No code/config changes at all | The patterns in scripts/modules/investigation_allowlist.py, which is the executable source |

Explicitly NOT skippable: .project-toolkit/planning/, .project-toolkit/architecture/ADR-*,

.github/, .claude/agents/, src/, and scripts/. Optional session logs,

analysis artifacts, and memory updates are filtered when deciding whether QA is

required.

Mixed work (investigation turned into code)? Split the commits. Commit

investigation work with skip evidence, then validate the code change with real

QA.

Record QA evidence in the PR, transcript, per-issue handoff, or an optional

session log.

Phase 6: Add tests for a new skill, hook, or script

Anti-Patterns

Each row cost real time. Do not re-earn these lessons.

| Anti-pattern | Incident | Binding rule |

|--------------|----------|--------------|

| Self-referential test (asserts generator output against itself) | First plugin-root fix shipped one; it passed while the artifact was broken (retro :49, :83) | Runtime-contract test + negative control (generated-artifacts.md:68-74) |

| Happy-path-only test suite | Origin-story PR: 20 tests, 24% coverage, bots caught the rest | TESTING-RIGOR.md pos+neg+edge, BLOCKING |

| Threshold detector never calibrated | Recursive-failure M4: threshold 6, repo max 4, could never fire | Calibration table against last ~5 real PRs before commit |

| Guard not run on its own branch | Recursive-failure M5: bot-cascade hook shipped but never applied to its own PR | Guard output on the shipping branch in the PR description |

| Test mutates the real repo | Repo-root conftest.py _guard_real_repo_head | Isolate in tmp_path, run git with cwd= the tmp repo |

| Silent default for missing signal | Verdict parser defaulted missing to PASS, 3 fix rounds (FM-10) | Test the missing-signal case; assert raise/block |

| Coverage theater (assertion-free tests, tautologies) | Testing philosophy work | TESTING-ANTI-PATTERNS.md 1: each test answers a stakeholder concern |

| Trusting the Pester test-location doc | test-location-standards.md predates ADR-042; zero .Tests.ps1 files remain | Use Phase 2 table + pyproject.toml [tool.pytest.ini_options].testpaths |

| Skipping QA on a mixed session | ADR-034 allowlist exists precisely to fence this | Split the session; skip evidence only with allowlisted paths staged |

Verification

Before claiming a change meets the evidence bar:

Scripts

The bundled instruments.py lists and runs this skill's checkers:

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-validation-and-qa/scripts/instruments.py --repo . list; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-validation-and-qa/scripts/instruments.py --repo . run <id>; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

Ids: citation-freshness (do path:line cites still hold), investigation-allowlist and qa-skip-evidence (Phase 5 paths and legal skip strings, read from source), pester-count, skill-tests (Phase 2), drift-self-check. A listing only proves the files exist. The prose keeps the reasons and the edges (mixed sessions, what a skip may hide).

Provenance and Maintenance

Re-verified 2026-10-31 at 42e409325: line cites, the Phase 4 workflow pins, the Pester count, and the two QA skip strings. Facts live in reverify.json; run the drift command after any edit to a cited file.

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/skill-bootstrap/scripts/bootstrap_drift.py check --repo . --skills-root .claude/skills --name ai-agents-validation-and-qa --require; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

<!-- citation-freshness: ignore -- source list as the skill was written; FAILURE-MODES and pytest.yml ranges predate the context diet -->

Sources: .agents/governance/TESTING-RIGOR.md (Status :5, origin :3-16, pragma :54, cost :97), .agents/governance/TESTING-ANTI-PATTERNS.md (:91, :165-172), .agents/governance/FAILURE-MODES.md (:29, :390), the repo-local ai-agents-generation-and-release skill's references/rule-generated-artifacts.md (MUST 2), .claude/rules/claude-agents.md (:29), pyproject.toml [tool.pytest.ini_options], root conftest.py, tests/conftest.py, .github/workflows/pytest.yml (:508-524), ADR-034, scripts/validate_session_json.py (_QA_SKIP_CHECKERS), and the 2026-05-10 and 2026-06-02 retros in .project-toolkit/retrospective/.

Calibration replay of a threshold detector over merged PRs (Phase 3, item 4) stays manual: it needs the GitHub API.

If TESTING-RIGOR.md, ADR-034, or the pytest.yml pins change, update the matching phase here in the same PR.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.