|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Fairsplice is a TypeScript/Bun CLI tool and GitHub Action that optimizes test distribution across parallel workers. It provides CircleCI-style test splitting based on historical timing data for GitHub Actions. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Run locally |
| 13 | +bun run index.ts |
| 14 | + |
| 15 | +# Run all tests |
| 16 | +bun test |
| 17 | + |
| 18 | +# Run tests in src directory |
| 19 | +bun test src/ |
| 20 | + |
| 21 | +# Run a specific test file |
| 22 | +bun test src/lib/splitFiles.test.ts |
| 23 | + |
| 24 | +# Compile to standalone binary |
| 25 | +bun build ./index.ts --compile --outfile fairsplice |
| 26 | +``` |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +**Entry Point**: `index.ts` - CLI with three commands: `split`, `convert`, `merge` |
| 31 | + |
| 32 | +**Source Structure**: |
| 33 | +- `src/commands/` - CLI command implementations |
| 34 | + - `split.ts` - Distributes test files across workers using bin packing |
| 35 | + - `merge.ts` - Aggregates timing JSON files and updates history |
| 36 | + - `convert.ts` - Converts JUnit XML to timing JSON |
| 37 | +- `src/lib/` - Core algorithms |
| 38 | + - `splitFiles.ts` - Greedy bin packing algorithm (assigns heaviest tests first to balance workload) |
| 39 | + - `junit.ts` - JUnit XML parser using `fast-xml-parser` |
| 40 | + - `average.ts` - Timing averaging utility |
| 41 | +- `src/backend/` - Storage layer |
| 42 | + - `fileStorage.ts` - JSON-based timing persistence with rolling window of last 10 timings per file |
| 43 | +- `src/config.ts` - Constants (`NUMBER_OF_TIMINGS_TO_KEEP=10`, `DEFAULT_TIMING_IF_MISSING=10000ms`) |
| 44 | + |
| 45 | +**GitHub Action**: `action.yml` - Composite action wrapping the CLI with automatic cache handling |
| 46 | + |
| 47 | +**Data Flow**: |
| 48 | +1. `split` loads cached timings, globs test files, applies bin packing, outputs bucket assignments |
| 49 | +2. Tests run in parallel workers, each outputting JUnit XML |
| 50 | +3. `convert` transforms JUnit XML to timing JSON (one per worker) |
| 51 | +4. `merge` aggregates timing JSONs into cached timings history |
| 52 | + |
| 53 | +## Testing |
| 54 | + |
| 55 | +Tests are co-located with source files (`*.test.ts`). Test fixtures for JUnit parsing are in `src/lib/fixtures/`. |
| 56 | + |
| 57 | +The CI workflow (`.github/workflows/test.yml`) runs unit tests plus a 3-worker integration test that exercises the full split→run→convert→merge pipeline. |
0 commit comments