Skip to main content

PR Test Auditor

The PR Test Auditor reads the diff of a pull request and asks one question: does this change make the tests weaker?

It catches the shortcuts that turn a red pipeline green without fixing anything: a focused test that silently skips the rest of the suite, a new test.skip, a fixed sleep, a forced click, or an assertion that was deleted or commented out. Coding agents take these shortcuts too, so the auditor is also an MCP tool that an agent calls on its own changes before it opens a pull request.

The auditor is deterministic: no AI is involved, and the same diff always gives the same findings. It judges only what the pull request adds or removes; existing code is never reported. It works offline: no API key is needed. With an API key, it also tells you which changed test files hold tests that Agnox has quarantined or graded unstable.

You can run it in two places:

  • agnox audit pr in your terminal or CI pipeline;
  • the audit_pr_tests MCP tool for coding agents.

What is audited​

FilesRules
Playwright, JS and TS tests: *.spec.*, *.test.*, and any .js/.ts file under a tests/, test/, e2e/ or __tests__/ folderAll rules
Maestro flows: .yaml/.yml files under a maestro/, .maestro/ or flows/ folder, or whose lines use Maestro commands (appId:, - launchApp, - tapOn, - assertVisible…)weakened-assertions
Source files: code outside tests, docs, scripts, migrations and tool configurationmissing-test-updates

Comments and string literals are ignored. // test.only( or 'use test.fixme(' never fires a rule.


Rules​

RuleSeverityWhat it finds in the added lines
no-only-testserrortest.only, test.describe.only, describe.only, it.only, fit, fdescribe. A focused test runs alone and silently skips every other test in CI.
no-new-skipswarn (--error-on-skips makes it an error)test.skip, test.fixme, test.describe.skip, describe.skip, xit, xdescribe, including conditional test.skip(condition, reason). Fix the test, or quarantine a flaky one in Agnox so it keeps running.
no-hard-waitswarnpage.waitForTimeout(…), new Promise with setTimeout (on the same line or the two lines before it), and the 'networkidle' load state. Wait for a condition instead: await expect(locator).toBeVisible().
no-force-clickwarn{ force: true } in a Playwright action (click, check, fill, hover, dragTo…, also when the options object spans lines). It skips actionability checks, so the test can pass where a user couldn't click. fs.rm(dir, { force: true }) is not a click and is ignored.
weakened-assertionswarnA hunk that removes more expect(…) calls (or Maestro assertVisible, assertNotVisible, assertTrue, assertWithAI) than it adds, including an assertion turned into a comment. Also an added empty catch {} / catch (e) {} / .catch(() => {}) that swallows errors, a Maestro step made optional: true, and a deleted test file that had assertions.
missing-test-updateswarnSource files changed and no test file did: no JS/TS test, Maestro flow, or other test file (test_*.py, *_test.go, *Test.java, *_spec.rb…). Turn it off with --ignore-missing-tests.
invalid-suppressionerrorAn agnox-audit-ignore comment without a reason, or naming an unknown rule. It suppresses nothing.

A rewritten assertion is not a weakened one: removing expect(total).toHaveText('$10') and adding expect(total).toHaveText('$12') in the same hunk is fine.

Verdict​

VerdictMeaning
Pass (PASS)No findings.
Warnings (WARN)Only warnings.
Fail (FAIL)At least one error.

--fail-on decides which findings fail the command: error (default), warn or never.


Suppressing a finding​

When a finding is a deliberate, reviewed choice, suppress it in the code with a reason:

// agnox-audit-ignore no-force-click: the cookie banner overlays this button on mobile only (#482)
await page.getByRole('button', { name: 'Accept' }).click({ force: true });

await page.waitForTimeout(300); // agnox-audit-ignore no-hard-waits: the canvas animation has no DOM signal
# agnox-audit-ignore weakened-assertions: the onboarding screen was removed in 4.2
- tapOn: "Continue"
  • The comment covers its own line, or the next line of code when it stands alone.
  • Name several rules with commas: // agnox-audit-ignore no-hard-waits, no-force-click: <reason>.
  • A removed assertion has no line of its own, so a suppression for weakened-assertions anywhere in the same hunk covers it.
  • The reason is required. Without one, or with an unknown rule, the comment suppresses nothing and is reported as invalid-suppression (an error).
  • missing-test-updates concerns the whole change, so it can't be suppressed inline. Use --ignore-missing-tests.

Suppressed findings are not hidden: every output format lists them with their reasons, so a reviewer sees each one.


CLI: agnox audit pr​

npx -y @agnox/mcp-server@latest audit pr # origin/main to the working tree
npx -y @agnox/mcp-server@latest audit pr --base origin/develop --head HEAD
npx -y @agnox/mcp-server@latest audit pr --staged --fail-on warn # e.g. in a pre-commit hook
git diff main... > pr.diff && npx -y @agnox/mcp-server@latest audit pr --diff-file pr.diff
OptionDescription
--base <ref>The branch the pull request targets. Default origin/main.
--head <ref>Audit base...head (the commits of the pull request, as GitHub shows them). Without it, the working tree is compared with the merge base of --base and HEAD: committed and uncommitted changes, plus untracked files.
--stagedAudit only the staged changes (git diff --cached). With --base, the staged changes since the merge base.
--diff-file <path>Audit a unified diff file instead of reading git.
--fail-on error|warn|neverThe lowest severity that exits 1. Default error.
--format text|json|markdown|githubtext (default); the whole report as json; a markdown summary table for $GITHUB_STEP_SUMMARY or a pull request comment; github workflow commands that become inline annotations on the pull request.
--ignore-missing-testsTurn off missing-test-updates, for example in a repository that holds only tests (the source they test lives elsewhere).
--error-on-skipsReport no-new-skips as an error.
--project <id>Agnox project for the Agnox context (default AGNOX_PROJECT_ID).

