Skip to content

Commit da76ac3

Browse files
authored
Merge pull request #1805 from dandi/enh-lad-framework
Adapt LAD framework to dandi-cli project practices
2 parents fb21800 + a344d4d commit da76ac3

12 files changed

+324
-447
lines changed

.lad/.copilot-instructions.md

Lines changed: 38 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,89 @@
11
# Global Copilot Instructions
22

3-
* Prioritize **minimal scope**: only edit code directly implicated by the failing test.
3+
* Prioritize **minimal scope**: only edit code directly implicated by the failing test.
44
* Protect existing functionality: do **not** delete or refactor code outside the immediate test context.
55
* Before deleting any code, follow the "Coverage & Code Safety" guidelines below.
66

77
Copilot, do not modify any files under .lad/.
88
All edits must occur outside .lad/, or in prompts/ when explicitly updating LAD itself.
99

1010
Coding & formatting
11-
* Follow PEP 8; run Black.
11+
* Follow PEP 8; formatting enforced by pre-commit hooks (black, isort).
1212
* Use type hints everywhere.
13-
* External dependencies limited to numpy, pandas, requests.
14-
* Target Python 3.11.
13+
* Respect existing project dependencies declared in pyproject.toml.
1514

1615
Testing & linting
17-
* Write tests using component-appropriate strategy (see Testing Strategy below).
18-
* Run flake8 with `--max-complexity=10`; keep complexity ≤ 10.
16+
* Write tests using pytest; run via `tox -e py3` or `python -m pytest dandi`.
17+
* Tests requiring the DANDI archive use Docker Compose fixtures.
18+
* Mark AI-generated tests with `@pytest.mark.ai_generated`.
1919
* Every function/class **must** include a **NumPy-style docstring** (Sections: Parameters, Returns, Raises, Examples).
2020

2121
## Testing Strategy by Component Type
2222

23-
**API Endpoints & Web Services:**
24-
* Use **integration testing** - import the real FastAPI/Django/Flask app
25-
* Mock only external dependencies (databases, external APIs, file systems)
26-
* Test actual HTTP routing, validation, serialization, and error handling
27-
* Verify real request/response behavior and framework integration
23+
**CLI Commands:**
24+
* Use click's `CliRunner` for testing CLI entry points
25+
* Test argument parsing, output formatting, and error messages
26+
* Mock API calls and filesystem where appropriate
2827

29-
**Business Logic & Algorithms:**
30-
* Use **unit testing** - mock all dependencies completely
31-
* Test logic in complete isolation, focus on edge cases
32-
* Maximize test speed and reliability
33-
* Test pure business logic without framework concerns
28+
**API Client Operations (upload, download, move, etc.):**
29+
* Use **integration testing** with Docker Compose fixtures for archive interactions
30+
* Mock only external services not under test
31+
* Test actual HTTP interactions, authentication, and error handling
3432

35-
**Data Processing & Utilities:**
33+
**File Processing & Utilities:**
3634
* Use **unit testing** with minimal dependencies
37-
* Use test data fixtures for predictable inputs
35+
* Use test data fixtures (tmp_path, simple NWB files) for predictable inputs
3836
* Focus on input/output correctness and error handling
3937

4038
## Regression Prevention
4139

4240
**Before making changes:**
43-
* Run full test suite to establish baseline: `pytest -q --tb=short`
41+
* Run full test suite to establish baseline: `tox -e py3` or `python -m pytest dandi`
4442
* Identify dependencies: `grep -r "function_name" . --include="*.py"`
4543
* Understand impact scope before modifications
4644

4745
**During development:**
48-
* Run affected tests after each change: `pytest -q tests/test_modified_module.py`
46+
* Run affected tests after each change: `python -m pytest dandi/tests/test_modified_module.py`
4947
* Preserve public API interfaces or update all callers
5048
* Make minimal changes focused on the failing test
5149

5250
**Before commit:**
53-
* Run full test suite: `pytest -q --tb=short`
51+
* Run full test suite: `tox -e py3`
5452
* Verify no regressions introduced
5553
* Ensure test coverage maintained or improved
5654

57-
## Code Quality Setup (One-time per project)
55+
## Code Quality Setup
5856

59-
**1. Install quality tools:**
60-
```bash
61-
pip install flake8 pytest coverage radon flake8-radon black
62-
```
63-
64-
**2. Configure .flake8 file in project root:**
65-
```ini
66-
[flake8]
67-
max-complexity = 10
68-
radon-max-cc = 10
69-
exclude =
70-
__pycache__,
71-
.git,
72-
.lad,
73-
.venv,
74-
venv,
75-
build,
76-
dist
77-
```
78-
79-
**3. Configure .coveragerc file (see kickoff prompt for template)**
80-
81-
**4. Verify setup:**
82-
```bash
83-
flake8 --version # Should show flake8-radon plugin
84-
radon --version # Confirm radon installation
85-
pytest --cov=. --version # Confirm coverage plugin
86-
```
87-
88-
## Installing & Configuring Radon
57+
**This project already has quality tooling configured.** Do not create new config files; use existing ones.
8958

90-
**Install Radon and its Flake8 plugin:**
59+
**Verify setup:**
9160
```bash
92-
pip install radon flake8-radon
61+
pre-commit install # Install pre-commit hooks if not present
62+
tox -e lint # Run linting
63+
tox -e typing # Run type checking
64+
python -m pytest dandi # Run tests
9365
```
94-
This installs Radon's CLI and enables the `--radon-max-cc` option in Flake8.
9566

