Skip to content

RUST-REF-005: Decompose oversized Rust modules #7

Open

Description

@itlezy

RUST-REF-005 - Decompose oversized Rust modules by responsibility

Summary

Reduce the Rust client's legacy oversized source files through small,
behavior-preserving extractions. Start with emulebb-core/src/lib.rs, which is
13,711 lines at the start of this item, then continue through the largest
responsibility-mixed production and test modules.

Release Triage (2026-09-30)

Post-beta. Responsibility-based decomposition remains worthwhile, but the
quality policy treats file size as an advisory and the candidate passes policy,
Clippy, tests, and the hosted OS matrix. No remaining module-size concern is a
release defect; resume this as small post-beta maintenance slices.

Invariants

  • Preserve public Rust paths, REST/OpenAPI behavior, serialization, persistence,
    and configuration semantics.
  • Preserve stock-compatible eD2K/Kad behavior and all VPN fail-closed boundaries.
  • Keep module boundaries responsibility-based; do not split cohesive control flow
    solely to satisfy a mechanical line count.
  • Remove private dead code and dependencies only when repository-wide references,
    all-target Clippy, and tests prove they are unused.
  • Deliver each extraction as a separate reviewed and validated commit.

Work Plan

  1. Split the inline emulebb-core tests into responsibility-focused modules.
  2. Move the EmulebbCore facade and API implementations into focused modules.
  3. Split download and Kad orchestration into explicit runtime responsibilities.
  4. Use non-failing maintainability advisories to identify files that deserve a
    responsibility review; do not treat line count as a validation limit.
  5. Continue with the largest mixed-responsibility modules in the core and
    protocol crates.

Acceptance Criteria

  • emulebb-core/src/lib.rs is a thin crate root with stable public re-exports.
  • Inline core tests are grouped by subsystem with unchanged assertions.
  • Static IPv4 and P2P binding audits cover every relocated boundary.
  • No repository-local Cargo target directory is created.
  • Workspace format, Clippy, tests, Kad swarm, and VPN leak gates pass.
  • Remaining large files are reviewed by responsibility without hard limits
    or per-file allowlist rationales.
  • Substantial tests live in sibling test modules or integration-test trees;
    only focused white-box tests remain inline with production code.

Validation

  • python tools\rust_quality_gate.py policy
  • python -m emule_workspace validate --include-product-family --product-family-tier full
  • Rust workspace, isolated Kad swarm, and VPN leak gates through supported
    workspace orchestration.

Current Evidence

  • fcd6f36 makes the UI executable a three-line entry point over a library
    application boundary.
  • 86b64da, 4a94087, 8caaef7, 5087dab, and 8a326e2 separate UI
    presentation, models, REST transport, background commands, and rendering from
    application wiring. Each extraction passed isolated all-target UI Clippy.
  • 50070b3 moves the 1,796-line kad_store test suite into a sibling test
    module; all 41 focused tests pass and the production module is 539 lines.
  • cf380fd replaces permanent lint allows with checked, reasoned expectations;
    two obsolete expectations and one ownership-only dead-code field suppression
    were removed during the review.

Activity

  1. moved this from Todo to In Progress in eMuleBB Roadmap MFC (archive)on Jul 10, 2026
  2. itlezy commented on Jul 10, 2026

    @itlezy
    ContributorAuthor

    2026-07-10 implementation wave

    Completed and pushed 23 granular RUST-REF-005 commits.

    • Reduced crates/emulebb-core/src/lib.rs from 13,711 to 6,132 lines.
    • Split the 4,974-line inline test module into nine responsibility-focused files; largest is 717 lines.
    • Extracted application, server, search, category, friend, transfer creation/control/state, shared-file, upload, network lifecycle, and direct-download runtime modules.
    • Ratcheted the lib.rs hard limit to 6,132 and removed the temporary core-test allowlist.
    • Extended the P2P fail-closed scanner to cover the relocated network_api.rs boundary.
    • Removed compiler-proven redundant diagnostics conversions; all-target Clippy is green with -D warnings.

    Evidence:

    • Rust policy and rustfmt checks pass.
    • cargo test --workspace --locked -- --skip local_kad_swarm passes.
    • 302 core library tests pass.
    • VPN egress-audit suite: 3/3 pass serially.
    • Orchestrated Release client build: 0 warnings.
    • Orchestrated diagnostics Release client build: 0 warnings.
    • No repository-local target directory exists.

    The workspace-wide validate --include-product-family entrypoint remains blocked before product checks by 67 pre-existing virtual-environment binaries under other managed repositories; no unrelated environments were deleted.

    Next wave: split the remaining Kad publish/runtime and core download orchestration blocks, then address kad_store/mod.rs, the Slint UI client, and upload queue hotspots.

  3. itlezy commented on Jul 11, 2026

    @itlezy
    ContributorAuthor

    Additional responsibility-based decomposition landed in granular commits: fcd6f36 (thin UI binary), 86b64da (presentation), 4a94087 (models), 8caaef7 (REST client), 5087dab (worker), 8a326e2 (rendering), and 50070b3 (kad_store sibling tests). The UI app wiring is now 495 lines with cohesive modules; kad_store production is 539 lines and its 41-test suite is separate. cf380fd also replaces permanent lint allows with checked reasoned expectations. Focused tests and all-target Clippy pass.

  4. moved this to In Progress in eMuleBB Roadmapon Jul 12, 2026
  5. itlezy commented on Sep 30, 2026

    @itlezy
    ContributorAuthor

    Phase C backlog triage: reclassified to post-beta polish. Current candidate policy, Clippy, tests, and hosted OS CI are green; no remaining module-size concern is a beta release defect. Suite project status returns to Todo.

  6. itlezy commented on Sep 30, 2026

    @itlezy
    ContributorAuthor

    Beta code freeze is active as of 2026-09-30. This refactor remains valid post-beta work, but it must not start during the freeze. The good first issue and help wanted labels have been removed so they do not conflict with the freeze admission rules in RUST-FEAT-033.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions