CODI Testing Guide

CODI ships with a comprehensive pytest suite covering parsing, rendering, CLI/API flows, LLM integration, and data pipelines. This guide details available tests and how to run them.

1. Test Environment

2. Running Tests

make test          # python -m pytest
python -m pytest   # direct invocation
python -m pytest -k render
python -m pytest --cov=core --cov-report=html

Use -m "not slow" once slow tests exist; currently all tests run quickly.

3. Test Categories

Module Location Focus
Parser & detector tests/test_parse.py, tests/test_detect.py Dockerfile parsing, stack detection heuristics.
Analyzer tests/test_analyzer.py (if present) / tests/test_rules.py Smell detection, rule selection.
Renderer tests/test_render.py Template rendering, CMD rewrites, rationale comments.
Build runner tests/test_build.py Metrics estimation, policy enforcement.
Store & RAG tests/test_store.py Run directory handling, SQLite index updates.
Security tests/test_security.py Air-gap guard, adapter path validation.
CLI/API tests/test_cli.py, tests/test_api.py Command behaviours, FastAPI endpoints.
Dashboard tests/test_dashboard.py Dataset aggregation, JSON schema validation.
Performance tests/test_perf.py CPU perf harness.
LLM tests/test_llm.py, tests/test_llm_ranking.py Local server stub, ranking logic, telemetry.
Data pipeline tests/test_data_pipeline.py Collection/labeling/standardisation scripts.
Eval suite tests/test_eval_suite.py Evaluation harness sanity checks.
Training tests/test_training.py Ensures training script arguments and configs stay consistent.
Smoke tests/test_smoke.py End-to-end validations across demo stacks.

4. Adding Tests

  1. Place new tests under tests/ with descriptive filenames.
  2. Import modules using absolute paths (project root already in PYTHONPATH).
  3. Use fixtures for run directories to keep tests isolated.
  4. For CLI tests, use Typer’s CliRunner to capture output.
  5. For API tests, use FastAPI TestClient and configure allowlists as needed.

5. Test Data

6. Continuous Integration

7. Debugging Failures

Failure Type Tips
Parser errors Print problematic Dockerfile snippet; ensure parser handles instruction permutations.
Renderer assertions Regenerate expected outputs by running CLI and comparing to tests; ensure templates remained deterministic.
CLI/API snapshot mismatches Update fixtures if output schema changed intentionally.
LLM tests failing Check adapter environment variables; use stub mode by setting LLM_ENABLED=false.

8. Coverage Expectations