Architecture and module walkthrough
Code walkthrough of the QA tooling under tooling/qa/ and scripts/.
This guide explains how the QA system is put together under the hood. All QA code lives in two locations:
scripts/. Command line entry points called by npm scripts and Git hooks.tooling/qa/. Modules handling candidate capture, materialization, policy resolution, subprocess execution, agent sessions, and gate evaluation.
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

1. Candidate capture and materialization
These modules isolate the code under test so that uncommitted working tree edits never pollute test results.
- File:
tooling/qa/candidate/capture.mjswriteTree(cwd). Runsgit write-treein the host repository. Git creates a tree object in.git/objects/representing the current staging index and returns its 40-character SHA. This does not create a commit or alter your working branch.captureCandidateIdentity(cwd). Returns the candidate tree SHA, base commit SHA, parent commits, current branch name, and a parsed list of all staged files with their statuses (added,modified,deleted).verifyIndexConcurrency(expectedTreeSha, cwd). Runsgit write-treeagain after tests complete. If the hash changed, the staging area was modified during execution and the gate blocks.
- File:
tooling/qa/candidate/materializer.mjsmaterializeCandidateTree(...). Unpacks the captured tree hash into an isolated temporary folder. It configures Git alternates so the isolated folder can read repository objects without copying full Git history.checkSymlinkEscapes(...). Verifies that no symlinks in the snapshot point outside the isolated folder.
2. Policy, resolver, and switch
Before running tests, the system determines which suites and reviews are required based on which files were touched.
- File:
tooling/qa/policy/resolver.mjsresolveExecutionPlan(...). Inspects staged files and matches them against policy rules. It freezes a plan containing required deterministic suites (likepnpm check), required agent journey tasks, and whether product-intent reviews are needed.- Calculates composite SHA256 digests for repository policies, tool configurations, and the acceptance manifest. If any policy file changes, earlier receipts are automatically invalidated.
- File:
tooling/qa/policy/switch.json- Stores the boolean state (
"autoRun": "off"or"on") governing whether Git hooks execute QA automatically.
- Stores the boolean state (
3. Sandboxed subprocess execution
- File:
tooling/qa/executor/subprocess.mjsexecuteSandboxedCommand(command, options). Runs allowlisted test commands inside the isolated directory using Node’s child process tools.- Strips sensitive authentication tokens and environment variables from the execution context.
- Enforces command timeouts (default 5 minutes) and captures standard output and standard error streams.
4. Agent harness and MCP server
Coordinates the unattended AI reviewer session that inspects the staged diff and exercises product journeys.
- File:
tooling/qa/agent/runner.mjsrunAgentSession(...). Launches a fresh, isolated agent session using the Google Antigravity CLI (agy).- Supplies the candidate diff, requirements, and tasks while tracking request limits, token usage, and execution timeouts.
- File:
tooling/qa/agent/prompt.mjs- Assembles the reviewer prompt with strict instructions: the agent is an independent auditor, must ground all findings in concrete evidence, and cannot approve broken tests.
- Validates returned structured JSON reports against defined schemas.
- File:
tooling/qa/agent/mcp-server.mjs- Provides controlled MCP tools (such as browser automation endpoints) to the reviewer session.
- File:
tooling/qa/agent/repair.mjsexecuteRepairLoop(...). Orchestrates up to two automated repair cycles for formatting errors, updating Git staging directly without modifying unstaged hunks.
5. Evidence collector
- File:
tooling/qa/evidence/collector.mjsaddEvidence({ type, content, filename }). Writes captured test logs, diffs, and transcripts into the run’s evidence directory.- Assigns each evidence item a unique ID and computes its SHA256 digest.
verifyIntegrity(). Verifies that every recorded evidence file exists on disk and matches its recorded checksum.
6. Gate evaluator and receipt issuance
- File:
tooling/qa/gate/evaluator.mjsevaluateGate(...). The decision engine that computes whether a candidate passes, fails, or blocks.- It checks that:
- All required suites executed and exited with code 0.
- No concurrency violations occurred.
- The candidate snapshot remained unmodified throughout the run.
- The agent reported no critical or major defects.
- For releases, all 28 acceptance criteria are implemented and passing.
- File:
tooling/qa/gate/receipt.mjsissueReceipt(...). Emits a signed receipt (receipt.json) containing candidate tree hashes, policy digests, and timestamps when a run passes.verifyReceipt(...). Checks incoming commit receipts during CI runs.
7. Acceptance manifest and reporter
- File:
tooling/qa/manifest/acceptance-manifest.json- Tracks all 28 project acceptance criteria, linking each requirement to owning feature specifications, automated test selectors, and browser tasks.
- File:
tooling/qa/reporter/writer.mjs- Writes
gate-result.jsonand human-readablesummary.mdinside.qa-reports/runs/<runId>/.
- Writes