ReviewOS

also looking at this

zig-utils/zig-test-framework

Make watch mode rerun affected tests

#28
Merged glennmichael123 wants to merge codex/issue-11-watch-affected into main
5 files +621 -105
docs/watch-mode.mdadded+45-0
Changes to docs/watch-mode.md
@@ -0,0 +1,45 @@
1# Watch mode
2
3Watch mode runs the full discovered suite once, then polls Zig source and test
4files after the configured debounce interval. Start it with a test directory:
5
6```bash
7zig-test --test-dir tests --watch
8```
9
10Type `r` and press Enter at any time to request an explicit full-suite rerun.
11Ctrl-C stops the watcher and any UI server cleanly.
12
13## Affected-test selection
14
15Each rerun prints both the selected test and the reason it was selected:
16
17```text
18Watch selection:
19 - math.test.zig (imports changed source: src/math.zig)
20```
21
22The selection rules are conservative:
23
24- A modified or newly added test file runs by itself. Multiple changed tests
25 are batched by the debounce interval and run together.
26- For a source change, the watcher follows relative `.zig` imports from every
27 discovered test, including transitive imports, and runs tests whose import
28 graph contains the changed file.
29- Named module imports such as `` cannot be resolved from
30 source text alone. If any test has unresolved imports, or a changed source
31 file maps to no test, the watcher safely runs the full suite.
32- Deleting a test, or renaming one (observed as a delete plus an add), runs the
33 full suite so reporters and the live UI receive the new test topology.
34- Deleting or renaming an imported source file also falls back to the full
35 suite when its dependency graph can no longer be resolved.
36
37The watcher scans the project root for `.zig` changes while using `--test-dir`,
38`--pattern`, and recursive-discovery settings to decide which files are tests.
39It excludes Git metadata, Zig caches/output, `node_modules`, and `.codex`.
40
41## Debouncing
42
43`--watch-debounce <ms>` controls the polling and batching interval. The default
44is 300 milliseconds. A test run is never interrupted: edits made while tests
45are running are detected on the next poll and cause another affected run.