codespeak coverage
Improve test coverage in an existing project.
Synopsis
codespeak coverage [spec_path] --target N --max-iterations M [--no-interactive]Description
Runs the test suite, measures code coverage, identifies uncovered code, and iteratively adds tests to bring coverage to the target level.
The iterative loop:
- Run tests with coverage measurement
- Identify uncovered lines and branches
- Generate new tests targeting uncovered code
- Repeat until target is reached or max iterations exhausted
Pre-existing test failures are ignored during improvement โ CodeSpeak only focuses on adding coverage, not fixing existing broken tests.
Flags
| Flag | Description |
|---|---|
spec_path | Path to the specification file. If omitted, all registered specs are processed |
--target N | Target coverage percentage (1-100). **Required** |
--max-iterations M | Maximum number of coverage improvement iterations (1-30). **Required** |
--no-interactive | Run in non-interactive mode without real-time progress updates |
Language support
codespeak coverage is language-agnostic. When you run codespeak test --auto-configure, it detects your language and test framework and writes the necessary commands to run tests with coverage in LCOV format. This works across Python, JavaScript, Go, and other languages.
Test runner configuration
CodeSpeak needs to know how to run tests with coverage reporting. This is stored in codespeak.json under test_runner_configurations. You can either:
- Auto-configure with
codespeak test --auto-configure(recommended) - Manually configure the test runner commands in
codespeak.json
The configuration must include a run_all_tests_with_coverage_command containing both {tests_report_file} (JUnit XML results) and {tests_coverage_report_file} (LCOV coverage data) macros.
Error messages
| Error | Cause | Resolution |
|---|---|---|
| Can't find spec to build | No .cs.md files found and no specs registered in codespeak.json | Create a spec file or register one in codespeak.json |
| Cannot specify both a positional spec path and --spec | Both positional path and --spec flag provided | Use one or the other |
| Anthropic API Key not found | No API key configured | Set the ANTHROPIC_API_KEY environment variable or run through the interactive setup |
| Circular spec dependency detected: A -> B -> A | Spec imports form a cycle | Remove the circular import |
| {path} does not belong to a CodeSpeak project | No codespeak.json found | Run codespeak init first |
| --max-iterations must be between 1 and 30 | Invalid iteration count | Use a value between 1 and 30 |
| --target is required | Missing --target flag | Specify a target: --target 100 |
| --max-iterations is required | Missing --max-iterations flag | Specify iterations: --max-iterations 5 |
| --target must be between 1 and 100 | Target out of range | Use a value between 1 and 100 |
| '{field}' is missing in codespeak.json | Test runner not configured | Run codespeak test --auto-configure or configure manually |
| '{field}' in codespeak.json is still a placeholder | Auto-configured field was not filled in | Edit the placeholder value in codespeak.json |
| Coverage command must include {tests_coverage_report_file} placeholder | Coverage command missing LCOV output macro | Add the macro to the command string |
| No testable source files found | No managed files with source code for this spec | Ensure the spec has managed files |
| Reached target coverage but N new test failures remain | Tests were added but some fail | Fix the failing tests manually or increase --max-iterations |
| Failed to reach target coverage after N iterations | Coverage target not achievable in the given iterations | Increase --max-iterations or lower --target |
See also
- Improve Test Coverage tutorial โ step-by-step walkthrough
codespeak testโ run and fix tests