diff --git a/Cargo.lock b/Cargo.lock index 39f9fdec94..b8ab58f2ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5272,6 +5272,8 @@ version = "3.1.0" dependencies = [ "binascii", "derive_more 2.1.1", + "quickcheck", + "quickcheck_macros", "serde", "serde_json", "tdyne-peer-id", diff --git a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md index 91c0a46263..df3a825449 100644 --- a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md +++ b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md @@ -96,7 +96,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | 8 | #2301 - Review package coverage rollout | `docs/issues/open/2301-1347-review-package-coverage-rollout/ISSUE.md` | TODO | After the EPIC completes, review real rollout evidence before retaining, revising, or proposing a required coverage check. | | 9 | #2361 - Keep the report-only package coverage summary from failing on a discovery failure | `docs/issues/open/2361-1347-package-coverage-summary-discovery-failure/ISSUE.md` | TODO | Bug follow-up of #2347 (`review-finding:pr-2293-f1`): the #2222 summary check goes red with a JSON parse error when discovery fails. | | 10 | #2637 - Add tests to the axum-rest-api-server package | `docs/issues/closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md` | DONE | S0 (spec and T1 baseline) merged through #2638; S1 (authentication and shared responses) merged through #2667; S2 (routes) merged through #2687; S3 (auth-key and whitelist contexts) merged through #2702; S4 (torrent and stats contexts) merged through #2718; S5 (server lifecycle) merged through #2744; S6 (crate root, wiring and final tasks) merged through #2772; the issue is closed. Replaces the former draft that was misfiled under #1349. | -| 11 | #2824 - Add tests to the primitives package | `docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md` | IN_PROGRESS | Spec-only PR carries the specification and the T1 baseline and inventory; S0 (the spec, #2828) is merged and S1 (the `PeerRole` JSON casing fix, #2834) is in review; S2-S4 follow. Findings F1 (fixed through #2811), F3 (#2804) and the `AddAssign` and `peer::Id::new` follow-ups are handed off to their own issues. | +| 11 | #2824 - Add tests to the primitives package | `docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md` | IN_PROGRESS | Spec-only PR carries the specification and the T1 baseline and inventory; S0 (the spec, #2828) is merged and S1 (the `PeerRole` JSON casing fix, #2834) is merged and S2 (the `peer.rs` tests, #2841) is in review; S3-S4 follow. Findings F1 (fixed through #2811), F3 (#2804) and the `AddAssign` and `peer::Id::new` follow-ups are handed off to their own issues. | | 12 | Additional package-testing subissues | Create a folder-style spec when a concrete package need is identified | TODO | Permitted but not required upfront; retain scope in this EPIC. | ## Package Coverage Tracking @@ -121,7 +121,7 @@ level or determine whether unit coverage is adequate. | `torrust-tracker-udp-core` | [#1348](../../closed/1348-1347-add-tests-udp-core/ISSUE.md) | Lines: 72.49%; regions: 78.56%; functions: 71.27% | Lines: 98.04%; regions: 98.15%; functions: 97.61% | Lines: +25.55 pp; regions: +19.58 pp; functions: +26.34 pp | [Coverage evidence](../../closed/1348-1347-add-tests-udp-core/coverage-evidence.md) | | `torrust-tracker-http-core` | [#1349](../../closed/1349-1347-add-tests-http-core/ISSUE.md) | Lines: 88.88%; regions: 90.41%; functions: 84.29% | Lines: 99.28%; regions: 99.25%; functions: 99.74% | Lines: +10.40 pp; regions: +8.84 pp; functions: +15.45 pp | [Coverage evidence](../../closed/1349-1347-add-tests-http-core/coverage-evidence.md) | | `torrust-tracker-axum-rest-api-server` | [#2637](../../closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md) | Lines: 87.98%; regions: 84.10%; functions: 83.42% | Lines: 97.67%; regions: 97.13%; functions: 95.48% | Lines: +9.69 pp; regions: +13.03 pp; functions: +12.06 pp | [Coverage evidence](../../closed/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md) | -| `torrust-tracker-primitives` | [#2824](../2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 62.73%; regions: 70.29%; functions: 59.49% | Lines: +2.17 pp; regions: +2.35 pp; functions: +2.26 pp | [Coverage evidence](../2824-1347-add-tests-primitives/coverage-evidence.md) | +| `torrust-tracker-primitives` | [#2824](../2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 85.23%; regions: 89.31%; functions: 82.99% | Lines: +24.67 pp; regions: +21.37 pp; functions: +25.76 pp | [Coverage evidence](../2824-1347-add-tests-primitives/coverage-evidence.md) | ### Unit-Only Coverage @@ -136,7 +136,7 @@ weak unit-only result with aggregate, integration, example, or end-to-end covera | `torrust-tracker-udp-core` | [#1348](../../closed/1348-1347-add-tests-udp-core/ISSUE.md) | Lines: 72.49%; regions: 78.56%; functions: 71.27% | Lines: 98.04%; regions: 98.15%; functions: 97.61% | Lines: +25.55 pp; regions: +19.58 pp; functions: +26.34 pp | [Coverage evidence](../../closed/1348-1347-add-tests-udp-core/coverage-evidence.md) | | `torrust-tracker-http-core` | [#1349](../../closed/1349-1347-add-tests-http-core/ISSUE.md) | Lines: 88.88%; regions: 90.41%; functions: 84.29% | Lines: 99.28%; regions: 99.25%; functions: 99.74% | Lines: +10.40 pp; regions: +8.84 pp; functions: +15.45 pp | [Coverage evidence](../../closed/1349-1347-add-tests-http-core/coverage-evidence.md) | | `torrust-tracker-axum-rest-api-server` | [#2637](../../closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md) | Lines: 63.87%; regions: 63.98%; functions: 51.34% | Lines: 96.67%; regions: 96.38%; functions: 93.97% | Lines: +32.80 pp; regions: +32.40 pp; functions: +42.63 pp | [Coverage evidence](../../closed/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md) | -| `torrust-tracker-primitives` | [#2824](../2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 62.73%; regions: 70.29%; functions: 59.49% | Lines: +2.17 pp; regions: +2.35 pp; functions: +2.26 pp | [Coverage evidence](../2824-1347-add-tests-primitives/coverage-evidence.md) | +| `torrust-tracker-primitives` | [#2824](../2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 85.23%; regions: 89.31%; functions: 82.99% | Lines: +24.67 pp; regions: +21.37 pp; functions: +25.76 pp | [Coverage evidence](../2824-1347-add-tests-primitives/coverage-evidence.md) | ## Delivery Strategy @@ -344,6 +344,9 @@ For each subissue implementation, the completion policy is: - 2026-11-06 16:37 UTC - Claude Code - #2637 S6 (crate root, wiring and final tasks) finished: ledger rows 19-31 done, one test added (`authenticate` with a duplicated token value, found by the mutation run), manual scenarios M1-M5 passed. Final figures: unit-only lines 96.67% (170 unit tests), aggregate 97.67%; both "Latest" tables carry them. - 2026-11-11 11:22 UTC - Claude Code - Created #2824 (`primitives`) as a subissue of this EPIC (the link under #1347 is set by the maintainer). Clean baseline at `eaae0e487`, filtered to the package source: unit-only = aggregate lines 60.56% (453/748), regions 67.94% (712/1,048), functions 57.23% (91/159), 47 unit tests, no integration tests. Delivered in slices S0-S4; the row stays `TODO` until the first implementation slice starts. - 2026-11-11 14:32 UTC - Claude Code - #2824 S1 (PR #2834) re-measured `primitives` unit-only (= aggregate) at lines 62.73% (468 / 746), regions 70.29%, functions 59.49%, 49 unit tests. The figures include the changes merged to `develop` since the baseline (`Peer` lost `Ord`, the unused `AddAssign` was deleted), not only the slice. Both "Latest" tables carry them; the row is `IN_PROGRESS`. +- 2026-11-12 13:40 UTC - Claude Code - #2824 S2 (`peer.rs` tests, 31 added) re-measured `primitives` unit-only (= aggregate) at lines 84.86% (824 / 971), regions 88.93%, functions 82.90%, 80 unit tests; the figures include the added in-file test code. Both "Latest" tables carry them; the row stays `IN_PROGRESS`. +- 2026-11-12 14:10 UTC - Claude Code - #2824 S2 review round 1 of #2841: Copilot asked for trait-qualified `ReadInfo` role cases (positive, zero, negative `left`, and the stopped event, on `Peer` and `Arc`); one test was added, so `primitives` unit-only (= aggregate) is lines 85.20% (846 / 993), regions 89.28%, functions 82.99%, 81 unit tests. Both "Latest" tables carry the new values. +- 2026-11-12 18:24 UTC - Claude Code - #2824 S2 review round 3 of #2841: two assertions were added to the `is_completed` test, so `primitives` unit-only (= aggregate) is lines 85.23% (848 / 995), regions 89.31%, functions 82.99%, 81 unit tests. Both "Latest" tables carry the new values. ## Acceptance Criteria diff --git a/docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md b/docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md index b93f325c78..9d85de71ec 100644 --- a/docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md +++ b/docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2824 spec-path: docs/issues/open/2824-1347-add-tests-primitives/ISSUE.md branch: "2824-1347-add-tests-primitives-fixes" related-pr: 2834 -last-updated-utc: "2026-11-11 14:31" +last-updated-utc: "2026-11-12 18:24" semantic-links: skill-links: - create-issue @@ -200,8 +200,9 @@ maintainer decides to fix in this issue are not handed off: they go to the T2a s | F1 | `peer::Peer` derives `Eq`/`Hash` over all fields but implements `Ord` by `peer_id` only, so two unequal peers compare `Ordering::Equal` (violates the `Ord`/`Eq` contract). No production collection orders peers today (the swarm keys by `PeerId`), so the impact is latent. | Throwaway test, 2026-11-10: a seeder and a copy with `left = 5` give `a == b` false and `a.cmp(&b) == Equal`. | Handled by a separate bug issue and session, not fixed here (maintainer decision, 2026-11-10). Bug issue: #2798, spec PR #2800. Fixed by PR #2811 (merged 2026-11-11): `Ord` and `PartialOrd` removed from `Peer` (option A, maintainer's choice), guarded by a `compile_fail` doctest in `peer.rs`. | FIXED (upstream) | | F3 | `ParsePeerRoleError::InvalidPeerRole` records `Location::caller()` inside `PeerRole::from_str`, which has no `#[track_caller]`, so every error reports the same line inside `peer.rs` (`peer.rs:73:27`) instead of the caller's. Adding `#[track_caller]` fixes only a direct `from_str` call: through `str::parse` the location is a line in Rust's standard library. The pattern is wider than this type: `Location::caller()` appears 65 times across the packages and `#[track_caller]` 3 times, and the located error may reach production output. | Throwaway test, 2026-11-10: `"x".parse::()` reports `peer.rs:73:27`; with `#[track_caller]`, `parse` reports `core/src/str/mod.rs:2783:9` and a direct `from_str` call reports the caller's line. | Handed off to a follow-up issue that audits every use of `Location::caller()` (maintainer decision, 2026-11-10). Follow-up issue: #2804 (spec PR #2805). Nothing is fixed in this issue. | HANDED OFF | | F4 | `AggregateActiveSwarmMetadata::add_assign` uses plain `+=` on four `u64` fields (panic in debug, wrap in release on overflow; practically unreachable). The registry and `torrent-repository-benchmarking` sum the fields by hand, so the impl may be dead code. | Code reading, 2026-11-11. | Handed off to a follow-up issue/session `aggregate-addassign` (maintainer decision, 2026-11-11): check whether the impl is used (remove it and run all tests, check git history); delete it if unused, otherwise make overflow explicit (`checked_add` + panic, test, comment). Follow-up issue: #2823. Outcome (maintainer approved, 2026-11-11): the unused `AddAssign` impl is being deleted, so the `AddAssign` lines of `swarm_metadata.rs` are not tested here. Nothing is fixed in this issue. | HANDED OFF | -| F5 | `peer::Id::new` (public, in a production crate) builds a 20-byte id from a little-endian `i128` (4 zero bytes + 16 bytes). Behavior is correct and lossless, including negatives (two's complement). But it is a test-only helper: the only callers found are `torrent-repository-benchmarking` tests, and its ids look like no real client (`get_client_name()` is `None`). It has no doc comment and no tests. | Code reading and caller search, 2026-11-11 (not a behavior defect; a design problem). | Handed off to a follow-up issue/session `peer-id-test-helper` (maintainer decision, 2026-11-11): prove it is unused in production, move it to a testing helper that generates realistic ids, decide with it whether `peer::fixture` (and `Id::new`) move behind a `testing` feature, as the ADR on shared test support asks (EPIC #2482 is closed and did not reorganize `peer::fixture`). Follow-up issue: not yet created when S0 was written (proposal `peer-id-test-helper`); fill in its number. The `Id::new` tests in `peer.rs` wait on its outcome. | HANDED OFF | +| F5 | `peer::Id::new` (public, in a production crate) builds a 20-byte id from a little-endian `i128` (4 zero bytes + 16 bytes). Behavior is correct and lossless, including negatives (two's complement). But it is a test-only helper: the only callers found are `torrent-repository-benchmarking` tests, and its ids look like no real client (`get_client_name()` is `None`). It has no doc comment and no tests. | Code reading and caller search, 2026-11-11 (not a behavior defect; a design problem). | Handed off to a follow-up issue/session `peer-id-test-helper` (maintainer decision, 2026-11-11): prove it is unused in production, move it to a testing helper that generates realistic ids, decide with it whether `peer::fixture` (and `Id::new`) move behind a `testing` feature, as the ADR on shared test support asks (EPIC #2482 is closed and did not reorganize `peer::fixture`). Follow-up issue: not yet created when S2 was written (proposal `peer-id-test-helper`); fill in its number. The `Id::new` tests in `peer.rs` wait on its outcome. | HANDED OFF | | F2 | `PeerRole` derives `Serialize` with `#[serde(rename_all_fields = "lowercase")]`, which does not apply to unit variants, so it serializes as `"Seeder"` and `"Leecher"` while `Display` and the `peer_role` metric label use `seeder` and `leecher`. No production code serializes `PeerRole` today. | Throwaway test, 2026-11-10: `serde_json::to_string(&PeerRole::Seeder)` gives `"Seeder"`. | Fixed in this issue, in slice S1 (maintainer decision, 2026-11-10): `rename_all = "lowercase"` plus a regression test, in its own `fix` commit. | FIXED through #2834 | +| F6 | `Peer::is_seeder` classifies a negative `left` as a seeder because `NumberOfBytes` is signed; the UDP announce accepts a negative `left` while HTTP rejects it. | Found writing the `peer.rs` tests (S2), 2026-11-12. | Handed off to issue #2838; its fix PR #2839 was closed unmerged, and #2850 (non-negative number of bytes by construction, spec PR #2851) will remove the case. The S2 test pins the classification of the signed domain value and is removed by the #2850 implementation. | HANDED OFF | While F3 is open, no test pins the reported `location` of `ParsePeerRoleError`; the `peer.rs` record tests only that the error carries the rejected input (`raw_param`). @@ -216,7 +217,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`, `DEFERRED`. | --- | ------ | ---- | ----------------------- | | T1 | DONE | Coverage evidence and complete module inventory | [coverage-evidence.md](coverage-evidence.md): baseline, per-file uncovered groups, property candidacy, initial hypothesis for the 16 files. Delivered with this spec (S0). | | T2a | DONE | Fix the small defects decided in this issue (slice S1) | F2 only: F1 is fixed upstream and F3, F4, F5 are handed off to their own issues. Each fix: failing regression test first, then a separate `fix` commit, per the `fix-bug` skill. Merged before the test slices. Done: the commits `test(primitives): [#2824] pin the lowercase JSON form of PeerRole` (fails before the fix) and `fix(primitives): [#2824] serialize PeerRole in lowercase`. | -| T2 | TODO | Shared plan guidance | `test-refactor-plans/README.md`: two-phase sequence, guardrails, toolchain-pinned commands. First test slice (S2). | +| T2 | DONE | Shared plan guidance | `test-refactor-plans/README.md`: two-phase sequence, guardrails, toolchain-pinned commands. First test slice (S2). | | T3 | TODO | Process every ledger row through the per-file workflow | Each row ends in exactly one of: test added, no-change with reason, deferred with owner. | | T4 | TODO | Bounded mutation assessment | `mutation-evidence.md`: configuration, survivors, reason for each unviable mutant. | | T5 | TODO | Reconcile evidence and progress state | Ledger, plans, slice table, acceptance rows and both EPIC coverage tables agree; grep for `status: proposed` and stray `TODO` labels in finished records. | @@ -232,8 +233,8 @@ the maintainer (2026-11-10): | Slice | Content | Ledger rows | Branch | PR | Status | | --- | --- | --- | --- | --- | --- | | S0 | This specification, the T1 evidence, and the EPIC registration with the baseline | - | `2824-1347-add-tests-primitives-spec` | #2828 | DONE | -| S1 | Defect fixes decided in this issue (T2a): F2 `PeerRole` JSON casing, only (F1 fixed upstream; F3, F4, F5 handed off). Merged first, so the test slices pin the fixed behavior. | - | `2824-1347-add-tests-primitives-fixes` | #2834 | IN_PROGRESS | -| S2 | T2, then `peer.rs` (rank 1, the largest gap) | 1 | `2824-1347-add-tests-primitives-peer` | - | TODO | +| S1 | Defect fixes decided in this issue (T2a): F2 `PeerRole` JSON casing, only (F1 fixed upstream; F3, F4, F5 handed off). Merged first, so the test slices pin the fixed behavior. | - | `2824-1347-add-tests-primitives-fixes` | #2834 | DONE | +| S2 | T2, then `peer.rs` (rank 1, the largest gap) | 1 | `2824-1347-add-tests-primitives-peer` | #2841 | IN_PROGRESS | | S3 | Configuration defaults and bounded values: `announce.rs`, `policy.rs`, `mode.rs`, `pagination.rs`, `announce_interval.rs` | 2-6 | `2824-1347-add-tests-primitives-defaults` | - | TODO | | S4 | `swarm_metadata.rs`, no-change decisions for the covered and wiring files, then T4-T6; the clean-up moves the spec to `docs/issues/closed/` and updates the EPIC tables | 7-16 | `2824-1347-add-tests-primitives-final` | - | TODO | @@ -281,7 +282,7 @@ States: `PENDING`, `IN_PROGRESS`, `BLOCKED`, `DONE`. Unit-only lines are the bas | Order | Source module | Rank | Slice | Unit-only lines | Initial hypothesis | State | | ---: | --- | ---: | --- | ---: | --- | --- | -| 1 | `peer.rs` | 1 | S2 | 115 / 325 | Test candidate; property candidate (`Id`) | PENDING | +| 1 | `peer.rs` | 1 | S2 | 115 / 325 | Test candidate; property candidate (`Id`) | DONE (S2; the `Id::new` and `peer::fixture` groups wait on the F5 follow-up) | | 2 | `announce_interval.rs` | 2 | S3 | 79 / 88 | Test candidate (3 gaps); property candidate | PENDING | | 3 | `announce.rs` | 2 | S3 | 0 / 16 | Test candidate | PENDING | | 4 | `policy.rs` | 2 | S3 | 0 / 16 | Test candidate | PENDING | @@ -325,6 +326,9 @@ The 16 rows are every `.rs` file under `packages/primitives/src/`, each once. - 2026-11-10 (time not recorded) - Claude Code (session `i1347 primitives tests`) - Maintainer approved slicing, `quickcheck` for two seams, the `peer::fixture` and `driver.rs`/`service_role.rs` decisions. Finding F1 (`Peer` `Ord` vs `Eq`) confirmed and handed to a separate bug session. - 2026-11-11 11:22 UTC - Claude Code (Sonnet 5.5) - Created issue #2824, moved the spec to `docs/issues/open/`, registered the subissue and baseline in EPIC #1347. S0 branch `2824-1347-add-tests-primitives-spec`. - 2026-11-11 14:07 UTC - Claude Code (Sonnet 5.5) - S1: two regression tests for the `PeerRole` JSON casing failed before the fix (`"Seeder"`, `"Leecher"`) and pass after `rename_all = "lowercase"`; unit tests 49 passed. No other package serializes `PeerRole` to JSON. +- 2026-11-12 14:10 UTC - Claude Code (Sonnet 5.5) - S2: `peer.rs` tests (32 added, 81 unit tests), decision record `test-refactor-plans/peer.md`, 14 of 14 sampled mutants killed; unit-only lines 85.20%, regions 89.28%, functions 82.99%. F6 (negative `left`) handed to #2838 (fix PR #2839). PR #2841, round 1 fixes (Copilot's `ReadInfo` cases; the reviewer's record and commit-split findings). +- 2026-11-12 16:45 UTC - Claude Code (Sonnet 5.5) - S2 review round 1 timing (for the 14:10 entry above): the reviews arrived at 14:09 (Copilot) and 14:11 and 14:28 (da2ce7); the fixes were pushed at 16:16 after a history rewrite approved by the maintainer; round 2 (da2ce7, 16:41) asked to rebuild the history from the pre-split commits (done, keeping the case table and records as their own commits) and to correct records and the audit. +- 2026-11-12 17:53 UTC - Claude Code (Sonnet 5.5) - Correction of the entry stamped 16:45 UTC above: the rebuilt commits were made between 16:44 and 16:47 UTC and pushed at 17:26 UTC; the rebuild was done at 16:47 UTC, not at the stamp. ## Acceptance Criteria diff --git a/docs/issues/open/2824-1347-add-tests-primitives/coverage-evidence.md b/docs/issues/open/2824-1347-add-tests-primitives/coverage-evidence.md index 26ba386eed..37374bf2f5 100644 --- a/docs/issues/open/2824-1347-add-tests-primitives/coverage-evidence.md +++ b/docs/issues/open/2824-1347-add-tests-primitives/coverage-evidence.md @@ -46,6 +46,21 @@ tests; most of the change is not from them: `develop` moved since the baseline ( through #2827, which took 6 uncovered lines from `swarm_metadata.rs`, now 3 / 12 lines). `peer.rs` is 130 / 329 lines (baseline 115 / 325). The other files are unchanged. +### S2 (`peer.rs` tests), 2026-11-12 + +Measured on branch `2824-1347-add-tests-primitives-peer` after the S1 merge, with `cargo-llvm-cov 0.6.16` +and stable Rust 1.99.1, same command as the baseline: + +| Scope | Tests | Lines | Regions | Functions | +| --- | ---: | ---: | ---: | ---: | +| Unit-only (`--lib`) = aggregate | 81 unit | 848 / 995 (85.23%) | 1,345 / 1,506 (89.31%) | 161 / 194 (82.99%) | + +Change from S1: lines +22.50 pp, regions +19.02 pp, functions +23.50 pp (from the baseline: +24.67, ++21.37, +25.76 pp). The slice adds 32 tests, all in `peer.rs` (130 / 329 lines before, 510 / 578 after); +the line totals include the in-file test modules, so part of the rise is the added test code itself. The +uncovered `peer.rs` lines are the `Id::new` group (F5), the dead `Display` `None` branch and +`peer::fixture` (the F5 follow-up). Details and the mutation table: `test-refactor-plans/peer.md`. + ## Module Inventory Every `.rs` file under `packages/primitives/src/` (16 files), once. "Initial hypothesis" is a diff --git a/docs/issues/open/2824-1347-add-tests-primitives/test-refactor-plans/README.md b/docs/issues/open/2824-1347-add-tests-primitives/test-refactor-plans/README.md new file mode 100644 index 0000000000..c0023803ca --- /dev/null +++ b/docs/issues/open/2824-1347-add-tests-primitives/test-refactor-plans/README.md @@ -0,0 +1,47 @@ +--- +doc-type: test-refactor-plan-guidance +issue: 2824 +package: torrust-tracker-primitives +status: in-progress +last-updated-utc: "2026-11-12 16:45" +--- + +# `primitives` File Test Plan Guidance + +This folder holds one decision record per Rust source file in `packages/primitives/src/` that needs +one (`.md`), plus `s1-peer-role-serialization.md`, the design review of slice S1. The +workflow, the two maintainer gates, the commit points, the slices and the ledger are defined once in +[ISSUE.md](../ISSUE.md#per-file-workflow); do not duplicate them here. The +[coverage evidence](../coverage-evidence.md) holds the numbers. + +Create a record right before starting its file, never in advance. A record authorizes neither test +changes nor work on another file until the maintainer approves it. Files with no change share one record. + +## Records + +| Sequence | Record | State | +| ---: | --- | --- | +| 0 | [s1-peer-role-serialization.md](s1-peer-role-serialization.md) | DONE (reviewed in PR #2834) | +| 1 | [peer.md](peer.md) | DONE (S2, PR #2841) | + +## Shared Guardrails + +- **Unit-only coverage is the primary metric** (`cargo llvm-cov -p torrust-tracker-primitives + --all-features --lib`); the package has no integration tests. Do not add a test merely for coverage: + a line is classified **unit**, **collaborator-owned**, **finding** or **unselected** with the reason. +- Judge existing tests against the `write-unit-test` skill (name `it_should_*`, visible + Arrange-Act-Assert, state-centred Arrange, one reason to fail, expected values written in the test, + no production-derived expectations, no logic in the test). List concrete smells; "clean" is also a + recorded conclusion. +- **Prose-First AAA Review** row for every added or changed test, before the completed-file review. +- **Ownership:** `peer::fixture` is owned by the F5 follow-up (`peer-id-test-helper`; #2482 is closed and did not move it); the `AddAssign` of the swarm aggregate is gone + (#2823); `Peer::Ord` is gone (#2798); `Location::caller()` is owned by #2804; `peer::Id::new` waits for its + follow-up (F5). Do not test behavior that an open finding reports as wrong without a recorded maintainer + decision (see [Findings During Implementation](../ISSUE.md#findings-during-implementation)). +- **Properties** only where the record names a natural invariant, and kept only if they protect state that + examples miss. `quickcheck` is the approved dev-dependency (two seams), added with the + `add-rust-dependency` skill and checked with `cargo machete --with-metadata`. +- **Toolchains:** stable Rust for tests and coverage, `cargo +nightly fmt --all -- --check` for + formatting, `git diff --check` after each increment, `linter markdown` and `linter cspell` after + changing these records. Record the toolchain with every validation result. +- Cite commits by their unique Conventional Commit subject, never by id, until merged. diff --git a/docs/issues/open/2824-1347-add-tests-primitives/test-refactor-plans/peer.md b/docs/issues/open/2824-1347-add-tests-primitives/test-refactor-plans/peer.md new file mode 100644 index 0000000000..720528135c --- /dev/null +++ b/docs/issues/open/2824-1347-add-tests-primitives/test-refactor-plans/peer.md @@ -0,0 +1,141 @@ +--- +doc-type: file-test-plan +issue: 2824 +package: torrust-tracker-primitives +target-file: packages/primitives/src/peer.rs +status: done +last-updated-utc: "2026-11-12 18:24" +--- + +# `peer.rs` File Test Plan + +Follow the shared [guidance](README.md). Ledger row 1, slice S2. Status: **completed**: approved by the maintainer on 2026-11-11 with the answers to Q1 to Q3 below (Q1 settled +on 2026-11-12), and the completed file was approved on 2026-11-12 (second gate). + +## Current State + +- **Unit-only coverage:** 130 / 329 lines (39.51%), 191 / 428 regions, 22 / 66 functions, measured 2026-11-11 on + `develop` after #2834. 10 unit tests: peer comparison (1), `ser_unix_time_value` (3), `PeerRole` JSON (2, S1), + `peer::Id` conversion and hex (4). +- **Review of the existing tests: `clean`.** Names, visible Act and literal expectations follow the skill. Two + `should_panic` tests pin the error variant by name (`NotEnoughBytes`, `TooManyBytes`) through `unwrap`; a + `matches!` on the `Err` would say it more directly, but they have one reason to fail and stay. +- **Hypothesis:** the gap is almost all straight-line logic that no test calls: role handling, the `Peer` state + predicates (three duplicated copies), the JSON shape of `Peer` and `Id`, and the `Id` conversions. + +## Coverage And Decision Analysis + +| Behavior group | Lines | Classification | Decision | +| --- | --- | --- | --- | +| `PeerRole::opposite`, `FromStr` (case-insensitive, unknown value) | 48-77 | Unit | Test both variants of `opposite` and its involution; `parse` for lower, mixed and upper case and for an unknown word (assert `raw_param`). **Not** the `location` field: owned by F3 / #2804. | +| `Peer` predicates `is_seeder`, `is_leecher`, `is_completed`, `role` | 269-290 | Unit | Table test of the seeder rule: `left = 0` seeder; `left = 1` leecher; `Stopped` with `left = 0` leecher; `Completed` seeder. See question Q1 for a negative `left`. | +| The same rule in `ReadInfo for Peer` and `ReadInfo for Arc`, and the accessors `get_*` | 216-264 | Unit | One consistency test per entry point against the inherent `is_seeder`; no refactor of the triple copy (maintainability note, not a finding). | +| `Peer` mutators `ip`, `change_ip`, `mark_as_completed`, `into_completed`, `into_seeder` | 292-318 | Unit | Assert whole values: `change_ip` keeps the port; the `into_*` builders change only their own field. `ip(&mut self)` takes `&mut` needlessly: observation only. | +| JSON shape of `Peer` (`ser_peer_id`, `ser_announce_event`, `ser_number_of_bytes`, `Id` `Serialize`) | 176-204, 465-480 | Unit | One whole-`Peer` JSON test against a literal document (fixture not used; the value is built in the test), plus `Id` alone. | +| `Id`: `TryFrom>` success, `From`, `DerefMut`, `get_client_name` | 348-364, 402-405, 458-461 | Unit | `try_from` with 20 bytes gives the same bytes; `get_client_name` for `-qB...` is the qBittorrent client and `None` for an unknown prefix (collaboration with the `tdyne` registry, labelled; production reaches it through `rest-api-runtime-adapter`). `From` and `DerefMut` are compiler-guarded delegation: **unselected** in the approved plan, but two cheap tests were added anyway (`it_should_be_created_from_a_peer_id`, `it_should_give_mutable_access_to_the_peer_id_bytes`) to pin the delegation; recorded as a deviation. | +| `Id` `Display` `None` branch | 413 | Unit-unreachable | `to_hex_string` only returns `None` for invalid UTF-8, and hex output is ASCII: dead defensive branch, **unselected**, recorded. | +| `Id::new` | 369-382 | Owned elsewhere | Deferred: F5 moves it out of production code. No test until that issue decides. | +| `FromIterator for Vec` | 487-495 | Unit | One test with a local `Encoding` type: order preserved, one element per peer. | +| `peer::fixture` (`PeerBuilder`) | 547-636 | Owned elsewhere | Deferred to the F5 follow-up (`peer-id-test-helper`): #2482 is closed and did not move it (maintainer decision 2026-11-10 named #2482; the closed state was found later). | + +## Property-Test Decision + +One `quickcheck` property (the approved seam): for any 20-byte vector, `Id::try_from` succeeds and +`to_hex_string` is `0x` plus the 40 lowercase hex digits of the same bytes; for any other length it fails. +It protects the encoding of every possible id, which the two example ids do not. Nothing else in the file has +a natural property (the role has two values). + +## Decisions (2026-11-11; Q1 settled 2026-11-12) + +- **Q1: pin the current behavior (option A).** `is_seeder` is `left <= 0 && event != Stopped`, so a negative + `left` is a seeder. A characterization test with a name that states the rule is added. The maintainer wants the + tracker to reject a negative `left` at the UDP boundary (HTTP already does: it parses a `u64`), which is outside + `primitives`: finding F6, handed to issue #2838 (the maintainer approved rejecting a negative `left`, `uploaded` and `downloaded`), together with + an ADR on tolerance of malformed inbound values (proposal `inbound-tolerance-adr`). The pinned test stays valid + after that fix because it tests the signed domain type; its comment points at #2850. Update, 2026-11-12: the fix PR #2839 was closed unmerged; #2850 makes a negative count unrepresentable by construction, and its implementation removes this test. +- **Q2: yes.** Correct the doc comment of `to_hex_string` (output has the `0x` prefix). Documentation only. +- **Q3: yes.** Add `quickcheck` as a dev-dependency (the first property test), following `add-rust-dependency`. + +## Results (2026-11-12) + +Toolchains: stable Rust 1.99.1 for tests and coverage, `cargo-llvm-cov 0.6.16`, nightly `cargo fmt`. + +| Measure | Before | After | +| --- | ---: | ---: | +| Unit tests of the package | 49 | 81 (32 added, all in `peer.rs`) | +| `peer.rs` lines | 130 / 329 | 510 / 578 | +| Package unit-only lines | 468 / 746 (62.73%) | 848 / 995 (85.23%) | +| Package unit-only regions | 743 / 1,057 (70.29%) | 1,345 / 1,506 (89.31%) | +| Package unit-only functions | 94 / 158 (59.49%) | 161 / 194 (82.99%) | + +The line totals include the in-file test modules (the baseline did too), so the percentage rises partly because +the added tests are covered code. The 68 uncovered lines of `peer.rs` are exactly the groups the plan leaves +alone: `Id::new` (12 lines, F5), the dead `Display` `None` branch (1 line) and `peer::fixture` (55 lines, the F5 follow-up). + +All the planned groups are tested (`PeerRole`, the `Peer` predicates and mutators, `ReadInfo` for `Peer` and +`Arc`, the JSON of `Peer` and `Id`, the `Id` conversions, the collection, one `quickcheck` property with two +tests). Decisions applied: Q1 pinned with `it_should_treat_a_negative_number_of_bytes_left_as_a_seeder` (comment +points at #2850); Q2 corrected the `to_hex_string` doc comment; Q3 added `quickcheck` and `quickcheck_macros` as +dev-dependencies (same requirements as `udp-core`; both already locked at their latest stable versions, 1.1.0 and +1.2.0; `cargo machete --with-metadata` is run by the pre-commit gate). + +**A fixture lesson (for the F5 follow-up).** The id the existing `PeerBuilder` fixture uses, `-qB00000000000000000`, is +not a valid Azureus-style id (the character after the four version characters must be `-`), so the client +registry reports no client for it. The new tests use `-qB4650-abcdefghijkl`, which the registry knows as +qBittorrent. This confirms the maintainer's concern that test ids should look like real ones. + +### Mutation sample (18 mutants, each applied alone to `peer.rs` and reverted exactly) + +The first eight mutants were run first, the next six in review round 1 and the last four in review rounds 2 and 3 of #2841 (2026-11-12). The "Killed by" +column is the set of tests that fail on the final test set, re-checked after the case table was added, with the +mutant applied to one place only (the inherent `Peer` rule for the first two rows). + +| Mutant | Result | Killed by | +| --- | --- | --- | +| `is_seeder` `left <= 0` to `left == 0` | killed | the negative-`left` test and the read-info role-case table (`(-1, Started)`, through `is_leecher`) | +| `is_seeder` `!= Stopped` to `== Stopped` | killed | 5 tests (the 4 state tests that name stopped, completed, no bytes left and negative `left`, and the read-info role-case table) | +| `ReadInfo for Arc` `<=` to `<` | killed | the read-info role-case table and the shared-peer read-info test | +| `opposite` of the seeder returns the seeder | killed | the opposite-role test | +| `change_ip` resets the port | killed | the keep-the-port test | +| hex string without `0x` | killed | 6 tests (incl. the property) | +| `get_client_name` always `None` | killed | 3 tests | +| `FromStr` case sensitive | killed | the case-insensitive parse test | +| `ReadInfo for Peer` `is_seeder` returns `false` (round 1 of #2841) | killed | the read-info role-case table | +| `ReadInfo for Peer` `is_seeder` `<=` to `==` | killed | the read-info role-case table | +| `ReadInfo for Peer` `is_leecher` not negated | killed | the read-info role-case table and the read-info accessor test (it asserts `is_leecher` on a leecher) | +| `ReadInfo for Arc` `is_seeder` returns `true` | killed | the read-info role-case table | +| `ReadInfo for Arc` `is_seeder` `<=` to `==` | killed | the read-info role-case table | +| `ReadInfo for Arc` `is_leecher` not negated | killed | the read-info role-case table and the shared-peer read-info test (it asserts `!is_leecher` on a seeder) | +| `mark_as_completed` also clears `uploaded` | killed | the mark-as-completed test (fixture with nonzero totals) | +| `into_completed` also clears `downloaded` | killed | the into-completed test | +| `into_seeder` also clears `uploaded` | killed | the into-seeder test | +| `is_completed` is `event != Started` | killed | the completed-only-on-completed test (it now also asserts `Stopped` and `None`) | + +No survivor. Run with `cargo test -p torrust-tracker-primitives --lib` per mutant; `cmp` against a saved copy +showed the file restored byte for byte. + +## Prose-First AAA Review (every added test) + +Temporary prose per section was written for each group and compared with the code; the code expresses it, so no +prose is kept as a comment, except where a comment states a rule that the test name cannot (F6). + +| Group | Arrange (the one causal state) | Act | Assert (literal, independent) | Outcome | +| --- | --- | --- | --- | --- | +| `peer_role` | none: the role or the text is the input | `opposite()` / `parse` | the other role; the parsed role; `raw_param` | clean | +| `peer_state` | a peer from `a_peer_with(left, event)`: only `left` and `event` vary, everything else is fixed (the transfer totals are distinct nonzero values, so a mutator that resets one is caught) | the predicate or mutator | `is_seeder`, `is_leecher` and `role` agree; whole-value `assert_eq!` against the expected peer | clean; helper owns only the incidental fields | +| `peer_state::read_info` | a leecher, and a completed seeder in an `Arc` | each trait accessor | literal id, state; fields compared with the peer's own | clean | +| `peer_state::read_info` (round 1 of #2841) | five `(left, event)` cases: positive, zero and negative `left` with `Started`, zero and negative `left` with `Stopped`, each as a `Peer` and as an `Arc` | `ReadInfo::is_seeder` and `is_leecher` | the expected role literal per case, and its negation for the leecher | clean | +| `peer_serialization` | the peer built in the test with distinct values per field | `serde_json::to_value` | one whole JSON document written in the test; one event per test | clean | +| `peer_id` | an id from a realistic prefix, or all zeros | conversion, `get_client_name`, JSON | bytes, client name or `None`, JSON literal | clean | +| `peer_id_encoding` | any bytes (property) | `try_from`, `to_hex_string` | expected hex built independently with `format!("{byte:02x}")` | clean | +| `peer_collection` | three peers with distinct ports; a local `Encoding` type | `collect` | order and one element per peer | clean | + +Review round 1 of PR #2841 (Copilot) found the `ReadInfo` role predicates only covered by two cases, so a constant result or a removed stopped-event check could survive; the case table above closes it (the sampled mutants stay killed). + +Test smells found and fixed while writing: none left. Existing tests judged `clean` in the plan are unchanged. + +## Validation + +`cargo test -p torrust-tracker-primitives`; `cargo +nightly fmt --all -- --check`; `git diff --check`; the +pre-commit gate; unit-only coverage re-run with before and after recorded here. The Prose-First AAA Review rows +and the mutation proofs are above. diff --git a/docs/pr-reviews/pr-2841-review/PR-REVIEW.md b/docs/pr-reviews/pr-2841-review/PR-REVIEW.md new file mode 100644 index 0000000000..3a7b69702a --- /dev/null +++ b/docs/pr-reviews/pr-2841-review/PR-REVIEW.md @@ -0,0 +1,569 @@ +--- +semantic-links: + skill-links: + - process-pr-review + related-artifacts: + - .github/skills/dev/pr-reviews/process-pr-review/SKILL.md +--- + +# PR #2841 Review Audit + +Source: pull-request reviews and inline review threads for https://github.com/torrust/torrust-tracker/pull/2841. + +## Ownership + +The PR author owns this tracked audit record. Reviewers, including repository review agents, +deliver findings through GitHub and have no repository-artifact obligation. + +- Post-merge workflow approval: N/A + +## Status Values + +- Relationship: `ORIGINAL`, `RE_RAISE_OF:` +- Disposition: `FIXED`, `NO_ACTION`, `SUPERSEDED`, `FOLLOW_UP` +- Thread state: `OPEN`, `RESOLVED`, `NON_RESOLVABLE`, `SUPERSEDED`. `OPEN` applies prospectively + to audits created or updated for approved follow-up work; historical audits remain valid without + bulk migration. +- Severity: `Blocker`, `Major`, `Minor`, `Nit`, `Suggestion`; append `(inferred)` when derived + from free prose. +- Author class: `Copilot`, `Human`, `Unknown` +- Category: `link-integrity`, `formatting`, `metadata`, `testing`, `correctness`, + `documentation`, `maintainability`, `security`, `other` +- An outdated thread whose concern was fixed is `FIXED`/`RESOLVED`, even when GitHub marks the + original thread outdated after the push. For in-PR feedback, use `NO_ACTION`/`SUPERSEDED` only + for a duplicate, superseded, or no-change concern. A post-merge `NO_ACTION` requires maintainer + approval to decline the follow-up work. +- When the current identity cannot resolve a thread (`viewerCanResolve` is `false`), keep the + disposition established from the current tree and record `Thread state=OPEN`. The reviewer or PR + author resolves it; permission says nothing about whether the concern was fixed. + +## Findings + +Round 1 is Copilot's review `5875845096` (F13, numbered after the others) and da2ce7's review `5875864302` (F1 to F8), both submitted on the head whose last commit had the subject `docs(issues): [#2824] record the S2 coverage and the F6 finding`, and da2ce7's review `5876129658` (F9 to F12), submitted on the head whose last commit has the subject `test(primitives): [#2824] cover the ReadInfo role predicates for every state`. Round 2 is da2ce7's review `5878329038` (F14 to F20), submitted on the head whose last commit has the subject `docs(pr-reviews): [#2824] correct a log stamp of the PR 2841 audit`, and Copilot's review `5878380545` (F21), submitted on the same head as `5878329038`. Round 3 is da2ce7's approving review `5879377639` (F22 to F24) and Copilot's review `5879536305` (F25 to F27). Round 4 is da2ce7's review `5879809319` (F28 to F33). Round 5 is da2ce7's review `5880156295` (F34 and F35). The branch history was rebuilt after round 2 (see F14), so the subjects of the round 1 fix commits are those listed in each `Resolution reference` below. + +| Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | +| ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | +| F1 | review-finding:pr-2841-f1 | Human | Major | maintainability | ORIGINAL | FIXED | RESOLVED | +| F2 | review-finding:pr-2841-f2 | Human | Minor | testing | RE_RAISE_OF:F13 | FIXED | RESOLVED | +| F3 | review-finding:pr-2841-f3 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F4 | review-finding:pr-2841-f4 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F5 | review-finding:pr-2841-f5 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F6 | review-finding:pr-2841-f6 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F7 | review-finding:pr-2841-f7 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F8 | review-finding:pr-2841-f8 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | +| F9 | review-finding:pr-2841-f9 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F10 | review-finding:pr-2841-f10 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F11 | review-finding:pr-2841-f11 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F12 | review-finding:pr-2841-f12 | Human | Nit | documentation | ORIGINAL | NO_ACTION | SUPERSEDED | +| F13 | review-finding:pr-2841-f13 | Copilot | Minor (inferred) | testing | ORIGINAL | FIXED | RESOLVED | +| F14 | review-finding:pr-2841-f14 | Human | Major | maintainability | ORIGINAL | FIXED | RESOLVED | +| F15 | review-finding:pr-2841-f15 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F16 | review-finding:pr-2841-f16 | Human | Minor | maintainability | ORIGINAL | FIXED | RESOLVED | +| F17 | review-finding:pr-2841-f17 | Human | Nit | metadata | ORIGINAL | FIXED | RESOLVED | +| F18 | review-finding:pr-2841-f18 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F19 | review-finding:pr-2841-f19 | Human | Nit | documentation | RE_RAISE_OF:F8 | FIXED | RESOLVED | +| F20 | review-finding:pr-2841-f20 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F21 | review-finding:pr-2841-f21 | Copilot | Minor | testing | ORIGINAL | FIXED | RESOLVED | +| F22 | review-finding:pr-2841-f22 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F23 | review-finding:pr-2841-f23 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F24 | review-finding:pr-2841-f24 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F25 | review-finding:pr-2841-f25 | Copilot | Minor | testing | ORIGINAL | FIXED | RESOLVED | +| F26 | review-finding:pr-2841-f26 | Copilot | Minor | documentation | RE_RAISE_OF:F22 | FIXED | RESOLVED | +| F27 | review-finding:pr-2841-f27 | Copilot | Minor | documentation | RE_RAISE_OF:F22 | FIXED | RESOLVED | +| F28 | review-finding:pr-2841-f28 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F29 | review-finding:pr-2841-f29 | Human | Minor | metadata | ORIGINAL | FIXED | RESOLVED | +| F30 | review-finding:pr-2841-f30 | Human | Nit | documentation | ORIGINAL | NO_ACTION | SUPERSEDED | +| F31 | review-finding:pr-2841-f31 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F32 | review-finding:pr-2841-f32 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F33 | review-finding:pr-2841-f33 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | +| F34 | review-finding:pr-2841-f34 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F35 | review-finding:pr-2841-f35 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | + +## Finding Details + +### F1 - The commits do not match their messages + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530157 +- Concern: The docs commit carried the `peer.rs` tests, the manifests and the lock, and the test commit carried only a TOML re-spacing, so history and blame would point at the wrong commits; the description repeated the mismatch and lacked a "Validation performed" part. +- Solution: Rewrote the unmerged branch (force-push with lease, with the maintainer's approval): the docs commit carried only the plan files and the test commit the code. Round 2 (F14, F16) found that the rewrite folded steps and put the record apart from its tests; the history was rebuilt from the pre-split commits (see F14). +- Current-tree verification: Listed the files of each rewritten commit with `git show --stat`; the test commit contains `peer.rs`, `packages/primitives/Cargo.toml` and `Cargo.lock`, the docs commit (before the round 2 rebuild) only the two plan files; after the rebuild it holds only `README.md` and `peer.md` is in the test commit. +- Resolution reference: test(primitives): [#2824] test the peer module +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553083185 + +### F2 - Each ReadInfo copy of the seeder rule is pinned on one side only + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530167 +- Concern: The `ReadInfo` tests asserted only a leecher through one entry point and only a seeder through the other, so replacing the trait `is_seeder` by a constant or its `<=` by `==` survived. +- Solution: Added a case table (positive, zero and negative `left` with `Started`; zero and negative `left` with `Stopped`) asserting both `is_seeder` and `is_leecher` through the trait, on `Peer` and on `Arc`, and ran the six standard mutants of both impls. +- Current-tree verification: Applied each mutant alone and ran `cargo test -p torrust-tracker-primitives --lib`: all six fail the case table; the file was restored byte for byte (`cmp`). +- Resolution reference: test(primitives): [#2824] cover the ReadInfo role predicates for every state +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553083786 + +### F3 - The slice table and the EPIC row are not reconciled + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530175 +- Concern: The S2 row said "PR number at open", S1 stayed `IN_PROGRESS`, the EPIC row still said S1 was in review and the spec had no S2 Progress Log entry. +- Solution: S1 is `DONE`, S2 names #2841, the EPIC row says S1 is merged and S2 in review, and the Progress Log has an S2 entry. +- Current-tree verification: Read the three places back in the tree: the slice table, the EPIC subissue row and the Progress Log. +- Resolution reference: docs(issues): [#2824] fix the S2 records after review round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553084277 + +### F4 - The EPIC log entry sits under References and is stamped after its commit + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530191 +- Concern: The S2 EPIC entry was appended after the References list and was stamped 13:40 UTC, before the commit that carries it. +- Solution: Moved the entries under the Progress Log after the S1 entry; the rewritten commits are dated after every stamp (13:40 and 14:10 UTC). +- Current-tree verification: Compared the stamps with `git log --format=%cI` for the rewritten commits. +- Resolution reference: docs(issues): [#2824] fix the S2 records after review round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553084785 + +### F5 - peer::fixture is deferred to a closed EPIC + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530198 +- Concern: Several records named #2482 (closed, did not move the fixture) as owner of `peer::fixture`, against the F5 row and the inventory. +- Solution: The README, `peer.md`, `coverage-evidence.md` and the ledger row now name the F5 follow-up (`peer-id-test-helper`) as the owner and cite #2482 only as closed. +- Current-tree verification: Searched the issue folder for `2482`: the remaining mentions say it is closed. +- Resolution reference: docs(issues): [#2824] fix the S2 records after review round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553085358 + +### F6 - The approved record marks From and DerefMut as unselected, but the PR tests them + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530203 +- Concern: The approved record said `From` and `DerefMut` are unselected, yet the PR adds a test for each. +- Solution: Recorded the deviation and its reason in the record row: two cheap tests that pin the delegation. +- Current-tree verification: Read the row in `peer.md`. +- Resolution reference: docs(issues): [#2824] fix the S2 records after review round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553085818 + +### F7 - The record states say the completed-file review is still to come + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530220 +- Concern: The frontmatter, the intro, the README index and the Validation section still described the completed-file review as pending. +- Solution: Set the status to `done` (first `completed`, changed after F17) and updated the intro, the README row and the Validation section; the second gate was passed on 2026-11-12. +- Current-tree verification: Searched `peer.md` and the README for `pending` and `are added at the completed-file review`: none left. +- Resolution reference: docs(issues): [#2824] fix the S2 records after review round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553086615 + +### F8 - The S2 dates disagree + +- PR number: 2841 +- Source review ID: 5875864302 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551530228 +- Concern: The results heading and the coverage evidence dated the same measurement differently, and the Decisions section dated the Q1 resolution before it happened. +- Solution: The results are dated 2026-11-12; the Decisions heading says Q1 was settled on 2026-11-12. +- Current-tree verification: Read the two headings and the coverage-evidence section. +- Resolution reference: docs(issues): [#2824] fix the S2 records after review round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553087247 + +### F9 - The mutation table "Killed by" column no longer matches the tests + +- PR number: 2841 +- Source review ID: 5876129658 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551735656 +- Concern: After the case table was added, several mutants are also killed by it, so the recorded attributions were stale. +- Solution: Re-ran the affected mutants and updated the column; round 2 (F18) found three cells still differing, and they were corrected from a run of each mutant at one place. +- Current-tree verification: Mutated lines of `peer.rs` one at a time, listed the failing tests and restored the file (`cmp`). +- Resolution reference: docs(issues): [#2824] re-check the mutation attributions of the peer.rs record +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553155043 + +### F10 - A review thread has a reply, but the branch has no review audit record + +- PR number: 2841 +- Source review ID: 5876129658 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551735667 +- Concern: The first replies were posted before the audit record `PR-REVIEW.md` existed. +- Solution: Created this record from the template in its own commit and logged the late start in the Processing Log. +- Current-tree verification: The record exists at `docs/pr-reviews/pr-2841-review/PR-REVIEW.md` and has a row and a detail entry for every thread of the PR. +- Resolution reference: docs(pr-reviews): [#2824] record the review of PR 2841 round 1 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553155545 + +### F11 - The PR description still gives the pre-review figures + +- PR number: 2841 +- Source review ID: 5876129658 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551735678 +- Concern: The description still said 31 tests, 80 unit tests and the first coverage figures, and listed three commits. +- Solution: Edited the description: 32 tests, 81 unit tests, 85.20% / 89.28% / 82.99%, the rewritten commit list and a "Validation performed" part; a PR conversation comment states the edit. +- Current-tree verification: Read the description back through the API after the edit. +- Resolution reference: https://github.com/torrust/torrust-tracker/pull/2841#issuecomment-6829216025 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553156049 + +### F12 - The commit subject says "for every state", but the table has five cases + +- PR number: 2841 +- Source review ID: 5876129658 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551735687 +- Concern: The subject of the commit that added the case table overstated what the five cases cover. +- Solution: No change; superseded by F14. The first rewrite folded that commit, but the rebuild after round 2 restored it with its subject (F14 requires every step to be kept). The subject overstates the five cases, which are enough for the standard mutants of both impls; only the wording is off. +- Current-tree verification: `git log --format=%s` lists the restored commit with the subject `test(primitives): [#2824] cover the ReadInfo role predicates for every state`. +- Resolution reference: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554627975 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554627975 + +### F13 - The ReadInfo tests leave the trait predicates unprotected + +- PR number: 2841 +- Source review ID: 5875845096 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551515165 +- Concern: Copilot reported that the `ReadInfo` tests cover one positive-left peer and one zero-left completed shared peer, so a constant result or a removed stopped-event check survives; it asked for trait-qualified cases on `Peer` and `Arc`. +- Solution: The case table described under F2 adds exactly those cases and asserts both seeder and leecher results. +- Current-tree verification: Same mutant run as F2: all killed. +- Resolution reference: test(primitives): [#2824] cover the ReadInfo role predicates for every state +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4551572064 + +### F14 - The rewrite drops two steps the branch had, so the merged history hides a correction + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379899 +- Concern: The first rewrite folded the case-table commit and the TOML re-spacing step into the test commit, hiding a correction, and the description did not say the history was rewritten. +- Solution: Rebuilt the history from the pre-split commits: README alone, then the test commit with `peer.md`, the records commit, the case-table commit as its own commit, and the record fixes and audit commits above them. The TOML re-spacing step cannot be a separate commit because the pre-commit gate rejects the unformatted array; the test commit carries the formatted array and its body says so. The description says the history was rewritten. +- Current-tree verification: Listed the rebuilt branch with `git log --format=%s` and compared its final tree with the previous head before the round 2 fixes: identical. +- Resolution reference: test(primitives): [#2824] test the peer module +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553981820 + +### F15 - This log entry is stamped before the review it reports as fixed + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379918 +- Concern: A spec Progress Log entry was stamped before the review it reports, and the README frontmatter date was stale. +- Solution: Added a new Progress Log entry with the real times of the round without editing the old one, and updated the README date. +- Current-tree verification: Read the new entry and the frontmatter in the tree. +- Resolution reference: docs(issues): [#2824] correct the S2 record statuses, mutation cells and timing +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553982318 + +### F16 - The decision record sits in the docs commit, apart from its tests + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379928 +- Concern: The spec puts a file's decision record, tests and coverage in one commit, but the record was in the docs commit before the tests. +- Solution: The rebuild puts `peer.md` in the test commit; only the shared README is in the docs commit. +- Current-tree verification: `git show --stat` of the test commit lists `peer.md`. +- Resolution reference: test(primitives): [#2824] test the peer module +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553982792 + +### F17 - status: completed is a status no other file test plan uses + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379936 +- Concern: Every other file test plan says `status: done`. +- Solution: Changed the status to `done`. +- Current-tree verification: Read the frontmatter of `peer.md`. +- Resolution reference: docs(issues): [#2824] correct the S2 record statuses, mutation cells and timing +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553983267 + +### F18 - Three "Killed by" cells still differ from the tests that fail + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379945 +- Concern: Three mutation table cells did not list every test that fails; the audit repeated a count of 6. +- Solution: Re-ran each mutant at one place and recorded the failing tests; corrected the three cells and the audit text. +- Current-tree verification: Ran the nine mutants listed in the table one at a time and compared the failing tests with the cells; the file was restored byte for byte. +- Resolution reference: docs(issues): [#2824] correct the S2 record statuses, mutation cells and timing +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553983709 + +### F19 - The first run is dated before the decision that added its killing test + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379960 +- Concern: The note dated the first eight mutants to 2026-11-11, before the decision that added their killing test. +- Solution: The note no longer dates the runs by day. +- Current-tree verification: Read the note in `peer.md`. +- Resolution reference: docs(issues): [#2824] correct the S2 record statuses, mutation cells and timing +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553984173 + +### F20 - The audit misstates two facts that the forge records + +- PR number: 2841 +- Source review ID: 5878329038 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553379971 +- Concern: The audit named the reviewed heads by subjects they did not have and marked F13 as the re-raise of F2 although F13 came first. +- Solution: Corrected the head subjects and the relationship (F2 is `RE_RAISE_OF:F13`) and logged the correction as a new entry. +- Current-tree verification: Compared the heads and comment times with the API output of the PR. +- Resolution reference: docs(pr-reviews): [#2824] correct the PR 2841 audit facts after round 2 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553984607 + +### F21 - Mutator fixture uses zero transfer totals + +- PR number: 2841 +- Source review ID: 5878380545 +- Reviewer finding ID: F14 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553421890 +- Concern: Both transfer counters of the fixture were zero, so the three mutator tests also pass if a mutator clears `uploaded` or `downloaded`. +- Solution: The fixture uses distinct nonzero totals; three mutants that clear a total are killed by their test and recorded in the mutation table. +- Current-tree verification: Applied each mutant alone and ran the package tests: each fails exactly its mutator test. +- Resolution reference: test(primitives): [#2824] use nonzero transfer totals in the peer mutator fixture +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4553985041 + +### F22 - The audit still describes the history before the rebuild, and a correction misses it + +- PR number: 2841 +- Source review ID: 5879377639 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554219050 +- Concern: Several audit fields still described the history before the rebuild (the case-table commit named wrongly, F12 saying the commit is gone, F1 and F7 text, the round 2 review list, F21 severity and the F19 relationship), and the round 2 correction entry named the wrong replies. +- Solution: Corrected the fields (F2 and F13 name the case-table commit, F12 is `NO_ACTION` with a correcting reply, F1, F7, the round 2 list, F21 `Minor`, F19 `RE_RAISE_OF:F8`) and added a new Processing Log entry for the correction, leaving the earlier entry as it was. +- Current-tree verification: Read each corrected field in the record and ran the validator against GitHub. +- Resolution reference: docs(pr-reviews): [#2824] record round 3 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554278875 + +### F23 - This entry is stamped before the rebuild it reports as done + +- PR number: 2841 +- Source review ID: 5879377639 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554219058 +- Concern: A spec Progress Log entry was stamped 16:45 UTC and called the rebuild done while its commits were made until 16:47 UTC. +- Solution: Added a correcting entry with the real times and left the earlier entry as it was. +- Current-tree verification: Compared the stamps with `git log --format=%cI` of the rebuilt commits. +- Resolution reference: docs(issues): [#2824] point the F6 records at #2850 and fix the S2 stamps +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554279322 + +### F24 - The note puts the three new mutants in round 1, and the stamp was not moved + +- PR number: 2841 +- Source review ID: 5879377639 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554219069 +- Concern: The mutation note put the last three mutants in review round 1 although they answer a round 2 review, and the file stamp was not moved after the fixture commit. +- Solution: The note says round 2 and the frontmatter stamp is moved. +- Current-tree verification: Read the note and the frontmatter in the tree. +- Resolution reference: docs(issues): [#2824] point the F6 records at #2850 and fix the S2 stamps +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554279740 + +### F25 - Cover the remaining non-completed events + +- PR number: 2841 +- Source review ID: 5879536305 +- Reviewer finding ID: F22 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554347587 +- Concern: The `is_completed` test rejected only `Started`, so a predicate that accepted every event but `Started` still passed; the swarm coordinator uses it to count downloads. +- Solution: The test also asserts `Stopped` and `None`; the mutant `event != Started` is killed and recorded in the mutation table. +- Current-tree verification: Applied the mutant to `is_completed` and ran the package tests: the test fails; the file was restored byte for byte. +- Resolution reference: test(primitives): [#2824] assert that Stopped and None peers are not completed +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554413503 + +### F26 - Cite the commit that adds the ReadInfo case table + +- PR number: 2841 +- Source review ID: 5879536305 +- Reviewer finding ID: F23 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554347672 +- Concern: The resolution references of F2 and F13 named the initial test commit, not the commit that adds the case table. +- Solution: Already fixed by the round 3 audit commit, which was pushed after the head this review covers: F2 and F13 cite the case-table commit. +- Current-tree verification: Read the Resolution reference of F2 and F13 in the record. +- Resolution reference: docs(pr-reviews): [#2824] record round 3 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554414010 + +### F27 - Reconcile F12 with the restored case-table commit + +- PR number: 2841 +- Source review ID: 5879536305 +- Reviewer finding ID: F24 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554347733 +- Concern: F12 claimed the subject is gone although the rebuild restored the commit. +- Solution: Already fixed by the round 3 audit commit: F12 is `NO_ACTION` with a solution, verification and reference that state the deliberate restoration (F14). +- Current-tree verification: Read the F12 row and detail in the record. +- Resolution reference: docs(pr-reviews): [#2824] record round 3 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554414426 + +### F28 - The note still puts the six round-1 mutants in later rounds + +- PR number: 2841 +- Source review ID: 5879809319 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554562893 +- Concern: The mutation note placed the six round 1 `ReadInfo` mutants in later rounds. +- Solution: The note says the next six ran in round 1 and the last four in rounds 2 and 3. +- Current-tree verification: Read the note in `peer.md`. +- Resolution reference: docs(issues): [#2824] re-measure the S2 coverage and fix the peer.md round note +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554621358 + +### F29 - The spec's last-updated-utc is behind its own log + +- PR number: 2841 +- Source review ID: 5879809319 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554562914 +- Concern: The spec frontmatter date was older than its newest Progress Log entry. +- Solution: Set `last-updated-utc` to the time of the edit. +- Current-tree verification: Read the frontmatter of `ISSUE.md`. +- Resolution reference: docs(issues): [#2824] re-measure the S2 coverage and fix the peer.md round note +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554621784 + +### F30 - The record says the comment points at #2850 one commit before it does + +- PR number: 2841 +- Source review ID: 5879809319 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554562922 +- Concern: The record commit said the test comment points at #2850 one commit before the comment changed; the reviewer says nothing needs to change unless the history is rewritten again. +- Solution: No change; superseded by F14: the rebuilt order is kept. +- Current-tree verification: Read the reply and the commit order with `git log`. +- Resolution reference: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554622187 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554622187 + +### F31 - Two facts in the round 3 corrections are wrong + +- PR number: 2841 +- Source review ID: 5879809319 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554562936 +- Concern: The intro placed review `5878380545` on the rebuilt head, and the 17:58 entry said the round 1 replies cite no subject. +- Solution: Corrected line 42 and logged both corrections in a new Processing Log entry, leaving the 17:58 entry as it was. +- Current-tree verification: Compared the review heads and reply texts with the API output. +- Resolution reference: docs(pr-reviews): [#2824] record round 4 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554622653 + +### F32 - F12 is a no-change thread, so process-pr-review asks for SUPERSEDED + +- PR number: 2841 +- Source review ID: 5879809319 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554562947 +- Concern: F12 was recorded as `NO_ACTION`/`RESOLVED` with a reply that did not follow the prescribed form. +- Solution: Posted the prescribed reply `Superseded by F14: ...` on the F12 thread, pointed F12's `Reply URL` and `Resolution reference` at it and set the thread state to `SUPERSEDED`. +- Current-tree verification: Read the F12 row and detail in the record; ran the validator. +- Resolution reference: docs(pr-reviews): [#2824] record round 4 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554846413 + +### F33 - The line totals predate the two new assertions + +- PR number: 2841 +- Source review ID: 5879809319 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554562955 +- Concern: The recorded coverage figures were measured before the two assertions added in round 3. +- Solution: Re-measured: lines 848 / 995 (85.23%), regions 1,345 / 1,506 (89.31%), functions 161 / 194 (82.99%), `peer.rs` 510 / 578; updated `peer.md`, `coverage-evidence.md` and the EPIC. +- Current-tree verification: Ran `cargo llvm-cov` for the package and compared the JSON totals with the recorded figures. +- Resolution reference: docs(issues): [#2824] re-measure the S2 coverage and fix the peer.md round note +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554623600 + +### F34 - The reply this row cites says the opposite of the row + +- PR number: 2841 +- Source review ID: 5880156295 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554838004 +- Concern: The F32 `Reply URL` pointed at a reply that repeated the F12 text. +- Solution: Posted a correct reply on the F32 thread and pointed the field at it; logged the change. +- Current-tree verification: Read the rows and the Processing Log in the record; ran the validator. +- Resolution reference: docs(pr-reviews): [#2824] record round 5 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554846808 + +### F35 - This correction is incomplete, and the line 42 change is not logged + +- PR number: 2841 +- Source review ID: 5880156295 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554838015 +- Concern: The 18:29 correction omitted the F10 and F11 replies (which also cite no subject) and did not log the line 42 change. +- Solution: Appended an entry that corrects both points and left the earlier entry as it was. +- Current-tree verification: Read the rows and the Processing Log in the record; ran the validator. +- Resolution reference: docs(pr-reviews): [#2824] record round 5 of the PR 2841 review +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2841#discussion_r4554847235 + +## Processing Log + +- 2026-11-12 14:14 UTC - Copilot's review `5875845096` (1 finding, F13) processed before this record existed: fixed in the test commit and replied on its thread. +- 2026-11-12 16:17 UTC - da2ce7's review `5875864302` (8 findings, F1 to F8) fixed: the branch history was rewritten and pushed (force-push with lease, approved by the maintainer). Replied on the eight threads and resolved them. This record did not exist yet. +- 2026-11-12 16:17 UTC - da2ce7's review `5876129658` (4 findings, F9 to F12) arrived on the earlier head; its four threads were resolved by mistake in the same sweep, before being read. +- 2026-11-12 16:24 UTC - Started this audit late, after the first replies. F9 (mutation attributions) and F10 (this record) are real: their threads were reopened, F9 was fixed and replied, F10 got a reply that announces this record. F11 (description) was fixed and F12 was folded by the rewrite; both replied. F9 to F12 and F13 are recorded in the rows above; the F9 and F10 threads are resolved after this record is pushed. +- 2026-11-12 16:26 UTC - Correction: the entry above stamped 16:24 UTC is later than its commit (16:23 UTC); its content is accurate. The F9 and F10 threads were then resolved, and the validator passed (13 rows). +- 2026-11-12 17:31 UTC - Round 2: da2ce7's review `5878329038` (7 findings, F14 to F20) and Copilot's review `5878380545` (1 finding, F21; reviewer label F14) processed. The history was rebuilt and force-pushed with the maintainer's approval; the record, mutation cell, status and audit facts were fixed in new commits; F21 fixed with a mutation check. Replied on the eight threads. Correction of an earlier entry: the round 1 fix replies of 16:17 UTC cite subjects that the rebuilt history no longer has; the `Resolution reference` fields above name the current subjects. +- 2026-11-12 17:58 UTC - Round 3: da2ce7's approving review `5879377639` (3 findings, F22 to F24) processed: record, stamp and audit corrections, plus the comment of the negative-left test and the F6 records now point at #2850. Replied on the three threads. Correction of the 17:31 UTC entry above: its last sentence says the round 1 fix replies cite subjects that the rebuilt history no longer has; the stale replies are the F1 and F12 replies (F12 got a correcting reply), and the round 1 replies cite no subject. +- 2026-11-12 18:09 UTC - Round 3, Copilot's review `5879536305` (3 findings, F25 to F27, reviewer labels F22 to F24) on the head before the round 3 audit commit: F25 fixed with a mutation check; F26 and F27 were already fixed by the round 3 audit commit and are recorded as re-raises of F22. Replied on the three threads. +- 2026-11-12 18:29 UTC - Round 4: da2ce7's review `5879809319` (6 findings, F28 to F33) processed: five fixed, F30 superseded by F14; F12 became `SUPERSEDED` with the prescribed reply. Correction of the 17:58 UTC entry above: it says the round 1 replies cite no subject; the replies of F13 (14:14 UTC), F9 and F12 (16:22 UTC) do cite subjects, and only the replies of F1 to F8 (16:16 to 16:17 UTC) cite none. Replied on the six threads. +- 2026-11-12 18:48 UTC - Round 5: da2ce7's review `5880156295` (2 findings, F34 and F35) processed and replied. Corrections of the 18:29 UTC entries above: the F32 `Reply URL` now points at its own reply on the F32 thread (the earlier reply repeated the F12 text); the round 1 replies that cite no subject are those of F1 to F8 (16:16 to 16:17 UTC), F10 and F11 (16:22 UTC); and the change of line 42 (review `5878380545` is on the same head as `5878329038`, last commit `docs(pr-reviews): [#2824] correct a log stamp of the PR 2841 audit`) was made in the round 4 audit commit. + +## Completion Rules + +- Re-derive the reply claim against the current tree before replying or resolving a thread. +- Reply on every resolvable thread before resolving it. +- For an outdated thread whose concern was fixed, record `Disposition=FIXED` and + `Thread state=RESOLVED`, even if GitHub marks the thread outdated after the push. For a + duplicate, superseded, or no-change in-PR thread, reply exactly + `Superseded by : .`, record `Disposition=NO_ACTION` and + `Thread state=SUPERSEDED`, then resolve it. A post-merge `NO_ACTION` requires maintainer + approval to decline the follow-up work. When the current identity cannot resolve a thread + (`viewerCanResolve` is `false`), still reply, keep the disposition established from the current + tree, and record `Thread state=OPEN`; the reviewer or PR author resolves it. +- A consolidated PR conversation response may cover multiple review rounds only when it names + every review ID and every finding ID with its disposition and resolution reference. Record its + durable URL in each related row. +- Cite a fix by its unique Conventional Commit subject or durable reply URL, never by a branch SHA + that can change after a rebase. +- Refresh review threads using GraphQL and confirm that no unresolved actionable thread remains. diff --git a/packages/primitives/Cargo.toml b/packages/primitives/Cargo.toml index 7b0853ace4..42f34df9b2 100644 --- a/packages/primitives/Cargo.toml +++ b/packages/primitives/Cargo.toml @@ -31,4 +31,10 @@ torrust-clock = "3.0.0" url = "2" [dev-dependencies] +quickcheck = { version = "1", default-features = false } +quickcheck_macros = "1" serde_json = "1" + +[package.metadata.cargo-machete] +# The `#[quickcheck]` attribute expands to code that calls the `quickcheck` crate, which machete cannot see. +ignored = [ "quickcheck" ] diff --git a/packages/primitives/src/peer.rs b/packages/primitives/src/peer.rs index 01ff233996..9854a18fa4 100644 --- a/packages/primitives/src/peer.rs +++ b/packages/primitives/src/peer.rs @@ -419,15 +419,15 @@ pub const PEER_ID_BYTES_LEN: usize = 20; impl Id { #[must_use] - /// Converts to hex string. + /// Converts to hex string, prefixed with `0x`. /// - /// For the `PeerId` `-qB00000000000000000` it returns `2d71423030303030303030303030303030303030` + /// For the `PeerId` `-qB00000000000000000` it returns `0x2d71423030303030303030303030303030303030` /// /// For example: /// ///```text /// Bytes = Hex - /// -qB00000000000000000 = 2d71423030303030303030303030303030303030 + /// -qB00000000000000000 = 0x2d71423030303030303030303030303030303030 /// -qB00000000000000000 = 2d 71 42 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 /// /// ------------- @@ -655,6 +655,437 @@ pub mod test { } } + mod peer_role { + use crate::peer::{ParsePeerRoleError, PeerRole}; + + #[test] + fn it_should_have_the_leecher_as_the_opposite_of_the_seeder() { + assert_eq!(PeerRole::Seeder.opposite(), PeerRole::Leecher); + } + + #[test] + fn it_should_have_the_seeder_as_the_opposite_of_the_leecher() { + assert_eq!(PeerRole::Leecher.opposite(), PeerRole::Seeder); + } + + #[test] + fn it_should_be_parsed_from_its_lowercase_name() { + assert_eq!("seeder".parse::().unwrap(), PeerRole::Seeder); + assert_eq!("leecher".parse::().unwrap(), PeerRole::Leecher); + } + + #[test] + fn it_should_be_parsed_ignoring_the_case_of_its_name() { + assert_eq!("SeEdEr".parse::().unwrap(), PeerRole::Seeder); + assert_eq!("LEECHER".parse::().unwrap(), PeerRole::Leecher); + } + + #[test] + fn it_should_fail_to_parse_a_name_that_is_not_a_role_and_report_the_rejected_text() { + let error = "peer".parse::().unwrap_err(); + + let ParsePeerRoleError::InvalidPeerRole { raw_param, .. } = error; + + assert_eq!(raw_param, "peer"); + } + } + + mod peer_state { + use std::net::{IpAddr, Ipv4Addr, SocketAddr}; + + use torrust_clock::DurationSinceUnixEpoch; + + use crate::peer::{Peer, PeerRole}; + use crate::{AnnounceEvent, NumberOfBytes, PeerId}; + + fn a_peer_with(left: i64, event: AnnounceEvent) -> Peer { + Peer { + peer_id: PeerId(*b"-qB4650-abcdefghijkl"), + peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080), + updated: DurationSinceUnixEpoch::new(1_669_397_478, 0), + uploaded: NumberOfBytes::new(1_024), + downloaded: NumberOfBytes::new(4_096), + left: NumberOfBytes::new(left), + event, + } + } + + #[test] + fn it_should_be_a_seeder_when_it_has_no_bytes_left_to_download() { + let peer = a_peer_with(0, AnnounceEvent::Started); + + assert!(peer.is_seeder()); + assert!(!peer.is_leecher()); + assert_eq!(peer.role(), PeerRole::Seeder); + } + + #[test] + fn it_should_be_a_leecher_when_it_has_bytes_left_to_download() { + let peer = a_peer_with(1, AnnounceEvent::Started); + + assert!(peer.is_leecher()); + assert!(!peer.is_seeder()); + assert_eq!(peer.role(), PeerRole::Leecher); + } + + #[test] + fn it_should_be_a_leecher_when_it_has_stopped_even_with_no_bytes_left_to_download() { + let peer = a_peer_with(0, AnnounceEvent::Stopped); + + assert!(peer.is_leecher()); + assert_eq!(peer.role(), PeerRole::Leecher); + } + + #[test] + fn it_should_be_a_seeder_when_it_has_completed_the_download() { + let peer = a_peer_with(0, AnnounceEvent::Completed); + + assert!(peer.is_seeder()); + assert_eq!(peer.role(), PeerRole::Seeder); + } + + // A negative number of bytes left is not meaningful: issue #2850 makes it unrepresentable. + // This test pins how the signed domain value is classified until then; that change removes it. + #[test] + fn it_should_treat_a_negative_number_of_bytes_left_as_a_seeder() { + let peer = a_peer_with(-1, AnnounceEvent::Started); + + assert!(peer.is_seeder()); + assert_eq!(peer.role(), PeerRole::Seeder); + } + + #[test] + fn it_should_be_completed_only_when_its_last_event_is_completed() { + assert!(a_peer_with(0, AnnounceEvent::Completed).is_completed()); + assert!(!a_peer_with(0, AnnounceEvent::Started).is_completed()); + assert!(!a_peer_with(0, AnnounceEvent::Stopped).is_completed()); + assert!(!a_peer_with(0, AnnounceEvent::None).is_completed()); + } + + #[test] + fn it_should_keep_its_port_when_its_ip_address_changes() { + let mut peer = a_peer_with(0, AnnounceEvent::Started); + + peer.change_ip(&IpAddr::V4(Ipv4Addr::new(10, 0, 0, 7))); + + assert_eq!(peer.peer_addr, SocketAddr::new(IpAddr::V4(Ipv4Addr::new(10, 0, 0, 7)), 8080)); + assert_eq!(peer.ip(), IpAddr::V4(Ipv4Addr::new(10, 0, 0, 7))); + } + + #[test] + fn it_should_be_marked_as_completed_without_changing_anything_else() { + let mut peer = a_peer_with(1, AnnounceEvent::Started); + + peer.mark_as_completed(); + + assert_eq!(peer, a_peer_with(1, AnnounceEvent::Completed)); + } + + #[test] + fn it_should_be_converted_into_a_completed_peer_without_changing_anything_else() { + let peer = a_peer_with(1, AnnounceEvent::Started); + + assert_eq!(peer.into_completed(), a_peer_with(1, AnnounceEvent::Completed)); + } + + #[test] + fn it_should_be_converted_into_a_seeder_without_changing_anything_else() { + let peer = a_peer_with(1, AnnounceEvent::Started); + + assert_eq!(peer.into_seeder(), a_peer_with(0, AnnounceEvent::Started)); + } + + mod read_info { + use std::sync::Arc; + + use super::a_peer_with; + use crate::peer::ReadInfo; + use crate::{AnnounceEvent, PeerId}; + + #[test] + fn it_should_expose_the_peer_state_through_the_read_info_trait() { + let peer = a_peer_with(1, AnnounceEvent::Started); + + assert!(ReadInfo::is_leecher(&peer)); + assert!(!ReadInfo::is_seeder(&peer)); + assert_eq!(ReadInfo::get_event(&peer), AnnounceEvent::Started); + assert_eq!(ReadInfo::get_id(&peer), PeerId(*b"-qB4650-abcdefghijkl")); + assert_eq!(ReadInfo::get_updated(&peer), peer.updated); + assert_eq!(ReadInfo::get_address(&peer), peer.peer_addr); + } + + #[test] + fn it_should_expose_the_peer_state_through_the_read_info_trait_of_a_shared_peer() { + let peer = Arc::new(a_peer_with(0, AnnounceEvent::Completed)); + + assert!(ReadInfo::is_seeder(&peer)); + assert!(!ReadInfo::is_leecher(&peer)); + assert_eq!(ReadInfo::get_event(&peer), AnnounceEvent::Completed); + assert_eq!(ReadInfo::get_id(&peer), PeerId(*b"-qB4650-abcdefghijkl")); + assert_eq!(ReadInfo::get_updated(&peer), peer.updated); + assert_eq!(ReadInfo::get_address(&peer), peer.peer_addr); + } + + #[test] + fn it_should_classify_the_role_through_the_read_info_trait_like_the_peer_does() { + // (left, event, is seeder): the stopped event wins over zero bytes left. + let cases = [ + (1, AnnounceEvent::Started, false), + (0, AnnounceEvent::Started, true), + (-1, AnnounceEvent::Started, true), + (0, AnnounceEvent::Stopped, false), + (-1, AnnounceEvent::Stopped, false), + ]; + + for (left, event, is_seeder) in cases { + let peer = a_peer_with(left, event); + let shared = Arc::new(a_peer_with(left, event)); + + assert_eq!(ReadInfo::is_seeder(&peer), is_seeder, "left {left}, event {event:?}"); + assert_eq!(ReadInfo::is_leecher(&peer), !is_seeder, "left {left}, event {event:?}"); + assert_eq!( + ReadInfo::is_seeder(&shared), + is_seeder, + "shared, left {left}, event {event:?}" + ); + assert_eq!( + ReadInfo::is_leecher(&shared), + !is_seeder, + "shared, left {left}, event {event:?}" + ); + } + } + } + } + + mod peer_serialization { + use std::net::{IpAddr, Ipv4Addr, SocketAddr}; + + use serde_json::json; + use torrust_clock::DurationSinceUnixEpoch; + + use crate::peer::Peer; + use crate::{AnnounceEvent, NumberOfBytes, PeerId}; + + #[test] + fn it_should_serialize_every_field_in_its_json_form() { + let peer = Peer { + peer_id: PeerId(*b"-qB4650-abcdefghijkl"), + peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080), + updated: DurationSinceUnixEpoch::new(1_669_397_478, 934_000_000), + uploaded: NumberOfBytes::new(10), + downloaded: NumberOfBytes::new(20), + left: NumberOfBytes::new(30), + event: AnnounceEvent::Completed, + }; + + let serialized = serde_json::to_value(peer).unwrap(); + + assert_eq!( + serialized, + json!({ + "peer_id": { "id": "0x2d7142343635302d6162636465666768696a6b6c", "client": "qBittorrent" }, + "peer_addr": "126.0.0.1:8080", + "updated": 1_669_397_478_934_u64, + "uploaded": 10, + "downloaded": 20, + "left": 30, + "event": "Completed" + }) + ); + } + + #[test] + fn it_should_serialize_the_none_announce_event_as_its_name() { + let peer = Peer { + peer_id: PeerId(*b"-qB4650-abcdefghijkl"), + peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 8080), + updated: DurationSinceUnixEpoch::new(0, 0), + uploaded: NumberOfBytes::new(0), + downloaded: NumberOfBytes::new(0), + left: NumberOfBytes::new(0), + event: AnnounceEvent::None, + }; + + let serialized = serde_json::to_value(peer).unwrap(); + + assert_eq!(serialized["event"], json!("None")); + } + + #[test] + fn it_should_serialize_the_started_announce_event_as_its_name() { + let peer = Peer { + peer_id: PeerId(*b"-qB4650-abcdefghijkl"), + peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 8080), + updated: DurationSinceUnixEpoch::new(0, 0), + uploaded: NumberOfBytes::new(0), + downloaded: NumberOfBytes::new(0), + left: NumberOfBytes::new(0), + event: AnnounceEvent::Started, + }; + + let serialized = serde_json::to_value(peer).unwrap(); + + assert_eq!(serialized["event"], json!("Started")); + } + + #[test] + fn it_should_serialize_the_stopped_announce_event_as_its_name() { + let peer = Peer { + peer_id: PeerId(*b"-qB4650-abcdefghijkl"), + peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 8080), + updated: DurationSinceUnixEpoch::new(0, 0), + uploaded: NumberOfBytes::new(0), + downloaded: NumberOfBytes::new(0), + left: NumberOfBytes::new(0), + event: AnnounceEvent::Stopped, + }; + + let serialized = serde_json::to_value(peer).unwrap(); + + assert_eq!(serialized["event"], json!("Stopped")); + } + } + + mod peer_id { + use serde_json::json; + + use crate::{PeerId, peer}; + + #[test] + fn it_should_be_converted_from_exactly_twenty_bytes_keeping_the_bytes() { + let id = peer::Id::try_from(b"-qB4650-abcdefghijkl".to_vec()).unwrap(); + + assert_eq!(id.0, *b"-qB4650-abcdefghijkl"); + } + + #[test] + fn it_should_be_created_from_a_peer_id() { + let id = peer::Id::from(PeerId(*b"-qB4650-abcdefghijkl")); + + assert_eq!(id.0, *b"-qB4650-abcdefghijkl"); + } + + #[test] + fn it_should_give_mutable_access_to_the_peer_id_bytes() { + let mut id = peer::Id::from(PeerId(*b"-qB4650-abcdefghijkl")); + + id.0[1] = b'Q'; + + assert_eq!(id.0, *b"-QB4650-abcdefghijkl"); + } + + #[test] + fn it_should_know_the_client_that_generated_a_registered_peer_id_prefix() { + let id = peer::Id::from(PeerId(*b"-qB4650-abcdefghijkl")); + + assert_eq!(id.get_client_name(), Some("qBittorrent".to_string())); + } + + #[test] + fn it_should_not_know_the_client_of_an_unregistered_peer_id_prefix() { + let id = peer::Id::from(PeerId([0; 20])); + + assert_eq!(id.get_client_name(), None); + } + + #[test] + fn it_should_serialize_the_hex_string_and_the_client_name() { + let id = peer::Id::from(PeerId(*b"-qB4650-abcdefghijkl")); + + let serialized = serde_json::to_value(id).unwrap(); + + assert_eq!( + serialized, + json!({ "id": "0x2d7142343635302d6162636465666768696a6b6c", "client": "qBittorrent" }) + ); + } + + #[test] + fn it_should_serialize_an_unknown_client_as_null() { + let id = peer::Id::from(PeerId([0; 20])); + + let serialized = serde_json::to_value(id).unwrap(); + + assert_eq!( + serialized, + json!({ "id": "0x0000000000000000000000000000000000000000", "client": null }) + ); + } + } + + mod peer_id_encoding { + use std::fmt::Write; + + use quickcheck_macros::quickcheck; + + use crate::peer; + + #[quickcheck] + fn it_should_encode_any_twenty_bytes_as_a_hex_string_with_the_0x_prefix(bytes: Vec) -> bool { + let mut twenty_bytes = bytes; + twenty_bytes.resize(peer::PEER_ID_BYTES_LEN, 0); + + let id = peer::Id::try_from(twenty_bytes.clone()).unwrap(); + + let expected = twenty_bytes.iter().fold(String::from("0x"), |mut hex, byte| { + write!(hex, "{byte:02x}").unwrap(); + hex + }); + id.0.to_vec() == twenty_bytes && id.to_hex_string() == Some(expected) + } + + #[quickcheck] + fn it_should_reject_any_byte_vector_whose_length_is_not_twenty(bytes: Vec) -> bool { + bytes.len() == peer::PEER_ID_BYTES_LEN || peer::Id::try_from(bytes).is_err() + } + } + + mod peer_collection { + use std::net::{IpAddr, Ipv4Addr, SocketAddr}; + + use torrust_clock::DurationSinceUnixEpoch; + + use crate::peer::{Encoding, Peer}; + use crate::{AnnounceEvent, NumberOfBytes, PeerId}; + + #[derive(Debug, PartialEq)] + struct PeerPort(u16); + + impl From for PeerPort { + fn from(peer: Peer) -> Self { + Self(peer.peer_addr.port()) + } + } + + impl Encoding for PeerPort {} + + fn a_peer_listening_on(port: u16) -> Peer { + Peer { + peer_id: PeerId(*b"-qB4650-abcdefghijkl"), + peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port), + updated: DurationSinceUnixEpoch::new(0, 0), + uploaded: NumberOfBytes::new(0), + downloaded: NumberOfBytes::new(0), + left: NumberOfBytes::new(0), + event: AnnounceEvent::Started, + } + } + + #[test] + fn it_should_collect_peers_into_a_vector_of_their_encoding_in_order() { + let peers = [ + a_peer_listening_on(8081), + a_peer_listening_on(8082), + a_peer_listening_on(8083), + ]; + + let encoded: Vec = peers.into_iter().collect(); + + assert_eq!(encoded, vec![PeerPort(8081), PeerPort(8082), PeerPort(8083)]); + } + } + mod peer_role_serialization { use serde_json::json;