Skip to content

Commit 8276af5

Browse files
committed
• refactor: reorganize runtime and tests by serialization/RPC levels
- add `just install-path` plus grouped test recipes (`test-serialization`, `test-rpc-level0..3`) - split tests into `tests/serialization` and `tests/rpc/level{0,1,2,3}` - wire cumulative RPC level build targets and update default `test` aggregation - move serialization modules to `src/serialization/*` - reorganize RPC modules under `src/rpc/level{0,1,2,3}` - extract promise/pipelining code into level1 (`peer_promises`, `peer_return_send_helpers`, `promised_answer_copy`, `promise_pipeline`) - rewire `cap_table`/`peer`/`mod` imports and re-exports to keep API behavior intact - update README/AGENTS/docs/handoff path references to the new layout Validation: - `zig build test --summary all` - `just check`
1 parent 9d6d801 commit 8276af5

109 files changed

Lines changed: 475 additions & 385 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
## Project Structure & Module Organization
44
- `src/` holds the Zig library and plugin entry point.
5+
- `src/serialization/` contains wire-format, schema, and reader/validation modules.
56
- `src/capnpc-zig/` contains codegen utilities and generators.
6-
- `tests/` contains Zig test suites; fixture schemas live in `tests/test_schemas/`.
7+
- `src/rpc/level0`, `src/rpc/level1`, `src/rpc/level2`, and `src/rpc/level3` group RPC runtime modules by Cap'n Proto level.
8+
- `src/rpc/level1/` contains promise and pipelining primitives shared by higher-level peer flows.
9+
- `tests/serialization/` contains serialization-focused suites; `tests/rpc/level0..level3/` contain RPC suites by level.
10+
- `tests/` also contains support assets; fixture schemas live in `tests/test_schemas/`.
711
- `build.zig` defines build/test steps; `Justfile` wraps common tasks.
812
- `zig-out/` and `.zig-cache/` are build artifacts.
913

1014
## Build, Test, and Development Commands
1115
- `just build` builds the project (`zig build`).
1216
- `just release` builds optimized (`zig build -Doptimize=ReleaseSafe`).
1317
- `just test` runs all tests with summary output (`zig build test --summary all`).
18+
- `just test-serialization` runs serialization-focused suites.
19+
- `just test-rpc`, `just test-rpc-level0`, `just test-rpc-level1`, `just test-rpc-level2`, `just test-rpc-level3` run RPC suites by level.
1420
- `zig build test-message`, `zig build test-codegen`, `zig build test-integration`, `zig build test-real-world`, `zig build test-union` run focused suites.
21+
- `zig build test-serialization` runs all non-RPC serialization suites.
22+
- `zig build test-rpc-level0`, `zig build test-rpc-level1`, `zig build test-rpc-level2`, `zig build test-rpc-level3` run cumulative RPC levels.
1523
- `zig build test-capnp-testdata` and `zig build test-capnp-test-vendor` run Cap’n Proto fixture suites.
1624
- `just fmt` formats `src/` and `tests/` (`zig fmt`).
1725
- `just check` compiles without linking (`zig build check`).
@@ -27,8 +35,8 @@
2735
- Files are `snake_case.zig` (examples: `message.zig`, `integration_test.zig`).
2836

2937
## Testing Guidelines
30-
- Tests use Zig’s built-in `test` blocks in `tests/*.zig`.
31-
- Name new test files `*_test.zig` and group by feature area (message, codegen, integration).
38+
- Tests use Zig’s built-in `test` blocks in `tests/**/*.zig`.
39+
- Name new test files `*_test.zig` and group by area (`tests/serialization` or `tests/rpc/level0..level3`).
3240
- Run `just test` before submitting changes; add targeted tests for new behavior.
3341

