Skip to content

Commit 3b05e45

Browse files
committed
ai(rules[AGENTS]): Add comprehensive doctest guidelines
why: Ensure AI agents write real, executable doctests instead of using workarounds what: - Add Doctests section with critical rules - Document available doctest_namespace fixtures - Prohibit # doctest: +SKIP workaround - Add g-specific doctest patterns for VCS detection
1 parent c109f95 commit 3b05e45

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

AGENTS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ tests/test_cli.py
114114
- Ruff is the source of truth for lint rules; see `pyproject.toml` for enabled checks (E, F, I, UP, A, B, C4, COM, EM, Q, PTH, SIM, TRY, PERF, RUF, D, FA100).
115115
- Type checking is strict (`mypy --strict`); favor precise types and avoid `Any` unless necessary.
116116

117+
## Doctests
118+
119+
**All functions and methods MUST have working doctests.** Doctests serve as both documentation and tests.
120+
121+
**CRITICAL RULES:**
122+
- Doctests MUST actually execute - never comment out function calls or similar
123+
- Doctests MUST NOT be converted to `.. code-block::` as a workaround (code-blocks don't run)
124+
- If you cannot create a working doctest, **STOP and ask for help**
125+
126+
**Available tools for doctests:**
127+
- `doctest_namespace` fixtures: `tmp_path`
128+
- Ellipsis for variable output: `# doctest: +ELLIPSIS`
129+
- Update `conftest.py` to add new fixtures to `doctest_namespace`
130+
131+
**`# doctest: +SKIP` is NOT permitted** - it's just another workaround that doesn't test anything. If a VCS binary might not be installed, use proper skip markers in pytest.
132+
133+
**Using fixtures in doctests:**
134+
```python
135+
>>> from g import find_repo_type
136+
>>> find_repo_type('/some/git/repo') # doctest: +ELLIPSIS
137+
'git'
138+
```
139+
140+
**When output varies, use ellipsis:**
141+
```python
142+
>>> import pathlib
143+
>>> pathlib.Path.cwd() # doctest: +ELLIPSIS
144+
PosixPath('...')
145+
```
146+
117147
## Debugging Tips
118148

119149
- Add logging with `logging` configured in `run`; keep output minimal because the CLI forwards to underlying VCS.

0 commit comments

Comments
 (0)