Repository navigation
test(http-core): [#1349] pin the announce service and error mapping decisions with unit tests - #2575
Conversation
… slice S2 develop changed packages/http-core after the S1 baseline: torrust#2454 marked the public error enums non_exhaustive and added a wildcard arm to error_mapping.rs, and torrust#2560 replaced whole_total with counter_total and added the first metrics.rs test. Re-measured at 87690b1: lines 1,751 / 1,970 (88.88%), regions 90.41%, functions 84.29%, 33 unit tests. Update the evidence, the ledger, the announce plan line references and the EPIC rows. Record that the new wildcard arm cannot be reached by a test while TrackerCoreError has four variants. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
…th unit tests Refactor the 8 existing announce tests onto a small in-file fixture, a recording event sender and rstest tables, then add the tests the file plan approved. The 8 tests become 48 cases that protect: - private-mode authentication, public mode ignoring a key, and listed mode - the order authenticate, authorize, resolve the client IP, select the peer IP and announce, proven by nothing being published or registered after an early failure - peer IP selection: the connection address, a literal IP, the loopback substitution by the external IP, and a client-supplied loopback literal - the request-to-announcement mapping, numwant, an absent event sender, the public URL in the event, a failing persisted-downloads store, and the client-visible failure reasons Each named mutation (M1-M5 and variants) makes exactly its test fail. A probe found one surviving mutant, a loopback ip literal replaced by the external IP; one added example kills it, so no property-test dependency is added. Unit-only coverage of the file: lines 92.85% to 99.06%, functions 100%. Production code is unchanged. Add rstest 0.28.0 as a dev-dependency of http-core for the case tables. It is the latest stable version; the workspace requirement "0" would have locked 0.27.0 here because Cargo reuses an existing compatible lock entry. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
…r core error services/error_mapping.rs had no unit coverage. Add one rstest table with a case for each TrackerCoreError variant (announce, scrape, whitelist, authentication). Each case expects the literal package-owned prefix followed by the wrapped error's own text, so swapping a prefix or dropping the wrapped text fails its case. Mutations of both kinds were applied, caught and reverted. The wildcard arm added by torrust#2454 for an unknown variant stays uncovered: no code outside tracker-core can build a fifth variant of the non_exhaustive enum. The file plan records it as tracker-core's to unlock. Unit-only coverage of the file: lines 0 / 18 to 26 / 29 (the three uncovered lines are the wildcard arm). Production code is unchanged. The commit also records the interim package coverage after slice S2 in the evidence, the ledger and the EPIC tables. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
… record the S2 review The independent Task Reviewer found a mutant of select_peer_ip_with_policy that survived all 77 tests: PeerIp::Empty returning the connection address, which skips the loopback substitution that an absent ip gets. That contradicted the announce plan's claim that no mutation survives the examples. Add a two-case test (absent and empty ip, loopback connection, external IP) that fails the mutant, and rework the tracker-core delegation test to compare with error_mapping's own result so the failure-reason prefix is pinned once. Record the review in agent-review-reports.md, fix the E2 mutation wording in the error mapping plan (an unused pattern variable does not compile under the workspace lints), and update the plans, evidence, ledger and EPIC rows to the final slice S2 numbers: 79 unit tests; package lines 91.34%, regions 92.45%, functions 89.59%. Production code is unchanged. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
…ication Set related-pr to torrust#2575 and the S2 slice row to the pull request, and log that the pre-push checks passed and the pull request was opened. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
Production code is unchanged, the tests have documented validation, and no blocking issues remain.
No open issues 🎉
What changed in this PR
Implements slice S2 of #1349, strengthening HTTP-core announce and error-mapping tests without changing production code.
Changes:
- Expands announce coverage to 50 cases and adds four error-mapping cases.
- Adds
rstestas a development dependency. - Records coverage, mutation results, review outcomes, and issue progress.
| File | Description |
|---|---|
packages/http-core/src/services/error_mapping.rs |
Tests each error variant’s failure reason. |
packages/http-core/src/services/announce.rs |
Refactors fixtures and expands decision coverage. |
packages/http-core/Cargo.toml |
Adds the rstest development dependency. |
docs/issues/open/1349-1347-add-tests-http-core/test-refactor-plans/services-error-mapping-tests.md |
Records error-mapping tests and evidence. |
docs/issues/open/1349-1347-add-tests-http-core/test-refactor-plans/services-announce-tests.md |
Records announce tests and mutation results. |
docs/issues/open/1349-1347-add-tests-http-core/test-refactor-plans/README.md |
Marks both plans complete. |
docs/issues/open/1349-1347-add-tests-http-core/ISSUE.md |
Updates slice progress and baseline. |
docs/issues/open/1349-1347-add-tests-http-core/coverage-evidence.md |
Records baseline and S2 coverage. |
docs/issues/open/1349-1347-add-tests-http-core/agent-review-reports.md |
Adds review results and follow-up resolutions. |
docs/issues/open/1347-overhaul-packages-testing/EPIC.md |
Updates package progress and coverage tables. |
Cargo.lock |
Records HTTP-core’s rstest dependency. |
Review effort: Balanced
|
ACK 61c3460 Posted on behalf of @josecelano, at his instruction. Copilot reviewed this head with no open issues, all checks are green and there are no unresolved threads. @da2ce7 was requested but did not reply within 15 minutes, so the review round is considered approved without waiting longer. |
Mark slice S2 done after the merge of #2575, point the specification at the S3 branch, and log that the baseline for S3 is the final S2 measurement because packages/http-core changed on develop only through S2. Update the EPIC row. Related to #1349 Co-authored-by: Copilot <[email protected]>
|
Post-merge note: this pull request requested a review from this account and was closed without one at its final head. A post-merge review will not be done: All 1,044 executable lines it added are tests, benchmarks or test support with no production behaviour, and 1,009 of them are still present. |
Summary
Slice S2 of #1349 (tests for the
torrust-tracker-http-corepackage, EPIC #1347): the unit tests for the announce service and its error mapping. It changes test code, one dev-dependency and documentation only. Production code is unchanged: everything before the#[cfg(test)]module ofservices/announce.rsis byte-identical todevelop, andservices/error_mapping.rsonly gains a test module after the function. The remaining files follow in the slices S3-S6 of the specification, each starting after the previous one merges.Related to #1349
Parent EPIC: #1347
What this slice adds
services/announce.rs. The 8 existing tests are refactored onto a small in-file fixture, a recording event sender andrstesttables, and the approved plan adds the rest: 50 cases in total. They pin private-mode authentication (missing, unknown and registered key), public mode ignoring a key, listed mode, the order authenticate, authorize, resolve the client IP, select the peer IP and announce (each order test also asserts that no event was published and no peer registered after the early failure), peer IP selection (connection address, literalip, loopback substitution by the external IP, a client-supplied loopback literal, an emptyip), the request-to-announcement mapping,numwant, an absent event sender, the public URL in the event, a failing persisted-downloads store (throughtracker-core'sMockTorrentMetricsStore, no database) and the client-visible failure reasons. The old precedence test never gave the service an external IP, so it could not prove its name; the new one does.services/error_mapping.rs. It had no unit coverage. Onerstesttable with a case perTrackerCoreErrorvariant pins the package-owned prefix of each failure reason.rstest = "0.28.0"becomes a dev-dependency oftorrust-tracker-http-core, for the case tables. It is the latest stable version. The workspace requirement"0"used elsewhere would have locked 0.27.0 here, because Cargo reuses an existing compatible lock entry.developchangedpackages/http-coreafter S1), the two file plans with their prose-first Arrange, Act and Assert reviews and mutation results, the per-file evidence, the ledger, and the EPIC Overhaul: Packages Testing #1347 rows and both coverage tables.Evidence
cargo-llvm-cov 0.6.16, stable Rust 1.99.0, clean unit-only runs). Package lines 1,751 / 1,970 (88.88%) to 1,919 / 2,101 (91.34%), regions 90.41% to 92.45%, functions 84.29% to 89.59%, and 33 to 79 unit tests.services/announce.rsgoes from 92.85% to 99.06% of lines, and every production line, region and function of the file is covered; the uncovered lines are the failure branches ofmatches!assertions in the test module. The totals include the test modules, so the mutation results below are the stronger signal.Stoppedevent mapping, the public URL (two variants), the precedence arm, and the prefix and wrapped text of the failure reasons. Two mutants of the peer IP selection survived the first examples and were each fixed with one added example, so no property-testing dependency is added: a client-supplied loopbackipliteral replaced by the external IP, and an emptyip=that skipped the loopback substitution. The second was found by the independent review.error_mapping.rs(three lines, added by Mark public error enums #[non_exhaustive] before first publish #2454) cannot be reached:TrackerCoreErroris#[non_exhaustive]with four variants, so no code outsidetracker-corecan build a fifth. The plan records it astracker-core's to unlock. This corrects an earlier note in the spec that suggested testing it.From<TrackerCoreError> for HttpAnnounceErroris a public conversion with no caller in the repository; it is pinned by one test and kept, because removing it would be a breaking API change. That is a possible separate cleanup, not part of this issue.Review guidance
The production diff is empty, so review the tests, not the behavior. Each plan lists every test with the Arrange, Act and Assert it was written from, the mutation that proves it, and the maintainer's approval of the plan, of the R1 refactor and of each completed file. The four commits are the baseline re-measurement, one commit per file, and the fixes from the independent Task Reviewer, all kept as separate steps.
Files
packages/http-core/src/services/announce.rs(test module only)packages/http-core/src/services/error_mapping.rs(test module only)packages/http-core/Cargo.tomlandCargo.lock(rstest)docs/issues/open/1349-1347-add-tests-http-core/(ISSUE.md,coverage-evidence.md,agent-review-reports.md,test-refactor-plans/README.md,test-refactor-plans/services-announce-tests.md,test-refactor-plans/services-error-mapping-tests.md(new))docs/issues/open/1347-overhaul-packages-testing/EPIC.mdValidation
cargo test -p torrust-tracker-http-core: 79 unit tests and the 3 doc tests pass, also under--test-threads=1(the frozen clock is thread-local).cargo +nightly fmt --all -- --check,cargo clippy -p torrust-tracker-http-core --all-targets --all-features -- -D warnings,cargo machete --with-metadata,git diff --check,linter markdownandlinter cspellpass../contrib/dev-tools/git/hooks/pre-commit.sh) passed for every commit../contrib/dev-tools/git/hooks/pre-push.sh: nightly Rust format, check and docs, then the stable Rust 1.99.0 test suite) passed on the final head.MEDIUMand twoLOWfindings, all fixed; the report is inagent-review-reports.md.open-pull-requestskill prints nothing (no branch commit ids cited).develop: it changed only outsidepackages/http-coresince this branch was cut, andgit merge-treeagainst it reports no conflict.