# ClaudeDo.Worker.Tests

xUnit integration tests for the Worker and Data layers.

## Framework

- xUnit 2.5.3 with `xunit.runner.visualstudio`
- No mocking library — custom sealed fakes (FakeClaudeProcess, FakeHubContext, FakeHubClients, FakeClientProxy)
- Real SQLite databases per test via `DbFixture`
- Real git repos for worktree tests via `GitRepoFixture`
- coverlet for coverage collection

## Test Infrastructure

- **DbFixture** — creates unique temp SQLite DB, applies schema, cleans up DB + WAL/SHM files on dispose
- **GitRepoFixture** — creates temp git repo with initial commit, configures user/email, handles Windows read-only .git cleanup. Tests skip if git is unavailable.

## Test Areas

| Area | File | What it covers |
|------|------|----------------|
| Repositories | `ListRepositoryTests` | CRUD, tag junctions |
| | `TaskRepositoryTests` | CRUD, status transitions, agent tag filtering, effective tags, stale flip |
| Runner | `WorktreeManagerTests` | Worktree creation, commit detection, error on non-git dir |
| | `CommitMessageBuilderTests` | Slug generation, title/description truncation |
| | `MessageParserTests` | NDJSON parsing, malformed input |
| Services | `QueueServiceTests` | FIFO ordering, override slot contention, cancellation, active tracking |
| | `StaleTaskRecoveryTests` | Flips orphaned running tasks to failed |

## Conventions

- Test classes implement `IDisposable` and create fixtures in constructor
- Helper factory methods for entities: `MakeTask()`, `CreateListAsync()`, `SeedListWithAgentTag()`
- Concurrency tests use `TaskCompletionSource` as gates for deterministic ordering
- Git-dependent tests are conditionally skipped via `Skip = ...` when git is not available

## Running

```bash
dotnet test tests/ClaudeDo.Worker.Tests
```
