1. Automated QA system complete reference manual

Automated QA system complete reference manual

The full QA system reference on one page.

This document is the consolidated technical manual for the automated QA system in this repository. It brings together system concepts, CLI references, module contracts, the acceptance manifest, maintenance procedures, and troubleshooting into a single document.


1. System overview

The automated QA system stops broken or unverified code from reaching Git commits, pull request merges, and production releases. It provides an independent, software-driven gate before code enters history.

Why this system exists

We are building a tool for employees who need to calculate real driving distances between campuses and retailer locations. If the software swaps a branch campus for a main campus, drops duplicate rows from a customer file, or fabricates a distance when an API fails, employees make bad planning decisions based on bad data.

We use autonomous coding agents to build features. But an agent that just wrote code cannot objectively certify its own work. It will usually assume its solution works.

This QA system solves that problem by separating roles:

  • The implementer writes code, stages changes, and writes tests.
  • An independent QA agent session reviews the staged changes in an isolated sandbox.
  • Deterministic software evaluates the outcome. Code, not an AI model, decides whether tests passed.

How changes get checked

  • Staged changes. The pre-commit gate inspects the Git staging area using git write-tree. It unpacks those exact files into an isolated directory and runs all checks there.
  • Unstaged changes. The runner rejects unstaged changes. If nothing is staged, it exits with an error asking you to run git add. Unstaged edits in your working tree never touch the test run.
  • Committed changes. The CI runner (pnpm qa:ci) inspects committed history. You can pass explicit commit hashes or branch ranges to verify introduced commits against a base branch.

The auto-run switch

Running an independent AI reviewer on every commit takes time. To keep everyday development fast, a committed configuration file in tooling/qa/policy/switch.json controls automatic hook execution.

Automatic hooks versus manual invocation

  • Switch is off (default). Git pre-commit hooks print a notice naming pnpm qa and exit cleanly. You can commit immediately without waiting for an AI review.
  • Switch is on. Git pre-commit hooks run the full automated QA assessment before every commit.
  • Manual verification (pnpm qa). You can run pnpm qa anytime. It bypasses the switch and runs the complete pre-commit gate on your staged changes, issuing a signed verification receipt when it passes.

Four rules that govern the design

  1. Test the staged index, never the dirty working folder. The pre-commit runner calls git write-tree to capture the exact staged index. It unpacks that tree into a temporary directory outside the working tree and runs all checks there.
  2. Code has the final word, not the AI. Language models are useful reviewers, but they are not truth oracles. The QA agent has zero authority to approve a run. If pnpm check exits with code 1, the gate fails immediately. The agent can flag defects and fail the gate, but it can never override a broken test.
  3. Every run leaves a permanent trail. Every test run generates a run folder under .qa-reports/runs/<runId>/. It stores command outputs, git diffs, agent transcripts, and sha256 checksums. Passing runs receive a signed receipt.
  4. Self-enforcing code growth. Tripwire scripts in scripts/check-repository.mjs ensure that the moment you add code to src/app/, the build breaks until you register real application build and test commands in package.json.

End to end workflow

5-step QA workflow

Three execution profiles

  1. Commit profile. Runs locally before commits (via pnpm qa manually, or pnpm qa:commit via hooks when auto-run is on). Focuses on fast deterministic tests, index concurrency, and agent code review.
  2. CI profile. Runs on pull requests via pnpm qa:ci. Verifies commit receipts, validates merge candidates against their base branch, and runs live checks.
  3. Release profile. Runs before deployment via pnpm qa:release. Evaluates build artifacts and checks all 28 accepted criteria in tooling/qa/manifest/acceptance-manifest.json.

2. CLI commands

Everyday commands