3442
## Commit & Pull Request Guidelines

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- **Wire format** (`src/message.zig`, `src/message/*`): Full Cap'n Proto binary
12+
- **Wire format** (`src/serialization/message.zig`, `src/serialization/message/*`): Full Cap'n Proto binary
1313
format support including segment management, pointer encoding/decoding
1414
(struct, list, far, capability), text/data serialization, and packed encoding.
1515
Key types: `Message`, `MessageBuilder`, `StructReader`, `StructBuilder`, and
1616
typed list readers/builders for all primitive types.
1717

18-
- **Schema types** (`src/schema.zig`): In-memory representation of Cap'n Proto
18+
- **Schema types** (`src/serialization/schema.zig`): In-memory representation of Cap'n Proto
1919
schema graphs mirroring `schema.capnp` -- `Node`, `Field`, `Type`, `Value`,
2020
and supporting types.
2121

22-
- **Schema parsing** (`src/request_reader.zig`): Parser for
22+
- **Schema parsing** (`src/serialization/request_reader.zig`): Parser for
2323
`CodeGeneratorRequest` messages received from the Cap'n Proto compiler plugin
2424
protocol over stdin.
2525

26-
- **Schema validation** (`src/schema_validation.zig`): Validation and
26+
- **Schema validation** (`src/serialization/schema_validation.zig`): Validation and
2727
canonicalization of schema graphs with configurable traversal limits and
2828
nesting depth.
2929

@@ -32,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
structs, enums, constants, unions, groups, nested types, default values, and
3333
schema manifests with JSON serde exports.
3434

35-
- **Reader convenience** (`src/reader.zig`): High-level `Reader` type for
35+
- **Reader convenience** (`src/serialization/reader.zig`): High-level `Reader` type for
3636
segment-framed message reading, including packed-format support and
3737
stream-based message reading.
3838

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ Requires **Zig 0.15.2** (use `mise install` to set up toolchain).
3636

3737
Four-layer design, each building on the previous:
3838

39-
**Wire Format** (`src/message.zig` + `src/message/*`, ~2000 LOC) — Core Cap'n Proto binary format: segment management, pointer encoding/decoding, struct/list/text/data serialization, packing, far pointers. Key types: `MessageBuilder`, `Message`, `StructBuilder`, `StructReader`.
39+
**Wire Format** (`src/serialization/message.zig` + `src/serialization/message/*`, ~2000 LOC) — Core Cap'n Proto binary format: segment management, pointer encoding/decoding, struct/list/text/data serialization, packing, far pointers. Key types: `MessageBuilder`, `Message`, `StructBuilder`, `StructReader`.
4040

41-
**Schema** (`src/schema.zig`, `src/request_reader.zig`, `src/schema_validation.zig`) — Schema type definitions (Node, Field, Type, Value), CodeGeneratorRequest parsing from stdin, schema validation and canonicalization.
41+
**Schema** (`src/serialization/schema.zig`, `src/serialization/request_reader.zig`, `src/serialization/schema_validation.zig`) — Schema type definitions (Node, Field, Type, Value), CodeGeneratorRequest parsing from stdin, schema validation and canonicalization.
4242

4343
**Code Generation** (`src/capnpc-zig/`) — Generates idiomatic Zig Reader/Builder types from Cap'n Proto schemas. `generator.zig` is the main driver; `struct_gen.zig` generates field accessors; `types.zig` maps Cap'n Proto types to Zig types.
4444

HANDOFF_CONTEXT.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Purpose: Resume decomposition work quickly without re-reading the entire RPC sta
77
## Current branch state (important)
88

99
Modified/new RPC files in working tree:
10-
- `src/rpc/peer.zig` (modified)
11-
- `src/rpc/peer_forward_orchestration.zig` (modified)
10+
- `src/rpc/level3/peer.zig` (modified)
11+
- `src/rpc/level3/peer/forward/peer_forward_orchestration.zig` (modified)
1212
- `src/rpc/mod.zig` (modified)
13-
- `src/rpc/peer_third_party_adoption.zig` (new)
14-
- `src/rpc/peer_provide_join_orchestration.zig` (new)
13+
- `src/rpc/level3/peer/third_party/peer_third_party_adoption.zig` (new)
14+
- `src/rpc/level3/peer/provide/peer_provide_join_orchestration.zig` (new)
1515

