Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
81cf0fe
docs(issues): [#2876] record the maintainer's answers to Q1-Q7
josecelano-bot Nov 16, 2026
85c6341
docs(issues): [#2876] re-run the caller inventory, compile proof and …
josecelano-bot Nov 16, 2026
edddf58
test(primitives): [#2876] add qbittorrent_peer_id, a fixture helper f…
josecelano-bot Nov 16, 2026
51b8de2
test(torrent-repository-benchmarking): [#2876] build peer ids with qb…
josecelano-bot Nov 16, 2026
88f9d2c
refactor(primitives)!: [#2876] remove peer::Id::new
josecelano-bot Nov 16, 2026
ebe5394
feat(primitives)!: [#2876] put peer::fixture behind a testing feature
josecelano-bot Nov 16, 2026
71d30b4
test(primitives): [#2876] build the fixture's peer ids with qbittorre…
josecelano-bot Nov 16, 2026
19ed968
test(primitives): [#2876] cover the peer fixture's builder and Defaul…
josecelano-bot Nov 16, 2026
e285146
docs(adrs): [#2876] amend the test-support ADR for shared fixtures su…
josecelano-bot Nov 16, 2026
50e59b3
docs(issues): [#2876] record the final verification, acceptance crite…
josecelano-bot Nov 16, 2026
9ade83e
docs(issues): [#2876] record why the short peer.rs tests carry no AAA…
josecelano-bot Nov 16, 2026
f3aee50
docs(adrs): [#2876] say when cargo machete flags a testing self dev-d…
josecelano-bot Nov 16, 2026
20cb3f1
docs(pr-reviews): [#2876] add the PR 2888 review audit
josecelano-bot Nov 16, 2026
90ea411
docs(issues): [#2876] correct the statement count of the short peer.r…
josecelano-bot Nov 16, 2026
a31c219
docs(pr-reviews): [#2876] record review round 2 of PR 2888
josecelano-bot Nov 16, 2026
c4def24
docs(pr-reviews): [#2876] restore the round-1 log entry and append it…
josecelano-bot Nov 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ torrust-net-primitives = "0.1.0"
torrust-peer-id = "0.1.0"
torrust-tracker-client-lib = { version = "0.1.0", path = "packages/tracker-client" }
torrust-tracker-http-protocol = { version = "0.1.0", path = "packages/http-protocol" }
torrust-tracker-primitives = { version = "3.0.0", path = "packages/primitives", features = [ "testing" ] }
torrust-tracker-test-helpers = { version = "3.0.0", path = "packages/test-helpers" }
torrust-tracker-udp-protocol = { version = "0.1.0", path = "packages/udp-protocol" }
url = { version = "2", features = [ "serde" ] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ semantic-links:
- "issue #2482"
- "issue #2582"
- "issue #2618"
- "issue #2876"
- docs/issues/open/2876-1347-peer-id-test-helper/ISSUE.md
---

<!-- skill-link: create-adr -->
Expand Down Expand Up @@ -54,6 +56,20 @@ semantic-links:
> 3. **Naming.** A file that contains only test code outside a `#[cfg(test)] mod tests` carries the prefix
> `test_` (`test_support.rs`, and `tracker-core`'s `test_helpers.rs` and `whitelist/test_helpers.rs`,
> which already follow it and need no move).
>
> **Amendment of 2026-11-16 (issue #2876).** The decision stands. Rule D speaks of `mockall` mocks, but its
> reasoning covers any test fixture that other packages' tests use: such a fixture belongs to the crate whose
> types it builds and sits behind that crate's `testing` feature, with the self dev-dependency of rule A.3 for
Comment thread
josecelano-bot marked this conversation as resolved.
Resolved
> the crate's own tests and a `[dev-dependencies]` entry in each consumer (rule A.4). The O1c note that
> `cargo machete --with-metadata` does not flag the self dev-dependency holds only when the package's `tests/`
> or examples name the crate by its package name; a package without them, such as `primitives`, lists the self
> dev-dependency in its `[package.metadata.cargo-machete]` `ignored` list, with the reason. The first fixture moved
> this way is `peer::fixture` of `torrust-tracker-primitives` (`PeerBuilder`, `qbittorrent_peer_id` and the
> `Default` impls of `Peer` and `peer::Id`), which #2482 did not find because its inventory searched for
> plural module names such as `fixtures`. Trait impls inside such a module (here `Default`) are gated with it,
> so they leave production builds too. The ownership map has a row for it. The maintainer decided this on
> 2026-11-16 (the answers to Q2, Q5 and Q7 in the
> [#2876 spec](../issues/open/2876-1347-peer-id-test-helper/ISSUE.md)).

## Scope

Expand Down Expand Up @@ -256,6 +272,7 @@ package's environment.
| REST API environment | `axum-rest-api-server` | Own `tests/`, `axum-health-check-api-server` tests | `axum-rest-api-server` `testing` feature |
| Health check API environment | `axum-health-check-api-server` | Own `tests/` | `axum-health-check-api-server` `testing` feature |
| `MockTorrentMetricsStore` and the other `tracker-core` database mocks | `tracker-core` | Own `src/`; `http-core` and `udp-core` unit tests (`MockTorrentMetricsStore`) | `tracker-core` `testing` feature |
| Peer fixture (`peer::fixture`: `PeerBuilder`, `qbittorrent_peer_id`, the `Default` impls of `Peer` and `peer::Id`); added by the amendment of 2026-11-16 | `primitives` | Own `src/` unit tests; `src/` unit tests, `tests/` or benches of `axum-http-server`, `axum-rest-api-server`, `http-core`, `swarm-coordination-registry`, `torrent-repository-benchmarking`, `udp-core`, `udp-server` and the root crate | `primitives` `testing` feature |
| Ephemeral configurations, test logging, random strings | `test-helpers` (generic) | Seven packages | `[dev-dependencies]` entry |
| Protocol client helpers (`http`, `udp` modules today) | The root crate's `tests/common/` | The root crate's integration tests | Not shared |

Expand Down Expand Up @@ -342,3 +359,5 @@ so it is not an example of public test infrastructure. DEC-18 in the
- #2582, the packaging failure caused by a self dev-dependency with a `version`
- [Independent package versioning](20260629000000_adopt_independent_package_versioning.md)
- [`deny.toml`](../../deny.toml), the layer boundary rules referenced by rule B
- [#2876 spec](../issues/open/2876-1347-peer-id-test-helper/ISSUE.md), which moved `peer::fixture`
behind the `testing` feature of `primitives` (amendment of 2026-11-16)
152 changes: 107 additions & 45 deletions docs/issues/open/2876-1347-peer-id-test-helper/ISSUE.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
doc-type: coverage-evidence
issue: 2876
package: torrust-tracker-primitives
measured-commit: c8b1477ad
measured-utc: 2026-11-16
---

# Coverage Evidence - `torrust-tracker-primitives` (#2876)

## Baseline (T1)

Measured on 2026-11-16 at `develop` commit `c8b1477ad` (the merge of #2878), with
`cargo-llvm-cov 0.6.16` and stable Rust 1.99.1, from a clean workspace, with a separate
`CARGO_LLVM_COV_TARGET_DIR`:

```console
cargo llvm-cov clean --workspace
cargo llvm-cov -p torrust-tracker-primitives --all-features --lib --json --output-path <report>.json
cargo llvm-cov -p torrust-tracker-primitives --all-features --json --output-path <report>.json
```

Totals are filtered to `packages/primitives/src/`. The package has no `tests/` folder and no
examples, so the aggregate run (without `--lib`) ran the same 108 unit tests and gave the same
numbers.

| Scope | Tests | Lines | Regions | Functions |
| --- | ---: | ---: | ---: | ---: |
| Unit-only (`--lib`) | 108 unit | 1,075 / 1,143 (94.05%) | 1,694 / 1,778 (95.28%) | 210 / 223 (94.17%) |
| Aggregate | 108 unit | 1,075 / 1,143 (94.05%) | 1,694 / 1,778 (95.28%) | 210 / 223 (94.17%) |

The final measurement of #2824 was 1,078 / 1,146 lines; `develop` moved since then. As in #2824, every
uncovered line of the package is in `peer.rs`: 504 / 572 lines covered, 68 uncovered.

### Uncovered `peer.rs` lines and their owners

Line numbers are those of `develop` at `c8b1477ad`.

| Lines | Code | Owner |
| --- | --- | --- |
| 369-382 | `Id::new` | #2876 (T4 removes it) |
| 413 | `Display for Id`, the `None` branch | #2824 (recorded there as a dead branch); not F5 |
| 547-605 | `PeerBuilder` methods `with_peer_id` to `with_event_completed` | #2876 (T7) |
| 619-629 | `impl Default for Peer` | #2876 (T7) |
| 633-636 | `impl Default for Id` | #2876 (T7) |

`PeerBuilder::seeder`, `leecher`, `build` and `into` are already covered by #2824's tests.

## After T7 (fixture tests), 2026-11-16

Measured on branch `2876-peer-id-test-helper` with the T7 tests in the working tree (after the
commit with subject `test(primitives): [#2876] build the fixture's peer ids with qbittorrent_peer_id`),
same command and toolchain as the baseline (separate `CARGO_LLVM_COV_TARGET_DIR`), unit-only:

| Scope | Tests | Lines | Regions | Functions |
| --- | ---: | ---: | ---: | ---: |
| Unit-only (`--lib`) | 125 unit | 1,270 / 1,273 (99.76%) | 1,920 / 1,925 (99.74%) | 242 / 242 (100.00%) |

`peer.rs` is 699 / 702 lines (baseline 504 / 572). `Id::new` is gone (T4); the new lines are
`qbittorrent_peer_id`, its tests and the fixture tests. The 3 uncovered lines:

| Line | Code | Owner / decision |
| --- | --- | --- |
| 417 | `Display for Id`, the `None` branch | #2824 (dead branch); not F5 |
| 1087 | The failure message of the `qbittorrent_peer_id` format test | No test: test code that runs only when the assertion fails |
| 1100 | `TestResult::discard()` in the distinctness property | No test: test code that runs only when quickcheck draws two equal numbers |

No line owned by F5 is left uncovered in production or fixture code.

## Final Measurement (T9)

Measured on the finished branch (head commit with subject `docs(adrs): [#2876] amend the
test-support ADR for shared fixtures such as peer::fixture`), same commands and toolchain as the
baseline, from a clean `CARGO_LLVM_COV_TARGET_DIR`. Both runs ran the same 125 unit tests (the
package still has no `tests/` folder):

| Scope | Tests | Lines | Regions | Functions |
| --- | ---: | ---: | ---: | ---: |
| Unit-only (`--lib`) | 125 unit | 1,274 / 1,277 (99.77%) | 1,920 / 1,925 (99.74%) | 242 / 242 (100.00%) |
| Aggregate | 125 unit | 1,274 / 1,277 (99.77%) | 1,920 / 1,925 (99.74%) | 242 / 242 (100.00%) |

From the baseline: lines +5.72 pp, regions +4.46 pp, functions +5.83 pp. The line count differs from
"After T7" by 4 because the nightly formatter re-wrapped the new tests. `peer.rs` is 703 / 706; the 3
uncovered lines are the same as after T7 (417, 1087, 1100) with the same owners and decisions. No
uncovered line is owned by F5.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
semantic-links:
skill-links:
- write-markdown-docs
related-artifacts:
- docs/issues/open/2876-1347-peer-id-test-helper/ISSUE.md
- docs/adrs/20261021190318_share_workspace_test_support_through_testing_features.md
---

# Implementation Retrospective — #2876 Peer Id Test Helper

## Purpose

Record evidence-based process improvements discovered while implementing #2876. This is a blameless
review of the implementation approach; it does not replace acceptance-criteria verification.

## Outcome

`peer::Id::new` is removed (a `compile_fail` doctest guards it). `peer::fixture`, with its new
`qbittorrent_peer_id(u32) -> Id` helper and the `Default` impls of `Peer` and `Id`, compiles only
with the new `testing` feature of `primitives`. Eight consumers enable it from `[dev-dependencies]`.
The fixture's ids are realistic, every fixture line is tested, and the test-support ADR is amended.
Evidence: `test-plans/qbittorrent-peer-id.md`, `manual-verification-evidence.md`,
`coverage-evidence.md`.

## What Went Well

1. The red stub that returned today's `Id::new` ids showed which helper tests guard new behavior (the
format and the client name) and which do not (distinct ids, which the old function had too), so
that one got its own mutation.
2. Changing the fixture ids before touching any assertion gave the list of dependent assertions by
running the tests: it was empty, which no text search could have shown.

## What Changed During Implementation

- **The workspace build hides missing consumer entries.** `cargo test --workspace --no-run` passed
without any consumer `[dev-dependencies]` entry, because the self dev-dependency of `primitives`
turns `testing` on for every member of a workspace build. Building each of the 34 members on its
own found the eight that need it. The ADR already notes this for per-package runs (O1a, V4); it
mattered here because the consumer list had to be complete.
- **`cargo machete --with-metadata` flagged the self dev-dependency.** The ADR (O1c) says machete
does not flag it. That held for the server packages, whose `tests/` and examples name the crate by
its package name; `primitives` has no `tests/` folder and its `src/` uses `crate::`, so machete saw
no use. The self dev-dependency is now in the package's machete `ignored` list, with the reason.
- **No assertion depended on the fixture's id bytes.** The spec (Q6, T6) expected some in the
`axum-http-server` and `axum-rest-api-server` tests; the tests that read the ids compare them with
values from the same fixture.

## Root Cause

The O1c statement about machete was verified on packages that all had integration tests or
examples. The spec's T6 expectation came from a text search for the old literals, which cannot tell
hand-written literals from bytes the fixture produces.

## Improvements for Future Work

1. When a `testing` feature gets a self dev-dependency, run `cargo machete --with-metadata` and,
for a package without `tests/` or examples, expect to add the self dev-dependency to its machete
`ignored` list. The ADR amendment of 2026-11-16 now says so (added after review finding F2 of
PR #2888).
2. To find the consumers of a newly gated module, build each member on its own
(`cargo test -p <member> --no-run`), not the workspace.

## Avoiding Overcorrection

No new check is justified: `cargo machete` already fails the commit, and the per-package build is a
one-off step of a gating change, not something CI needs to repeat.

## Evidence

- [Issue specification](ISSUE.md), T5 and T6
- [Test plan](test-plans/qbittorrent-peer-id.md), sections `testing` Feature and Realistic Fixture Ids
Loading
Loading