ReviewOS

also looking at this

zig-utils/zig-test-framework

Add deterministic test sharding for distributed CI

#22
Merged glennmichael123 wants to merge codex/issue-4-deterministic-sharding into main
10 files +322 -5
README.mdmodified+38-2
Changes to README.md
@@ -95,6 +95,8 @@ This will automatically discover and run all `*.test.zig` files in the `tests` d
9595- `--no-recursive` - Disable recursive directory search
9696- `--bail` - Stop on first failure
9797- `--filter <text>` / `--grep <text>` - Run only Zig tests whose names contain the text
98- `--shard-index <N>` - Run one one-based file shard
99- `--shard-count <N>` - Set the total number of file shards
98100- `--no-color` - Disable color in child Zig test processes
99101- `--verbose` - Show detailed output
100102
@@ -117,6 +119,34 @@ zig-test --test-dir tests --no-recursive
117119
118120# Stop on first failure
119121zig-test --test-dir tests --bail
122
123# Run the second of four deterministic file shards
124zig-test --test-dir tests --shard-index 2 --shard-count 4
125```
126
127#### Distributed CI sharding
128
129Sharding is opt-in and file-based. Both options are required, shard indices are
130one-based, and `1 <= shard-index <= shard-count`. Test files are assigned from
131their normalized relative paths with a fixed FNV-1a 64 hash, so the same paths
132and shard count always produce the same assignment on every platform. Each file
133belongs to exactly one shard; a valid shard with no matching files succeeds.
134
135Discovery and file-pattern selection happen before sharding. `--filter` is then
136forwarded to `zig test` for every file in the selected shard. Coverage and bail
137behavior apply only to that shard. The summary prints the shard, selected file
138count, and total discovered file count.
139
140```yaml
141jobs:
142 test:
143 strategy:
144 matrix:
145 shard: [1, 2, 3, 4]
146 steps:
147 - uses: actions/checkout@v4
148 - run: zig build
149 - run: zig build run -- --test-dir tests --shard-index ${{ matrix.shard }} --shard-count 4
120150```
121151
122152### Configuration files
@@ -135,6 +165,10 @@ precedence over configured values.
135165 "recursive": true,
136166 "filter": "database"
137167 },
168 "sharding": {
169 "index": 1,
170 "count": 4
171 },
138172 "coverage": {
139173 "enabled": false,
140174 "output_dir": "coverage"
@@ -142,8 +176,8 @@ precedence over configured values.
142176}
143177```
144178
145The accepted top-level sections are `test`, `parallel`, `reporter`, `snapshot`,
146`watch`, `memory`, `ui`, and `coverage`. Options retain the same execution-mode
179The accepted top-level sections are `test`, `sharding`, `parallel`, `reporter`,
180`snapshot`, `watch`, `memory`, `ui`, and `coverage`. Options retain the same execution-mode
147181limitations as their CLI equivalents; unsupported combinations fail explicitly.
148182
149183### Parallel execution semantics
@@ -607,6 +641,8 @@ zig-test --no-color
607641| `--test-dir <dir>` | | Directory to search for tests |
608642| `--pattern <pattern>` | | Test file pattern (default: *.test.zig) |
609643| `--no-recursive` | | Disable recursive directory search |
644| `--shard-index <N>` | | Run one one-based file shard |
645| `--shard-count <N>` | | Set the total number of file shards |
610646| `--coverage` | | Enable code coverage collection |
611647| `--coverage-dir <dir>` | | Coverage output directory (default: coverage) |
612648| `--coverage-tool <tool>` | | Coverage tool to use (kcov or grindcov) |