<!-- Generated by gz agent sync — do not edit -->
---
paths:
  - "tests/**"
---

# Test Policy (canonical)

> **Flag defects, never excuse them.** If a test reveals a defect in code, config, or test infrastructure — flag it as a defect. Never rationalize a failing or skipped test as "pre-existing" or "not in scope". Fix it or file a GHI.

- Use **stdlib `unittest`**; no pytest.
- Prefer **table-driven** tests with deterministic seeds; no network/external services.
- **Smoke/BVT <=60s**; cover current-scope surfaces only.
- Fixtures: local, small, reproducible; avoid huge goldens.
- **Database isolation**: Unit tests MUST use `tempfile` temp DBs; NEVER use live/production databases.

## DB Isolation (Django-like philosophy)

- Never touch live/production DBs from tests.
- Prefer shared in-memory SQLite DB for speed and isolation.
- Always pass `sqlite_path`/`db_path` to functions under test.

## Cross-Platform Test Cleanup (Windows-Critical)

**BINDING RULE:** Never use raw `shutil.rmtree()` in test tearDown.

### Pattern 1: Context Manager (Preferred)

```python
class TestSomething(unittest.TestCase):
    def test_with_temp_dir(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            test_file = Path(temp_dir) / "data.json"
            test_file.write_text("{}")
            result = process_dir(temp_dir)
            self.assertEqual(result, expected)
```

## Coverage Floor

- **Minimum line coverage: 40.00%**
- Before closing any brief, verify coverage has not regressed.

## Run

- `uv run ruff check . --fix && uv run ruff format .`
- `uv run -m unittest -v`

## Verify

- All tests PASS; smoke suite <=60s.
- Coverage >=40.00%.