agnox audit pr --help prints these options with their defaults, the rules, the suppression syntax, the exit codes and examples (@agnox/mcp-server 2.4.1 and later).

Exit codes:

CodeMeaning
0No finding at or above --fail-on.
1At least one finding at or above --fail-on.
2A git, usage or configuration error: not a repository, an unknown ref, a shallow clone without the merge base, an unreadable diff file, a bad option.

Only the report goes to stdout, so >> "$GITHUB_STEP_SUMMARY" gets a clean document; notes go to stderr. Code, file names and test titles from the diff are escaped in every format, so a pull request from a fork can't forge a workflow command or inject HTML into the summary.


GitHub Actions​

name: PR test audit

on:
pull_request:

permissions:
contents: read

jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # the audit needs the base branch and the merge base

- uses: actions/setup-node@v4
with:
node-version: 20

# 1. A summary table on the job page; never fails the job
- name: PR test audit summary
run: npx -y @agnox/mcp-server@latest audit pr --base "origin/$BASE_REF" --head HEAD --format markdown --fail-on never >> "$GITHUB_STEP_SUMMARY"
env:
BASE_REF: ${{ github.base_ref }}
AGNOX_API_KEY: ${{ secrets.AGNOX_API_KEY }} # optional: Agnox context
AGNOX_PROJECT_ID: ${{ vars.AGNOX_PROJECT_ID }}

# 2. Inline annotations on the pull request; fails the job on errors
- name: PR test audit
run: npx -y @agnox/mcp-server@latest audit pr --base "origin/$BASE_REF" --head HEAD --format github
env:
BASE_REF: ${{ github.base_ref }}
AGNOX_API_KEY: ${{ secrets.AGNOX_API_KEY }}
AGNOX_PROJECT_ID: ${{ vars.AGNOX_PROJECT_ID }}
  • fetch-depth: 0 is required. With the default shallow clone, the base branch and the merge base are missing and the audit exits 2 with a message that says so.
  • --head HEAD audits exactly the commits of the pull request. Without it, untracked files the job creates (build output that isn't in .gitignore) would be audited too.
  • The base branch is passed through env rather than written into the shell command, as GitHub recommends for any github.* value.
  • Add --fail-on warn to the second step to fail on warnings as well, or --fail-on never to report without blocking.
  • GitHub shows a limited number of annotations per step (currently 10 errors and 10 warnings). The summary table lists up to 50 findings.
  • The API key is optional. On pull requests from forks, secrets are not available and the audit simply runs without Agnox context.

Agnox context​

With AGNOX_API_KEY and a project (--project or AGNOX_PROJECT_ID), the auditor also checks whether the changed test files hold tests that Agnox lists as quarantined, unstable (stability grade D or F) or suspected regressions. It adds them as notes in every format, and as ::notice annotations with --format github:

Agnox context (informational):
tests/checkout.spec.ts: "pays with a saved card" is quarantined in Agnox
.maestro/login.yaml: "login with SSO" is unstable in Agnox (grade D)

The notes are informational. They never change the verdict or the exit code. When Agnox can't be reached within 10 seconds, the audit carries on and says that the context was skipped. A changed file matches when one path ends with the other (Agnox stores paths relative to the test runner's root, e.g. checkout.spec.ts for tests/checkout.spec.ts).


MCP: audit_pr_tests​

Coding agents get the same audit through the audit_pr_tests tool of the Agnox MCP server. It's read-only, needs no API key, and spends no AI tokens.

ArgumentDescription
baseRefGit ref to compare against. Default origin/main.
headRefAudit baseRef...headRef instead of the working tree.
stagedAudit only the staged changes.
diffTextA unified diff to audit instead of reading git (up to 5 000 000 characters).
cwdRepository directory. Defaults to the directory the MCP server runs in; a relative path is resolved against it.
projectIdAgnox project for the context notes. Defaults to AGNOX_PROJECT_ID.
failOnerror (default), warn or never: decides passes.
ignoreMissingTests, skipsAsErrorsAs --ignore-missing-tests and --error-on-skips.

The result is a summary line with counts only, followed by JSON under untrusted_data: verdict, passes, failOn, source, counts, findings (at most 50, then findingsOmitted), suppressed, notes and enrichment. Snippets come from the code under review, so the agent treats them as data, never as instructions.

"Audit my test changes before I open the pull request."

The assistant calls audit_pr_tests, fixes each finding (replaces the sleep with a condition, restores the assertion, removes the .only), and calls it again until the verdict passes. It never adds an agnox-audit-ignore comment, a skip or optional: true just to turn the verdict green. When a suppression is genuinely needed, it writes the real reason and names it in the pull request description. The Agnox Quality skill and the server's instructions tell agents to do this before every pull request that touches tests.