QA Audit Diff
Execute read-only change-risk forensics on a diff to uncover outward Blast Radius, missed sibling patterns in unchanged code, 10-class Failure Mode risks, and test gaps before merge.
Guardrails, Language & Boundaries
- Strictly read-only on target code and runtime: Inspect repository files, git history, and PR diffs read-only; leave application source code, tests, schemas, and databases untouched. Persist output only to
.qa/reports/<slug>-diff-audit.mdwhen chaining.qa/reports/<slug>-*checkpoints or explicitly requested by the user. - No Raw Secrets Rule: Never read
.env, private key files, or credential dumps, and never echo literal tokens, passwords, or keys found in a diff—mask any discovered literal as<REDACTED>and cite onlyfile:lineand variable name. - Zero-config context load: Read
GLOSSARY.mdanddocs/qa/context.mdif present to align domain terms, system pointers, andArtifact language; fall back silently to.qa/defaults when absent. - Bilingual policy: Keep
SKILL.mdschema keys, report headings,RISK-*IDs, evidence tags,Severitycues (S1-Blocker–S4-Minor),Diff Risk Posture(High-Risk|Medium-Risk|Low-Risk), and canonicalGLOSSARY.mdterms in English. Adapt conversational responses to the user's prompt language (English or Vietnamese); honorArtifact languageindocs/qa/context.mdwhen persisting.qa/reports/<slug>-diff-audit.md. - Skill boundaries: Target concrete diffs, PRs, commit ranges, working-tree changes, or pasted patches. Route static module exploration without a diff to
qa-audit-codebase(if installed; otherwise map entry points and persistence sites directly), whole-suite scoring toqa-audit-coverage, liveDefectdebugging toqa-investigate-defect, and formalGo/Conditional-Go/No-Godecisions toqa-release-gate.
Step 1 — Diff Resolution & Context Load
Resolve the target diff strictly in this priority order:
- Explicit PR or commit/branch range: PR URL/number (via repo tracker CLI if configured) or explicit git range (
<base>..<head>,<base>...<head>, or commit SHA). - Current branch vs. base branch: Compare
HEADagainst repository default base (main,master, or configured default) plus any uncommitted local changes if part of the branch work. - Working tree: Inspect staged (
git diff --cached), unstaged (git diff), and newly created untracked files when no branch diff applies. - Pasted patch (
Diff-Only Mode): When repo access is absent and the user supplies a patch or diff snippet, activateDiff-Only Mode.
If no diff source exists in steps 1–4, pause and ask the user for a PR, branch/commit range, or patch (or suggest qa-audit-codebase when auditing a static module without changes). Derive a kebab-case <slug> (^[a-z0-9-]+$) from the PR, ticket, or branch name, and load GLOSSARY.md and docs/qa/context.md if present.
Completion criterion: Exact diff target, resolved ref, execution mode (diff-repo or diff-only), changed file list, and total changed lines are established before triage.
Step 2 — Large-Diff Risk Triage (Conditional)
Check diff size (total changed files and added + deleted lines):
- Standard diff (
<= 15files AND<= 600changed lines): Audit every changed file at Tier 1 depth. - Large diff (
> 15files OR> 600changed lines): Activate Large-Diff Risk Triage and partition files using references/failure-mode-probes.md:- Tier 1 (Deep Audit): Auth/authz guards, DB migrations and schemas, state transitions and lifecycle enums, persistence/billing/external I/O, public APIs/contracts/events, feature flags, and background job/cron handlers.
- Tier 2 (Surface Scan): UI copy, styling/CSS, formatting-only changes, static assets, lockfiles, generated artifacts, and pure fixture data.
Promote any Tier 2 file to Tier 1 immediately if a surface scan spots inline logic, permission checks, SQL/API calls, or hardcoded credentials. Record all Tier 2 surface-scanned files explicitly in Blind Spots.
Completion criterion: Every changed file is classified as Tier 1 or Tier 2, and every Tier 2 file is queued for explicit Blind Spots reporting.
Step 3 — Diff-Hunk Forensics & Outward Blast Radius
Inspect all Tier 1 hunks and trace outward exposure across unchanged code (consult references/failure-mode-probes.md for stack-agnostic cues):
- Changed-hunk invariants: Examine modified logic, defaults, guards, queries, transactions, and exception-handling branches.
- 1-hop callers & consumers (
diff-repo): Trace direct callers, route mounts, UI callers, event/queue subscribers, scheduled jobs, and shared table/cache consumers. - Sibling-pattern sweep (
diff-repo): Search unchanged code for parallel endpoints, handlers, serializers, or queries that still rely on the old pattern or lack a guard introduced by the diff. - Mode & messy-codebase fallbacks:
- Dynamic dispatch / raw strings: Supplement symbol search with route string, event-name, and SQL table/column greps; tag unresolved dynamic edges
OpaqueinBlast RadiusandBlind Spots. Diff-Only Mode: Audit the pasted hunks directly and logNo repo access for 1-hop caller tracing or sibling-pattern sweepinBlind Spots.
- Dynamic dispatch / raw strings: Supplement symbol search with route string, event-name, and SQL table/column greps; tag unresolved dynamic edges
Completion criterion: Every Tier 1 change has changed-hunk invariants checked, 1-hop callers/consumers traced (or logged as Opaque / Diff-Only Mode in Blind Spots), and a sibling-pattern sweep completed across unchanged code.
Step 4 — 10-Class Failure Mode Diff-Lens Audit
Evaluate Tier 1 changes and their outward Blast Radius across all 10 canonical Failure Mode classes (load references/failure-mode-probes.md for per-class probes):
Spec Ambiguity: Behavior changed without clear spec/PR rationale or conflicting withGLOSSARY.mdor a linkedTestable Acceptance Criterion.Implicit Business Rule: Change overrides, duplicates, or diverges from an existing invariant or sibling rule.Boundary & Input Validation Defect: Altered regex, schema, numeric precision, range limit, off-by-one threshold, or missing null/empty guard.Broken State Transition: Modified status enum, skipped transition guard, or partial multi-step write leaving records stuck mid-lifecycle.Cross-Module Side Effect: Unchanged callers, triggers, caches, webhooks, or counters broken by altered return values or side effects.Contract / Integration Drift: Altered request/response shape, HTTP status code, nullability, or event payload without synchronized consumer updates.Concurrency Defect: Non-atomic read-modify-write, missing transaction/lock/idempotency key, or shared mutable state across async handlers.Auth & Permission Leak: Missing auth/tenant/ownership middleware, broadened query filter, leaky serializer/log payload, or literal secret (redact per No Raw Secrets Rule).Migration & Compatibility Defect: Destructive orNOT NULLmigration without backfill, rolling-deploy skew between old code and new schema, or unmigrated legacy rows.Silent Failure: Newtry/catchsuppressing failures, fire-and-forget async call without propagation, or misleading HTTP200/ success signal on partial failure.
Assign every finding: RISK-* ID, canonical Failure Mode class, file:line citation (or patch:<hunk> in Diff-Only Mode), evidence tag (Confirmed-in-Code | Inferred-from-Pattern | Opaque), Severity cue (S1-Blocker–S4-Minor), and concrete failure scenario.
Completion criterion: All 10 Failure Mode classes evaluated; every finding carries RISK-*, class, file:line, evidence confidence tag, Severity cue, and concrete failure scenario.
Step 5 — Diff Test-Gap Signals, Diff Risk Posture & Output
- Evaluate diff test-gap signals: Inspect test changes in the diff (and adjacent tests when in
diff-repo) for untested Tier 1 changes, uncovered 1-hop consumers or sibling paths, andFalse-Confidence Testpatterns (tautological assertions, over-mocked persistence, or happy-path-only checks). - Assign
Diff Risk Posture(distinct fromRelease Gate):High-Risk: AnyS1-Blockerfinding, anyConfirmed-in-CodeS2-Criticalfinding in auth, migrations, state transitions, concurrency, or contracts, or severe unmitigated outwardBlast Radius/ critical Tier 1 test gap.Medium-Risk:S2-Critical(Inferred-from-Pattern/Opaque) orS3-Majorfindings, missed sibling checks needing verification, or moderate Tier 1 test gaps.Low-Risk: OnlyS4-Minorfindings or clean diff with verified 1-hop consumers, consistent siblings, and adequate tests.
- Compile
Must-Verify Before Merge: Order concrete actions bySeverityand confidence (code fixes, sibling alignment, missing tests, and runtime/DB checks forOpaqueedges). If anOpaquemodule outside the diff needs deep reverse-engineering, recommendqa-audit-codebaseif installed (otherwise suggest direct entry-point and persistence inspection). - Emit report: Follow references/report-template.md to present the 5-section report in chat. Write
.qa/reports/<slug>-diff-audit.md(with checkpoint YAML frontmatter +<= 25-line## Handoff Summary+ the 5 sections) only when chaining.qa/reports/<slug>-*checkpoints or explicitly requested.
Completion criterion: Report includes resolved diff summary, Diff Risk Posture, outward Blast Radius, 10-class Failure Mode findings with file:line and evidence tags, diff test-gap signals, prioritized Must-Verify Before Merge checklist, and Blind Spots (plus .qa/reports/<slug>-diff-audit.md if chaining checkpoints or requested).