1616
## Stable verification baseline
1717

@@ -25,23 +25,23 @@ Use those as minimum gate before/after additional slices.
2525
## What was extracted recently
2626

2727
1. Third-party adoption/await lifecycle
28-
- Module: `src/rpc/peer_third_party_adoption.zig`
28+
- Module: `src/rpc/level3/peer/third_party/peer_third_party_adoption.zig`
2929
- Entry points:
3030
- `adoptThirdPartyAnswer(...)`
3131
- `handleThirdPartyAnswer(...)`
3232
- `handleReturnAcceptFromThirdParty(...)`
3333
- `peer.zig` now delegates adoption/await orchestration to this module.
3434

3535
2. Provide/accept/join orchestration
36-
- Module: `src/rpc/peer_provide_join_orchestration.zig`
36+
- Module: `src/rpc/level3/peer/provide/peer_provide_join_orchestration.zig`
3737
- Entry points:
3838
- `handleProvide(...)`
3939
- `handleAccept(...)`
4040
- `handleJoin(...)`
4141
- `peer.zig` now delegates provide/accept/join flow orchestration.
4242

4343
3. Forward/tail coordination centralization
44-
- Module: `src/rpc/peer_forward_orchestration.zig`
44+
- Module: `src/rpc/level3/peer/forward/peer_forward_orchestration.zig`
4545
- `finishForwardResolvedCall(...)` now mutates forward/tail maps directly and returns a completion directive.
4646
- Added callback-factory helpers for control-path callback signatures.
4747

@@ -51,16 +51,16 @@ Use those as minimum gate before/after additional slices.
5151
## Key navigation anchors
5252

5353
- Forward call/return orchestration path:
54-
- `src/rpc/peer.zig` around `forwardResolvedCall(...)` and `onForwardedReturn(...)`
55-
- `src/rpc/peer_forward_orchestration.zig`
54+
- `src/rpc/level3/peer.zig` around `forwardResolvedCall(...)` and `onForwardedReturn(...)`
55+
- `src/rpc/level3/peer/forward/peer_forward_orchestration.zig`
5656

5757
- Provide/accept/join path:
58-
- `src/rpc/peer.zig` around `handleProvide(...)`, `handleAccept(...)`, `handleJoin(...)`
59-
- `src/rpc/peer_provide_join_orchestration.zig`
58+
- `src/rpc/level3/peer.zig` around `handleProvide(...)`, `handleAccept(...)`, `handleJoin(...)`
59+
- `src/rpc/level3/peer/provide/peer_provide_join_orchestration.zig`
6060

6161
- Third-party adoption path:
62-
- `src/rpc/peer.zig` around `handleThirdPartyAnswer(...)`, `adoptThirdPartyAnswer(...)`, return-accept adapter
63-
- `src/rpc/peer_third_party_adoption.zig`
62+
- `src/rpc/level3/peer.zig` around `handleThirdPartyAnswer(...)`, `adoptThirdPartyAnswer(...)`, return-accept adapter
63+
- `src/rpc/level3/peer/third_party/peer_third_party_adoption.zig`
6464

6565
## Next practical slice (if continuing decomposition)
6666

Justfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ release:
1010
test:
1111
zig build test --summary all
1212