CommandLifecycle stagePrimary file
pnpm qaManual pre-commit assessmentscripts/qa-commit.mjs
pnpm qa:commitAutomatic pre-commit hook runnerscripts/qa-commit.mjs
pnpm qa:ciContinuous integration and pull requestsscripts/qa-ci.mjs
pnpm qa:releaseStaging and production release checksscripts/qa-release.mjs
pnpm qa:setupMachine and repository setupscripts/qa-setup.mjs
pnpm checkFast deterministic code and QA checkspackage.json
pnpm test:qaQA system self-test suitetests/qa/

pnpm qa

The primary command you run locally to verify changes before committing.

  • Script: scripts/qa-commit.mjs --manual
  • Usage: pnpm qa [--verbose] [--dry-run] [--repair]
  • Behavior: Bypasses the "off" switch in switch.json and executes the full commit assessment on currently staged files.
  • Flags:
    • --verbose. Prints candidate tree hashes, staged file lists, and real-time suite execution updates.
    • --dry-run. Displays the planned test suites and agent tasks without running tests or calling the reviewer agent.
    • --repair. Automatically runs up to two repair cycles to fix staged formatting issues before failing the gate.
  • Exit codes:
    • 0: Gate passed. Staged files are clean and a receipt is issued.
    • 1: Demonstrated failure. A test failed, linting broke, or the QA agent filed a critical finding.
    • 2: Blocked. Index was modified during testing, a tool timed out, or prerequisites were missing.

pnpm qa:commit

Executed by Git hooks when committing.

  • Script: scripts/qa-commit.mjs
  • Behavior: When tooling/qa/policy/switch.json has autoRun: "off", it prints a notice pointing to pnpm qa and exits cleanly. When the switch is "on", it runs the full pre-commit gate.

pnpm qa:ci

Evaluates incoming commits and pull request merges in continuous integration.

  • Script: scripts/qa-ci.mjs
  • Usage: pnpm qa:ci [--base=<sha>] [--head=<sha>] [--require-receipts]
  • Flags:
    • --base=<sha>. The base branch or commit hash to compare against. Defaults to origin/main, then to the initial empty tree.
    • --head=<sha>. The tip commit of the pull request. Defaults to HEAD.
    • --require-receipts. Fails if any introduced commit lacks a valid pre-commit receipt.
  • Behavior: Checks .qa-reports/receipts/<commitSha>.json for each commit in the range. Valid receipts allow CI to verify that commits were already assessed.

pnpm qa:release

Verifies that an application build artifact meets all release requirements.

  • Script: scripts/qa-release.mjs
  • Usage: pnpm qa:release --artifact=<sha256> --env=<staging|production>
  • Behavior: Fails closed with exit code 2 (blocked) until all 28 product criteria in acceptance-manifest.json are implemented and verified by automated tests.

pnpm qa:setup

Validates tool prerequisites (Node.js 26.8.2+, pnpm 12.3.4+, git 2.0.0+, agy 1.1.9+) and configures Git hooks without destroying existing custom hook scripts.

pnpm check

Runs deterministic code checks: formatting, ESLint, TypeScript types, architecture rules, knip unused file checks, repository policies, and all unit and QA test suites.

pnpm test:qa

Executes all 18 adversarial test files in tests/qa/ that validate the QA system itself.


3. Architecture and module contracts

Directory layout

