Skip to content

Commit 9731c1b

Browse files
committed
ai(rules[claude]) Update instructions
1 parent 8ee64aa commit 9731c1b

File tree

1 file changed

+137
-3
lines changed

1 file changed

+137
-3
lines changed

CLAUDE.md

Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
## CRITICAL REQUIREMENTS
6+
7+
### Test Success
8+
- ALL tests MUST pass for code to be considered complete and working
9+
- Never describe code as "working as expected" if there are ANY failing tests
10+
- Even if specific feature tests pass, failing tests elsewhere indicate broken functionality
11+
- Changes that break existing tests must be fixed before considering implementation complete
12+
- A successful implementation must pass linting, type checking, AND all existing tests
13+
514
## Project Overview
615

716
libvcs is a lite, typed Python tool for:
@@ -10,12 +19,12 @@ libvcs is a lite, typed Python tool for:
1019
- Synchronizing repositories locally
1120
- Creating pytest fixtures for testing with temporary repositories
1221

13-
The library powers [vcspull](https://www.github.com/vcs-python/vcspull/).
22+
The library powers [vcspull](https://www.github.com/vcs-python/vcspull/), a tool for managing and synchronizing multiple git, svn, and mercurial repositories.
1423

1524
## Development Environment
1625

1726
This project uses:
18-
- Python 3.9+
27+
- Python 3.9+
1928
- [uv](https://github.com/astral-sh/uv) for dependency management
2029
- [ruff](https://github.com/astral-sh/ruff) for linting and formatting
2130
- [mypy](https://github.com/python/mypy) for type checking
@@ -67,12 +76,29 @@ make ruff_format
6776
# or directly
6877
uv run ruff format .
6978

79+
# Run ruff linting with auto-fixes
80+
uv run ruff check . --fix --show-fixes
81+
7082
# Run mypy for type checking
7183
make mypy
7284
# or directly
7385
uv run mypy src tests
86+
87+
# Watch mode for linting (using entr)
88+
make watch_ruff
89+
make watch_mypy
7490
```
7591

92+
### Development Workflow
93+
94+
Follow this workflow for code changes:
95+
96+
1. **Format First**: `uv run ruff format .`
97+
2. **Run Tests**: `uv run pytest`
98+
3. **Run Linting**: `uv run ruff check . --fix --show-fixes`
99+
4. **Check Types**: `uv run mypy`
100+
5. **Verify Tests Again**: `uv run pytest`
101+
76102
### Documentation
77103

78104
```bash
@@ -119,7 +145,115 @@ libvcs uses pytest for testing with many custom fixtures. The pytest plugin (`py
119145
- `create_git_remote_repo`: Creates a git repository for testing
120146
- `create_hg_remote_repo`: Creates a Mercurial repository for testing
121147
- `create_svn_remote_repo`: Creates a Subversion repository for testing
148+
- `git_repo`, `svn_repo`, `hg_repo`: Pre-made repository instances
149+
- `set_home`, `gitconfig`, `hgconfig`, `git_commit_envvars`: Environment fixtures
122150

123151
These fixtures handle setup and teardown automatically, creating isolated test environments.
124152

125-
For running tests with actual VCS commands, tests will be skipped if the corresponding VCS binary is not installed.
153+
For running tests with actual VCS commands, tests will be skipped if the corresponding VCS binary is not installed.
154+
155+
### Example Fixture Usage
156+
157+
```python
158+
def test_repo_sync(git_repo):
159+
# git_repo is already a GitSync instance with a clean repository
160+
# Use it directly in your tests
161+
assert git_repo.get_revision() == "initial"
162+
```
163+
164+
### Parameterized Tests
165+
166+
Use `typing.NamedTuple` for parameterized tests:
167+
168+
```python
169+
class RepoFixture(t.NamedTuple):
170+
test_id: str # For test naming
171+
repo_args: dict[str, t.Any]
172+
expected_result: str
173+
174+
@pytest.mark.parametrize(
175+
list(RepoFixture._fields),
176+
REPO_FIXTURES,
177+
ids=[test.test_id for test in REPO_FIXTURES],
178+
)
179+
def test_sync(
180+
# Parameters and fixtures...
181+
):
182+
# Test implementation
183+
```
184+
185+
## Coding Standards
186+
187+
### Imports
188+
189+
- Use namespace imports: `import enum` instead of `from enum import Enum`
190+
- For typing, use `import typing as t` and access via namespace: `t.NamedTuple`, etc.
191+
- Use `from __future__ import annotations` at the top of all Python files
192+
193+
### Docstrings
194+
195+
Follow NumPy docstring style for all functions and methods:
196+
197+
```python
198+
"""Short description of the function or class.
199+
200+
Detailed description using reStructuredText format.
201+
202+
Parameters
203+
----------
204+
param1 : type
205+
Description of param1
206+
param2 : type
207+
Description of param2
208+
209+
Returns
210+
-------
211+
type
212+
Description of return value
213+
"""
214+
```
215+
216+
### Git Commit Standards
217+
218+
Format commit messages as:
219+
```
220+
Component/File(commit-type[Subcomponent/method]): Concise description
221+
222+
why: Explanation of necessity or impact.
223+
what:
224+
- Specific technical changes made
225+
- Focused on a single topic
226+
227+
refs: #issue-number, breaking changes, or relevant links
228+
```
229+
230+
Common commit types:
231+
- **feat**: New features or enhancements
232+
- **fix**: Bug fixes
233+
- **refactor**: Code restructuring without functional change
234+
- **docs**: Documentation updates
235+
- **chore**: Maintenance (dependencies, tooling, config)
236+
- **test**: Test-related updates
237+
- **style**: Code style and formatting
238+
239+
Example:
240+
```
241+
url/git(feat[GitURL]): Add support for custom SSH port syntax
242+
243+
why: Enable parsing of Git URLs with custom SSH ports
244+
what:
245+
- Add port capture to SCP_REGEX pattern
246+
- Update GitURL.to_url() to include port if specified
247+
- Add tests for the new functionality
248+
249+
refs: #123
250+
```
251+
252+
## Debugging Tips
253+
254+
When stuck in debugging loops:
255+
256+
1. **Pause and acknowledge the loop**
257+
2. **Minimize to MVP**: Remove all debugging cruft and experimental code
258+
3. **Document the issue** comprehensively for a fresh approach
259+
4. **Format for portability** (using quadruple backticks)

0 commit comments

Comments
 (0)