Skip to content

test(http-core): [#1349] pin the scrape service decisions with unit tests - #2586

Merged
josecelano merged 4 commits into
torrust:developfrom
josecelano:1349-1347-add-tests-http-core-scrape
Oct 20, 2026
Merged

josecelano merged 4 commits into
torrust:developfrom
josecelano:1349-1347-add-tests-http-core-scrape

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Slice S3 of #1349 (tests for the torrust-tracker-http-core package, 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 of services/scrape.rs and of services/announce.rs is byte-identical to develop, lib.rs only 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 and rstest tables, 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 (through tracker-core's MockTorrentMetricsStore, 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.
  • Cleanup of the old tests. Four near-identical event tests, two of them in a module named for zeroed data that actually used a public tracker, become one IPv4 and IPv6 table. The real SQLite database and the mock! double are gone.
  • Shared helper. RecordingSender, the announce tests' event sender from S2, moves into the existing crate::tests module so both files share it; the approved plan records why. It 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.
  • Records. The S2 merge record, the scrape plan with its prose-first Arrange, Act and Assert review and mutation results, the per-file evidence, the ledger, the independent review report, and the EPIC Overhaul: Packages Testing #1347 rows and both coverage tables.

Evidence

  • Coverage (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.rs goes 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 of matches! assertions in the test module. The totals include the test modules, so the mutation results below are the stronger signal.
  • Mutations. Each named mutation was applied by hand, run and reverted, and each made exactly the tests named for it fail: always requiring authentication, any key authenticating, no key authenticating, resolving the client IP before the scrape, the public URL (it needs the lint cap, as the plan predicted), zeroing returning an empty set, and ignoring the reverse-proxy mode. The independent review then found a mutant that survived all 90 tests: the zeroed branch for a private tracker returning early, which skips the client-IP resolution and the event. A private-tracker event test and a private case in the unresolvable-client-IP table now kill it. It also found that the recording sender did not notice a dropped send future; that is fixed too.
  • Dropped test. The plan listed a test that a public tracker ignores a presented key. It was dropped while verifying: AuthenticationService::authenticate accepts any key on a public tracker, so no mutation of this file can make that test fail. The plan records this.
  • No bug found, so no hand-off was needed. From<WhitelistError>, From<authentication::key::Error> and From<TrackerCoreError> for HttpScrapeError have 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.
  • Process note. The plan gates the R1 refactor on a maintainer review before the new tests. R1 and R2 were coded together because the fixture serves both, and the maintainer approved the R1 result and the completed file together; the plan and the specification log say so.

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 shared RecordingSender)
  • 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.md

Validation

  • 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 markdown and linter cspell pass.
  • Pre-commit (./contrib/dev-tools/git/hooks/pre-commit.sh) passed for every commit.
  • Pre-push (./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.
  • The independent Task Reviewer passed the slice with one MEDIUM and six LOW findings; the MEDIUM and the actionable LOW findings are fixed, and the report is in agent-review-reports.md.
  • The commit-id citation check from the open-pull-request skill prints nothing (no branch commit ids cited).
  • The branch is not rebased onto the latest develop: it changed only outside packages/http-core since this branch was cut, and git merge-tree against it reports no conflict.

josecelano and others added 3 commits October 20, 2026 17:51
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]>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 17:54
…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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@josecelano

Copy link
Copy Markdown
Member Author

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.

@josecelano josecelano self-assigned this Oct 20, 2026
@josecelano
josecelano merged commit fefefdd into torrust:develop Oct 20, 2026
25 of 26 checks passed
josecelano added a commit that referenced this pull request Oct 21, 2026
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]>
@da2ce7

da2ce7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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.

This branch was previously deployed

1 inactive deployment
coverage — 1b017641 Deployed Oct 20, 2026 by josecelano via Generate Coverage Report #2645
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants