# Testing

## Unit Tests

```sh
cd adpilot-indexing-code-parser.com
make test
```

## Integration Tests

Requires a running Redis instance (default `redis://localhost:6379`, override with `REDIS_URL`):

```sh
make test-integration
# equivalent:
go test -tags=integration ./...
```

Integration tests skip automatically when Redis is unreachable.

### With Docker Compose

Start Redis + app, then run integration tests against the compose Redis:

```sh
cd adpilot-indexing-code-parser.com

# Terminal 1 — stack
docker compose up --build -d

# Terminal 2 — integration tests (host → compose Redis on 6379)
REDIS_URL=redis://localhost:6379 make test-integration

docker compose down
```

Publisher integration tests publish to `chunks.ready`, `graph.artifact.ready`, and `parser.diagnostics.ready`. Consumer integration tests verify `files.changed` delivery.

## Current Coverage

| Area | Package | Notes |
| --- | --- | --- |
| Contract validation + JSON round-trip | `internal/contracts/...` | Events, graph IR, validate |
| Config loading | `internal/config` | Defaults, env overrides, non-local validation, git workspace ready |
| ArtifactStore | `internal/store` | Save/load, metadata, ready probe, concurrent writes |
| Mongo artifact chunking | `internal/store/mongo` | `splitGraphPayload` / reassembly unit tests; integration tests when MongoDB is reachable |
| Parse orchestration | `internal/service/parser` | Worker pool concurrency, failure isolation, skips, pipeline test |
| Go analyzer | `internal/service/parser/go` | Valid/syntax-error/empty fixtures, imports/calls |
| Redis client | `internal/redis` | Ping, ready, invalid URL |
| Redis consumer | `internal/redis` | Delegate, skip non-code, idempotency, malformed ACK, snapshot ACK |
| Redis publisher | `internal/redis` | All producer streams, validation rejection, stream prefix |
| HTTP health + debug | `internal/http` | `/healthz`, `/readyz`, `/parse-jobs`, `/artifacts`, `/diagnostics` |
| Observability | `internal/service/parser` | Structured completion logs with correlation fields |

## Lint

```sh
make lint
```

## Future Tests

- End-to-end pipeline with Repo Sync publishing real `files.changed` events
- REST debug API integration tests against a running service container