13+
# Run serialization-focused tests (message/codegen/schema/interop)
14+
test-serialization:
15+
zig build test-serialization --summary all
16+
17+
# Run all RPC tests
18+
test-rpc:
19+
zig build test-rpc --summary all
20+
21+
# Run Cap'n Proto RPC level 0 tests (framing/protocol/cap-table)
22+
test-rpc-level0:
23+
zig build test-rpc-level0 --summary all
24+
25+
# Run Cap'n Proto RPC level 1 tests (promises/pipelining)
26+
test-rpc-level1:
27+
zig build test-rpc-level1 --summary all
28+
29+
# Run Cap'n Proto RPC level 2 tests (runtime plumbing)
30+
test-rpc-level2:
31+
zig build test-rpc-level2 --summary all
32+
33+
# Run Cap'n Proto RPC level 3+ tests (advanced peer semantics)
34+
test-rpc-level3:
35+
zig build test-rpc-level3 --summary all
36+
1337
# Build e2e reference images
1438
e2e-build:
1539
just --justfile tests/e2e/Justfile build

PROGRESS_REPORT.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ Scope: Active workstream to close P1/P2 recommendations from `QUALITY_REPORT.md`
1919
## P1/P2 Checklist
2020

2121
1. P1-4: Split `peer.zig` into focused modules. **In progress (near-complete)**
22-
- `src/rpc/peer.zig` reduced from monolith to orchestrator + state holder.
22+
- `src/rpc/level3/peer.zig` reduced from monolith to orchestrator + state holder.
2323
- Extracted submodules include:
24-
- `src/rpc/peer/call/*`
25-
- `src/rpc/peer/forward/*`
26-
- `src/rpc/peer/provide/*`
27-
- `src/rpc/peer/return/*`
28-
- `src/rpc/peer/third_party/*`
24+
- `src/rpc/level3/peer/call/*`
25+
- `src/rpc/level3/peer/forward/*`
26+
- `src/rpc/level3/peer/provide/*`
27+
- `src/rpc/level3/peer/return/*`
28+
- `src/rpc/level3/peer/third_party/*`
2929
- Latest slice:
30-
- `src/rpc/peer/peer_state_types.zig` extracted for provide/join state types.
30+
- `src/rpc/level3/peer/peer_state_types.zig` extracted for provide/join state types.
3131

3232
2. P1-5: Add allocation-size limits to reader path. **Done**
33-
- `src/reader.zig` uses bounded `max_total_words` checks and overflow-safe arithmetic.
33+
- `src/serialization/reader.zig` uses bounded `max_total_words` checks and overflow-safe arithmetic.
3434

3535
3. P2-6: Add comments in critical paths. **In progress**
3636
- Message packing/unpacking and far/double-far pointer resolution comments added.
@@ -55,6 +55,6 @@ Latest full run in this branch state:
5555

5656
## Next Execution Order
5757

58-
1. Finish remaining P1 decomposition slice(s) that reduce `src/rpc/peer.zig` readability risk without API churn.
58+
1. Finish remaining P1 decomposition slice(s) that reduce `src/rpc/level3/peer.zig` readability risk without API churn.
5959
2. Complete P2 comments pass over remaining complex pointer/state-machine sections.
6060
3. (Done) Vendored `vendor/ext/libxev` removed; libxev is now sourced exclusively via `build.zig.zon` URL+hash.

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,19 @@ The project includes comprehensive tests:
207207
# Run all tests
208208
just test
209209

210-
# Run specific test suites
211-
zig build test-message # Message tests
212-
zig build test-codegen # Codegen tests
213-
zig build test-rpc # RPC tests
210+
# Run broad test groups
211+
zig build test-serialization # Serialization-focused suites
212+
zig build test-rpc # All RPC suites
213+
214+
# Run RPC suites by Cap'n Proto level (cumulative)
215+
zig build test-rpc-level0 # Framing/protocol/cap-table
216+
zig build test-rpc-level1 # Promises/pipelining
217+
zig build test-rpc-level2 # Runtime plumbing
218+
zig build test-rpc-level3 # Advanced peer semantics (level 3+)
219+
220+
# Run specific focused suites
221+
zig build test-message # Message tests
222+
zig build test-codegen # Codegen tests
214223
just e2e # Cross-language interop harness
215224
```
216225

0 commit comments

Comments
 (0)