AI CodeOps

Python service: tests first, with a coverage floor in CI

Write missing pytest tests with Quality-Gated Change, record coverage from pytest-cov in the sandbox, and have CI deny the merge below an 80% coverage floor.

Use this template

Untested pricing code is where refunds come from. This template asks the agents to write the missing tests first, runs them against the code that was actually written, and gives your CI a coverage floor to enforce.

Which agents run

Quality-Gated Change is the shortest code workflow, with no planning step:

  1. Build, by the Builder: the test file and any fix the cases call for.
  2. Test, by the Tester: named cases for the happy path, edge cases and failure modes, checked against what the Builder wrote.
  3. Review, by the Reviewer: whether the tests assert real behavior or only exercise lines.

The code pass then writes the change. The verify step rebuilds it in a sandbox, installs dependencies, cuts the network and runs your test command. The pytest summary is parsed into passed, failed and skipped, and the coverage TOTAL line from pytest-cov is recorded as line coverage.

Set the test command

On the project, set:

Project fieldExample value
Test commandpytest -q --cov=app --cov-report=term

Without a command, AI CodeOps detects pytest from pyproject.toml, setup.cfg, pytest.ini or tox.ini, but runs pytest -q with no coverage. Each command has a two-minute limit.

Gates that apply

  • Failing tests block the pull request, and only a result for the current version of the change counts.
  • Open high or critical findings block until triaged.
  • A person other than the session's starter approves, when the workspace has another approver.

Enforce the floor in CI

Coverage is gated only when your pipeline asks. Pass the pull request URL and a floor:

curl -sf -X POST "https://console.aicodeops.dev/api/release/check" \
  -H "Authorization: Bearer $WORKSPACE_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"pullRequestURL\":\"$PR_URL\",\"minCoveragePct\":80}" \
  | jq -e '.allowed == true'

The most recent test run that reported coverage must meet 80, or the response is denied with a coverageShortfall, for example "Coverage 71% is below the required 80%". The floor applies to whatever your command measures, so --cov=app gates the whole package, not just the file you changed. Field details are in the release check reference.

For the dependency side of the same service, see the SBOM and license gate template.

Frequently asked questions

Does the per-run quality gate check coverage?

No. Coverage floors are a CI option. The run's own gate checks tests, findings and approval; minCoveragePct is applied only when your CI asks.

What if the sandbox can't install pytest-cov?

The verify step records a skip with the reason, not a failure and not a pass. Add pytest-cov to the dependencies your project installs.