96-
**Enable Radon in Flake8** by adding to `.flake8` or `setup.cfg`:
97-
```ini
98-
[flake8]
99-
max-complexity = 10
100-
radon-max-cc = 10
101-
```
102-
Functions exceeding cyclomatic complexity 10 will be flagged as errors (C901).
103-
104-
**Verify Radon raw metrics:**
105-
```bash
106-
radon raw path/to/your/module.py
107-
```
108-
Outputs LOC, LLOC, comments, blank lines—helping you spot oversized modules quickly.
109-
110-
**(Optional) Measure Maintainability Index:**
111-
```bash
112-
radon mi path/to/your/module.py
113-
```
114-
Gives a 0–100 score indicating code maintainability.
67+
**Existing configuration locations:**
68+
- **Linting/formatting**: `.pre-commit-config.yaml` (black, isort, flake8)
69+
- **Pytest config**: `tox.ini` under `[pytest]` section
70+
- **Type checking**: `tox.ini` under `[testenv:typing]`
71+
- **Dependencies**: `pyproject.toml`
11572

11673
Coverage & Code Safety
117-
* For safety checks, do **not** run coverage inside VS Code.
118-
Instead, ask the user:
119-
> "Please run in your terminal:
120-
> ```bash
121-
> coverage run -m pytest [test_files] -q && coverage html
122-
> ```
123-
> then reply **coverage complete**."
124-
12574
* Before deleting code, verify:
12675
1. 0% coverage via `coverage report --show-missing`
127-
2. Absence from Level-2 API docs
128-
If both hold, prompt:
129-
130-
Delete <name>? (y/n)
131-
Reason: 0% covered and not documented.
132-
(Tip: use VS Code "Find All References" on <name>.)
76+
2. No references found via grep
77+
If both hold, prompt for confirmation before deletion.
13378

13479
Commits
135-
* Use Conventional Commits. Example:
136-
`feat(pipeline-filter): add ROI masking helper`
137-
* Keep body as bullet list of sub-tasks completed.
80+
* Follow existing project conventions for commit messages.
81+
* pre-commit hooks will auto-fix formatting; if commit fails due to auto-fixes, re-run the commit.
13882

13983
Docs
140-
* High-level docs live under the target project's `docs/` and are organised in three nested levels using `<details>` tags.
84+
* High-level docs live under the target project's `docs/` directory (Sphinx RST format).
14185

14286
* After completing each **main task** (top-level checklist item), run:
143-
`flake8 {{PROJECT_NAME}} --max-complexity=10`
144-
`python -m pytest --cov={{PROJECT_NAME}} --cov-context=test -q --maxfail=1`
87+
`tox -e lint`
88+
`python -m pytest dandi -q --maxfail=1`
14589
If either step fails, pause for user guidance.
146-
147-
* **Radon checks:** Use `radon raw <file>` to get SLOC; use `radon mi <file>` to check maintainability. If `raw` LOC > 500 or MI < 65, propose splitting the module.

.lad/CLAUDE.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*Auto-updated by LAD workflows - current system understanding*
55

66
## Code Style Requirements
7-
- **Docstrings**: NumPy-style required for all functions/classes
8-
- **Linting**: Flake8 compliance (max-complexity 10)
9-
- **Testing**: TDD approach, component-aware strategies
10-
- **Coverage**: 90%+ target for new code
7+
- **Docstrings**: NumPy-style for public APIs
8+
- **Formatting**: Black (line length 100), isort (profile="black"), enforced via pre-commit
9+
- **Linting**: `tox -e lint`; type checking: `tox -e typing`
10+
- **Testing**: pytest via `tox -e py3`; Docker Compose for integration tests
1111

1212
## Communication Guidelines
1313
**Objective, European-Style Communication**:
@@ -26,9 +26,10 @@
2626
- **Progress tracking**: Update both TodoWrite and plan.md files consistently
2727

2828
## Testing Strategy Guidelines
29-
- **API Endpoints**: Integration testing (real app + mocked external deps)
30-
- **Business Logic**: Unit testing (complete isolation + mocks)
31-
- **Data Processing**: Unit testing (minimal deps + test fixtures)
29+
- **CLI Commands**: click CliRunner + mocked API calls
30+
- **API Client Operations**: Integration testing with Docker Compose fixtures
31+
- **File Processing & Utilities**: Unit testing (tmp_path + test data fixtures)
32+
- **AI-generated tests**: Mark with `@pytest.mark.ai_generated`
3233

3334
## Project Structure Patterns
3435
*Learned from exploration - common patterns and conventions*
@@ -46,6 +47,8 @@
4647

4748
### Token Optimization for Large Codebases
4849
**Standard test commands:**
50+
- **Full suite**: `tox -e py3` or `python -m pytest dandi`
51+
- **Single test**: `python -m pytest dandi/tests/test_file.py::test_function -v`
4952
- **Large test suites**: Use `2>&1 | tail -n 100` for pytest commands to capture only final results/failures
5053
- **Coverage reports**: Use `tail -n 150` for comprehensive coverage output to include summary
5154
- **Keep targeted tests unchanged**: Single test runs (`pytest -xvs`) don't need redirection
@@ -94,4 +97,4 @@
9497
- *No anti-patterns logged*
9598

9699
---
97-
*Last updated by Claude Code LAD Framework*
100+
*Last updated by Claude Code LAD Framework*

0 commit comments

Comments
 (0)