Skip to content

refactor(serve): split serve.zig into focused modules - #436

Merged
apotema merged 1 commit into
developmentfrom
refactor/split-serve
Sep 26, 2026
Merged

apotema merged 1 commit into
developmentfrom
refactor/split-serve

Conversation

@apotema

@apotema apotema commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Refactor only. src/cli/serve.zig was 2,156 lines, over the toolkit's 1,000-line limit. It is now a thin root that re-exports the same public API over src/cli/serve/, following the same pattern as the labelle-bgfx gfx/ split. Nothing changes behaviour: code was moved, and imports and pub markers were fixed to match. Tests moved with the code they cover.

File map

File Lines Contents
src/cli/serve.zig 46 Root: module doc, re-exports (serveAndOpen, installCancelHandler, RebuildFn, WatchConfig, watchIgnorePath, pub const cancel so cancel.cancel_requested is still reachable), and a test {} block that references every module
serve/server.zig 213 serveAndOpen, serveLoop (the accept loop), openBrowser, and the serveLoop test
serve/http.zig 631 handleConnection, resolveTarget, resolveRoot, MIME table, live-reload endpoint, reload client, injectReloadScript, and their tests
serve/cancel.zig 101 cancel_requested, installCancelHandler, the POSIX signal handler, the Windows SetConsoleCtrlHandler handler, wakeListener/wakeLoop, and the wakeLoop test
serve/watch.zig 188 RebuildFn, WatchConfig, WatchState, shouldRebuild, watchLoop, and the debounce tests
serve/baseline.zig 497 WatchBaseline (follow-up, cap and ceiling policy) and its 10 tests
serve/tree.zig 540 TreeSignature, TreeSnapshot, changedPaths, the key-set helpers, the walk and its skip rules (build output, declared outputs, nested checkouts), and their tests
serve/testing.zig 35 Shared test helpers: testSig, testDelta, testBindFreePort

One test changed files for a reason other than following its code. computeSignature: a same-size in-place edit triggers a rebuild now lives in watch.zig because it asserts shouldRebuild. Its comment now says "test in tree.zig" instead of "test above".

Agnosticism guard allowlist delta

  • Added (4): cli/serve/http.zig, cli/serve/server.zig, cli/serve/tree.zig, cli/serve/watch.zig. They carry the platform words that moved out of serve.zig: web_dir, the WASM rebuild log line, emcc, and the raylib_wasm test fixture path.
  • Kept: cli/serve.zig. The root keeps the original module doc ("serving WASM builds"), so it is still dirty. The existing stale-entry test that names it is unchanged.
  • Clean, so not listed: cancel.zig, baseline.zig, testing.zig.
  • The allowlist goes from 54 to 58 entries, and the doc comment is updated to match.

Test counts (zig build test --summary all)

Before After
Build summary 1070/1075 passed (5 skipped) 1071/1076 passed (5 skipped)
Main CLI test binary 1038 total 1039 total
Named test "…" decls in serve 48 48 (same names, diffed)
Guard 17 pass 17 pass

The +1 is the new unnamed test {} aggregator block in serve.zig, which the runner counts as a test. Since the named-test set is identical and the runner total is exactly +1, all 48 moved tests still run and none were dropped by lazy analysis.

Verification

Each command's exit code was checked on its own:

  • zig fmt --check: 0
  • zig build: 0
  • zig build -Dtarget=x86_64-windows: 0 (covers the Windows console-control path)
  • zig build test: 0
  • test/provider_dispatch_e2e.py, provider_github_e2e.py, provider_config_e2e.py, provider_hooks_e2e.py, provider_targets_e2e.py, plugin_compat_e2e.py: all 0

https://claude.ai/code/session_01R2K5sJDL5Msn1uRTkybiDP


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

serve.zig (2,156 lines) becomes a thin root re-exporting the same public
API (serveAndOpen, installCancelHandler, RebuildFn, WatchConfig,
watchIgnorePath; the stop flag stays reachable as cancel.cancel_requested)
over src/cli/serve/:

  server.zig    serveAndOpen, the accept loop, browser launch
  http.zig      request handling, target resolution, MIME, live-reload
  cancel.zig    signal / console handler and the waker
  watch.zig     WatchConfig, WatchState, debounce, watchLoop
  baseline.zig  WatchBaseline follow-up / cap / ceiling policy
  tree.zig      TreeSignature, TreeSnapshot, key sets, the walk
  testing.zig   shared test helpers

Moves plus import/pub fixes only; tests move with their code and every
file is referenced from the root's test block (48 named tests before and
after). The four new files carrying the moved platform words join the
agnosticism guard allowlist; serve.zig stays on it.

Claude-Session: https://claude.ai/code/session_01R2K5sJDL5Msn1uRTkybiDP
@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: c9257754-e6b6-49f2-99d5-277c56c637fb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T21:35:11.723470Z bf90f07 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@apotema
apotema merged commit 697d282 into development Sep 26, 2026
8 checks passed
@apotema
apotema deleted the refactor/split-serve branch September 26, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant