Skip to content

Addresses #4421 (policy.rs): extract SnapshotIntegrityError into a submodule - #4645

Merged
psaab merged 1 commit into
masterfrom
refactor/4421-increment-1
Jul 8, 2026
Merged

psaab merged 1 commit into
masterfrom
refactor/4421-increment-1

Conversation

@psaab

@psaab psaab commented Jul 8, 2026

Copy link
Copy Markdown
Owner

What

Bounded, pure code-motion first increment for the #4421 policy.rs
modularity backlog. Relocates the SnapshotIntegrityError enum plus its
Display and Error impls (~888 LOC — the #1606 snapshot integrity error
group) out of the 4483-LOC userspace-dp/src/policy.rs into a new
#[path]-included sibling submodule userspace-dp/src/policy_snapshot_error.rs.

policy.rs: 4483 → 3598 LOC.

Why this unit

The enum group is fully self-contained:

  • variants use only primitive / prelude types (String, i32, u16, u32, u8);
  • the Display impl is entirely write!(f, …) over Self:: variants;
  • the Error impl is empty.

So the new file needs no imports. It is re-exported with
pub(crate) use snapshot_error::SnapshotIntegrityError; so all ~20 crate-wide
call sites keep the existing crate::policy::SnapshotIntegrityError path, and
policy_tests.rs (attached via use super::*) is unchanged. This mirrors the
#[path = "policy_tests.rs"] idiom already used in the same file.

Pure code-motion proof

  • Moved block is byte-identical to master policy.rs lines 14–901 (empty diff).
  • policy.rs retained content is byte-identical (empty diff), only a 3-line
    #[path]/mod/use stub inserted.
  • Moved block deliberately not rustfmt'd — kept byte-identical to preserve the
    code-motion guarantee; only the stub + //! module-doc lines are new.

Validation

  • cargo build green.
  • cargo test3738 passed (245 policy tests + all 5 snapshot-integrity-error
    tests green). The single native_gre_decap_checksum_present_yields_inner_packet
    failure in the parallel run is a pre-existing shared-counter test-isolation
    flake
    — it touches no SnapshotIntegrityError code and passes in isolation.

Docs

README source-map table row for policy.rs unchanged: it lists top-level feature
modules, not their #[path] submodules (policy_tests.rs is likewise omitted),
and the module contract is unchanged. _Log.md updated.

Scope

The deeper policy.rs decomposition (parse / evaluate / applications splits) is a
function-restructuring task that needs /triple-review; this PR ships only the
clean, self-contained down-payment.

🤖 Generated with Claude Code

https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi

Addresses #4421 (policy.rs modularity backlog) with a bounded, pure
code-motion first increment: relocate the `SnapshotIntegrityError` enum
plus its `Display` and `Error` impls (~888 LOC, the #1606 snapshot
integrity error group) out of the 4483-LOC `userspace-dp/src/policy.rs`
into a new `#[path]`-included sibling submodule
`userspace-dp/src/policy_snapshot_error.rs`.

The enum group is fully self-contained — variants use only primitive /
prelude types (String, i32, u16, u32, u8), the `Display` impl is entirely
`write!(f, ...)` over `Self::` variants, and the `Error` impl is empty, so
the new file needs no imports. It is re-exported with
`pub(crate) use snapshot_error::SnapshotIntegrityError;` so all ~20
crate-wide call sites keep the existing `crate::policy::SnapshotIntegrityError`
path, and `policy_tests.rs` (attached via `use super::*`) is unchanged.
This mirrors the `#[path = "policy_tests.rs"]` idiom already used in the
same file.

This is verified pure code-motion, not a behavior change:
- the moved block is byte-identical to master `policy.rs` lines 14-901
  (empty diff);
- `policy.rs`'s retained content is byte-identical (empty diff) with only
  a 3-line `#[path]`/`mod`/`use` stub inserted;
- `policy.rs` shrinks 4483 -> 3598 LOC.

The moved block is left byte-identical (not rustfmt'd) to preserve the
code-motion guarantee; only the new stub + module-doc lines are new.

Validation: `cargo build` green; `cargo test` 3738 passed (245 policy
tests + all 5 snapshot-integrity-error tests green). The single
`native_gre_decap_checksum_present_yields_inner_packet` failure in the
parallel run is a pre-existing shared-counter test-isolation flake — it
touches no SnapshotIntegrityError code and passes in isolation.

The README source-map table row for `policy.rs` is unchanged: it lists
top-level feature modules, not their `#[path]` submodules (`policy_tests.rs`
is likewise omitted), and the module contract is unchanged. The deeper
policy.rs decomposition (parse / evaluate / applications splits) is a
function-restructuring task that needs /triple-review; this ships only the
clean, self-contained down-payment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR is a focused modularity/code-organization change in the Rust userspace dataplane: it extracts the large SnapshotIntegrityError enum (and its Display/Error impls) out of the monolithic userspace-dp/src/policy.rs into a sibling submodule, while preserving the existing crate::policy::SnapshotIntegrityError access path via a re-export.

Changes:

  • Moved SnapshotIntegrityError (+ Display/Error impls) into userspace-dp/src/policy_snapshot_error.rs and wired it in via #[path] mod snapshot_error;.
  • Re-exported the type from policy.rs (pub(crate) use snapshot_error::SnapshotIntegrityError;) to keep all existing call sites unchanged.
  • Added a corresponding _Log.md entry documenting the write action and touched files.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
userspace-dp/src/policy.rs Replaces the in-file enum/impl block with a #[path] submodule include and re-export to keep the public-in-crate path stable.
userspace-dp/src/policy_snapshot_error.rs New submodule containing the extracted SnapshotIntegrityError definition and impls (verbatim code-motion plus new module docs).
_Log.md Records the extraction action per repository logging practice.

@psaab
psaab deleted the refactor/4421-increment-1 branch September 7, 2026 14:56
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.

2 participants