# Test Gap Finder: Test the Risky Code First

> Ranks your untested code by real risk (untested lines and branches, complexity, how often it changes, auth/payment/delete logic) from your coverage report, then writes behaviour tests that are proven to catch breakage.

Test Gap Finder: Test the Risky Code First is a free AI agent skill on Agensi by Abhineet Sharma. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Abhineet Sharma](https://www.agensi.io/creators/abhineet-sharma)
- Version: 1.0
- Last updated: 2026-11-28
- Security: scan passed (2026-11-28); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/test-gap-finder-test-the-risky-code-first
- Tags: testing-debugging, code-quality-review, apis-backend

## What it does

- Identifies untested code that handles risky tasks like payments or deleting data
- Ranks code by how often it changes and how complex the logic is
- Writes behavior tests that follow your existing project style and fixtures
- Verifies new tests by temporarily breaking code to ensure they catch the error
- Reports potential bugs found during testing instead of just hiding them

## Who it's for

- **Founders with a growing codebase:** Find and fix the blind spots in your app where bugs are most likely to hide. Try: "Find the riskiest untested parts of my app and write tests for them."
- **Freelance developers taking over old projects:** Quickly understand which parts of a messy project have no safety net before you start changing things. Try: "Rank the most dangerous untested code in this new repo."
- **Small dev teams focused on stability:** Stop guessing what to test and focus your time on code that handles money, logins, or deletes data. Try: "Look at my coverage report and tell me what critical features are missing tests."

## About this skill

Coverage percentage is a vanity number. 80% coverage with the refund logic untested is worse than 60% with it nailed down. This skill finds the untested code most likely to hurt you and writes tests that actually catch bugs.

**The ranker** (`gaps.py`, stdlib only, read-only, no network)
- Reads the coverage report you already have: **coverage.py / pytest-cov JSON, Istanbul (Jest, Vitest, nyc) JSON, lcov (c8, Jest, Vitest, pytest-cov and tools for Go/Rust), and Cobertura XML**. Auto-detects the format.
- Maps uncovered lines and branches to the **functions** that contain them (Python via the AST; JS/TS via the report's function map), handling nested functions, methods and module-level code.
- Scores each function by: share of untested lines, untested branches, complexity, **git churn** (how often the file changed recently), and **risk words** in the code (auth, permission, payment, refund, price, delete, migrate, parse, validate, webhook, retry, rate limit...).
- Flags functions **no test runs at all**, and prints the exact untested line ranges so you know which behaviours are missing.
- No coverage yet? **Static mode** lists Python functions that no test file even mentions.

**The workflow**
1. Generate coverage with your existing setup (commands included for pytest, coverage.py, Vitest, Jest, c8, Go).
2. Rank, then sanity-check the list: promote money/auth/data-deletion code, demote thin wrappers and generated code.
3. For each target, list behaviours (happy path, every branch, boundaries, error paths, side effects) and write one clearly-named test each, in **your** framework and style, mocking only at the edges.
4. **Prove the tests work**: temporarily break the code (flip a condition, shift a boundary) and confirm a new test fails, then revert. Tests that can't fail get strengthened.
5. Before/after coverage for the targets, and a list of **possible bugs found**. It reports bugs instead of writing tests that bless them, and never edits production code to make tests pass.

Free, no API keys.

## Requires

- Python 3.9+
- Your project's test runner
- Optional: Git (for churn ranking)
- Optional: Coverage tooling (pytest-cov, @vitest/coverage-v8, c8)

## Known limitations

Needs a coverage report from your test suite (static mode is a rough fallback for Python only). The risk score is a heuristic to prioritise, not a bug detector. Doesn't build end-to-end test suites from scratch or refactor code to make it testable (it suggests those). Installing coverage tooling, if missing, needs your OK.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Test Gap Finder: Test the Risky Code First skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### Which coverage formats are supported?

coverage.py JSON (pytest-cov --cov-report=json), Istanbul coverage-final.json (Jest, Vitest, nyc), lcov.info (c8, Jest, Vitest, pytest-cov, and converters for Go/Rust), and Cobertura XML. The format is detected automatically.

### Will it change my code?

Only test files. To prove a test works it temporarily breaks the code (e.g. flips a condition), checks a test fails, then reverts and confirms with git diff. It never edits production code to make tests pass.

### What if a new test fails?

That may be a real bug. The skill reports it (file, line, input, expected vs actual) and asks you, instead of rewriting the test to match the buggy behaviour.

### How is risk scored?

Untested share of the function, untested branches, complexity, how often the file changed in git recently, and whether the code touches auth, payments, deletion, parsing and similar. It's a prioritisation heuristic you can override.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
