- new tests/common/mod.rs — the single-sourced shapes, compiled into the lib test crate (#[cfg(test)] #[path] mod in src/lib.rs + extern crate self as alksocks) and the integration suite (tests/harness.rs declares it and re-exports under the consumed names; the per-test use-harness surface is unchanged) - single-sourced: the echo dial (plain + witnessing), the refusing dial, the queue egress + echo factory (the harness ChanEgress / producer QueueEgress mutex-wrapper divergence collapsed), the refusing egress, the raw RFC 1928 client trio (generic over the stream; harness RawRfcClient delegates), the datagram frame codec helpers (three copies to one), the parked accept factory - deliberately left test-local: HotNoneEgress / PureHotNoneEgress (R-1's two shapes), Witness / FailingSendWitness (drop flags), core-integration's HotNoneEgress (concurrency-load variant), the typed accept-refusal factories - zero behavior change: same test population (145 lib / 38 associate / 41 bind / 40 connect / 41 integration / 30 harness / 37 differential / 3 doc-tests), no tests folded, net -307 lines Verification: cargo test + --all-features green (same counts), clippy -D warnings clean (native + wasm), fmt clean, doc clean, both wasm checks clean, publish dry-run completes.
9.7 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | |
|---|---|---|---|---|---|---|---|---|
| implementation/fix-test-helper-consolidation | Tests — consolidate the duplicated harness shapes (review-002 N-5) | completed |
|
narrow | low | component | implementation |
Description
The producer's test module re-implements the harness's shapes four
times — ~250 structural-duplicate test lines
(docs/reviews/002-protocol-core-implementation-review.md §N-5).
The cause is legitimate (unit tests in src/ cannot import
tests/harness.rs — separate crates), so the fix is the standard
shared-module pattern, not a harness import:
src/producer.rs:954-987(QueueEgress),1237-1274(HotNoneEgress),1321-1359(PureHotNoneEgress),1504-1553(Witnessegress) — fourEgressimpls of the same queue shapesrc/producer.rs:792-814(greet/write_request/read_reply) vstests/harness.rs:876-933(the same trio)src/producer.rs:719-745(echo-dial) vstests/harness.rs:131
Fix per the review's sketch: a tests/common/ path or a
#[cfg(test)] pub(crate) module in src/ compiled into both the
lib test and the integration suite via a path-included module
(the standard mod common pattern). Consolidates ~200 lines and
keeps the two harness shapes from diverging further (they already
have: the harness's ChanEgress and the producer's QueueEgress
differ only in the mutex wrapper).
Not collapsible (deliberately different — leave them):
HotNoneEgress/PureHotNoneEgress (R-1's two distinct violation
shapes) and the Witness egress (carries the drop flag). The
consolidation targets the byte-near-identical shapes only:
QueueEgress/echo-dial and the greet/reply trio.
This task rides after the coverage-residue task so the consolidation sees the final test population (new tests from N-8 may add more duplicates to fold). If the coverage task's new tests introduce fresh duplicates of harness shapes, fold them here too.
Acceptance Criteria
- The shared module exists and both the lib tests and the
integration suite compile against it (the
mod commonpattern; notests/harness.rsimport fromsrc/) QueueEgress/echo-dial and thegreet/write_request/read_replytrio are single-sourced (the byte-near-identical shapes)HotNoneEgress/PureHotNoneEgress/Witnessremain test-local (deliberately distinct shapes — not collapsed)- Zero behavior change: the full suite green with the same test count (minus any folded duplicates, recorded in the Notes)
cargo testgreen; clippy/fmt clean; both wasm checks clean
References
- docs/reviews/002-protocol-core-implementation-review.md §N-5
- tests/harness.rs (the shapes being single-sourced)
- src/producer.rs (the four
Egressimpls + the trio)
Notes
Filled by the implementation agent (2026-09-25):
- The shared module is
tests/common/mod.rs(314 lines), the standardmod commonpattern with two wiring details worth recording:- The lib-test include rides
lib.rs, not the test module:src/lib.rsdeclares#[cfg(test)] #[path = "../tests/common/mod.rs"] pub(crate) mod test_common;plus#[cfg(test)] extern crate self as alksocks;. The#[path]from a nested module (src/producer.rs's tests) does not resolve —#[path]is relative to the containing module's directory (src/producer/tests/for an inline child), and#[path]rejects non-literal expressions (noconcat!(env!("CARGO_MANIFEST_DIR"), ...)), so the only clean mount point is the crate root, where../tests/common/mod.rsresolves. Theextern crate selfalias is the standard companion: the module is written once against the extern-crate paths (alksocks::…) the integration suite resolves; inside the lib test crate the alias makes the same paths resolve.src/producer.rsconsumes it asuse crate::test_common as common;— notests/harness.rsimport fromsrc/. - The integration suite reaches the same copy through
harness:tests/harness.rsdeclares#[path = "common/mod.rs"] pub mod common;and re-exports the consumed subset under the names its callers already use (echo_egressforecho_egress_factory,udp_frame/udp_unframefordatagram_frame/decode_datagram,witnessing_echo_dialforecho_dial_witnessed) — the per-testuse harness::{…}surface is unchanged, so the consumer-* suites needed no edits at all.
- The lib-test include rides
- Single-sourced shapes (the task's named targets plus the
byte-identical stragglers the consolidation surfaced):
- The echo dial: harness
echo_dial+witnessing_echo_dial+ producer'secho_dial(targets)→ common'secho_dial_witnessed+echo_dial(a throwaway-witness wrapper); the producer keeps a one-lineecho_dial(targets)adapter since its witness arg is per-test. - The refusing dial (all five
SocksDialErrorvariants reconstructed per call) — three copies → one. - The queue egress + echo factory: harness
ChanEgress+ producer'sQueueEgress(the review's mutex-wrapper-only divergence) +echo_egress/echo_egress_factory→ common'sQueueEgress+echo_egress_factory(the mutex-wrapped shape both had converged on;next_replyparks onrecv()— the readiness contract preserved verbatim). - The refusing egress factory → common's
refusing_egress(harness copy; the producer's inlineErr(EgressError::Unreachable(…))closures stayed — they are one-liners, not the shape). - The raw RFC 1928 client trio: harness
RawRfcClient'sgreet/request/read_replybodies + producer'sgreet/write_request/read_reply→ common'sraw_greet/raw_request/raw_read_reply(generic overS: AsyncRead + AsyncWrite + Unpin, substrate-agnostic per convention 7) + the unwrapping producer-shape wrappers (greet/write_request/read_reply_v4, the v4-only reply shape the producer tests' BND.ADDR assertions index). The harness'sRawRfcClientnow delegates to the common trio; itsconnect()convenience and two-ATYP-unaware API stay (its callers use it). - The datagram frame helpers: harness
udp_frame/udp_unframe(test module) + core-integration'sudp_frame/udp_unframe+ producer'sdatagram_frame/decode_datagram→ common'sdatagram_frame/decode_datagram(re-exported under both names). - The parked accept factory: harness-era producer
parked_accept_factory+ core-integration'sparked_accept→ common'sparked_accept_factory(bind addr127.0.0.1:2121— the ECHO_BIND_PORT carrier; core-integration imports it aliased asparked_accept).
- The echo dial: harness
- Deliberately not collapsed (per the task; verified
test-local): producer's
HotNoneEgress(mutex-yielding hotOk(None)) andPureHotNoneEgress(zero-yield — R-1's two distinct violation shapes),Witness/FailingSendWitness(the drop flags), core-integration'sHotNoneEgress(same-named but the concurrency-load variant), and the refusing accept-factory/accept-future pair (typed per error class; used by the harness and consumer-bind only). Also left: harness'secho_accept+ producer'sbind_accept_factory(the echo-pipe accept shape) — the producer copy carries the per-test requested- target witness, so the bodies differ beyond the mutex wrapper; noted for the next touch but out of this task's named scope. - Zero behavior change, same test count: 145 lib / 38 associate / 41 bind / 40 connect / 41 integration / 30 harness / 37 differential / 3 doc-tests — byte-identical to the coverage task's post-N-8 population (no folded duplicates; the coverage task's new tests were all consumer-side unit shapes with no harness duplicates to fold). Net −307 lines (81 insertions / 388 deletions across the four touched files + the new 314-line module).
- Verification:
cargo test+--all-featuresgreen (same counts), clippy-D warningsclean (native + wasm), fmt clean,cargo doc --no-depsclean, both wasm checks clean (check+clippyonwasm32-unknown-unknown),cargo publish --dry-run --allow-dirtycompletes. Thetests/common/path rides the existingexclude = ["tasks/", …]-style packaging posture automatically (dev-only;#[cfg(test)]keeps it out of the published lib; the integration binaries are not packaged).
Summary
Consolidated review 002 N-5's duplicated harness shapes into
tests/common/mod.rs — the standard mod common pattern, mounted
from src/lib.rs (#[cfg(test)] #[path] pub(crate) mod test_common
extern crate self as alksocks) for the lib test crate and fromtests/harness.rs(#[path = "common/mod.rs"]+ name-preserving re-exports) for the integration suite, so the per-testuse harness::{…}surface and the producer tests' local names are unchanged. Single-sourced: the echo dial (plain + witnessing), the refusing dial, the queue egress + its echo factory (the harness/ producer mutex-wrapper divergence collapsed to one shape), the refusing egress, the raw RFC 1928 client trio (generic over the stream type; the harness'sRawRfcClientdelegates to it), the datagram frame codec helpers (three copies → one), and the parked accept factory. Left deliberately distinct: the hot-none egress variants (R-1's two shapes), the drop-witness egresses, and the typed accept-refusal factories. Zero behavior change — full suite green with the identical test population (375 + 2 ignored doc), no tests folded. Verification:cargo test+--all-featuresgreen, clippy-D warningsclean (native + wasm), fmt clean, doc clean, both wasm checks clean, publish dry-run completes.