tooling/qa/
├── candidate/
│   ├── capture.mjs          # Calls git write-tree and captures staged files
│   └── materializer.mjs     # Unpacks git trees into isolated folders
├── policy/
│   ├── resolver.mjs         # Resolves required test suites and agent tasks
│   ├── switch.json          # Controls whether pre-commit hooks run automatically
│   ├── switch.mjs           # Reads and validates the switch configuration
│   ├── case-catalog.mjs     # Catalogs acceptance cases and impact maps
│   ├── intent.mjs           # Formulates product-intent review context
│   └── schemas.mjs          # Data validation schemas for records and reports
├── agent/
│   ├── runner.mjs           # Spawns isolated reviewer sessions and tracks budgets
│   ├── prompt.mjs           # Builds prompts and validates structured findings
│   ├── browser-qualification.mjs # Validates browser automation safety rules
│   ├── mcp-server.mjs       # Exposes tool capabilities to reviewer sessions
│   └── repair.mjs           # Executes the automated format repair loop
├── executor/
│   └── subprocess.mjs       # Runs commands in sandboxed child processes
├── evidence/
│   ├── collector.mjs        # Collects logs, diffs, and computes sha256 digests
│   └── probes.mjs           # Evaluates runtime assertions and logs
├── gate/
│   ├── evaluator.mjs        # Evaluates test exit codes, findings, and criteria
│   └── receipt.mjs          # Signs and verifies cryptographic proof tokens
├── manifest/
│   └── acceptance-manifest.json # Tracks all 28 product criteria
├── reporter/
│   └── writer.mjs           # Writes gate-result.json, receipt.json, and summary.md
└── evaluation/
    └── reviewer-eval.mjs    # Benchmarks agent defect detection on test corpora

Dual checks architecture

Module responsibilities

  1. Candidate capture and materialization (candidate/).
    • capture.mjs: Runs git write-tree to generate a 40-character SHA of the staging index without creating commits or altering refs. Parses staged files and verifies index concurrency.
    • materializer.mjs: Unpacks the candidate tree into an isolated folder, binds Git alternates for object sharing without history duplication, and checks for symlink directory escapes.
  2. Policy, resolver, and switch (policy/).
    • resolver.mjs: Freezes execution plans before test execution, mapping staged file diffs to required suites and agent tasks. Computes composite digests of policies and configurations.
    • switch.json & switch.mjs: Governs automatic hook execution ("off" or "on").
    • case-catalog.mjs & intent.mjs: Catalogs acceptance IDs and prepares product-intent review assignments when material features change.
    • schemas.mjs: Enforces schemas for execution records, receipts, and reviews.
  3. Command execution (executor/).
    • subprocess.mjs: Runs allowlisted test commands inside the clean candidate folder, strips sensitive environment tokens, enforces timeouts, and streams output.
  4. Agent harness and tools (agent/).
    • runner.mjs: Starts fresh, unattended sessions with the Google Antigravity CLI (agy), monitors token usage, and manages execution budgets.
    • prompt.mjs: Generates reviewer instructions and validates structured JSON findings.
    • mcp-server.mjs: Exposes browser tools to agent sessions.
    • repair.mjs: Runs the automated format repair loop.
  5. Evidence collection (evidence/).
    • collector.mjs: Stores test logs, command outputs, diffs, and agent transcripts outside the candidate folder. Verifies integrity by comparing saved files to recorded SHA256 checksums.
  6. Gate evaluation and receipts (gate/).
    • evaluator.mjs: Executes the decision engine across exit codes, index concurrency, snapshot immutability, agent defect severities, and release criteria.
    • receipt.mjs: Signs and verifies cryptographic proof receipts.
  7. Acceptance manifest and reporter (manifest/ and reporter/).
    • acceptance-manifest.json: Single source of truth tracking all 28 criteria.
    • writer.mjs: Formats and outputs gate-result.json and human-readable summary.md.

4. Acceptance manifest

The manifest at tooling/qa/manifest/acceptance-manifest.json tracks all 28 accepted criteria:

