|
| 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 | +HTTPSpec is a command-line tool written in Zig that extends HTTP files with assertions for integration testing. It parses `.http` or `.httpspec` files, executes HTTP requests sequentially, and validates responses against user-defined assertions. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +- **Build**: `zig build` |
| 12 | +- **Run**: `zig build run -- [file_or_directory]` |
| 13 | +- **Test**: `zig build test` |
| 14 | +- **Install**: `zig build install` |
| 15 | + |
| 16 | +## Architecture |
| 17 | + |
| 18 | +### Core Components |
| 19 | + |
| 20 | +- **`src/main.zig`**: Entry point with CLI parsing, file discovery, and parallel test execution using thread pools |
| 21 | +- **`src/httpfile/parser.zig`**: Parses `.http`/`.httpspec` files into structured HttpRequest objects with assertions |
| 22 | +- **`src/httpfile/http_client.zig`**: HTTP client for executing requests and capturing responses |
| 23 | +- **`src/httpfile/assertion_checker.zig`**: Validates responses against assertions (status codes, headers, body content) |
| 24 | +- **`src/reporters/test_reporter.zig`**: Test result reporting and statistics |
| 25 | + |
| 26 | +### File Format |
| 27 | + |
| 28 | +HTTPSpec extends standard `.http` files with assertion syntax: |
| 29 | +``` |
| 30 | +### Request name |
| 31 | +GET https://example.com/api/endpoint |
| 32 | +Header: value |
| 33 | +
|
| 34 | +//# status == 200 |
| 35 | +//# header["content-type"] == "application/json" |
| 36 | +//# body contains "expected" |
| 37 | +``` |
| 38 | + |
| 39 | +### Assertion Types |
| 40 | +- **Status**: `status == 200`, `status != 404` |
| 41 | +- **Headers**: `header["content-type"] == "application/json"` |
| 42 | +- **Body**: `body == "exact match"`, `body contains "substring"` |
| 43 | +- **Not equals**: Uses `!=` or `not_contains` operators |
| 44 | + |
| 45 | +### Configuration |
| 46 | + |
| 47 | +- **Threading**: Set `HTTP_THREAD_COUNT` environment variable to control parallel execution |
| 48 | +- **File Discovery**: Recursively finds `.http`/`.httpspec` files when no specific files are provided |
| 49 | + |
| 50 | +### Dependencies |
| 51 | + |
| 52 | +- **clap**: Command-line argument parsing (defined in `build.zig.zon`) |
| 53 | + |
| 54 | +## Testing Strategy |
| 55 | + |
| 56 | +The build system automatically discovers and tests all `.zig` files in the `src/` directory. Tests are run in parallel for better performance. |
0 commit comments