Repository navigation
refactor(primitives)!: [#2876] replace peer::Id::new with a realistic test helper behind a testing feature #2888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josecelano
merged 16 commits into
torrust:develop
from
josecelano-bot:2876-peer-id-test-helper
Nov 16, 2026
Merged
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 85c6341
docs(issues): [#2876] re-run the caller inventory, compile proof and …
josecelano-bot edddf58
test(primitives): [#2876] add qbittorrent_peer_id, a fixture helper f…
josecelano-bot 51b8de2
test(torrent-repository-benchmarking): [#2876] build peer ids with qb…
josecelano-bot 88f9d2c
refactor(primitives)!: [#2876] remove peer::Id::new
josecelano-bot ebe5394
feat(primitives)!: [#2876] put peer::fixture behind a testing feature
josecelano-bot 71d30b4
test(primitives): [#2876] build the fixture's peer ids with qbittorre…
josecelano-bot 19ed968
test(primitives): [#2876] cover the peer fixture's builder and Defaul…
josecelano-bot e285146
docs(adrs): [#2876] amend the test-support ADR for shared fixtures su…
josecelano-bot 50e59b3
docs(issues): [#2876] record the final verification, acceptance crite…
josecelano-bot 9ade83e
docs(issues): [#2876] record why the short peer.rs tests carry no AAA…
josecelano-bot f3aee50
docs(adrs): [#2876] say when cargo machete flags a testing self dev-d…
josecelano-bot 20cb3f1
docs(pr-reviews): [#2876] add the PR 2888 review audit
josecelano-bot 90ea411
docs(issues): [#2876] correct the statement count of the short peer.r…
josecelano-bot a31c219
docs(pr-reviews): [#2876] record review round 2 of PR 2888
josecelano-bot c4def24
docs(pr-reviews): [#2876] restore the round-1 log entry and append it…
josecelano-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 107 additions & 45 deletions
152
docs/issues/open/2876-1347-peer-id-test-helper/ISSUE.md
Large diffs are not rendered by default.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
docs/issues/open/2876-1347-peer-id-test-helper/coverage-evidence.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
72 changes: 72 additions & 0 deletions
72
docs/issues/open/2876-1347-peer-id-test-helper/implementation-retrospective.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.