Skip to content

refactor: Split protocol.rs into protocol/ submodule#128

Merged
2witstudios merged 1 commit intomainfrom
pu/refactor-protocol
Mar 10, 2026
Merged

refactor: Split protocol.rs into protocol/ submodule#128
2witstudios merged 1 commit intomainfrom
pu/refactor-protocol

Conversation

@2witstudios
Copy link
Owner

@2witstudios 2witstudios commented Mar 10, 2026

Summary

  • Split the 2,614-line crates/pu-core/src/protocol.rs into a protocol/ directory module with 6 focused files: encoding.rs, grid.rs, targets.rs, payloads.rs, tests.rs, and mod.rs
  • Pure refactoring — no behavior changes, all public API paths preserved via re-exports
  • All 527 tests pass across pu-core, pu-engine, and pu-cli

Test plan

  • cargo test -p pu-core — 304 tests pass
  • cargo test -p pu-engine — 130 tests pass
  • cargo test -p pu-cli — 93 tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Reorganized protocol layer into modular structure for improved code organization and maintainability
    • Restructured protocol message definitions and payload structures for better clarity
  • Tests

    • Expanded protocol test coverage with comprehensive serialization and deserialization validation tests

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72b077e4-e242-46b9-ad84-a8a8535f227b

📥 Commits

Reviewing files that changed from the base of the PR and between f8db725 and 4d25306.

📒 Files selected for processing (7)
  • crates/pu-core/src/protocol.rs
  • crates/pu-core/src/protocol/encoding.rs
  • crates/pu-core/src/protocol/grid.rs
  • crates/pu-core/src/protocol/mod.rs
  • crates/pu-core/src/protocol/payloads.rs
  • crates/pu-core/src/protocol/targets.rs
  • crates/pu-core/src/protocol/tests.rs
📝 Walkthrough

Walkthrough

The protocol layer is being reorganized from a single monolithic file (protocol.rs) into a modular structure with separate files for encoding helpers, grid commands, target types, and payload definitions. The public API surface is maintained through module re-exports and a new mod.rs that acts as the entry point.

Changes

Cohort / File(s) Summary
Protocol Removal
crates/pu-core/src/protocol.rs
Deleted entire public protocol surface (2614 lines) including Request/Response enums, payload structs, conversions, constants, and test suite.
Modular Protocol Structure
crates/pu-core/src/protocol/mod.rs, crates/pu-core/src/protocol/encoding.rs, crates/pu-core/src/protocol/grid.rs, crates/pu-core/src/protocol/targets.rs, crates/pu-core/src/protocol/payloads.rs
Reorganized protocol definitions across specialized modules: mod.rs (Request/Response enums and re-exports), encoding.rs (hex serialization helpers), grid.rs (GridCommand enum), targets.rs (KillTarget/SuspendTarget enums), payloads.rs (payload structs and From trait conversions).
Test Suite
crates/pu-core/src/protocol/tests.rs
Added comprehensive test coverage (1831 lines) validating JSON round-trips for all protocol messages, default values, optional fields, and various enum variants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 The warren rejoices, no more one big file!
Protocol split into modules with style—
Encoding and grids, each tucked in their place,
Payloads and targets now have breathing space.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: a refactoring that splits a monolithic protocol.rs file into a protocol/ submodule directory with six organized files (encoding, grid, targets, payloads, tests, mod).
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pu/refactor-protocol

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/pu-core/src/protocol/tests.rs (1)

482-484: Consider extracting the protocol version constant assertion.

The hardcoded value 4 here will need updating when PROTOCOL_VERSION changes. This test ensures the version is intentional, which is good, but consider adding a comment explaining why this assertion exists (to catch accidental version bumps).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/pu-core/src/protocol/tests.rs` around lines 482 - 484, The test
given_protocol_version_should_be_current currently asserts PROTOCOL_VERSION
equals the hardcoded value 4; update the test to keep the explicit assertion but
add a clarifying comment above the assertion explaining that this check is
intentional to catch accidental protocol bumps and must be manually updated when
the protocol is intentionally versioned, and optionally extract the literal into
a named test-constant (e.g., EXPECTED_PROTOCOL_VERSION) referenced in the
assertion to make intent clearer; locate this in the
given_protocol_version_should_be_current function referencing PROTOCOL_VERSION
and modify accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/pu-core/src/protocol/tests.rs`:
- Around line 482-484: The test given_protocol_version_should_be_current
currently asserts PROTOCOL_VERSION equals the hardcoded value 4; update the test
to keep the explicit assertion but add a clarifying comment above the assertion
explaining that this check is intentional to catch accidental protocol bumps and
must be manually updated when the protocol is intentionally versioned, and
optionally extract the literal into a named test-constant (e.g.,
EXPECTED_PROTOCOL_VERSION) referenced in the assertion to make intent clearer;
locate this in the given_protocol_version_should_be_current function referencing
PROTOCOL_VERSION and modify accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e71dfce7-f776-4dc2-ac87-27ac4f197ae5

📥 Commits

Reviewing files that changed from the base of the PR and between 2a876e0 and f8db725.

📒 Files selected for processing (7)
  • crates/pu-core/src/protocol.rs
  • crates/pu-core/src/protocol/encoding.rs
  • crates/pu-core/src/protocol/grid.rs
  • crates/pu-core/src/protocol/mod.rs
  • crates/pu-core/src/protocol/payloads.rs
  • crates/pu-core/src/protocol/targets.rs
  • crates/pu-core/src/protocol/tests.rs
💤 Files with no reviewable changes (1)
  • crates/pu-core/src/protocol.rs

@2witstudios
Copy link
Owner Author

Addressed the CodeRabbit nitpick: added a clarifying comment to the protocol version assertion in tests.rs (6eb2db6). The hardcoded check is intentional to catch accidental protocol bumps.

Break up the 2,614-line protocol.rs into focused subfiles:
- encoding.rs: hex serde helper
- grid.rs: GridCommand enum
- targets.rs: KillTarget/SuspendTarget enums
- payloads.rs: all payload structs and From impls
- tests.rs: all tests
- mod.rs: Request/Response enums, re-exports

Pure refactoring — no behavior changes. All public API paths preserved
via re-exports from mod.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@2witstudios 2witstudios force-pushed the pu/refactor-protocol branch from 6eb2db6 to 4d25306 Compare March 10, 2026 03:24
@2witstudios
Copy link
Owner Author

Rebased onto main to incorporate PR #131 (trigger opt-in). Changes applied to the submodule structure:

  • protocol/mod.rs: PROTOCOL_VERSION 4→5, added trigger: Option<String> to Spawn, added AssignTrigger request variant and AssignTriggerResult response variant
  • protocol/tests.rs: Added trigger: None to all Spawn test constructions, added round-trip tests for AssignTrigger and AssignTriggerResult, updated version assertion to 5

All 306 pu-core + 93 pu-cli + 130 pu-engine tests pass.

@2witstudios 2witstudios merged commit 572e38c into main Mar 10, 2026
5 checks passed
@2witstudios 2witstudios deleted the pu/refactor-protocol branch March 10, 2026 14:45
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