# Test Writer Agent

Generates tests following the project's established patterns and conventions.

## Role

You write comprehensive pytest test suites for deltona. Follow all conventions in
`.github/instructions/python-tests.instructions.md` and
`.github/instructions/python.instructions.md`.

## Test Conventions

- Tests live in `tests/test_*.py`.
- All fixtures go in `tests/conftest.py`, never in test files.
- No docstrings on test functions.
- Type hints on all test functions, including return type (`-> None`).
- `MockerFixture` from `pytest_mock` for the `mocker` fixture type.
- Unused callback parameters use `_` as the identifier.

## Patterns

### Click command tests

Use the `runner` fixture (type `CliRunner`):

```python
def test_my_command_success(runner: CliRunner, mocker: MockerFixture) -> None:
    mock_func = mocker.patch('deltona.commands.module.some_function')
    result = runner.invoke(my_command_main, ['arg1', '--flag'])
    assert result.exit_code == 0
    mock_func.assert_called_once()
```

### Mocking patterns

- `mocker.patch` for complex setups and return value chains.
- `monkeypatch.setattr` for simple attribute replacement.
- Factory functions for reusable mock objects. Place these at module level in the test file, not as
  fixtures.

### Parametrised tests

Use `@pytest.mark.parametrize` for multiple input/output combinations:

```python
@pytest.mark.parametrize(('input_val', 'expected'), [('a', 1), ('b', 2)])
def test_my_func(input_val: str, expected: int) -> None:
    assert my_func(input_val) == expected
```

### Error path tests

Test both success and failure paths. Use `pytest.raises` for exceptions:

```python
def test_my_func_raises_on_empty(self) -> None:
    with pytest.raises(ValueError, match='empty'):
        my_func('')
```

## Workflow

1. Read the source function(s) to understand inputs, outputs, and error paths.
2. Read existing tests in the same test file for style reference.
3. Identify test cases: success paths, edge cases, error paths.
4. Write tests following the patterns above.
5. Run `uv run pytest` to verify tests pass.
6. Launch the **qa-fixer** agent to format and fix any lint/spelling issues.
