Skip to content

Add missing requires so each src file compiles standalone#22

Merged
antondalgren merged 1 commit into
mainfrom
standalone-requires
Jun 9, 2026
Merged

Add missing requires so each src file compiles standalone#22
antondalgren merged 1 commit into
mainfrom
standalone-requires

Conversation

@antondalgren

Copy link
Copy Markdown
Contributor

Summary

Each `.cr` in `src/` now declares its own dependencies via `require`, so
```
crystal build --no-codegen --error-on-warnings -Dpreview_mt -Dexecution_context src/raft/http/handler.cr
```
(and the same for every other file) succeeds standalone, not only via the `src/raft.cr` aggregator. Mirrors what Carl's `29fb3fb` was originally trying to land but with the deps relevant to today's tree.

What was missing

  • `node.cr` used `Role`, `NodeID`, `Log`, `StateMachine`, `Metrics`, `Peer`, `LogEntry`, `EntryType`, `Message`, `Config` without requiring any of them.
  • `log.cr` / `log/segment.cr` / `log_entry.cr` didn't pull in their type dependencies (`Config`, `EntryType` from `message.cr`).
  • `message.cr` / `peer.cr` / `metrics.cr` used the `NodeID` alias from `config.cr` without requiring it.
  • `transport.cr` (abstract base) didn't require `config` / `message` for the types in its abstract signatures.
  • `transport/tcp_transport.cr` and `transport/memory_transport.cr` didn't require `../transport` (their base class), `../config`, etc.
  • `server.cr` used `Node`, `StateMachine`, etc. without requiring them.
  • `http/handler.cr` used `TCPTransport` without requiring it.

Test plan

  • `crystal build --no-codegen --error-on-warnings -Dpreview_mt -Dexecution_context ` — clean for all files (lib + tui)
  • `crystal build --no-codegen ... src/raft.cr` (the aggregator) — still clean
  • `crystal tool format --check src/ spec/` — clean
  • `lib/ameba/bin/ameba --fail-level error src/ spec/` — clean
  • `crystal spec spec/raft/ -Dpreview_mt -Dexecution_context` — 113/113

Why it matters

  • LavinMQ's `compile-changed-files` CI job (which we may want to port) iterates each changed `.cr` and tries to build it standalone. With this PR, that pattern would work for raft.cr.
  • Editor tooling (LSP, jump-to-def) often resolves `require` graphs per-file; explicit requires make each file's dependencies obvious to both humans and tools.
  • It prevents a class of "works in CI, doesn't work when someone reorders the aggregator" surprises.

🤖 Generated with Claude Code

Each .cr in src/ now declares its own dependencies via require, so
crystal build --no-codegen --error-on-warnings -Dpreview_mt
-Dexecution_context <file> succeeds for any single file rather than
only via the src/raft.cr aggregator.

Verified for every src/ file (incl. tui). Suite, format, and ameba
all still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@antondalgren antondalgren merged commit e024c01 into main Jun 9, 2026
5 checks passed
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