Acceptance IDAreaSpecSummary
ACCESS-01access03Approved employee sign-in succeeds; unapproved sessions rejected.
ACCESS-02access03Employee data isolation holds.
IMPORT-01import04CSV, XLSX, Sheets, and paste import preview cleanly.
IMPORT-02import04Duplicate rows and leading zeros survive the pipeline.
RETAILER-01lookup06Any retailer name accepted as run input.
LOCATION-01lookup06Specific address wins over general university name.
LOCATION-02input05Ambiguous campus names flagged for employee review.
LOCATION-03lookup06Outlets filtered accurately to eliminate distribution centers.
LOCATION-04lookup06Measures driving routes rather than straight lines across rivers.
LOCATION-05lookup06Shortest valid driving distance selected.
MODEL-01input05Neutralize prompt injections embedded in raw rows.
RUN-01lookup06Durable batch processing in original order.
RUN-02lookup06Queue delivery reconciliation without duplicate rows.
RUN-03recovery07Revision fencing stops older retries from overwriting fixes.
RUN-04recovery07Respect retry budgets when external providers fail.
RUN-05recovery07Cancellation state settles background workers safely.
REPORT-01reports08Summary math matches the independent calculation oracle.
REPORT-02reports08Filtering and sorting operations preserve underlying rows.
REPORT-03reports08Refresh expired provider cache data only through approved paths.
OUTPUT-01export10File export preserves row order, columns, and units.
OUTPUT-02export11Google Sheets writes reconcile idempotently.
OUTPUT-03export10Neutralize spreadsheet formula injections.
EXPERIENCE-01UI03Clear loading, empty, review, and error states.
EXPERIENCE-02a11y03Accessible keyboard navigation, labels, and focus rings.
OPERATIONS-01ops06Queue admission limits hold under heavy batch load.
OPERATIONS-02ops12Deployment and rollback rehearsal with zero data loss.
ADMIN-01admin13Only explicit administrators can access the admin dashboard.
ADMIN-02admin13Request and token usage attributed accurately to runs.

5. Maintenance procedures

When adding new product code under src/:

  1. Implement feature and unit tests. Write business logic and corresponding unit or integration tests under tests/.
  2. Handle build tripwires. If adding the first file to src/app/, update package.json to include "build" and "test:app" in pnpm check.
  3. Update manifest status. When a feature is completed, flip its status in acceptance-manifest.json from unimplemented to implemented and add test file paths.
  4. Update execution plan resolver. Map newly added feature paths to their corresponding agent tasks in tooling/qa/policy/resolver.mjs.
  5. Verify locally. Stage changes with git add and run pnpm qa to confirm the gate passes.

6. Troubleshooting and failure recovery

Quick diagnostic table

Exit codeStatusMeaningFirst action
0PassAll checks and agent tasks passed.Proceed with commit or merge.
1FailA test failed, linting broke, or the QA agent found a critical defect.Inspect test logs or agent findings in summary.md.
2BlockedEnvironmental issue, concurrency conflict, timeout, or missing release criteria.Check whether the index changed, tools are missing, or release criteria are incomplete.

Where to find evidence on disk

Every QA run saves its full context under .qa-reports/runs/<runId>/:

.qa-reports/runs/qa-run-1773729900000-a1b2c3d4/
├── gate-result.json   # Full JSON payload with timings, hashes, and findings
├── summary.md         # Readable Markdown summary of the gate decision
├── receipt.json       # Signed token (present only on passing runs)
└── evidence/
    ├── ev-qa-run-1-check-output.txt    # Captured stdout and stderr from tests
    ├── ev-qa-run-2-candidate-staged.diff # The exact git diff tested
    └── ev-qa-run-3-agent-session-transcript.txt # Full conversation log with the QA agent

Common failure scenarios

  1. No staged changes: The pre-commit runner tests the Git staging index. Stage candidate files with git add before running pnpm qa.
  2. Auto-run is OFF notice: The hook prints a notice pointing to pnpm qa because switch.json has autoRun: "off". Run pnpm qa manually to assess staged changes, or change "autoRun": "on".
  3. Formatting failures: Run pnpm qa --repair to automatically fix Prettier formatting on staged files.
  4. Concurrent index modification: Avoid modifying Git staging or running git add while pnpm qa is executing.
  5. Missing Antigravity CLI: Verify that agy is installed and accessible in your PATH.
  6. Agent critical or major findings: Open .qa-reports/runs/<runId>/summary.md, review expected versus actual behavior, fix the defect in src/, stage, and re-run.
  7. Release gate blocked: pnpm qa:release purposefully blocks until all 28 acceptance criteria in acceptance-manifest.json are implemented.