clearml-mcp / rules
Cursor rule16 starsChanged 17 months agoMITView on GitHub
test coverage improvement patterns and lessons learned
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/ci-cd-philosophy.mdcCursor rule
- .cursor/rules/linting-philosophy.mdcCursor rule
- .cursor/rules/testing-philosophy.mdcCursor rule
The file
We split this test-coverage-improvement.mdc into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Hard to maintain: when internal code changed
- Distinctive: line 21
Complete public API coverage: - every function tested
- Distinctive: line 37
Empty responses: Test when API returns no data
- Distinctive: line 38
Error conditions: Test exception handling paths
- Distinctive: line 39
Different data structures: Test various response formats
- Very specific: line 81
Test suite: tests/test_clearml_mcp.py
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "test coverage improvement patterns and lessons learned"
globs: "tests/**/*.py"
---
# Test Coverage Improvement: From 34% to 69%
## Achievement Summary
**Improved test coverage by +35 percentage points** (34% → 69%) through comprehensive behavioral testing rewrite.
## What We Learned
### ❌ White-Box Testing Problems (Original 34%)
- **Brittle tests** that broke during refactoring
- **Implementation-dependent** test structure
- **Incomplete coverage** of public API behaviors
- **Hard to maintain** when internal code changed
### ✅ Behavioral Testing Success (New 69%)
- **Stable tests** that survive refactoring
- **Complete public API coverage** - every function tested
- **Realistic scenarios** with proper edge case handling
- **Easy to maintain** - tests focus on contracts, not internals
## Key Implementation Patterns
### Comprehensive Mock Strategy
```python
# Mock external dependencies completely
@patch('clearml.Task.get_task')
@patch('clearml.Task.query_tasks')
# Test all public API paths with realistic data
```
### Edge Case Coverage
- **Missing attributes**: Handle optional fields gracefully
- **Empty responses**: Test when API returns no data
- **Error conditions**: Test exception handling paths
- **Different data structures**: Test various response formats
### Proper Mock Attribute Handling
```python
# Correct way to mock optional attributes
with patch('builtins.hasattr') as mock_hasattr:
mock_hasattr.side_effect = lambda obj, attr: not (obj is mock_obj and attr == "missing_field")
```
## Coverage Configuration
Configuration in [pyproject.toml](mdc:pyproject.toml):
```toml
[tool.coverage.run]
branch = true
source = ["src"]
omit = ["_*.py", "__*.py"]
[tool.coverage.report]
skip_empty = true
show_missing = true
fail_under = 65 # Raised from default after improvement
```
## Testing Commands
```bash
# Coverage testing (matches CI exactly)
coverage run -m pytest tests && coverage report
# Local development
uv run pytest --verbose --color=yes tests
uv run coverage run -m pytest tests && uv run coverage report
```
## Success Metrics
- ✅ **Coverage**: 69% (vs 34% before)
- ✅ **Test count**: 26 comprehensive behavioral tests
- ✅ **API coverage**: All public functions tested
- ✅ **Edge cases**: Missing data, errors, empty responses
- ✅ **Stability**: Tests survive refactoring
- ✅ **CI integration**: Passes in all environments
## Key Files
- Test suite: [tests/test_clearml_mcp.py](mdc:tests/test_clearml_mcp.py)
- Coverage config: [pyproject.toml](mdc:pyproject.toml) `[tool.coverage.*]`
- CI testing: [.github/workflows/ci.yml](mdc:.github/workflows/ci.yml)
This improvement demonstrates that **behavioral testing with comprehensive mocking** is far more effective than white-box testing for achieving both high coverage and maintainable tests.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

