Repository navigation
test(http-core): [#1349] pin the scrape service decisions with unit tests - #2586
Conversation
Mark slice S2 done after the merge of torrust#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 torrust#1349 Co-authored-by: Copilot <[email protected]>
… unit tests Refactor the 8 existing scrape tests onto a small in-file fixture, the recording event sender and rstest tables, then add the tests the approved file plan lists. The 8 tests become 19 cases that protect: - private-mode zeroing of every requested torrent for an unauthenticated peer, including a key that does not authenticate, and the real data for a key that does - the persisted downloads of a torrent absent from memory, read through tracker-core's MockTorrentMetricsStore instead of a SQLite database - the order scrape before client IP resolution, and no event after a failure - the remote client, binding and public URL in the published event, the reverse proxy policy, and an absent event sender - the client-visible failure reasons and the public error conversions The four duplicate event tests (two in a module named for zeroed data that used a public tracker) become one IPv4 and IPv6 table. Move the announce tests' RecordingSender into crate::tests so both files share it; the approved plan records why. Each named mutation (M1-M4) and two probes made exactly the tests named for them fail. One planned test, a public tracker ignoring a presented key, was dropped because no mutation of the file can fail it. Unit-only coverage of scrape.rs: lines 93.89% to 99.19%, functions 100%. Production code is unchanged. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
…d the S3 review The independent Task Reviewer found a mutant of handle_scrape that survived all 90 tests: the zeroed branch for an unauthenticated peer on a private tracker returning early, which skips the client IP resolution and the event. No test published an event or resolved the client IP on a private tracker, because the replacement for the old tests in the misnamed zeroed-data module was never written. Add a private-tracker event test and a private case in the unresolvable client IP table; both fail the mutant. Also: - RecordingSender now records an event when the future returned by send is polled, like the production broadcaster, so a service that drops that future publishes nothing - one test pins that an HTTP tracker not behind a reverse proxy ignores a forwarded address, which kills the always-enabled proxy mutant directly - the no-sender test asserts the scrape data Record the review in agent-review-reports.md and update the plan, the evidence, the ledger and the EPIC rows: the scrape file has 22 cases and the package 93 unit tests (lines 92.72%, regions 93.55%, functions 93.57%). Production code is unchanged. Related to torrust#1349 Co-authored-by: Copilot <[email protected]>
…ication Set related-pr to torrust#2586 and the S3 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
The test-only changes preserve production behavior, with no unresolved blocking issues identified.
No open issues 🎉
What changed in this PR
Completes slice S3 of #1349 by strengthening HTTP scrape service tests without changing production code.
Changes:
- Expands scrape coverage from 8 tests to 22 cases covering authentication, events, proxy policy, persistence and errors.
- Shares a recording event sender that records only when its future is polled.
- Updates test plans, review records and coverage evidence.
| File | Description |
|---|---|
packages/http-core/src/services/scrape.rs |
Refactors fixtures and expands scrape tests. |
packages/http-core/src/services/announce.rs |
Imports the shared recording sender. |
packages/http-core/src/lib.rs |
Adds the shared test-only sender. |
docs/issues/open/1349-1347-add-tests-http-core/test-refactor-plans/services-scrape-tests.md |
Records test design, mutations and approvals. |
docs/issues/open/1349-1347-add-tests-http-core/test-refactor-plans/README.md |
Registers the completed scrape plan. |
docs/issues/open/1349-1347-add-tests-http-core/ISSUE.md |
Updates slice status and progress. |
docs/issues/open/1349-1347-add-tests-http-core/coverage-evidence.md |
Records S3 coverage results. |
docs/issues/open/1349-1347-add-tests-http-core/agent-review-reports.md |
Records review results and follow-up fixes. |
docs/issues/open/1347-overhaul-packages-testing/EPIC.md |
Updates package progress and coverage totals. |
Review effort: Balanced
|
ACK 1b01764 Posted on behalf of @josecelano, at his instruction. Copilot reviewed this head with no open issues, all checks are green (the macOS stable job was cancelled by the runner before running any step and passed on re-run) 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 S3 done after the merge of #2586, point the specification at the S4 branch, and log that the baseline for S4 is the final S3 measurement because packages/http-core did not change on develop after the S3 head. 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 637 executable lines it added are tests, benchmarks or test support with no production behaviour, and 631 of them are still present. |
Summary
Slice S3 of #1349 (tests for the
torrust-tracker-http-corepackage, EPIC #1347): the unit tests for the scrape service. It changes test code and documentation only. Production code is unchanged: everything before the#[cfg(test)]module ofservices/scrape.rsand ofservices/announce.rsis byte-identical todevelop,lib.rsonly gains a shared test helper in its test module, and there is no manifest change. The remaining files follow in the slices S4-S6 of the specification, each starting after the previous one merges.Related to #1349
Parent EPIC: #1347
What this slice adds
services/scrape.rs. The 8 existing tests are refactored onto a small in-file fixture, the recording event sender andrstesttables, and the approved plan adds the rest: 22 cases in total. They pin private-mode zeroing of every requested torrent for an unauthenticated peer (including one whose key does not authenticate, and the real data for a registered key), the persisted downloads of a torrent absent from memory (throughtracker-core'sMockTorrentMetricsStore, no database), the order scrape before client-IP resolution, no event after a failure, the remote client, binding and public URL in the published event, the reverse-proxy policy (including a tracker that is not behind a proxy ignoring a forwarded address), an absent event sender, the client-visible failure reasons and the public error conversions.mock!double are gone.RecordingSender, the announce tests' event sender from S2, moves into the existingcrate::testsmodule so both files share it; the approved plan records why. It now records an event when the future returned bysendis polled, like the production broadcaster, so a service that drops that future publishes nothing.Evidence
cargo-llvm-cov 0.6.16, stable Rust 1.99.0, clean unit-only runs). Package lines 91.34% to 92.72% since S2 (88.88% originally), regions 92.45% to 93.55%, functions 89.59% to 93.57%, and 79 to 93 unit tests.services/scrape.rsgoes from 93.89% to 99.26% 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.AuthenticationService::authenticateaccepts any key on a public tracker, so no mutation of this file can make that test fail. The plan records this.From<WhitelistError>,From<authentication::key::Error>andFrom<TrackerCoreError>forHttpScrapeErrorhave no caller in the repository; they are public conversions pinned by one test each and kept, because removing them would be a breaking API change.Review guidance
The production diff is empty, so review the tests, not the behavior. The plan lists every test with the Arrange, Act and Assert it was written from, the mutation that proves it, and the maintainer's approvals. The commits are the S2 merge record, one commit for the file and the fixes from the independent Task Reviewer, kept as separate steps.
Files
packages/http-core/src/services/scrape.rs(test module only)packages/http-core/src/services/announce.rs(test module only: it imports the sharedRecordingSender)packages/http-core/src/lib.rs(test module only:RecordingSender)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-scrape-tests.md(new))docs/issues/open/1347-overhaul-packages-testing/EPIC.mdValidation
cargo test -p torrust-tracker-http-core: 93 unit tests and the 3 doc tests pass, also under--test-threads=1(the frozen clock of the announce tests 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 sixLOWfindings; theMEDIUMand the actionableLOWfindings are fixed, and 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.