QA system overview
Why the QA gates exist, how they handle staged and committed code, and the end to end pipeline.
The QA system in this repository stops broken or unverified code from reaching git commits, pull request merges, and production releases. It provides an independent, software-driven safety net 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
The system treats staged, unstaged, and committed files differently based on their Git state:
- Staged changes. The pre-commit gate inspects the Git staging area using
git write-tree. It unpacks those exact staged 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.

- Switch is off (default). Git pre-commit hooks print a notice naming
pnpm qaand 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 runpnpm qaanytime. 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
Engineers often have scratch files, half-finished edits, or extra test fixtures lying around in their working directory. Traditional test commands run against whatever is on disk. A test might pass on your machine only because of an unstaged file you forgot to add to Git.
Our 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. They can hallucinate, overlook subtle edge cases, or get distracted by plausible looking comments.
For that reason, 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.
When a run passes, the system signs a receipt containing the tree hash, policy digest, and issuer. CI checks these receipts so it does not waste time rerunning tests on commits that were already verified.
4. Self-enforcing code growth
You cannot build product features without updating tests. Tripwire scripts in scripts/check-repository.mjs enforce this. 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 pipeline

+-----------------------------------------------------------------------------------+
| 1. Capture Git Index |
| captureCandidateIdentity runs git write-tree on host repo |
| Returns 40-character tree SHA and staged files list |
+-----------------------------------------------------------------------------------+
|
v
+-----------------------------------------------------------------------------------+
| 2. Materialize Isolated Workspace |
| materializeCandidateTree unpacks files into an isolated directory |
| Sets up isolated git alternates and checks for symlink escapes |
+-----------------------------------------------------------------------------------+
|
v
+-----------------------------------------------------------------------------------+
| 3. Freeze Execution Plan |
| resolveExecutionPlan hashes policy files, configs, and acceptance manifest |
| Picks required suites and agent tasks based on which files changed |
+-----------------------------------------------------------------------------------+
| |
v v
+------------------------------------+ +--------------------------------------------+
| 4a. Run Test Suites | | 4b. Run Independent QA Agent |
| Strips credentials from env | | Spawns unattended reviewer session |
| Runs required checks with timeout| | Reads diff against product specs |
| Saves stdout and stderr logs | | Returns structured JSON findings |
+------------------------------------+ +--------------------------------------------+
| |
+-------------------+-------------------+
|
v
+-----------------------------------------------------------------------------------+
| 5. Verify Index Concurrency |
| verifyIndexConcurrency runs git write-tree again on host repo |
| Blocks if you modified staged files while tests were running |
+-----------------------------------------------------------------------------------+
|
v
+-----------------------------------------------------------------------------------+
| 6. Deterministic Gate Evaluation |
| evaluateGate runs sequential checks: |
| 1. Identity and policy digest integrity |
| 2. Concurrency checks |
| 3. Execution completeness |
| 4. Deterministic exit codes |
| 5. Agent findings and task observations |
| 6. Product intent and conflict verification |
| 7. Release criteria status |
| 8. Pass result |
+-----------------------------------------------------------------------------------+
|
v
+-----------------------------------------------------------------------------------+
| 7. Save Reports and Issue Receipt |
| Writes gate-result.json and summary.md |
| If passed: Issues receipt.json |
| Exits with code 0 for pass, 1 for fail, or 2 for blocked |
+-----------------------------------------------------------------------------------+
Dual checks: deterministic suites and independent reviewers

Three execution profiles
The system adjusts its depth depending on where it runs:
- Commit profile. Runs locally before commits (via
pnpm qamanually, orpnpm qa:commitvia hooks when auto-run is on). Focuses on fast deterministic tests, index concurrency, and agent code review. - CI profile. Runs on pull requests via
pnpm qa:ci. Verifies commit receipts, validates merge candidates against their base branch, and runs live checks. - Release profile. Runs before deployment via
pnpm qa:release. Evaluates build artifacts and checks all 28 accepted criteria intooling/qa/manifest/acceptance-manifest.json. Because product features are still being built, release QA blocks today with exit code 2 by design.
Where to go next
- CLI command reference. Learn flags, options, and exit codes.
- Module walkthrough. Inspect the code under
tooling/qa/. - Acceptance manifest. See all 28 product criteria.
- Maintenance guide. Learn how to add tests as you build features.
- Troubleshooting. Fix common errors and index conflicts.