|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build and Development Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Setup |
| 9 | +uv venv && uv pip install -e ".[dev]" |
| 10 | + |
| 11 | +# Run tests |
| 12 | +uv run pytest tests/ # all tests |
| 13 | +uv run pytest tests/unit/ # unit tests only |
| 14 | +uv run pytest -m "unit" # by marker |
| 15 | +uv run pytest -m "not e2e and not multipass" # exclude slow tests |
| 16 | +uv run pytest tests/unit/lb_runner/test_foo.py::test_bar # single test |
| 17 | + |
| 18 | +# Quick smoke test |
| 19 | +uv run python example.py |
| 20 | + |
| 21 | +# Linting & formatting |
| 22 | +uv run black . |
| 23 | +uv run flake8 |
| 24 | +uv run mypy lb_runner lb_controller lb_app lb_ui |
| 25 | + |
| 26 | +# Docs |
| 27 | +uv pip install -e ".[docs,controller]" |
| 28 | +uv run mkdocs serve |
| 29 | +``` |
| 30 | + |
| 31 | +## Architecture |
| 32 | + |
| 33 | +The library follows a layered architecture with strict import boundaries: |
| 34 | + |
| 35 | +``` |
| 36 | +lb_ui/ → lb_app/ → lb_controller/ → lb_runner/ |
| 37 | +(CLI/TUI) (Stable facade) (Orchestration) (Execution) |
| 38 | + ↓ |
| 39 | + lb_plugins/ |
| 40 | + (Workloads) |
| 41 | +``` |
| 42 | + |
| 43 | +**Module responsibilities:** |
| 44 | +- `lb_runner/` - Core execution: metric collectors (PSUtil, CLI, perf, eBPF), local runner |
| 45 | +- `lb_controller/` - Remote orchestration via Ansible, run journaling, state machine |
| 46 | +- `lb_app/` - Stable API facade for CLI/UI integrations |
| 47 | +- `lb_ui/` - CLI/TUI implementation (does not import into runner/controller) |
| 48 | +- `lb_analytics/` - Data aggregation and reporting (Pandas, Matplotlib) |
| 49 | +- `lb_plugins/` - Workload plugins (stress-ng, fio, dd, hpl, stream, dfaas) |
| 50 | +- `lb_provisioner/` - Docker/Multipass provisioning helpers |
| 51 | +- `lb_common/` - Shared utilities and logging configuration |
| 52 | + |
| 53 | +**Key rules:** |
| 54 | +- Always use the public `api.py` exports: `lb_runner.api`, `lb_controller.api`, `lb_app.api` |
| 55 | +- Never import internal modules directly (enforced by flake8-tidy-imports in `.flake8`) |
| 56 | +- Configure logging via `lb_common.api.configure_logging()` in entrypoints |
| 57 | +- Keep stdout clean for `LB_EVENT` streaming when building custom UIs |
| 58 | + |
| 59 | +## Plugin System |
| 60 | + |
| 61 | +Workloads are registered via Python entry points in `pyproject.toml`: |
| 62 | + |
| 63 | +```toml |
| 64 | +[project.entry-points."linux_benchmark.workloads"] |
| 65 | +stress_ng = "lb_plugins.plugins.stress_ng.plugin:PLUGIN" |
| 66 | +``` |
| 67 | + |
| 68 | +Each plugin in `lb_plugins/plugins/<name>/` contains: |
| 69 | +- `plugin.py` - Plugin definition and `PLUGIN` constant |
| 70 | +- `generator.py` - Command generation logic |
| 71 | +- `ansible/` - Optional Ansible playbooks for setup/teardown |
| 72 | + |
| 73 | +## Test Organization |
| 74 | + |
| 75 | +Tests live in `tests/` with markers for filtering: |
| 76 | +- `tests/unit/` - Fast, isolated tests (subdirs: `lb_runner/`, `lb_controller/`, etc.) |
| 77 | +- `tests/integration/` - Service-level tests, no provisioning |
| 78 | +- `tests/e2e/` - Full end-to-end with Multipass VMs or Docker |
| 79 | +- `tests/fixtures/` - Static test data |
| 80 | + |
| 81 | +Markers: `unit`, `integration`, `e2e`, `docker`, `multipass`, `slow`, `slowest` |
| 82 | + |
| 83 | +## Output Directories |
| 84 | + |
| 85 | +Generated at runtime (gitignored): |
| 86 | +- `benchmark_results/` - Raw metric data per run |
| 87 | +- `reports/` - Generated text reports and plots |
| 88 | +- `data_exports/` - Exported data files |
| 89 | + |
| 90 | +## Style |
| 91 | + |
| 92 | +- Python 3.12+, Black (88 chars), strict MyPy |
| 93 | +- `snake_case` for functions/variables, `PascalCase` for classes |
| 94 | +- Prefer dataclasses for configuration objects |
0 commit comments