From c4f9720b3aef896646bf82978d1f156fabae40d1 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 17 Nov 2026 16:17:41 +0000 Subject: [PATCH 01/40] docs(issues): [#2902] skip merge commits in the S0 commit lookup The merge of #2903 has the same subject as the S0 commit, so the subject search found the merge commit first. Add --no-merges to the lookup in coverage-evidence.md and in the F8 and F18 verifications of the #2903 review audit (review finding F20 of #2903). Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/coverage-evidence.md | 2 +- docs/pr-reviews/pr-2903-review/PR-REVIEW.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md b/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md index 3edae1b579..5956de594f 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md @@ -31,7 +31,7 @@ The container-gated row (T1b) was measured afterwards on the S0 branch, at its c `docs(issues): [#2902] specify the tracker-core package tests`. That commit changes no file under `packages/`, so the measured source is that of `develop` at `5833cdae98c0cfe3c2523c7f17e33bcfd3d7292f`: `git diff --stat 5833cdae9 -- packages`, with -`` from `git log --format=%H --fixed-strings --grep='specify the tracker-core package tests'`, +`` from `git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests'`, prints nothing. The run followed `docker pull mysql:8.0` and `docker pull postgres:16` (the tests' default tags, `mysql/mod.rs:115` and `postgres/mod.rs:102`), with the same separate target directory: diff --git a/docs/pr-reviews/pr-2903-review/PR-REVIEW.md b/docs/pr-reviews/pr-2903-review/PR-REVIEW.md index 8417f5345a..d87cb7dcde 100644 --- a/docs/pr-reviews/pr-2903-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2903-review/PR-REVIEW.md @@ -140,7 +140,7 @@ and F19. - Source URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4599332994 - Concern: Appending the 10:57 entry after the blank line before `## Acceptance Criteria` split the progress log into a loose list. - Solution: The blank line is removed, so the entries form one tight list again. -- Current-tree verification: `git diff $(git log --format=%H --fixed-strings --grep='specify the tracker-core package tests' -1) -- docs/issues/open/1347-overhaul-packages-testing/EPIC.md` (the diff against the S0 commit `docs(issues): [#2902] specify the tracker-core package tests`) shows the removed blank line and no other change to the earlier entries. +- Current-tree verification: `git diff $(git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests' -1) -- docs/issues/open/1347-overhaul-packages-testing/EPIC.md` (the diff against the S0 commit `docs(issues): [#2902] specify the tracker-core package tests`) shows the removed blank line and no other change to the earlier entries. - Resolution reference: docs(issues): [#1347] restore the 10:57 EPIC log entry and append T1b - Follow-up PR URL: N/A - Reply URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4599797846 @@ -309,7 +309,7 @@ and F19. - Source URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4600282774 - Concern: `git diff --stat 5833cdae9 HEAD -- packages` prints nothing only while `HEAD` is on this branch; after the merge, later slices change `packages/` and the check stops holding. - Solution: `coverage-evidence.md` and F8's verification name the range by the S0 commit, found by its subject, instead of `HEAD`. -- Current-tree verification: `git diff --stat 5833cdae9 $(git log --format=%H --fixed-strings --grep='specify the tracker-core package tests' -1) -- packages | wc -l` prints 0. +- Current-tree verification: `git diff --stat 5833cdae9 $(git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests' -1) -- packages | wc -l` prints 0. - Resolution reference: docs(issues): [#2902] name the S0 commit in the unchanged-source check - Follow-up PR URL: N/A - Reply URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4600363938 From e7fe4bd97978ae991f69951c6443b27cf89294b6 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 17 Nov 2026 16:19:21 +0000 Subject: [PATCH 02/40] docs(pr-reviews): [#2902] record the post-merge finding F20 of #2903 Co-Authored-By: Claude Opus 5.5 --- docs/pr-reviews/pr-2903-review/PR-REVIEW.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/pr-reviews/pr-2903-review/PR-REVIEW.md b/docs/pr-reviews/pr-2903-review/PR-REVIEW.md index d87cb7dcde..987eccc812 100644 --- a/docs/pr-reviews/pr-2903-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2903-review/PR-REVIEW.md @@ -77,6 +77,7 @@ and F19. | F17 | review-finding:pr-2903-f17 | Copilot | Minor | metadata | ORIGINAL | FIXED | RESOLVED | | F18 | review-finding:pr-2903-f18 | Human | Nit | correctness | ORIGINAL | FIXED | RESOLVED | | F19 | review-finding:pr-2903-f19 | Human | Nit | metadata | RE_RAISE_OF:F17 | NO_ACTION | SUPERSEDED | +| F20 | review-finding:pr-2903-f20 | Human | Nit | correctness | ORIGINAL | FOLLOW_UP | OPEN | ## Finding Details @@ -327,6 +328,19 @@ and F19. - Follow-up PR URL: N/A - Reply URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4600364534 +### F20 - After the merge the S0 lookup also matched the merge commit + +- PR number: 2903 +- Source review ID: 5939722814 +- Reviewer finding ID: F20 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4600527629 +- Concern: the merge commit of #2903 has the same subject as the S0 commit, so `git log --fixed-strings --grep='specify the tracker-core package tests'` lists it first and the verifications that take `-1` compare with the merge commit instead of the S0 commit. +- Solution: the maintainer merged #2903 with the nit open (2026-11-17); the S1 branch of #2902 adds `--no-merges` to the lookup in `coverage-evidence.md` and in the F8 and F18 verifications. +- Current-tree verification: on the S1 branch, `git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests'` prints one id, the S0 commit's, and `git diff --stat 5833cdae9 -- packages | wc -l` prints 0. +- Resolution reference: docs(issues): [#2902] skip merge commits in the S0 commit lookup +- Follow-up PR URL: pending, the S1 PR of #2902 (branch `2902-1347-add-tests-tracker-core-statistics`) +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4602399913 + ## Processing Log - 2026-11-17 12:48 UTC - Started audit late: the round 1 threads (12:08:23 UTC) and round 2 threads (12:28:40 UTC) had no reply before this record; the fixes were committed first, between 12:37 and 12:46 UTC, one commit per finding (F5 and F9 share one). @@ -337,6 +351,7 @@ and F19. - 2026-11-17 13:25 UTC - Pushed the round 4 fixes and audit commits; replied to the F14-F16 threads between 13:24:53 and 13:25:01 UTC and resolved each after its reply. - 2026-11-17 13:31 UTC - Round 5 (Copilot's review `5939369230`, 13:30:51 UTC, F17) was about the head before the round 4 replies were recorded; replied at 13:31:57 UTC and resolved the thread. - 2026-11-17 13:41 UTC - Round 6 (da2ce7's review `5939412622`, 13:33:52 UTC, F18-F19): F18 fixed in its own commit and pushed; replied to both threads at 13:41:03 and 13:41:07 UTC and resolved each after its reply (F19 superseded by F17). +- 2026-11-17 16:18 UTC - Round 7 (da2ce7's review `5939722814`, 13:55:00 UTC, approval with F20): the maintainer merged #2903 with F20 open. The fix is the first commit of the S1 branch of #2902; replied at 16:18:25 UTC and left the thread open until the S1 PR exists. ## Completion Rules From 132bf562a75a0c904e359de88bfb02cb46619530 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 17 Nov 2026 16:19:55 +0000 Subject: [PATCH 03/40] docs(issues): [#2902] add the S1 plan guidance and the statistics repository plan Start S1: the shared file test plan guidance (T2) and the plan of the first ledger row, statistics/repository.rs, for the maintainer's approval. The plan proposes finding F6 (unused public gauge methods) and asks decision D1. The spec records S0 as merged and S1 in progress. Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 21 +-- .../test-refactor-plans/README.md | 115 +++++++++++++++ .../statistics-repository-tests.md | 138 ++++++++++++++++++ 3 files changed, 264 insertions(+), 10 deletions(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 0f745ab374..a489eb36fe 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -2,12 +2,12 @@ schema-version: 1 doc-type: issue issue-type: task -status: planned +status: in-progress priority: p2 epic: 1347 github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md -branch: "2902-1347-add-tests-tracker-core-spec" +branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null last-updated-utc: "2026-11-17 18:04" semantic-links: @@ -276,9 +276,9 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`, `DEFERRED`. | --- | ------ | ---- | ----------------------- | | T1 | DONE | Coverage evidence and complete module inventory | [coverage-evidence.md](coverage-evidence.md): baseline in four scopes, per-file uncovered groups, property candidacy, initial hypothesis for the 62 files. Delivered with this spec (S0). | | T1b | DONE | Measure the container-gated scope | The `--all-features` run with `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST` and `TORRUST_TRACKER_CORE_RUN_POSTGRES_DRIVER_TEST` set (images pulled with the maintainer's permission, 2026-11-17): lines 93.80%. Recorded in `coverage-evidence.md`; informs the scope of S3. | -| T2 | TODO | Shared plan guidance | `test-refactor-plans/README.md`: two-phase sequence, guardrails, toolchain-pinned commands. First test slice (S1). | +| T2 | DONE | Shared plan guidance | [`test-refactor-plans/README.md`](test-refactor-plans/README.md): two-phase sequence, guardrails, toolchain-pinned commands. First test slice (S1). | | T2b | IN_PROGRESS | Design-review checkpoint | After the first listener test and the first `TempDir`-owned SQLite test pass in S1, the maintainer reviews the fixture shape (see [Asynchronous Work, Cleanup and Test Fixtures](#asynchronous-work-cleanup-and-test-fixtures)) before other files reuse it. The SQLite half is done: the fixture shape of the [temporary-database fix](test-refactor-plans/test-support-ephemeral-database-tests.md) was approved on 2026-11-17; the listener half comes with S1. | -| T3 | TODO | Process every ledger row through the per-file workflow | Each row ends in exactly one of: test added, no-change with reason, deferred with owner. | +| T3 | IN_PROGRESS | Process every ledger row through the per-file workflow | Each row ends in exactly one of: test added, no-change with reason, deferred with owner. | | T4 | TODO | Bounded mutation assessment | `mutation-evidence.md`: configuration, survivors, reason for each unviable mutant. Last slice. | | T5 | TODO | Reconcile evidence and progress state | Ledger, records, slice table, acceptance rows and both EPIC coverage tables agree; grep for `status: proposed` and stray `TODO` labels in finished records. | | T6 | TODO | Final verification, acceptance review, retrospective | Automatic checks, manual verification, acceptance review, `implementation-retrospective.md` (or a log entry saying none was needed). | @@ -292,8 +292,8 @@ is the proposal for the maintainer's approval (questions Q5, Q6): | Slice | Content | Ledger rows | Branch | PR | Status | | --- | --- | --- | --- | --- | --- | -| S0 | This specification, the T1 evidence, and the EPIC registration with the baseline | - | `2902-1347-add-tests-tracker-core-spec` | TBD | IN_PROGRESS | -| S1 | T2, then `statistics/`: `repository.rs`, `metrics.rs`, `persisted/mod.rs`, `persisted/downloads.rs`, `event/listener.rs`, `event/handler.rs`, `mod.rs` (the only area reached just by the integration binary) | 1-7 | `2902-1347-add-tests-tracker-core-statistics` | TBD | TODO | +| S0 | This specification, the T1 evidence, and the EPIC registration with the baseline | - | `2902-1347-add-tests-tracker-core-spec` | #2903 | DONE | +| S1 | T2, then `statistics/`: `repository.rs`, `metrics.rs`, `persisted/mod.rs`, `persisted/downloads.rs`, `event/listener.rs`, `event/handler.rs`, `mod.rs` (the only area reached just by the integration binary) | 1-7 | `2902-1347-add-tests-tracker-core-statistics` | TBD | IN_PROGRESS | | S2 | The SQLite persistence boundary: `sqlite/{auth_key_store,torrent_metrics_store,whitelist_store,mod,schema_migrator}.rs`, `databases/{error,setup}.rs`, `error.rs`, plus the `databases/traits` and `driver/mod.rs` no-change decisions | 8-17 | `2902-1347-add-tests-tracker-core-sqlite` | TBD | TODO | | S3 | MySQL and PostgreSQL drivers: assess after T1b; Docker-free error-path tests if non-flaky, otherwise no-change rows with the `db-compatibility` workflow as owner | 18-27 | `2902-1347-add-tests-tracker-core-server-drivers` | TBD | TODO | | S4 | Authentication and whitelist: failing-`Database` propagation, `Key` property decision (F3, F4 checks) | 28-39 | `2902-1347-add-tests-tracker-core-auth-whitelist` | TBD | TODO | @@ -347,7 +347,7 @@ rows are ordered by slice, then by risk. | Order | Source module | Slice | Unit-only lines | Initial hypothesis | State | | ---: | --- | --- | ---: | --- | --- | -| 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | PENDING | +| 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | IN_PROGRESS | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate | PENDING | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`) | PENDING | | 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | PENDING | @@ -394,9 +394,9 @@ The first slice's record checks the grouping against `find packages/tracker-core - [x] Read EPIC #1347, the subissue guidelines, the `create-issue` workflow and the closed specs of #1348, #1349, #2637 and #2824. - [x] Clean baseline coverage measured in four scopes and the complete module inventory recorded (T1). -- [ ] Specification and slicing reviewed and approved by the maintainer. -- [x] GitHub issue #2902 created. Linking it as a subissue of #1347 needs the maintainer (the bot account gets 404 from the sub-issues API). -- [ ] Spec-only PR (S0) merged before implementation. +- [x] Specification and slicing reviewed and approved by the maintainer (#2903 merged, 2026-11-17). +- [x] GitHub issue #2902 created and linked as a subissue of #1347 by the maintainer. +- [x] Spec-only PR (S0) merged before implementation (#2903). - [x] Container-gated scope measured (T1b) with the maintainer's permission. - [ ] Every ledger row `DONE` with a decision record, merged through its slice. - [ ] Maintainer review after the final test-producing increment. @@ -412,6 +412,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-17 10:57 UTC - Claude Code (Sonnet 5.5) - Created issue #2902; measured the baseline at `5833cdae9` in four scopes; drafted this specification and the coverage evidence; registered the subissue in EPIC #1347 (row 14). Open questions Q1-Q6 are for the maintainer. - 2026-11-17 12:16 UTC - Claude Code (Sonnet 5.5) - The maintainer allowed the Docker image pull (Q1); T1b measured the container-gated scope: lines 93.80% (server drivers 58-96% per file). No review of #2903 arrived within 60 minutes. - 2026-11-17 12:45 UTC - Claude Code (Opus 5.5) - Correction of the 12:16 UTC entry above: its last sentence is wrong as written. The poller I started right after the PR opened (11:05:26 UTC) timed out after its 60-minute wait with no review, but Cameron (`da2ce7`) had submitted a review of `690cfb5f5` with findings F1-F6 at 12:08:23 UTC, before that entry was written, and the six threads had no reply. A second review of `2b0c3fe36` (F7-F10) followed at 12:28:40 UTC. The ten findings are processed in `docs/pr-reviews/pr-2903-review/PR-REVIEW.md` (review finding F7 of #2903). +- 2026-11-17 16:16 UTC - Claude Code (Opus 5.5) - S0 merged (#2903); the maintainer linked #2902 to #1347 and said to start S1. S1 baseline: no file under `packages/` changed since the measured commit and the unit-only run gives the same 80.31% (4,099 / 5,104 lines). T2 done ([guidance](test-refactor-plans/README.md)). First plan proposed: [`statistics/repository.rs`](test-refactor-plans/statistics-repository-tests.md), which proposes finding F6 (unused public gauge methods) and asks decision D1. Questions Q2-Q7 still wait for the maintainer; Q7 decides the first S1 commit. - 2026-11-17 18:04 UTC - Claude Code (Opus 5.5) - F5 fixed for this package in its own PR, split from S1 at the maintainer's request because #2907 (EPIC #2392) plans the same fix for the shared helper: a full `cargo test -p torrust-tracker-core --all-features` leaves 0 `data_*.db` files (72 before). The maintainer approved the shape (a struct with a private `TempDir`, owned by the test), the scope (all six sources in the package) and the completed change. S1 continues on its own branch. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md new file mode 100644 index 0000000000..559f52af95 --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -0,0 +1,115 @@ +--- +doc-type: test-refactor-plan-guidance +issue: 2902 +package: torrust-tracker-core +status: in-progress +--- + +# Tracker Core File Test Plan Guidance + +This folder holds one **file test plan** per Rust source file in `packages/tracker-core/src/` that +needs one (`-tests.md`, with `/` replaced by `-`, for example +`statistics-repository-tests.md`). The workflow, the two maintainer gates, the commit points, the +slices and the processing order are defined once in +[ISSUE.md: Per-File Workflow](../ISSUE.md#per-file-workflow), the +[Pull-Request Slices](../ISSUE.md#pull-request-slices) and the +[Source File Ledger](../ISSUE.md#source-file-ledger); do not repeat them here. The +[coverage evidence](../coverage-evidence.md) holds the numbers, the uncovered line groups and the +T1 hypothesis of each file. + +Create a plan right before starting its file, never in advance, so that each plan learns from the +previous ones. A plan authorizes neither test changes nor work on another file until the maintainer +approves it. A group of declaration-only files may share one plan. + +## Plans + +| Plan sequence | Plan | State | Result | +| ---: | --- | --- | --- | +| 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | PROPOSED | Waiting for the maintainer's approval | + +Add a row when a plan is created; the remaining files and their order are in the ledger. + +## The Two-Phase Sequence + +Each file goes through the same two phases, with a maintainer gate after each: + +1. **Plan:** write the plan (current state, review of the existing tests, uncovered lines grouped by + behavior and classified, property-test decision, named mutations, steps). Stop for approval. +2. **Tests:** apply the approved steps (R1 refactor existing tests, R2 add unit tests, R3 the + integration increment, R4 measure), fill the prose-first AAA review and the results. Stop for + the completed-file review, then commit the file alone. + +## Shared Guardrails + +- Unit-only coverage (`--all-features --lib`) is the primary metric. A package integration test + needs a recorded reason that the public-API boundary is clearer or necessary. +- Do not add tests only for coverage, and do not test what another package owns: the metric + collection rules (`torrust-metrics`), the swarm registry and its events + (`swarm-coordination-registry`), the drain of queued events (`torrust-tracker-events`), the + clock (`torrust-clock`), or the configuration parsing (`torrust-tracker-configuration`). +- Judge existing tests against the `write-unit-test` skill (names `it_should_*`, visible AAA, + state-centred Arrange, one reason to fail, no production-derived expectations, no hidden Act or + fixture coupling, no logic or loops in the test). List the concrete smells in the plan; "clean" is + also a recorded conclusion. +- Never write a test that pins behavior a finding reports as wrong without a recorded maintainer + decision. Follow the [findings procedure](../ISSUE.md#findings-during-implementation); the open + findings F1 to F5 are in the [register](../ISSUE.md#findings-register). +- Asynchronous work and cleanup follow + [Asynchronous Work, Cleanup and Test Fixtures](../ISSUE.md#asynchronous-work-cleanup-and-test-fixtures): + a test that spawns a listener cancels it and awaits its `JoinHandle` under a 5 second + `tokio::time::timeout` that names the operation; a test that opens a SQLite file owns it in a + `tempfile::TempDir`; no test sleeps a fixed time to wait for a result. The first listener test + and the first `TempDir`-owned SQLite test stop at the design-review checkpoint T2b. +- Property-based tests are tried only where the plan names a natural property and kept only when + they protect state that examples miss; otherwise the plan records why examples suffice (Q5). +- Every added or materially changed test gets a **Prose-First AAA Review** row in its plan before + the completed-file review: temporary Arrange, Act and Assert prose, compared with the code, and + the outcome. +- Named mutations are temporary hand-made changes, each applied alone and reverted exactly. A + mutant that leaves an import or a variable unused does not compile under `unused = "deny"`; redo + it so that it compiles. +- New dev-dependencies follow the `add-rust-dependency` skill (latest stable version, minimal + features, rationale in the plan that needs them) and pass `cargo machete --with-metadata`. + +## Commands + +Use stable Rust for tests and coverage and the nightly toolchain for formatting only; record the +toolchain with every result. The S1 baseline used stable Rust 1.99.1 and `cargo-llvm-cov 0.6.16`. + +```bash +# Focused tests +cargo test -p torrust-tracker-core --all-features --lib + +# Unit-only coverage, in a separate target directory, after a clean +export CARGO_LLVM_COV_TARGET_DIR="$PWD/.tmp/llvm-cov-target" +cargo llvm-cov clean --workspace +cargo llvm-cov --package torrust-tracker-core --all-features --lib --json --output-path .tmp/cov/unit.json + +# Formatting, lints and whitespace +cargo +nightly fmt --all -- --check +cargo clippy -p torrust-tracker-core --all-targets --all-features +git diff --check + +# After changing these records +linter markdown +linter cspell +``` + +The other scopes (integration-only, aggregate, `--lib` without the feature and the container-gated +scope) are measured at the start and the end of each slice with the commands in +[coverage-evidence.md](../coverage-evidence.md). + +## Testing Lessons Carried From #2637, #1348 And #1349 + +- Re-check an "untestable" path against the exported test doubles (the `testing` feature's mocks) + and the derives before recording it as untestable. +- Assert whole values against literals written in the test, never against values computed by the + production code under test. +- Re-measure the package at the start of every slice and compare it with the previous baseline, + because `develop` moves under the work. + +## Reconciliation + +Before final verification, reconcile every plan state with the ledger, `coverage-evidence.md` and +EPIC #1347. Do not cite branch SHAs as evidence until the implementation is merged; cite unique +Conventional Commit subjects instead. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md new file mode 100644 index 0000000000..23928fb4a4 --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md @@ -0,0 +1,138 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/repository.rs +status: proposed +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/repository.rs + - packages/tracker-core/src/statistics/metrics.rs + - packages/tracker-core/src/statistics/mod.rs + - packages/tracker-core/src/statistics/persisted/mod.rs + - packages/tracker-core/src/statistics/event/handler.rs + - docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md +--- + +# Statistics Repository File Test Plan + +Follow the shared [guidance](README.md). This plan covers only +`packages/tracker-core/src/statistics/repository.rs`, ledger row 1, the first file of S1. + +## Current State + +- **Unit-only coverage:** 86 / 140 lines (61.43%), 117 / 172 regions, 22 / 29 functions, at the S1 + baseline (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, clean workspace, + `--all-features --lib`, 2026-11-17). It is the T1 figure: no file under `packages/` changed + between the measured commit and the S1 branch point. +- **Uncovered lines** (as `cargo-llvm-cov` reports them): 104 (the error arm of + `increment_counter`), 114-120 (the entry of `set_counter`), 139-158 (`set_gauge`), 164-182 + (`increment_gauge`) and 188-206 (`decrement_gauge`). The async bodies make the per-line split + of `set_counter` unreliable, so the decisions below are per behavior, not per line. +- **Existing tests:** 2 in the file: the persisted counter is omitted when persisted statistics are + disabled, and it is exported at zero when they are enabled. The handler tests + (`event/handler.rs`) reach `increment_counter` and the three `get_torrents_downloads_*` readers. +- **Module-owned decisions:** + - Each of the five write operations takes the write lock, delegates to the metric collection, + releases the lock, logs an error when the collection refuses the write, and returns the + collection's result unchanged. + - The three readers answer the value of one unlabeled counter, and `0` when that counter is not + in the collection (`map_or(0, ...)`), for example the persisted counter when persisted + statistics are disabled. + - Owned elsewhere: which metrics exist at start-up (`describe_metrics` in `statistics/mod.rs`, + row 7), the collection rules, including when a write is refused (`torrust-metrics`: a name + already used by a metric of the other type gives `Error::MetricNameCollisionAdding`), and the + thin `Metrics` wrapper (row 2). +- **Callers:** in this package, `increment_counter` (event handler) and `set_counter` (startup + load, `persisted/mod.rs`). `set_gauge`, `increment_gauge` and `decrement_gauge` have no caller in + the workspace, and the package describes no gauge (see the finding below). +- **T1 hypothesis:** test candidate (four counter and gauge methods and their error arms). + +## Finding Proposed: F6 + +`Repository::set_gauge`, `increment_gauge` and `decrement_gauge` are public but unused: no gauge is +described by `describe_metrics` and no code in the workspace calls them (`grep -rn` over +`packages/` and `src/`, 2026-11-17). Removing them is a public-API change of a published crate, +so it is not done here. Proposed register entry: F6, handed to a separate issue if the maintainer +wants them removed. + +## Maintainer Decisions + +None yet. The plan asks for one decision (D1): + +- **D1:** test the three unused gauge methods as public API (recommended: they are part of the + published crate API and the tests are three small cases; a removal issue would delete them with + the methods), or leave them uncovered with F6 as their owner. + +## Current Tests Review + +Both existing tests are **clean**: `it_should_*` names, visible AAA, literal expectations, one +reason to fail each. One smell in the first test: it asserts three booleans with three `assert!` +calls, so a failure names only the line, not the metric. R1 replaces them with one `assert_eq!` +on the tuple against `(true, true, false)`, which prints all three values on failure. + +## Coverage And Decision Analysis + +| Behavior group | Lines | Classification | Decision | +| --- | --- | --- | --- | +| `increment_counter` refused by the collection | 104 | unit | R2: increment a name that is already a gauge; the result is `Err(MetricNameCollisionAdding)` with that name, and the gauge is unchanged. | +| `set_counter` success | 114-120 | unit | R2: set the persisted counter to `7` in a repository with persisted statistics enabled; `get_torrents_downloads_persisted_total` reads `7`. | +| `set_counter` refused | 129 | unit | R2: set a name that is already a gauge; `Err(MetricNameCollisionAdding)`. | +| `set_gauge` success and refusal | 139-158 | unit (D1) | R2: set a new gauge to `2.5` and read it back from the collection; set the deprecated persistent counter's name as a gauge and get `Err(MetricNameCollisionAdding)`, with the counter still `0`. | +| `increment_gauge` success and refusal | 164-182 | unit (D1) | R2: from `2.5` to `3.5`; the counter-name case is refused as above. | +| `decrement_gauge` success and refusal | 188-206 | unit (D1) | R2: from `2.5` to `1.5`; the counter-name case is refused as above. | +| Reader of an absent counter | covered | unit | R2: with persisted statistics disabled, `get_torrents_downloads_persisted_total` answers `0`. The line is reached today but its result is not asserted; this pins the `map_or(0, ...)` decision. | +| The `tracing::error!` messages | the five error arms | not asserted | The log text is diagnostic, not a contract; the error value returned is asserted instead. | +| Lock release before logging (`drop(stats_lock)`) | covered | not tested | Not observable from a single-task test: the guard is dropped at the end of the function anyway. | +| When the collection refuses a write, and the values it holds | - | collaborator-owned | `torrust-metrics` has its own tests for each collision; these tests only prove that the repository returns the refusal unchanged and keeps the earlier value. | + +## Test Design + +- **Location:** the existing `#[cfg(test)] mod tests` of `repository.rs`. +- **Arrange:** `Repository::new(true, true)` (or `new(true, false)` for the absent-counter case). + The refusal of a counter write needs a gauge in the collection; the test creates one with + `set_gauge` in its Arrange and asserts that call succeeded, so a broken `set_gauge` fails in the + Arrange with its own message instead of pretending to be a counter failure. +- **Fixed time:** `DurationSinceUnixEpoch::from_secs(0)`, a literal; no clock. +- **Reading back:** the counter readers for counters; `read_metrics` with + `metric_collection().get_gauge_value(...)` for gauges, compared as `Option`. +- **Error assertion:** `matches!(result, Err(Error::MetricNameCollisionAdding { metric_name }) if + metric_name == metric_name!("..."))`, the pattern of the `torrust-metrics` tests. +- **Shape:** one test per operation and outcome, about ten small tests, no loops and no table + helper. A table over the five operations would need a closure per operation, which hides the Act. +- **Asynchronous work:** none spawned; `#[tokio::test]` only because the methods are `async`. +- **Dependencies:** none new. + +## Property-Test Decision + +Not selected. The candidate property (incrementing `n` times reads `n`) belongs to the collection +(`torrust-metrics`); the repository only delegates, so examples prove the delegation. + +## Named Mutations + +| ID | Site | Temporary change | Expected killer | +| --- | --- | --- | --- | +| M1 | `increment_counter` | Return `Ok(())` instead of `result`. | the counter-on-gauge refusal test | +| M2 | `set_counter` | Call `stats_lock.increment_counter(...)` instead of `set_counter` (value ignored). | the `set_counter` success test (reads `1`, not `7`) | +| M3 | `set_gauge` | Return `Ok(())` instead of `result`. | the `set_gauge` refusal test | +| M4 | `increment_gauge` | Call `decrement_gauge` instead. | the `increment_gauge` success test | +| M5 | `decrement_gauge` | Call `increment_gauge` instead. | the `decrement_gauge` success test | +| M6 | `get_counter_value` | `map_or(1, ...)` instead of `map_or(0, ...)`. | the absent-counter test | +| M7 | `get_torrents_downloads_persisted_total` | Read the in-session counter instead. | the `set_counter` success test | + +## Steps + +| ID | Status | Work | Completion evidence | +| --- | --- | --- | --- | +| R1 | TODO | Replace the three `assert!` calls of the first existing test with one tuple `assert_eq!`. | Focused tests pass. | +| R2 | TODO | Add the tests of the analysis table (the gauge ones only if D1 says so). | Focused tests, `cargo +nightly fmt --all -- --check`, `cargo clippy`, `git diff --check`, the prose-first AAA review, and the named mutations. | +| R3 | TODO | Integration increment: none expected; the integration binary reaches this file through the event handler. | Recorded here. | +| R4 | TODO | Re-run unit-only coverage; record before and after. | Results below and `coverage-evidence.md`. | + +## Prose-First AAA Review + +Filled in R2, before the completed-file review. + +## Results + +Filled in R4. From 0a06dd36470d56bf74eb034763d84cec7f99060d Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 17 Nov 2026 17:13:52 +0000 Subject: [PATCH 04/40] docs(issues): [#2902] record the maintainer's answers to Q2-Q7 and D1 Q2 after reading the code: the driver suites skip by design and db-compatibility.yaml runs them; S3 fixes the driver-test commands in the docs and a separate issue takes the visible skip and the published coverage. Q3 Docker-free S3, Q4 extract parse_valid_until in S2, Q5 quickcheck where natural, Q6 six slices, Q7 fix the temporary SQLite files in S1. F6 records the unused public gauge methods (D1: tested in S1). The statistics repository plan is approved. Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 19 ++++++++++--------- .../test-refactor-plans/README.md | 2 +- .../statistics-repository-tests.md | 15 ++++++--------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index a489eb36fe..3a5da72997 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -262,11 +262,12 @@ proposal for the maintainer unless its status says otherwise. | ID | Finding | Evidence | Proposed owner | Status | | --- | --- | --- | --- | --- | -| F1 | `run_mysql_driver_tests` and `run_postgres_driver_tests` return `Ok(())` immediately when `TORRUST_TRACKER_CORE_RUN_*_DRIVER_TEST` is unset, so `cargo test --all-features` reports them as passed without running anything, and the coverage runs count both drivers as 0-4% covered. A reader of a green run cannot tell. | `databases/driver/mysql/mod.rs:204-207`, `postgres/mod.rs:185-188`; the unit-only coverage log reports both tests `ok` in a 157-test run that finished in 0.13 s, and the run with the variables set took 9.32 s | A separate test-design issue: make the skip visible (`#[ignore = "..."]`, or a loud skip message) and keep the `db-compatibility` workflow as it is. Not part of this issue (Q2). | OPEN (proposed) | -| F2 | The row-to-`PeerKey` mapping and `parse_valid_until` (negative timestamp to `MalformedDatabaseRecord`) are copied in the SQLite, MySQL and PostgreSQL `auth_key_store.rs`; the `u32` conversion of the aggregate metric is copied likewise. A test of the SQLite copy protects none of the others, and Docker-less tests cannot reach the MySQL and PostgreSQL copies. | `parse_valid_until` is identical in the three files (MySQL and PostgreSQL lines 119-125, SQLite lines 122-128) | A refactor issue extracting one helper (Q4); until then each driver's copy is assessed in its own record. | OPEN (proposed) | +| F1 | `run_mysql_driver_tests` and `run_postgres_driver_tests` return `Ok(())` immediately when `TORRUST_TRACKER_CORE_RUN_*_DRIVER_TEST` is unset, so a local `cargo test --all-features` (and the Testing, coverage and container-build runs) reports them as `ok` without running anything; the skip notice is only a `tracing::info!` line. **This is by design, not a gap in CI:** `.github/workflows/db-compatibility.yaml` sets the variables and runs both suites on every change under `packages/tracker-core/`, against MySQL 8.0 and 8.4 and PostgreSQL 14 to 17; the gate keeps Docker out of the container-image build, which runs the unit tests (`packages/tracker-core/README.md`). What remains: (1) the README and `packages/AGENTS.md` commands omit `--features db-compatibility-tests` (without it the test module is not compiled, so they run nothing) and name only MySQL; (2) a skipped run reads as passed; (3) the published coverage (`coverage.yaml`) leaves the drivers out. | `databases/driver/mysql/mod.rs:204-207`, `postgres/mod.rs:185-188`, `.github/workflows/db-compatibility.yaml`, `packages/tracker-core/README.md` (Testing), `packages/AGENTS.md` (Testing Packages); the unit-only coverage log reports both tests `ok` in a 157-test run that finished in 0.13 s, and the run with the variables set took 9.32 s | Q2 answered: (1) fixed in S3 (documentation only); (2) and (3) handed to a separate issue (visible skip, for example `#[ignore = "..."]` with the workflow running `-- --ignored`, and the driver coverage in the published report). | DECIDED: (1) S3, (2)-(3) separate issue (to open) | +| F2 | The row-to-`PeerKey` mapping and `parse_valid_until` (negative timestamp to `MalformedDatabaseRecord`) are copied in the SQLite, MySQL and PostgreSQL `auth_key_store.rs`; the `u32` conversion of the aggregate metric is copied likewise. A test of the SQLite copy protects none of the others, and Docker-less tests cannot reach the MySQL and PostgreSQL copies. | `parse_valid_until` is identical in the three files (MySQL and PostgreSQL lines 119-125, SQLite lines 122-128) | Q4 answered: extract `parse_valid_until` into one shared function (taking the driver) in S2 and test it once; the plan of `sqlite/auth_key_store.rs` decides whether the row mapping follows. | DECIDED: S2 | | F3 | `authentication::key::Key` derives `Deserialize` over its inner `String`, so deserializing a key skips the 32-character, ASCII-alphanumeric validation of `Key::new`. To confirm in the `peer_key.rs` record: where (if anywhere) a `Key` is deserialized from untrusted input (REST path and JSON are the candidates). | `authentication/key/peer_key.rs:127` | Confirm first; if reachable, a bug issue under `fix-bug`. | TO CONFIRM | | F4 | `PersistedWhitelist::add` and `remove` read `is_info_hash_whitelisted` and then write, without a transaction; two concurrent adds of the same hash can reach the driver's duplicate-insert error that `it_should_fail_trying_to_add_the_same_infohash_twice` shows is an error. Probably benign (the in-memory whitelist is the read path), but the behavior is unspecified. | `whitelist/repository/persisted.rs:29-54` | Confirm with a throwaway test in the whitelist record; at most a documentation or small fix issue. | TO CONFIRM | | F5 | `ephemeral_sqlite_database()` (`packages/test-helpers/src/configuration.rs:85`) returns a bare `PathBuf` under `env::temp_dir()` with no cleanup owner. In this package it is called directly by `src/test_helpers.rs`, three other source files (`databases/driver/sqlite/mod.rs`, `sqlite/schema_migrator.rs`, `authentication/key/repository/persisted.rs`) and `tests/common/fixtures.rs`, and indirectly through `test_helpers::ephemeral_configuration` by most test modules that open a database, so every run leaves `data_*.db` files behind, the leak #2637 fixed for its own package in its S5. | Code reading, 2026-11-17 (review finding F1 of #2903); `grep -rn ephemeral_sqlite_database packages/tracker-core` | Q7 answered: fixed in this package with a `TempDir` guard owned by the test, in its own PR (split from S1 because #2907 planned the shared fix, which #2924 and #2925 (EPIC #2392) now take for the shared helper and the other packages). New tests never use the helper without a cleanup owner. | FIXED ([plan](test-refactor-plans/test-support-ephemeral-database-tests.md)): 0 files after a run, 72 before | +| F6 | `statistics::repository::Repository::set_gauge`, `increment_gauge` and `decrement_gauge` (and the `Metrics` wrappers they call) are public but unused: `describe_metrics` describes no gauge and no code in the workspace calls them. | `grep -rn` over `packages/` and `src/`, 2026-11-17 ([repository plan](test-refactor-plans/statistics-repository-tests.md)) | D1 answered: tested as public API in S1 while they exist; removing them is a breaking change for a separate issue if wanted. | DECIDED: tested in S1 | ## Implementation Plan @@ -294,8 +295,8 @@ is the proposal for the maintainer's approval (questions Q5, Q6): | --- | --- | --- | --- | --- | --- | | S0 | This specification, the T1 evidence, and the EPIC registration with the baseline | - | `2902-1347-add-tests-tracker-core-spec` | #2903 | DONE | | S1 | T2, then `statistics/`: `repository.rs`, `metrics.rs`, `persisted/mod.rs`, `persisted/downloads.rs`, `event/listener.rs`, `event/handler.rs`, `mod.rs` (the only area reached just by the integration binary) | 1-7 | `2902-1347-add-tests-tracker-core-statistics` | TBD | IN_PROGRESS | -| S2 | The SQLite persistence boundary: `sqlite/{auth_key_store,torrent_metrics_store,whitelist_store,mod,schema_migrator}.rs`, `databases/{error,setup}.rs`, `error.rs`, plus the `databases/traits` and `driver/mod.rs` no-change decisions | 8-17 | `2902-1347-add-tests-tracker-core-sqlite` | TBD | TODO | -| S3 | MySQL and PostgreSQL drivers: assess after T1b; Docker-free error-path tests if non-flaky, otherwise no-change rows with the `db-compatibility` workflow as owner | 18-27 | `2902-1347-add-tests-tracker-core-server-drivers` | TBD | TODO | +| S2 | The SQLite persistence boundary: `sqlite/{auth_key_store,torrent_metrics_store,whitelist_store,mod,schema_migrator}.rs`, `databases/{error,setup}.rs`, `error.rs`, the extraction of `parse_valid_until` (Q4), plus the `databases/traits` and `driver/mod.rs` no-change decisions | 8-17 | `2902-1347-add-tests-tracker-core-sqlite` | TBD | TODO | +| S3 | MySQL and PostgreSQL drivers: Docker-free error-path tests if non-flaky, otherwise no-change rows with the `db-compatibility` workflow as owner (Q3); the README and `packages/AGENTS.md` driver-test commands (Q2) | 18-27 | `2902-1347-add-tests-tracker-core-server-drivers` | TBD | TODO | | S4 | Authentication and whitelist: failing-`Database` propagation, `Key` property decision (F3, F4 checks) | 28-39 | `2902-1347-add-tests-tracker-core-auth-whitelist` | TBD | TODO | | S5 | `torrent/`, `announce_handler.rs`, `scrape_handler.rs`, `container.rs`, `lib.rs`, `test_helpers.rs`, `peer_tests.rs`, then T4-T6; updates the EPIC tables; the spec moves to `docs/issues/closed/` in a separate `cleanup-completed-issues` PR after the issue closes | 40-45 | `2902-1347-add-tests-tracker-core-final` | TBD | TODO | @@ -422,11 +423,11 @@ Each has a recommendation; the maintainer decides. | ID | Question | Recommendation | | --- | --- | --- | | Q1 | May the agent pull the `mysql` and `postgres` Docker images (hundreds of MB) to measure the container-gated scope (T1b)? | ANSWERED: yes (maintainer, 2026-11-17); measured. | -| Q2 | The two database suites skip themselves silently (F1). Is the visible-skip fix in scope here? | No: separate issue; this one only records the scope separately. | -| Q3 | Scope of S3 for the MySQL and PostgreSQL drivers? | Docker-free unit tests only for what needs no server (an unreachable endpoint gives `ConnectionError`), if they are not flaky or slow; the happy path stays with the `db-compatibility` workflow, recorded as owner. | -| Q4 | Extract the duplicated `parse_valid_until` and row mapping (F2)? | Separate refactor issue after this one; tests per driver meanwhile. | -| Q5 | Is `quickcheck` acceptable for `Key` and the expiry bounds, as in #2824 and #1348? | Decide in the `peer_key.rs` and `key/mod.rs` records; add only if examples leave a surviving mutant. | -| Q6 | Is the six-slice plan (S0-S5) right, or should S4 and S5 merge? | Keep six: S4 and S5 are mostly failing-fake cases and no-change decisions; merging them mixes a risky area with the closing tasks. | +| Q2 | The two database suites skip themselves when their variables are unset (F1). Is a fix in scope here? | ANSWERED (maintainer, 2026-11-17), after reading the code: the skip is by design and `db-compatibility.yaml` runs both suites. Fix the README and `packages/AGENTS.md` commands in S3; open a separate issue for the visible skip and the driver coverage in the published report. | +| Q3 | Scope of S3 for the MySQL and PostgreSQL drivers? | ANSWERED (maintainer, 2026-11-17): Docker-free unit tests only for what needs no server (configuration mapping, an unreachable endpoint gives `ConnectionError`), kept only if fast and not flaky; the happy path stays with `db-compatibility.yaml`, recorded as owner. | +| Q4 | Extract the duplicated `parse_valid_until` and row mapping (F2)? | ANSWERED (maintainer, 2026-11-17): extract `parse_valid_until` in this issue, in S2, and test the shared function once (recommendation was a separate refactor issue). | +| Q5 | Is `quickcheck` acceptable for `Key` and the expiry bounds, as in #2824 and #1348? | ANSWERED (maintainer, 2026-11-17): use it wherever a file has a natural property (for example `parse_valid_until`, the `Key` round trip, the expiry bounds), next to the examples; the dev-dependency is added by the first plan that needs it (recommendation was only when examples leave a surviving mutant). | +| Q6 | Is the six-slice plan (S0-S5) right, or should S4 and S5 merge? | ANSWERED (maintainer, 2026-11-17): keep six. | | Q7 | The temporary SQLite files the existing tests leave behind (F5): fix them here or hand them off? | ANSWERED (maintainer, 2026-11-17): fix here, package-local, with the package's helpers returning a `TempDir` guard with the configuration; the shared `test-helpers` function and the other packages are #2924 and #2925. Delivered in its own PR, split from S1 on the maintainer's request. | Which EPIC row is the "unit-only" baseline? Recommendation: `--all-features --lib` (80.31%), the same diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 559f52af95..d286c6156f 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -25,7 +25,7 @@ approves it. A group of declaration-only files may share one plan. | Plan sequence | Plan | State | Result | | ---: | --- | --- | --- | -| 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | PROPOSED | Waiting for the maintainer's approval | +| 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | IN_PROGRESS | Approved 2026-11-17 (D1: test the unused gauge methods) | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md index 23928fb4a4..934d0fcff8 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/repository.rs -status: proposed +status: in-progress semantic-links: related-artifacts: - packages/tracker-core/src/statistics/repository.rs @@ -48,21 +48,18 @@ Follow the shared [guidance](README.md). This plan covers only the workspace, and the package describes no gauge (see the finding below). - **T1 hypothesis:** test candidate (four counter and gauge methods and their error arms). -## Finding Proposed: F6 +## Finding F6 `Repository::set_gauge`, `increment_gauge` and `decrement_gauge` are public but unused: no gauge is described by `describe_metrics` and no code in the workspace calls them (`grep -rn` over `packages/` and `src/`, 2026-11-17). Removing them is a public-API change of a published crate, -so it is not done here. Proposed register entry: F6, handed to a separate issue if the maintainer -wants them removed. +so it is not done here. Recorded as F6 in the register. ## Maintainer Decisions -None yet. The plan asks for one decision (D1): - -- **D1:** test the three unused gauge methods as public API (recommended: they are part of the - published crate API and the tests are three small cases; a removal issue would delete them with - the methods), or leave them uncovered with F6 as their owner. +The maintainer approved the plan on 2026-11-17, with decision D1: test the three unused gauge +methods as public API while they exist (F6 records them as unused; removal would be a separate +issue). ## Current Tests Review From f3e70fa52b30132587dd48b4d504c30383705e18 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 17 Nov 2026 17:18:32 +0000 Subject: [PATCH 05/40] test(tracker-core): [#2902] cover the statistics repository writes and readers Ledger row 1 of S1. Add unit tests for the five write methods of statistics::repository::Repository (success, and the name collision the metric collection returns unchanged) and for a counter that is not in the collection reading as zero; one existing test asserts its three values as one tuple. The file goes from 86/140 to 277/277 lines (unit-only); all seven named mutations are killed. Plan and results in test-refactor-plans/statistics-repository-tests.md. Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 2 +- .../test-refactor-plans/README.md | 2 +- .../statistics-repository-tests.md | 57 ++++- .../tracker-core/src/statistics/repository.rs | 204 +++++++++++++++++- 4 files changed, 251 insertions(+), 14 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 3a5da72997..87605aa890 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -348,7 +348,7 @@ rows are ordered by slice, then by risk. | Order | Source module | Slice | Unit-only lines | Initial hypothesis | State | | ---: | --- | --- | ---: | --- | --- | -| 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | IN_PROGRESS | +| 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | DONE | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate | PENDING | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`) | PENDING | | 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | PENDING | diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index d286c6156f..4401818d64 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -25,7 +25,7 @@ approves it. A group of declaration-only files may share one plan. | Plan sequence | Plan | State | Result | | ---: | --- | --- | --- | -| 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | IN_PROGRESS | Approved 2026-11-17 (D1: test the unused gauge methods) | +| 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | DONE | Approved 2026-11-17 (D1: test the unused gauge methods); completed file approved 2026-11-17 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md index 934d0fcff8..2d42fb2350 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/repository.rs -status: in-progress +status: done semantic-links: related-artifacts: - packages/tracker-core/src/statistics/repository.rs @@ -121,15 +121,58 @@ Not selected. The candidate property (incrementing `n` times reads `n`) belongs | ID | Status | Work | Completion evidence | | --- | --- | --- | --- | -| R1 | TODO | Replace the three `assert!` calls of the first existing test with one tuple `assert_eq!`. | Focused tests pass. | -| R2 | TODO | Add the tests of the analysis table (the gauge ones only if D1 says so). | Focused tests, `cargo +nightly fmt --all -- --check`, `cargo clippy`, `git diff --check`, the prose-first AAA review, and the named mutations. | -| R3 | TODO | Integration increment: none expected; the integration binary reaches this file through the event handler. | Recorded here. | -| R4 | TODO | Re-run unit-only coverage; record before and after. | Results below and `coverage-evidence.md`. | +| R1 | DONE | Replace the three `assert!` calls of the first existing test with one tuple `assert_eq!`. | Focused tests pass. | +| R2 | DONE | Add the tests of the analysis table (the gauge ones only if D1 says so). | Focused tests, `cargo +nightly fmt --all -- --check`, `cargo clippy`, `git diff --check`, the prose-first AAA review, and the named mutations. | +| R3 | DONE | Integration increment: none expected; the integration binary reaches this file through the event handler. | Recorded here. | +| R4 | DONE | Re-run unit-only coverage; record before and after. | Results below and `coverage-evidence.md`. | ## Prose-First AAA Review -Filled in R2, before the completed-file review. +Temporary prose, written before comparing with the code. + +| Test | Arrange prose | Act prose | Assert prose | Outcome | +| --- | --- | --- | --- | --- | +| `it_should_omit_persisted_metric_when_persisted_completed_statistics_are_disabled` (R1) | A repository with persisted statistics disabled. | Ask the collection whether each of the three download counters exists. | The three answers, as one tuple, are present, present, absent. | One `assert_eq!` on the tuple replaces three `assert!` calls, so a failure prints all three values. Kept. | +| `it_should_export_persisted_metric_with_zero_value_when_persisted_completed_statistics_are_enabled` | A repository with persisted statistics enabled. | Ask whether the persisted counter exists. | It exists and reads `0`. | Unchanged (clean). | +| `it_should_read_a_counter_that_is_not_in_the_collection_as_zero` | A repository with persisted statistics disabled, so the persisted counter is not described. | Read the persisted total. | It is `0`. | Kept; pins the `map_or(0, ...)` decision. | +| `it_should_set_a_counter_to_the_given_value` | A repository with persisted statistics enabled. | Set the persisted counter to `7`. | The call succeeds and the persisted total reads `7`. | Kept. | +| `it_should_refuse_to_set_a_counter_that_has_the_name_of_a_gauge` | A repository with a gauge `test_gauge` set to `2.5`. | Set a counter with the gauge's name. | A name-collision error on that name, and the gauge still reads `2.5`. | Kept. The gauge is created by `set_gauge` in the Arrange helper, which fails with its own message if that call breaks. | +| `it_should_refuse_to_increment_a_counter_that_has_the_name_of_a_gauge` | The same gauge. | Increment a counter with the gauge's name. | The same error, and the gauge unchanged. | Kept. | +| `it_should_set_a_gauge_to_the_given_value` | A repository with no gauge. | Set `test_gauge` to `2.5`. | The call succeeds and the gauge reads `2.5`. | Kept. | +| `it_should_refuse_to_set_a_gauge_that_has_the_name_of_a_counter` | A repository; the deprecated persistent counter exists at `0`. | Set a gauge with that counter's name. | A name-collision error on that name, and the counter still `0`. | Kept. | +| `it_should_increment_a_gauge_by_one` | A gauge at `2.5`. | Increment it. | The call succeeds and the gauge reads `3.5`. | Kept. | +| `it_should_refuse_to_increment_a_gauge_that_has_the_name_of_a_counter` | As the set-gauge refusal. | Increment a gauge with the counter's name. | The same error, and the counter still `0`. | Kept. | +| `it_should_decrement_a_gauge_by_one` | A gauge at `2.5`. | Decrement it. | The call succeeds and the gauge reads `1.5`. | Kept. | +| `it_should_refuse_to_decrement_a_gauge_that_has_the_name_of_a_counter` | As the set-gauge refusal. | Decrement a gauge with the counter's name. | The same error, and the counter still `0`. | Kept. | + +Helpers: `repository_with_a_gauge_set_to` (Arrange), `gauge` (reads one unlabeled gauge through +`read_metrics`), `is_a_name_collision_on` (the error pattern), `no_labels` and the literal `NOW`. +Gauges are compared as `Option` (`Gauge` derives `PartialEq`), which keeps the exact values +`2.5`, `3.5` and `1.5` without a float comparison that `clippy::float_cmp` would reject. ## Results -Filled in R4. +- **Unit-only coverage** (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, clean workspace, + `--all-features --lib`): `statistics/repository.rs` 86 / 140 lines at the S1 baseline; 277 / 277 + lines (100.00%), 394 / 394 regions and 57 / 57 functions after (the counts include the test + module). Package unit-only lines after this file: 4,324 / 5,241 (82.50%), regions 6,023 / 7,349 + (81.96%), functions 726 / 982 (73.93%), 167 unit tests (157 before). +- **Covered but not asserted:** `statistics/metrics.rs` (row 2) is now 45 / 45 lines, because every + repository write calls its `Metrics` wrapper. Row 2 decides whether that needs its own tests. +- **Tests:** 10 added, 1 changed (R1), 1 unchanged. No integration test was added or changed. +- **Mutations** (each applied alone on the production part of the file, stable toolchain, then the + file restored from a copy and compared with `cmp`): M1 killed by + `it_should_refuse_to_increment_a_counter_that_has_the_name_of_a_gauge`; M2 by + `it_should_set_a_counter_to_the_given_value`; M3 by + `it_should_refuse_to_set_a_gauge_that_has_the_name_of_a_counter`; M4 by + `it_should_increment_a_gauge_by_one`; M5 by `it_should_decrement_a_gauge_by_one`; M6 by + `it_should_read_a_counter_that_is_not_in_the_collection_as_zero`; M7 by + `it_should_set_a_counter_to_the_given_value` and six handler and listener tests. M7 first did not + compile (it left the persisted-counter import unused under `unused = "deny"`) and was redone with + `let _ = TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL;` so that it compiles. +- **Dependencies:** none new. **Clippy allows:** none. +- **Validation:** `cargo test -p torrust-tracker-core --all-features --lib` (167 passed), + `cargo clippy -p torrust-tracker-core --all-targets --all-features` (stable; its only warning is + the existing `axum::serve` entry of `clippy.toml`), `cargo +nightly fmt --all -- --check` + (nightly) and `git diff --check` pass. +- **Review outcome:** the maintainer approved the plan (with D1) and the completed file on 2026-11-17. diff --git a/packages/tracker-core/src/statistics/repository.rs b/packages/tracker-core/src/statistics/repository.rs index c4a4a09a33..903e1bcb94 100644 --- a/packages/tracker-core/src/statistics/repository.rs +++ b/packages/tracker-core/src/statistics/repository.rs @@ -233,6 +233,10 @@ impl Repository { #[cfg(test)] mod tests { + use torrust_clock::DurationSinceUnixEpoch; + use torrust_metrics::gauge::Gauge; + use torrust_metrics::label::LabelSet; + use torrust_metrics::metric_collection::Error; use torrust_metrics::metric_name; use super::Repository; @@ -241,13 +245,41 @@ mod tests { TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL, }; + /// A gauge name the package does not describe, created by the tests that need a gauge. + const A_GAUGE: &str = "test_gauge"; + + const NOW: DurationSinceUnixEpoch = DurationSinceUnixEpoch::from_secs(0); + + fn no_labels() -> LabelSet { + LabelSet::default() + } + + async fn repository_with_a_gauge_set_to(value: f64) -> Repository { + let repository = Repository::new(true, true); + repository + .set_gauge(&metric_name!(A_GAUGE), &no_labels(), value, NOW) + .await + .expect("setting a new gauge should succeed"); + repository + } + + async fn gauge(repository: &Repository, name: &str) -> Option { + repository + .read_metrics(|metrics| metrics.metric_collection().get_gauge_value(&metric_name!(name), &no_labels())) + .await + } + + fn is_a_name_collision_on(result: &Result<(), Error>, name: &str) -> bool { + matches!(result, Err(Error::MetricNameCollisionAdding { metric_name }) if *metric_name == metric_name!(name)) + } + #[tokio::test] async fn it_should_omit_persisted_metric_when_persisted_completed_statistics_are_disabled() { // Arrange let repository = Repository::new(true, false); // Act - let (has_persistent, has_in_session, has_persisted) = repository + let described_counters = repository .read_metrics(|metrics| { let collection = metrics.metric_collection(); ( @@ -258,10 +290,8 @@ mod tests { }) .await; - // Assert - assert!(has_persistent); - assert!(has_in_session); - assert!(!has_persisted); + // Assert: (persistent, in-session, persisted) + assert_eq!(described_counters, (true, true, false)); } #[tokio::test] @@ -282,4 +312,168 @@ mod tests { assert!(has_persisted); assert_eq!(repository.get_torrents_downloads_persisted_total().await, 0); } + + #[tokio::test] + async fn it_should_read_a_counter_that_is_not_in_the_collection_as_zero() { + // Arrange: persisted statistics disabled, so the persisted counter is not described + let repository = Repository::new(true, false); + + // Act + let total = repository.get_torrents_downloads_persisted_total().await; + + // Assert + assert_eq!(total, 0); + } + + #[tokio::test] + async fn it_should_set_a_counter_to_the_given_value() { + // Arrange + let repository = Repository::new(true, true); + + // Act + let result = repository + .set_counter( + &metric_name!(TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL), + &no_labels(), + 7, + NOW, + ) + .await; + + // Assert + assert!(result.is_ok(), "{result:?}"); + assert_eq!(repository.get_torrents_downloads_persisted_total().await, 7); + } + + #[tokio::test] + async fn it_should_refuse_to_set_a_counter_that_has_the_name_of_a_gauge() { + // Arrange + let repository = repository_with_a_gauge_set_to(2.5).await; + + // Act + let result = repository.set_counter(&metric_name!(A_GAUGE), &no_labels(), 7, NOW).await; + + // Assert + assert!(is_a_name_collision_on(&result, A_GAUGE), "{result:?}"); + assert_eq!(gauge(&repository, A_GAUGE).await, Some(Gauge::from(2.5))); + } + + #[tokio::test] + async fn it_should_refuse_to_increment_a_counter_that_has_the_name_of_a_gauge() { + // Arrange + let repository = repository_with_a_gauge_set_to(2.5).await; + + // Act + let result = repository.increment_counter(&metric_name!(A_GAUGE), &no_labels(), NOW).await; + + // Assert + assert!(is_a_name_collision_on(&result, A_GAUGE), "{result:?}"); + assert_eq!(gauge(&repository, A_GAUGE).await, Some(Gauge::from(2.5))); + } + + #[tokio::test] + async fn it_should_set_a_gauge_to_the_given_value() { + // Arrange + let repository = Repository::new(true, true); + + // Act + let result = repository.set_gauge(&metric_name!(A_GAUGE), &no_labels(), 2.5, NOW).await; + + // Assert + assert!(result.is_ok(), "{result:?}"); + assert_eq!(gauge(&repository, A_GAUGE).await, Some(Gauge::from(2.5))); + } + + #[tokio::test] + async fn it_should_refuse_to_set_a_gauge_that_has_the_name_of_a_counter() { + // Arrange + let repository = Repository::new(true, true); + + // Act + let result = repository + .set_gauge( + &metric_name!(TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + &no_labels(), + 2.5, + NOW, + ) + .await; + + // Assert + assert!( + is_a_name_collision_on(&result, TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + "{result:?}" + ); + assert_eq!(repository.get_torrents_downloads_total().await, 0); + } + + #[tokio::test] + async fn it_should_increment_a_gauge_by_one() { + // Arrange + let repository = repository_with_a_gauge_set_to(2.5).await; + + // Act + let result = repository.increment_gauge(&metric_name!(A_GAUGE), &no_labels(), NOW).await; + + // Assert + assert!(result.is_ok(), "{result:?}"); + assert_eq!(gauge(&repository, A_GAUGE).await, Some(Gauge::from(3.5))); + } + + #[tokio::test] + async fn it_should_refuse_to_increment_a_gauge_that_has_the_name_of_a_counter() { + // Arrange + let repository = Repository::new(true, true); + + // Act + let result = repository + .increment_gauge( + &metric_name!(TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + &no_labels(), + NOW, + ) + .await; + + // Assert + assert!( + is_a_name_collision_on(&result, TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + "{result:?}" + ); + assert_eq!(repository.get_torrents_downloads_total().await, 0); + } + + #[tokio::test] + async fn it_should_decrement_a_gauge_by_one() { + // Arrange + let repository = repository_with_a_gauge_set_to(2.5).await; + + // Act + let result = repository.decrement_gauge(&metric_name!(A_GAUGE), &no_labels(), NOW).await; + + // Assert + assert!(result.is_ok(), "{result:?}"); + assert_eq!(gauge(&repository, A_GAUGE).await, Some(Gauge::from(1.5))); + } + + #[tokio::test] + async fn it_should_refuse_to_decrement_a_gauge_that_has_the_name_of_a_counter() { + // Arrange + let repository = Repository::new(true, true); + + // Act + let result = repository + .decrement_gauge( + &metric_name!(TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + &no_labels(), + NOW, + ) + .await; + + // Assert + assert!( + is_a_name_collision_on(&result, TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + "{result:?}" + ); + assert_eq!(repository.get_torrents_downloads_total().await, 0); + } } From f1f4c95c15bfce4e2f46680c5d8575d67dddcd49 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 17 Nov 2026 22:28:00 +0000 Subject: [PATCH 06/40] docs(issues): [#2902] record the merged temporary-database fix in the S1 plans Co-Authored-By: Claude Opus 5.5 --- docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md | 3 ++- .../test-refactor-plans/README.md | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 87605aa890..980c699f37 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-17 18:04" +last-updated-utc: "2026-11-17 22:27" semantic-links: skill-links: - create-issue @@ -415,6 +415,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-17 12:45 UTC - Claude Code (Opus 5.5) - Correction of the 12:16 UTC entry above: its last sentence is wrong as written. The poller I started right after the PR opened (11:05:26 UTC) timed out after its 60-minute wait with no review, but Cameron (`da2ce7`) had submitted a review of `690cfb5f5` with findings F1-F6 at 12:08:23 UTC, before that entry was written, and the six threads had no reply. A second review of `2b0c3fe36` (F7-F10) followed at 12:28:40 UTC. The ten findings are processed in `docs/pr-reviews/pr-2903-review/PR-REVIEW.md` (review finding F7 of #2903). - 2026-11-17 16:16 UTC - Claude Code (Opus 5.5) - S0 merged (#2903); the maintainer linked #2902 to #1347 and said to start S1. S1 baseline: no file under `packages/` changed since the measured commit and the unit-only run gives the same 80.31% (4,099 / 5,104 lines). T2 done ([guidance](test-refactor-plans/README.md)). First plan proposed: [`statistics/repository.rs`](test-refactor-plans/statistics-repository-tests.md), which proposes finding F6 (unused public gauge methods) and asks decision D1. Questions Q2-Q7 still wait for the maintainer; Q7 decides the first S1 commit. - 2026-11-17 18:04 UTC - Claude Code (Opus 5.5) - F5 fixed for this package in its own PR, split from S1 at the maintainer's request because #2907 (EPIC #2392) plans the same fix for the shared helper: a full `cargo test -p torrust-tracker-core --all-features` leaves 0 `data_*.db` files (72 before). The maintainer approved the shape (a struct with a private `TempDir`, owned by the test), the scope (all six sources in the package) and the completed change. S1 continues on its own branch. +- 2026-11-17 22:27 UTC - Claude Code (Opus 5.5) - #2923 (the F5 fix) merged into `develop`; the S1 branch was rebuilt on it with only its own commits (the F20 fix of #2903, the S1 guidance, the Q2-Q7 and D1 answers, the repository tests). S1 continues with `statistics/metrics.rs`. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 4401818d64..604aa86b83 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -26,6 +26,7 @@ approves it. A group of declaration-only files may share one plan. | Plan sequence | Plan | State | Result | | ---: | --- | --- | --- | | 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | DONE | Approved 2026-11-17 (D1: test the unused gauge methods); completed file approved 2026-11-17 | +| 2 | [test-support-ephemeral-database-tests.md](test-support-ephemeral-database-tests.md) | DONE | F5 fix and the SQLite half of checkpoint T2b; shape, scope and guard owner decided and the completed change approved 2026-11-17; merged in #2923 | Add a row when a plan is created; the remaining files and their order are in the ledger. From 7d9d91bc3b541b3683c43d0d4de2f326853027f6 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 04:16:23 +0000 Subject: [PATCH 07/40] docs(issues): [#2902] record the no-change decision for the statistics metrics `statistics/metrics.rs` only passes each call to its `MetricCollection`. The repository tests cover it 45 / 45 and kill all six hand-made mutants, so the maintainer approved no new test. Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 5 +- .../test-refactor-plans/README.md | 1 + .../statistics-metrics-tests.md | 65 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 980c699f37..e4f318d17a 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-17 22:27" +last-updated-utc: "2026-11-18 04:16" semantic-links: skill-links: - create-issue @@ -349,7 +349,7 @@ rows are ordered by slice, then by risk. | Order | Source module | Slice | Unit-only lines | Initial hypothesis | State | | ---: | --- | --- | ---: | --- | --- | | 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | DONE | -| 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate | PENDING | +| 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`) | PENDING | | 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | PENDING | | 5 | `statistics/event/handler.rs` | S1 | 179 / 203 | Mostly logging-only; one error arm | PENDING | @@ -416,6 +416,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-17 16:16 UTC - Claude Code (Opus 5.5) - S0 merged (#2903); the maintainer linked #2902 to #1347 and said to start S1. S1 baseline: no file under `packages/` changed since the measured commit and the unit-only run gives the same 80.31% (4,099 / 5,104 lines). T2 done ([guidance](test-refactor-plans/README.md)). First plan proposed: [`statistics/repository.rs`](test-refactor-plans/statistics-repository-tests.md), which proposes finding F6 (unused public gauge methods) and asks decision D1. Questions Q2-Q7 still wait for the maintainer; Q7 decides the first S1 commit. - 2026-11-17 18:04 UTC - Claude Code (Opus 5.5) - F5 fixed for this package in its own PR, split from S1 at the maintainer's request because #2907 (EPIC #2392) plans the same fix for the shared helper: a full `cargo test -p torrust-tracker-core --all-features` leaves 0 `data_*.db` files (72 before). The maintainer approved the shape (a struct with a private `TempDir`, owned by the test), the scope (all six sources in the package) and the completed change. S1 continues on its own branch. - 2026-11-17 22:27 UTC - Claude Code (Opus 5.5) - #2923 (the F5 fix) merged into `develop`; the S1 branch was rebuilt on it with only its own commits (the F20 fix of #2903, the S1 guidance, the Q2-Q7 and D1 answers, the repository tests). S1 continues with `statistics/metrics.rs`. +- 2026-11-18 04:16 UTC - Claude Code (Opus 5.5) - Row 2 (`statistics/metrics.rs`) is done as no change, approved by the maintainer: the repository tests cover it 45 / 45 and kill all six hand-made mutants ([record](test-refactor-plans/statistics-metrics-tests.md)). ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 604aa86b83..dacceff2e6 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -27,6 +27,7 @@ approves it. A group of declaration-only files may share one plan. | ---: | --- | --- | --- | | 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | DONE | Approved 2026-11-17 (D1: test the unused gauge methods); completed file approved 2026-11-17 | | 2 | [test-support-ephemeral-database-tests.md](test-support-ephemeral-database-tests.md) | DONE | F5 fix and the SQLite half of checkpoint T2b; shape, scope and guard owner decided and the completed change approved 2026-11-17; merged in #2923 | +| 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md new file mode 100644 index 0000000000..75dc42929a --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md @@ -0,0 +1,65 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/metrics.rs +status: done +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/metrics.rs + - packages/tracker-core/src/statistics/repository.rs + - docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md +--- + +# Statistics Metrics File Test Plan + +Follow the shared [guidance](README.md). This record covers only +`packages/tracker-core/src/statistics/metrics.rs`, ledger row 2. Decision: **no change**. + +## Current State + +- **Unit-only coverage:** 11 / 45 lines at the S1 baseline; 45 / 45 after the + [repository tests](statistics-repository-tests.md) (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, + `--all-features --lib`, 2026-11-17). The baseline left 36-44, 49-57, 62-69 and 74-81 uncovered: + `set_counter`, `set_gauge`, `increment_gauge` and `decrement_gauge`. +- **What the file decides:** nothing of its own. `Metrics` holds a `MetricCollection`; its accessor + returns it and its five write methods pass their arguments to the method of the same name and + return its result unchanged. +- **Callers in the package:** only `statistics/repository.rs`, which keeps `Metrics` behind a lock + and calls each write method. `statistics/mod.rs` (`describe_metrics`) builds a `Metrics` but + writes to its `metric_collection` field directly. +- **Existing tests:** none in the file. + +## Decision + +No change: a test here would repeat the repository tests one layer down, without the lock, and +kill no mutant they leave alive. Every line is covered by the repository tests, which assert the +values the collection holds after each write. + +## Mutation Proof + +Hand-made mutants, each applied alone and reverted; `cargo test -p torrust-tracker-core +--all-features --lib` on 2026-11-17. + +| ID | Mutation | Result | +| --- | --- | --- | +| M1 | `increment_counter` returns `Ok(())` without writing | Killed by the repository and event tests | +| M2 | `set_counter` returns `Ok(())` without writing | Killed: `it_should_set_a_counter_to_the_given_value` and the name-collision test | +| M3 | `set_gauge` returns `Ok(())` without writing | Killed by the six gauge and name-collision tests | +| M4 | `increment_gauge` calls `decrement_gauge` | Killed: `it_should_increment_a_gauge_by_one` | +| M5 | `decrement_gauge` calls `increment_gauge` | Killed: `it_should_decrement_a_gauge_by_one` | +| M6 | `set_counter` writes `value + 1` | Killed: `it_should_set_a_counter_to_the_given_value` | + +The accessor `metric_collection()` has no viable mutant: it returns a reference to the only field. + +## Risk Accepted + +The file relies on tests in `repository.rs`. If `Repository` stopped calling one of the methods, +that method would lose its coverage without a failing test; the methods are `pub`, so the +`unused` lint would not report them either. The next coverage run would show it. + +## Results + +- **Decision:** approved by the maintainer on 2026-11-18 (no change, with the mutation proof as + evidence). +- **Tests:** none added or changed. From 98676abeae43ea7184cebe2080a58ef2df2bd2f9 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 04:19:26 +0000 Subject: [PATCH 08/40] docs(issues): [#2902] add the plan for the persisted statistics loader tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 2 +- .../test-refactor-plans/README.md | 1 + .../statistics-persisted-mod-tests.md | 89 +++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index e4f318d17a..ab9f4b1869 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -350,7 +350,7 @@ rows are ordered by slice, then by risk. | ---: | --- | --- | ---: | --- | --- | | 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | DONE | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | -| 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`) | PENDING | +| 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`) | IN_PROGRESS | | 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | PENDING | | 5 | `statistics/event/handler.rs` | S1 | 179 / 203 | Mostly logging-only; one error arm | PENDING | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index dacceff2e6..97041e1289 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -28,6 +28,7 @@ approves it. A group of declaration-only files may share one plan. | 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | DONE | Approved 2026-11-17 (D1: test the unused gauge methods); completed file approved 2026-11-17 | | 2 | [test-support-ephemeral-database-tests.md](test-support-ephemeral-database-tests.md) | DONE | F5 fix and the SQLite half of checkpoint T2b; shape, scope and guard owner decided and the completed change approved 2026-11-17; merged in #2923 | | 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | +| 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 (pins the non-atomic load) | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md new file mode 100644 index 0000000000..81e15e61d8 --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md @@ -0,0 +1,89 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/persisted/mod.rs +status: approved +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/persisted/mod.rs + - packages/tracker-core/src/statistics/persisted/downloads.rs + - packages/tracker-core/src/statistics/repository.rs + - packages/tracker-core/src/databases/traits/torrent_metrics.rs + - packages/tracker-core/tests/common/test_env.rs +--- + +# Statistics Persisted Metrics Loader File Test Plan + +Follow the shared [guidance](README.md). This plan covers only +`packages/tracker-core/src/statistics/persisted/mod.rs`, ledger row 3. + +## Current State + +- **Unit-only coverage:** 0 / 11 lines, at the S1 baseline and after rows 1 and 2 (stable Rust + 1.99.1, `cargo-llvm-cov 0.6.16`, `--all-features --lib`). Uncovered: 21-46 + (`load_persisted_metrics`) and 58-68 (the two `From` conversions into `Error`). +- **Callers:** the tracker start-up (`src/app.rs:385`) and the integration test environment + (`tests/common/test_env.rs:138`), which unwraps the result on a real SQLite database with no + stored total. No unit test calls it. +- **Module-owned decisions:** + - With a stored global total `N`, both the persistent total (deprecated name) and the persisted + total are set to `N`; the in-session total is not touched. + - With no stored total, nothing is written and the result is `Ok`. + - A database failure is returned as `Error::DatabaseError`, and nothing is written. + - A refused metric write is returned as `Error::MetricsError`; the first refusal stops the load. + The load is not atomic: when the second write is refused, the first stays. Only the second can + be refused in practice, because `describe_metrics` always registers the persistent total as a + counter, while the persisted total exists only when persisted statistics are enabled. + +## Maintainer Decision + +Plan approved on 2026-11-18, including the test that pins the non-atomic load. + +## Test Design + +Unit tests in a new `tests` module of the file. The database is `MockTorrentMetricsStore` +(`automock` under the `testing` feature, as `scrape_handler.rs` uses it), wrapped in +`DatabaseDownloadsMetricRepository`; the statistics repository is a real +`Repository::new(true, true)`. Values are read back with the repository's three readers. + +| Test | Arrange | Assert | +| --- | --- | --- | +| `it_should_set_the_persistent_and_the_persisted_totals_to_the_stored_global_downloads` | the store returns `Some(7)` | `Ok`; both totals read 7; the in-session total reads 0 | +| `it_should_set_both_totals_to_the_largest_stored_value` | the store returns `Some(u32::MAX)` | both totals read `u64::from(u32::MAX)` (the widening is lossless) | +| `it_should_leave_the_totals_at_zero_when_no_global_downloads_are_stored` | the store returns `None` | `Ok`; both totals read 0 | +| `it_should_return_a_database_error_and_load_nothing_when_the_store_fails` | the store returns `MalformedDatabaseRecord` | `Err(Error::DatabaseError { .. })`; both totals read 0 | +| `it_should_return_a_metrics_error_and_keep_the_first_total_when_the_repository_refuses_the_second` | the store returns `Some(7)`; `Repository::new(true, false)` and the persisted total's name already holds a gauge (`set_gauge` first) | `Err(Error::MetricsError { .. })`; the persistent total reads 7 (the load is not atomic) | + +Each mock expectation uses `.times(1)`, so a second database read also fails the test. + +## Property-Test Decision + +No `quickcheck`: the function is async and has one numeric input, whose only rule is the lossless +`u32` to `u64` widening; the `Some(7)` and `Some(u32::MAX)` examples pin it. A property would need +a runtime per case for no extra mutant. + +## Named Mutations + +| ID | Mutation | Expected killer | +| --- | --- | --- | +| M1 | Remove the persistent-total write | the `Some(7)` test | +| M2 | Remove the persisted-total write | the `Some(7)` test | +| M3 | Write the in-session total instead of the persisted total | the `Some(7)` test (in-session reads 7) | +| M4 | `if let Some` branch skipped (always `Ok(())`) | the `Some(7)` test | +| M5 | Database error swallowed (`.unwrap_or(None)`) | the database-error test | +| M6 | Metrics error swallowed (`let _ =` on the second write) | the metrics-error test | +| M6b | The two writes swapped (persisted first) | the metrics-error test (the persistent total reads 0) | +| M7 | `u64::from(downloads) + 1` | the `Some(7)` test | + +## Steps + +| ID | Status | Work | Completion evidence | +| --- | --- | --- | --- | +| P1 | TODO | Add the five tests. | They pass; the file is 11 / 11. | +| P2 | TODO | Run M1-M7 and M6b. | Each is killed by its expected test. | +| P3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | + +## Results + +To be filled in after P3. From 9a63635e2c459b2c4b595cafe89e7338991fe611 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 04:22:36 +0000 Subject: [PATCH 09/40] test(tracker-core): [#2902] cover the persisted statistics loader `load_persisted_metrics` had no unit test. Five tests with a mocked torrent-metrics store pin that a stored global total sets both the persistent and the persisted totals, that an empty store writes nothing, that a store failure is a database error, and that a refused write is a metrics error after the first total was already written (the load is not atomic). Co-Authored-By: Claude Opus 5.5 --- .../src/statistics/persisted/mod.rs | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/packages/tracker-core/src/statistics/persisted/mod.rs b/packages/tracker-core/src/statistics/persisted/mod.rs index dc79e5035d..1ef412e6bf 100644 --- a/packages/tracker-core/src/statistics/persisted/mod.rs +++ b/packages/tracker-core/src/statistics/persisted/mod.rs @@ -66,3 +66,149 @@ impl From for Error { Self::MetricsError { err } } } + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use torrust_clock::DurationSinceUnixEpoch; + use torrust_metrics::label::LabelSet; + use torrust_metrics::metric_name; + use torrust_tracker_primitives::{Driver, NumberOfDownloads}; + + use super::{Error, load_persisted_metrics}; + use crate::databases::error::Error as DatabaseError; + use crate::databases::{MockTorrentMetricsStore, TorrentMetricsStore}; + use crate::statistics::TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL; + use crate::statistics::persisted::downloads::DatabaseDownloadsMetricRepository; + use crate::statistics::repository::Repository; + + const NOW: DurationSinceUnixEpoch = DurationSinceUnixEpoch::from_secs(0); + + /// A downloads repository whose store answers the global-downloads query once, with `stored`. + fn downloads_repository_storing( + stored: Result, DatabaseError>, + ) -> Arc { + let mut store = MockTorrentMetricsStore::new(); + store + .expect_load_global_downloads() + .times(1) + .return_once(move || Box::pin(std::future::ready(stored))); + let store: Arc = Arc::new(store); + + Arc::new(DatabaseDownloadsMetricRepository::new(&store)) + } + + /// A statistics repository with every downloads total registered as a counter. + fn statistics_repository() -> Arc { + Arc::new(Repository::new(true, true)) + } + + async fn persistent_and_persisted_totals(repository: &Repository) -> (u64, u64) { + ( + repository.get_torrents_downloads_total().await, + repository.get_torrents_downloads_persisted_total().await, + ) + } + + #[tokio::test] + async fn it_should_set_the_persistent_and_the_persisted_totals_to_the_stored_global_downloads() { + // Arrange + let downloads_repository = downloads_repository_storing(Ok(Some(7))); + let repository = statistics_repository(); + + // Act + let result = load_persisted_metrics(&repository, &downloads_repository, NOW).await; + + // Assert + assert!(result.is_ok(), "loading a stored total should succeed, got {result:?}"); + assert_eq!( + persistent_and_persisted_totals(&repository).await, + (7, 7), + "both totals should hold the stored global downloads" + ); + assert_eq!( + repository.get_torrents_downloads_in_session_total().await, + 0, + "the in-session total counts only this process's downloads" + ); + } + + #[tokio::test] + async fn it_should_set_both_totals_to_the_largest_stored_value() { + // Arrange + let downloads_repository = downloads_repository_storing(Ok(Some(u32::MAX))); + let repository = statistics_repository(); + + // Act + load_persisted_metrics(&repository, &downloads_repository, NOW).await.unwrap(); + + // Assert + let largest = u64::from(u32::MAX); + assert_eq!(persistent_and_persisted_totals(&repository).await, (largest, largest)); + } + + #[tokio::test] + async fn it_should_leave_the_totals_at_zero_when_no_global_downloads_are_stored() { + // Arrange + let downloads_repository = downloads_repository_storing(Ok(None)); + let repository = statistics_repository(); + + // Act + let result = load_persisted_metrics(&repository, &downloads_repository, NOW).await; + + // Assert + assert!(result.is_ok(), "an empty store is not an error, got {result:?}"); + assert_eq!(persistent_and_persisted_totals(&repository).await, (0, 0)); + } + + #[tokio::test] + async fn it_should_return_a_database_error_and_load_nothing_when_the_store_fails() { + // Arrange + let downloads_repository = downloads_repository_storing(Err(DatabaseError::MalformedDatabaseRecord { + message: "corrupt record".to_string(), + driver: Driver::Sqlite3, + })); + let repository = statistics_repository(); + + // Act + let result = load_persisted_metrics(&repository, &downloads_repository, NOW).await; + + // Assert + assert!( + matches!(result, Err(Error::DatabaseError { .. })), + "a store failure should be a database error, got {result:?}" + ); + assert_eq!(persistent_and_persisted_totals(&repository).await, (0, 0)); + } + + #[tokio::test] + async fn it_should_return_a_metrics_error_and_keep_the_first_total_when_the_repository_refuses_the_second() { + // Arrange + let downloads_repository = downloads_repository_storing(Ok(Some(7))); + let repository = Arc::new(Repository::new(true, false)); + repository + .set_gauge( + &metric_name!(TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL), + &LabelSet::default(), + 1.0, + NOW, + ) + .await + .unwrap(); + + // Act + let result = load_persisted_metrics(&repository, &downloads_repository, NOW).await; + + // Assert + assert!( + matches!(result, Err(Error::MetricsError { .. })), + "a refused write should be a metrics error, got {result:?}" + ); + assert_eq!( + repository.get_torrents_downloads_total().await, + 7, + "the load is not atomic: the persistent total written first stays" + ); + } +} From 8680f377066f67b4dfe5f6c82929f09a97036b99 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 04:23:23 +0000 Subject: [PATCH 10/40] docs(issues): [#2902] record the results of the persisted statistics loader tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 5 +-- .../test-refactor-plans/README.md | 2 +- .../statistics-persisted-mod-tests.md | 32 ++++++++++++++++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index ab9f4b1869..89347e322b 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 04:16" +last-updated-utc: "2026-11-18 04:23" semantic-links: skill-links: - create-issue @@ -350,7 +350,7 @@ rows are ordered by slice, then by risk. | ---: | --- | --- | ---: | --- | --- | | 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | DONE | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | -| 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`) | IN_PROGRESS | +| 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | | 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | PENDING | | 5 | `statistics/event/handler.rs` | S1 | 179 / 203 | Mostly logging-only; one error arm | PENDING | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | @@ -417,6 +417,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-17 18:04 UTC - Claude Code (Opus 5.5) - F5 fixed for this package in its own PR, split from S1 at the maintainer's request because #2907 (EPIC #2392) plans the same fix for the shared helper: a full `cargo test -p torrust-tracker-core --all-features` leaves 0 `data_*.db` files (72 before). The maintainer approved the shape (a struct with a private `TempDir`, owned by the test), the scope (all six sources in the package) and the completed change. S1 continues on its own branch. - 2026-11-17 22:27 UTC - Claude Code (Opus 5.5) - #2923 (the F5 fix) merged into `develop`; the S1 branch was rebuilt on it with only its own commits (the F20 fix of #2903, the S1 guidance, the Q2-Q7 and D1 answers, the repository tests). S1 continues with `statistics/metrics.rs`. - 2026-11-18 04:16 UTC - Claude Code (Opus 5.5) - Row 2 (`statistics/metrics.rs`) is done as no change, approved by the maintainer: the repository tests cover it 45 / 45 and kill all six hand-made mutants ([record](test-refactor-plans/statistics-metrics-tests.md)). +- 2026-11-18 04:23 UTC - Claude Code (Opus 5.5) - Row 3 (`statistics/persisted/mod.rs`) done: five tests, 11 / 11 production lines, all eight named mutants killed; they pin that the load is not atomic ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)). Plan and completed file approved by the maintainer. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 97041e1289..8e867bb26a 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -28,7 +28,7 @@ approves it. A group of declaration-only files may share one plan. | 1 | [statistics-repository-tests.md](statistics-repository-tests.md) | DONE | Approved 2026-11-17 (D1: test the unused gauge methods); completed file approved 2026-11-17 | | 2 | [test-support-ephemeral-database-tests.md](test-support-ephemeral-database-tests.md) | DONE | F5 fix and the SQLite half of checkpoint T2b; shape, scope and guard owner decided and the completed change approved 2026-11-17; merged in #2923 | | 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | -| 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 (pins the non-atomic load) | +| 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md index 81e15e61d8..421b44dc92 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/persisted/mod.rs -status: approved +status: done semantic-links: related-artifacts: - packages/tracker-core/src/statistics/persisted/mod.rs @@ -80,10 +80,32 @@ a runtime per case for no extra mutant. | ID | Status | Work | Completion evidence | | --- | --- | --- | --- | -| P1 | TODO | Add the five tests. | They pass; the file is 11 / 11. | -| P2 | TODO | Run M1-M7 and M6b. | Each is killed by its expected test. | -| P3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | +| P1 | DONE | Add the five tests. | They pass; the file is 11 / 11. | +| P2 | DONE | Run M1-M7 and M6b. | Each is killed by its expected test. | +| P3 | DONE | Record the results and ask for the completed-file review. | This record and the ledger. | ## Results -To be filled in after P3. +- **Coverage:** the file's production lines 0 / 11 to 11 / 11 (`--all-features --lib`, stable Rust + 1.99.1, 2026-11-18); the package's unit-only lines 4,351 / 5,266 (82.62%) to 4,474 / 5,378 + (83.19%), where the denominator grows with the 112 lines of the new test module. One region stays + uncovered: the `?` error arm of the first write (line 34), which cannot be reached because + `describe_metrics` always registers the persistent total as a counter. +- **Tests:** five added, all passing; 172 unit tests in the package. +- **Mutations** (each applied alone and reverted; a mutant that did not compile was rewritten to + keep the lint-required uses, for example `let _ = NAME;` for a removed write): + + | ID | Result | + | --- | --- | + | M1 | Killed by the `Some(7)`, `u32::MAX` and metrics-error tests | + | M2 | Killed by the same three tests | + | M3 | Killed by the same three tests | + | M4 | Killed by the same three tests | + | M5 | Killed by the database-error test | + | M6 | Killed by the metrics-error test (written as `drop(...)`: `let _ =` on the `Result` is denied) | + | M6b | Killed by the metrics-error test | + | M7 | Killed by the same three tests as M1 | + +- **Review outcome:** the maintainer approved the completed file on 2026-11-18. +- **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the + existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. From 20a09c6404c0f005c5c2661badd9e9987f15247b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 08:34:59 +0000 Subject: [PATCH 11/40] docs(issues): [#2902] add the plan for the statistics event listener tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 2 +- .../test-refactor-plans/README.md | 1 + .../statistics-event-listener-tests.md | 111 ++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 89347e322b..7f83e5dd6d 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -351,7 +351,7 @@ rows are ordered by slice, then by risk. | 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | DONE | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | -| 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | PENDING | +| 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | IN_PROGRESS | | 5 | `statistics/event/handler.rs` | S1 | 179 / 203 | Mostly logging-only; one error arm | PENDING | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | | 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 40 / 40, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 8e867bb26a..3c9283a39c 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -29,6 +29,7 @@ approves it. A group of declaration-only files may share one plan. | 2 | [test-support-ephemeral-database-tests.md](test-support-ephemeral-database-tests.md) | DONE | F5 fix and the SQLite half of checkpoint T2b; shape, scope and guard owner decided and the completed change approved 2026-11-17; merged in #2923 | | 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | | 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | +| 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | IN_PROGRESS | Plan approved 2026-11-18; listener half of checkpoint T2b | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md new file mode 100644 index 0000000000..691b19d2e2 --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md @@ -0,0 +1,111 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/event/listener.rs +status: approved +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/event/listener.rs + - packages/tracker-core/src/statistics/event/handler.rs + - packages/events/src/bus.rs + - packages/events/src/drain.rs + - src/bootstrap/jobs/tracker_core.rs + - packages/tracker-core/tests/common/test_env.rs +--- + +# Statistics Event Listener File Test Plan + +Follow the shared [guidance](README.md). This plan covers only +`packages/tracker-core/src/statistics/event/listener.rs`, ledger row 4. It is also the listener +half of the design-review checkpoint T2b: the first test that spawns a listener, handles one +event, cancels it and joins it under a deadline. + +## Current State + +- **Unit-only coverage:** 357 / 406 lines at the S1 baseline, 362 / 411 after rows 1 to 3 + (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, `--all-features --lib`, 2026-11-18). Uncovered: + 19-54 (the spawn wrappers `run_in_memory_event_listener` and + `run_persistent_completed_statistics_event_listener`), 62-91 (the public `*_unspawned` + functions), and 284-285 (the `Lagged` arm of the test receiver's `try_recv`, test code). +- **Callers:** the application runs the two `*_unspawned` functions under its own supervision + (`src/bootstrap/jobs/tracker_core.rs`) and uses the `Completion` they return. The spawn wrappers + are used only by the integration test environment (`tests/common/test_env.rs`), which discards + their result. +- **Existing tests:** 11, all on the private `dispatch_*` loops, with a scripted receiver: handling + events, lag, a closed receiver, a pending cancellation that drains queued events, and an expired + drain timeout. They already pin every decision of the loops. +- **Module-owned decisions not yet tested:** + - The `*_unspawned` functions pass the receiver, the token, the repositories and the drain + timeout through and return the loop's `Completion` (`Cancelled` after a cancellation). + - The spawn wrappers run the same listener in a task and finish when it finishes. + +## Asynchronous Work and Ownership + +From the spec's [ownership map](../ISSUE.md#asynchronous-work-cleanup-and-test-fixtures): + +- **Channel:** a real `EventBus` of the swarm registry (`torrust-tracker-events`), created by the + test. The receiver is subscribed before the event is sent, so the event is queued. +- **Listener:** the test owns it. It sends one event, cancels the token, then awaits the future or + the `JoinHandle` inside `tokio::time::timeout(5 s)`, which fails with a message naming the + operation. A failed assertion drops the per-test runtime, which drops the task. +- **Determinism:** on the single-threaded test runtime the listener first runs when the test + awaits it, after the cancellation. The `biased` select takes the cancellation, and the drain + handles the queued event. No fixed sleep. +- **Database:** the persistent tests use `ephemeral_configuration()`; the test keeps the returned + value, so the `TempDir` removes the database at the end, including on a failure. + +## Maintainer Decision + +Plan approved on 2026-11-18, with all four tests (the spawned pair keeps the T2b shape). + +## Test Design + +| Test | Act | Assert | +| --- | --- | --- | +| `it_should_handle_a_queued_event_and_return_cancelled_when_the_unspawned_in_memory_listener_is_cancelled` | `run_in_memory_event_listener_unspawned`, awaited under the deadline | `Completion::Cancelled`; both in-memory totals read 1 | +| `it_should_persist_a_queued_event_and_return_cancelled_when_the_unspawned_persistent_listener_is_cancelled` | `run_persistent_completed_statistics_event_listener_unspawned` | `Completion::Cancelled`; the database and the persisted total hold 1 | +| `it_should_handle_a_queued_event_then_finish_when_the_spawned_in_memory_listener_is_cancelled` | `run_in_memory_event_listener`, `JoinHandle` awaited under the deadline | the task ends without a panic; both in-memory totals read 1 | +| `it_should_persist_a_queued_event_then_finish_when_the_spawned_persistent_listener_is_cancelled` | `run_persistent_completed_statistics_event_listener` | the task ends without a panic; the database and the persisted total hold 1 | + +The tests reuse the module's existing helpers (`peer_download_completed_event`, +`database_downloads_repository`, `expect_in_memory_download_metrics_to_be`, +`expect_persisted_download_metrics_to_be`) and add one: a 5-second `join_within_deadline` helper. + +## Property-Test Decision + +No `quickcheck`: the functions are wiring with no input domain. + +## Named Mutations + +| ID | Mutation | Expected killer | +| --- | --- | --- | +| M1 | The in-memory spawn wrapper drops its arguments instead of running the listener | the spawned in-memory test | +| M2 | The persistent spawn wrapper drops its arguments instead of running the listener | the spawned persistent test | +| M3 | `run_in_memory_event_listener_unspawned` returns `Completion::Completed` | the unspawned in-memory test | +| M4 | `run_persistent_completed_statistics_event_listener_unspawned` returns `Completion::Completed` | the unspawned persistent test | +| M5 | The in-memory unspawned function passes `Duration::ZERO` instead of the drain timeout | the unspawned in-memory test (the event stays queued) | +| M6 | The persistent unspawned function passes `Duration::ZERO` | the unspawned persistent test | +| M7 | The in-memory spawn wrapper passes `Duration::ZERO` | the spawned in-memory test | + +M5 to M7 rely on the existing finding that an expired drain timeout leaves a queued event +unhandled (`it_should_leave_the_queued_event_unprocessed_and_return_cancelled_when_the_drain_timeout_has_expired`). + +## Out of Scope + +- Lines 284-285 are the test receiver's `Lagged` arm of `try_recv`: test code, not counted as a + decision. +- The `Completed` path through a closed real channel: the existing loop tests pin it with the + scripted receiver. + +## Steps + +| ID | Status | Work | Completion evidence | +| --- | --- | --- | --- | +| L1 | TODO | Add the four tests and the deadline helper. | They pass; lines 19-91 covered. | +| L2 | TODO | Run M1-M7. | Each is killed by its expected test. | +| L3 | TODO | Stop for the T2b fixture-shape review and the completed-file review. | The maintainer's decision recorded here. | + +## Results + +To be filled in after L3. From d3cba094f4ae0d4b50f137abe6232c11790ca34a Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 09:12:17 +0000 Subject: [PATCH 12/40] docs(issues): [#2902] re-measure the coverage with Rust 1.100.0 `rustup update` moved stable from Rust 1.99.1 to 1.100.0, and `cargo-llvm-cov 0.6.16` then reported 0% for every file: it still read test binaries from `target/debug/deps/`, where Cargo 1.100.0 no longer writes them. With `cargo-llvm-cov 0.9.1` every figure of the issue is measured again at the same commits: the baseline at `5833cdae9` in five scopes and the unit-only runs after rows 1 and 3. The coverage evidence, the spec's baseline and ledger, the row records and the EPIC's #2902 rows hold the new figures; the append-only logs keep the old ones. Co-Authored-By: Claude Opus 5.5 --- .../1347-overhaul-packages-testing/EPIC.md | 7 +- .../2902-1347-add-tests-tracker-core/ISSUE.md | 82 +++++----- .../coverage-evidence.md | 145 +++++++++--------- .../test-refactor-plans/README.md | 5 +- .../statistics-metrics-tests.md | 4 +- .../statistics-persisted-mod-tests.md | 10 +- .../statistics-repository-tests.md | 20 +-- 7 files changed, 144 insertions(+), 129 deletions(-) diff --git a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md index c03ece8a2f..b2bbee4f98 100644 --- a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md +++ b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md @@ -99,7 +99,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | 11 | #2824 - Add tests to the primitives package | `docs/issues/closed/2824-1347-add-tests-primitives/ISSUE.md` | DONE | S0 (the spec, #2828), S1 (the `PeerRole` JSON casing fix, #2834), S2 (the `peer.rs` tests, #2841), S3 (the configuration defaults and bounded values, #2852) and S4 (`swarm_metadata.rs`, the no-change files, the mutation run, the manual checks, #2864) are merged; the issue is closed. Unit-only lines 60.56% → 94.07%. Findings F1 (fixed through #2811), F2 (fixed in S1), F3 (#2804), F4 (#2823), F6 (#2838, #2850) and F5 (#2876, drafted through #2865) have owners. | | 12 | #2838 - UDP tracker accepts announces with a negative left, uploaded or downloaded | `docs/issues/closed/2838-1347-udp-reject-negative-announce-bytes/ISSUE.md` | DONE | Bug found by the #2824 primitives tests work. Fixed by the standalone issue #2850 (`docs/issues/closed/2850-non-negative-number-of-bytes/ISSUE.md`): its implementation PR #2872 merged on 2026-11-16 and closed this issue. The patch of PR #2839 was not merged; its tests were taken over by PR #2872. | | 13 | #2876 - Move `peer::Id::new` to a realistic test helper and decide whether `peer::fixture` goes behind a `testing` feature | `docs/issues/closed/2876-1347-peer-id-test-helper/ISSUE.md` | DONE | Finding F5 of #2824. Spec through #2878, implementation through #2888: `Id::new` removed, `qbittorrent_peer_id` helper, `peer::fixture` behind the new `testing` feature of `primitives`, test-support ADR amended. Breaking for the published `primitives` 3.0.0; adds to the 4.0.0 it owes (#2583). | -| 14 | #2902 - Add tests to the tracker-core package | `docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md` | TODO | Lowest unit-only lines of the packages in the EPIC coverage table: 80.31% (MySQL/PostgreSQL drivers 0-4%, SQLite failure branches, `statistics/` reached only by the integration binary). Slices S0-S5 proposed; S0 is the spec-only PR. | +| 14 | #2902 - Add tests to the tracker-core package | `docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md` | TODO | Lowest unit-only lines of the packages in the EPIC coverage table: 79.32% (MySQL/PostgreSQL drivers 0-4%, SQLite failure branches, `statistics/` reached only by the integration binary). Slices S0-S5 proposed; S0 is the spec-only PR. | | 15 | Additional package-testing subissues | Create a folder-style spec when a concrete package need is identified | TODO | Permitted but not required upfront; retain scope in this EPIC. | **Publishing gate (maintainer decision of 2026-11-18).** A workspace crate may be published @@ -134,7 +134,7 @@ level or determine whether unit coverage is adequate. | `torrust-tracker-http-core` | [#1349](../../closed/1349-1347-add-tests-http-core/ISSUE.md) | Lines: 88.88%; regions: 90.41%; functions: 84.29% | Lines: 99.28%; regions: 99.25%; functions: 99.74% | Lines: +10.40 pp; regions: +8.84 pp; functions: +15.45 pp | [Coverage evidence](../../closed/1349-1347-add-tests-http-core/coverage-evidence.md) | | `torrust-tracker-axum-rest-api-server` | [#2637](../../closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md) | Lines: 87.98%; regions: 84.10%; functions: 83.42% | Lines: 97.67%; regions: 97.13%; functions: 95.48% | Lines: +9.69 pp; regions: +13.03 pp; functions: +12.06 pp | [Coverage evidence](../../closed/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md) | | `torrust-tracker-primitives` | [#2824](../../closed/2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 94.07%; regions: 95.30%; functions: 94.17% | Lines: +33.51 pp; regions: +27.36 pp; functions: +36.94 pp | [Coverage evidence](../../closed/2824-1347-add-tests-primitives/coverage-evidence.md) | -| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 82.15%; regions: 81.23%; functions: 73.38% | Not yet measured | Not yet measured | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | +| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 81.15%; regions: 79.59%; functions: 73.35% | Not yet measured | Not yet measured | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | ### Unit-Only Coverage @@ -150,7 +150,7 @@ weak unit-only result with aggregate, integration, example, or end-to-end covera | `torrust-tracker-http-core` | [#1349](../../closed/1349-1347-add-tests-http-core/ISSUE.md) | Lines: 88.88%; regions: 90.41%; functions: 84.29% | Lines: 99.28%; regions: 99.25%; functions: 99.74% | Lines: +10.40 pp; regions: +8.84 pp; functions: +15.45 pp | [Coverage evidence](../../closed/1349-1347-add-tests-http-core/coverage-evidence.md) | | `torrust-tracker-axum-rest-api-server` | [#2637](../../closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md) | Lines: 63.87%; regions: 63.98%; functions: 51.34% | Lines: 96.67%; regions: 96.38%; functions: 93.97% | Lines: +32.80 pp; regions: +32.40 pp; functions: +42.63 pp | [Coverage evidence](../../closed/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md) | | `torrust-tracker-primitives` | [#2824](../../closed/2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 94.07%; regions: 95.30%; functions: 94.17% | Lines: +33.51 pp; regions: +27.36 pp; functions: +36.94 pp | [Coverage evidence](../../closed/2824-1347-add-tests-primitives/coverage-evidence.md) | -| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 80.31%; regions: 80.20%; functions: 72.01% | Not yet measured | Not yet measured | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | +| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 79.32%; regions: 78.62%; functions: 71.98% | Not yet measured | Not yet measured | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | ## Delivery Strategy @@ -369,6 +369,7 @@ For each subissue implementation, the completion policy is: - 2026-11-16 21:52 UTC - Claude Code (Opus 5.5) - #2876 closed by PR #2888 (merged 2026-11-16 21:49 UTC); row 13 set to `DONE` and the spec archived to `docs/issues/closed/2876-1347-peer-id-test-helper/`. - 2026-11-17 10:57 UTC - Claude Code (Sonnet 5.5) - Created #2902 (`tracker-core`, row 14; the link under #1347 is set by the maintainer). Clean baseline at `5833cdae9`, filtered to the package source: unit-only (`--all-features --lib`) lines 80.31% (4,099 / 5,104), regions 80.20%, functions 72.01%, 157 unit tests; aggregate lines 82.15%; integration-only 44.05% (12 tests). The MySQL and PostgreSQL driver suites skip themselves without Docker and two environment variables, so those 10 files count as 0-4% covered; the container-gated scope is not yet measured. Delivered in slices S0-S5; the row stays `TODO` until the first implementation slice starts. - 2026-11-17 12:43 UTC - Claude Code (Opus 5.5) - #2902 T1b, measured on 2026-11-17 after the maintainer allowed pulling the `mysql:8.0` and `postgres:16` images: with both driver suites running, the `tracker-core` aggregate is lines 93.80% (4,830 / 5,149). Correction: the commit that recorded T1b edited the 10:57 entry above in place; its original text is restored (review finding F9 of #2903). +- 2026-11-18 09:10 UTC - Claude Code (Opus 5.5) - #2902 re-measured its baseline with stable Rust 1.100.0 and `cargo-llvm-cov 0.9.1` (Rust 1.99.1 with `cargo-llvm-cov 0.6.16` cannot measure after the Cargo 1.100.0 test-binary layout change): `tracker-core` unit-only lines 79.32% (was 80.31%), aggregate 81.15% (was 82.15%), container-gated 92.67% (was 93.80%), at the same commit. The other packages' rows keep their own toolchains. - 2026-11-18 10:20 UTC - Claude Code (Claude Fable 5.2) - Added the "Publishing gate" paragraph under the `Subissues` table through PR torrust/torrust-tracker#2935 (issue #2583): by the maintainer's decision of 2026-11-18, a crate may be published under #2583 once its own package-testing subissues are closed, and EPIC #1669 no longer waits for this EPIC to close as a whole. No subissue was created or changed. ## Acceptance Criteria diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 7f83e5dd6d..8bef780bc2 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 04:23" +last-updated-utc: "2026-11-18 09:10" semantic-links: skill-links: - create-issue @@ -62,28 +62,31 @@ executable lines are at or above 98% unit-only coverage. The remaining gap is co the integration binary. - Many `?` regions (a failing `Database` or whitelist) are untested in the handlers and repositories. -Its unit-only lines (80.31%) are the lowest of the packages with a unit-only figure in the EPIC +Its unit-only lines (79.32%) are the lowest of the packages with a unit-only figure in the EPIC coverage table: the latest figures there are `primitives` 94.07%, `axum-rest-api-server` 96.67%, `udp-core` 98.04%, `udp-server` 98.18% and `http-core` 99.28%. Since the integration binary reaches only the `statistics/` files that no unit test reaches, the aggregate and unit-only numbers differ in exactly that area. ## Baseline Coverage -Measured 2026-11-17 at `develop` commit `5833cdae9` with `cargo-llvm-cov 0.6.16` and stable Rust -1.99.1 from a clean workspace; totals include only `packages/tracker-core/src/` (in-file test -modules and `src/test_helpers.rs` included). +Measured at `develop` commit `5833cdae9` with `cargo-llvm-cov 0.9.1` and stable Rust 1.100.0 from +a clean workspace (re-measured on 2026-11-18, after `stable` moved from Rust 1.99.1 and +`cargo-llvm-cov 0.6.16` stopped reading Cargo's new test-binary layout; see +[coverage-evidence.md](coverage-evidence.md)); totals include only `packages/tracker-core/src/` +(the helpers of in-file test modules and `src/test_helpers.rs` included; `#[test]` functions are +not counted). | Scope | Tests | Lines | Regions | Functions | | --- | ---: | ---: | ---: | ---: | -| Unit-only (`--all-features --lib`) | 157 unit | 4,099 / 5,104 (80.31%) | 5,716 / 7,127 (80.20%) | 687 / 954 (72.01%) | -| Integration-only (`--all-features --test integration`) | 12 integration | 841 / 1,909 (44.05%) | 936 / 2,506 (37.35%) | 145 / 484 (29.96%) | -| Aggregate (`--all-features`) | 157 unit + 12 integration | 4,230 / 5,149 (82.15%) | 5,834 / 7,182 (81.23%) | 703 / 958 (73.38%) | -| Unit-only without `db-compatibility-tests` (`--lib`) | 155 unit (the two driver tests are not compiled) | 4,085 / 4,780 (85.46%) | 5,700 / 6,691 (85.19%) | 683 / 916 (74.56%) | +| Unit-only (`--all-features --lib`) | 157 unit | 4,009 / 5,054 (79.32%) | 4,338 / 5,518 (78.62%) | 686 / 953 (71.98%) | +| Integration-only (`--all-features --test integration`) | 12 integration | 827 / 1,931 (42.83%) | 712 / 2,033 (35.02%) | 145 / 484 (29.96%) | +| Aggregate (`--all-features`) | 157 unit + 12 integration | 4,138 / 5,099 (81.15%) | 4,433 / 5,570 (79.59%) | 702 / 957 (73.35%) | +| Unit-only without `db-compatibility-tests` (`--lib`) | 155 unit (the two driver tests are not compiled) | 3,995 / 4,730 (84.46%) | 4,324 / 5,210 (82.99%) | 682 / 915 (74.54%) | With the MySQL and PostgreSQL suites actually running (Docker `mysql:8.0` and `postgres:16`, both -`TORRUST_TRACKER_CORE_RUN_*_DRIVER_TEST=true`, measured 2026-11-17 with the maintainer's permission) -the aggregate is lines 4,830 / 5,149 (93.80%), regions 93.61%, functions 84.45%: the server drivers -reach 58-96% per file, and what stays uncovered there are the failure branches (F2). The default +`TORRUST_TRACKER_CORE_RUN_*_DRIVER_TEST=true`, images pulled with the maintainer's permission) +the aggregate is lines 4,725 / 5,099 (92.67%), regions 89.39%, functions 84.43%: the server drivers +reach 53-94% per file, and what stays uncovered there are the failure branches (F2). The default runs above do not include them (F1). The per-file inventory and the uncovered-line groups are in [coverage-evidence.md](coverage-evidence.md). Indirect coverage from other packages' tests is not accepted as evidence. @@ -276,7 +279,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`, `DEFERRED`. | ID | Status | Task | Notes / Expected Output | | --- | ------ | ---- | ----------------------- | | T1 | DONE | Coverage evidence and complete module inventory | [coverage-evidence.md](coverage-evidence.md): baseline in four scopes, per-file uncovered groups, property candidacy, initial hypothesis for the 62 files. Delivered with this spec (S0). | -| T1b | DONE | Measure the container-gated scope | The `--all-features` run with `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST` and `TORRUST_TRACKER_CORE_RUN_POSTGRES_DRIVER_TEST` set (images pulled with the maintainer's permission, 2026-11-17): lines 93.80%. Recorded in `coverage-evidence.md`; informs the scope of S3. | +| T1b | DONE | Measure the container-gated scope | The `--all-features` run with `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST` and `TORRUST_TRACKER_CORE_RUN_POSTGRES_DRIVER_TEST` set (images pulled with the maintainer's permission, 2026-11-17): lines 92.67% (re-measured 2026-11-18 with Rust 1.100.0). Recorded in `coverage-evidence.md`; informs the scope of S3. | | T2 | DONE | Shared plan guidance | [`test-refactor-plans/README.md`](test-refactor-plans/README.md): two-phase sequence, guardrails, toolchain-pinned commands. First test slice (S1). | | T2b | IN_PROGRESS | Design-review checkpoint | After the first listener test and the first `TempDir`-owned SQLite test pass in S1, the maintainer reviews the fixture shape (see [Asynchronous Work, Cleanup and Test Fixtures](#asynchronous-work-cleanup-and-test-fixtures)) before other files reuse it. The SQLite half is done: the fixture shape of the [temporary-database fix](test-refactor-plans/test-support-ephemeral-database-tests.md) was approved on 2026-11-17; the listener half comes with S1. | | T3 | IN_PROGRESS | Process every ledger row through the per-file workflow | Each row ends in exactly one of: test added, no-change with reason, deferred with owner. | @@ -348,43 +351,43 @@ rows are ordered by slice, then by risk. | Order | Source module | Slice | Unit-only lines | Initial hypothesis | State | | ---: | --- | --- | ---: | --- | --- | -| 1 | `statistics/repository.rs` | S1 | 86 / 140 | Test candidate (four counter/gauge methods and error arms) | DONE | +| 1 | `statistics/repository.rs` | S1 | 85 / 139 | Test candidate (four counter/gauge methods and error arms) | DONE | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | -| 4 | `statistics/event/listener.rs` | S1 | 357 / 406 | Test candidate (spawn wrappers) | IN_PROGRESS | -| 5 | `statistics/event/handler.rs` | S1 | 179 / 203 | Mostly logging-only; one error arm | PENDING | +| 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers) | IN_PROGRESS | +| 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm | PENDING | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | -| 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 40 / 40, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | -| 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 50 | Test candidate | PENDING | -| 9 | `databases/driver/sqlite/torrent_metrics_store.rs` | S2 | 29 / 45 | Test candidate | PENDING | -| 10 | `databases/driver/sqlite/whitelist_store.rs` | S2 | 17 / 28 | Test candidate | PENDING | -| 11 | `databases/driver/sqlite/mod.rs` | S2 | 85 / 92 | Test candidate (aggregate-metric error branches) | PENDING | -| 12 | `databases/driver/sqlite/schema_migrator.rs` | S2 | 145 / 155 | No change likely; challenge each `?` | PENDING | +| 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | +| 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | +| 9 | `databases/driver/sqlite/torrent_metrics_store.rs` | S2 | 27 / 46 | Test candidate | PENDING | +| 10 | `databases/driver/sqlite/whitelist_store.rs` | S2 | 17 / 31 | Test candidate | PENDING | +| 11 | `databases/driver/sqlite/mod.rs` | S2 | 81 / 91 | Test candidate (aggregate-metric error branches) | PENDING | +| 12 | `databases/driver/sqlite/schema_migrator.rs` | S2 | 136 / 149 | No change likely; challenge each `?` | PENDING | | 13 | `databases/error.rs` | S2 | 28 / 35 | Test candidate (migration-error mapping) | PENDING | -| 14 | `databases/setup.rs` | S2 | 34 / 44 | Test candidate (SQLite arm and unreachable endpoint); server arms to S3 | PENDING | +| 14 | `databases/setup.rs` | S2 | 33 / 41 | Test candidate (SQLite arm and unreachable endpoint); server arms to S3 | PENDING | | 15 | `error.rs` | S2 | 38 / 50 | Test candidate (`From` conversions) | PENDING | -| 16 | `databases/driver/mod.rs` | S2 | 185 / 188 | No change (test-only retry helper) | PENDING | +| 16 | `databases/driver/mod.rs` | S2 | 186 / 189 | No change (test-only retry helper) | PENDING | | 17 | `databases/mod.rs`, `databases/traits/*` (6 files) | S2 | 2 / 2, no entries | No change (declarations and the mock) | PENDING | -| 18-22 | `databases/driver/mysql/{mod,auth_key_store,schema_migrator,torrent_metrics_store,whitelist_store}.rs` | S3 | 7 / 212, 0 / 50, 0 / 75, 0 / 45, 0 / 28 | Container-gated; assess after T1b | PENDING | -| 23-27 | `databases/driver/postgres/{mod,auth_key_store,schema_migrator,torrent_metrics_store,whitelist_store}.rs` | S3 | 7 / 189, 0 / 50, 0 / 6, 0 / 45, 0 / 28 | Container-gated; assess after T1b | PENDING | -| 28 | `authentication/handler.rs` | S4 | 371 / 371 | Failing-`Database` cases (two production `?` regions; seven assertion lines) | PENDING | -| 29 | `authentication/key/peer_key.rs` | S4 | 100 / 101 | `PartialEq` mixed-expiry arm; property candidate (`Key`); finding F3 check | PENDING | +| 18-22 | `databases/driver/mysql/{mod,auth_key_store,schema_migrator,torrent_metrics_store,whitelist_store}.rs` | S3 | 7 / 211, 0 / 55, 0 / 77, 0 / 46, 0 / 31 | Container-gated; assess after T1b | PENDING | +| 23-27 | `databases/driver/postgres/{mod,auth_key_store,schema_migrator,torrent_metrics_store,whitelist_store}.rs` | S3 | 7 / 188, 0 / 55, 0 / 6, 0 / 46, 0 / 31 | Container-gated; assess after T1b | PENDING | +| 28 | `authentication/handler.rs` | S4 | 366 / 366 | Failing-`Database` cases (two production `?` regions; seven assertion lines) | PENDING | +| 29 | `authentication/key/peer_key.rs` | S4 | 99 / 100 | `PartialEq` mixed-expiry arm; property candidate (`Key`); finding F3 check | PENDING | | 30 | `authentication/key/mod.rs` | S4 | 77 / 77 | Property candidate (expiry bounds) | PENDING | | 31 | `authentication/key/repository/persisted.rs` | S4 | 73 / 74 | Failing-`Database` cases | PENDING | -| 32 | `authentication/key/repository/in_memory.rs` | S4 | 92 / 92 | No change | PENDING | -| 33 | `authentication/service.rs` | S4 | 144 / 144 | No change; review breadth | PENDING | -| 34 | `authentication/mod.rs`, `authentication/key/repository/mod.rs` | S4 | 123 / 123, no entries | No change | PENDING | +| 32 | `authentication/key/repository/in_memory.rs` | S4 | 91 / 91 | No change | PENDING | +| 33 | `authentication/service.rs` | S4 | 143 / 143 | No change; review breadth | PENDING | +| 34 | `authentication/mod.rs`, `authentication/key/repository/mod.rs` | S4 | 114 / 114, no entries | No change | PENDING | | 35 | `whitelist/repository/persisted.rs` | S4 | 74 / 74 | Failing-`Database` cases; finding F4 check | PENDING | -| 36 | `whitelist/manager.rs` | S4 | 99 / 99 | Failing-`Database` cases | PENDING | -| 37 | `whitelist/authorization.rs` | S4 | 74 / 74 | No change (one test assertion line) | PENDING | +| 36 | `whitelist/manager.rs` | S4 | 97 / 97 | Failing-`Database` cases | PENDING | +| 37 | `whitelist/authorization.rs` | S4 | 71 / 71 | No change (one test assertion line) | PENDING | | 38 | `whitelist/repository/in_memory.rs` | S4 | 51 / 51 | No change | PENDING | | 39 | `whitelist/{mod,setup,test_helpers}.rs`, `whitelist/repository/mod.rs` | S4 | 18 / 18, 7 / 7, 12 / 12, no entries | No change | PENDING | | 40 | `torrent/repository/in_memory.rs` | S5 | 56 / 60 | Delegation of `get_torrent_peers` (owned by the registry) | PENDING | -| 41 | `torrent/manager.rs`, `torrent/services.rs`, `torrent/persisted_downloads.rs`, `torrent/mod.rs`, `torrent/repository/mod.rs` | S5 | 153 / 153, 267 / 267, 22 / 22, no entries | `manager.rs`: failing-`Database` case (line 66); the others no change, review breadth | PENDING | -| 42 | `announce_handler.rs` | S5 | 400 / 401 | Challenge the two `?` regions (one assertion line) | PENDING | -| 43 | `scrape_handler.rs` | S5 | 190 / 190 | No change (one assertion line) | PENDING | -| 44 | `container.rs` | S5 | 143 / 144 | Test candidate (`Persistence` error mapping) | PENDING | -| 45 | `lib.rs`, `peer_tests.rs`, `test_helpers.rs` | S5 | 58 / 58, 30 / 30, 109 / 123 | No change; test support classified | PENDING | +| 41 | `torrent/manager.rs`, `torrent/services.rs`, `torrent/persisted_downloads.rs`, `torrent/mod.rs`, `torrent/repository/mod.rs` | S5 | 150 / 156, 272 / 272, 22 / 22, no entries | `manager.rs`: failing-`Database` case (line 66); the others no change, review breadth | PENDING | +| 42 | `announce_handler.rs` | S5 | 388 / 389 | Challenge the two `?` regions (one assertion line) | PENDING | +| 43 | `scrape_handler.rs` | S5 | 184 / 184 | No change (one assertion line) | PENDING | +| 44 | `container.rs` | S5 | 136 / 138 | Test candidate (`Persistence` error mapping) | PENDING | +| 45 | `lib.rs`, `peer_tests.rs`, `test_helpers.rs` | S5 | 57 / 57, no entries (only `#[test]` functions), 110 / 124 | No change; test support classified | PENDING | The first slice's record checks the grouping against `find packages/tracker-core/src -name '*.rs'`. @@ -418,6 +421,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-17 22:27 UTC - Claude Code (Opus 5.5) - #2923 (the F5 fix) merged into `develop`; the S1 branch was rebuilt on it with only its own commits (the F20 fix of #2903, the S1 guidance, the Q2-Q7 and D1 answers, the repository tests). S1 continues with `statistics/metrics.rs`. - 2026-11-18 04:16 UTC - Claude Code (Opus 5.5) - Row 2 (`statistics/metrics.rs`) is done as no change, approved by the maintainer: the repository tests cover it 45 / 45 and kill all six hand-made mutants ([record](test-refactor-plans/statistics-metrics-tests.md)). - 2026-11-18 04:23 UTC - Claude Code (Opus 5.5) - Row 3 (`statistics/persisted/mod.rs`) done: five tests, 11 / 11 production lines, all eight named mutants killed; they pin that the load is not atomic ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)). Plan and completed file approved by the maintainer. +- 2026-11-18 09:10 UTC - Claude Code (Opus 5.5) - Every coverage figure re-measured, at the maintainer's request, with stable Rust 1.100.0 and `cargo-llvm-cov 0.9.1`: after `rustup update` moved `stable` from 1.99.1, `cargo-llvm-cov 0.6.16` reported 0% for every file (it read a stale binary from the old `target/debug/deps/` layout), and the maintainer upgraded it for everyone. Same commits as before: the T1 baseline at `5833cdae9` in five scopes (unit-only now 79.32%, was 80.31%; container-gated 92.67%, was 93.80%), and the unit-only run after rows 1 and 3. [coverage-evidence.md](coverage-evidence.md), the ledger, the baseline section and the row records hold the new figures; the entries above keep the old ones. The new toolchain does not count `#[test]` functions and adds a region per `tracing` call, classified as no decision. ## Open Design Questions @@ -433,7 +437,7 @@ Each has a recommendation; the maintainer decides. | Q6 | Is the six-slice plan (S0-S5) right, or should S4 and S5 merge? | ANSWERED (maintainer, 2026-11-17): keep six. | | Q7 | The temporary SQLite files the existing tests leave behind (F5): fix them here or hand them off? | ANSWERED (maintainer, 2026-11-17): fix here, package-local, with the package's helpers returning a `TempDir` guard with the configuration; the shared `test-helpers` function and the other packages are #2924 and #2925. Delivered in its own PR, split from S1 on the maintainer's request. | -Which EPIC row is the "unit-only" baseline? Recommendation: `--all-features --lib` (80.31%), the same +Which EPIC row is the "unit-only" baseline? Recommendation: `--all-features --lib` (79.32%), the same command as the other packages, with the container-gated figure reported separately in `coverage-evidence.md` and not in the EPIC tables. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md b/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md index 5956de594f..7a426f7886 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md @@ -3,19 +3,30 @@ doc-type: coverage-evidence issue: 2902 package: torrust-tracker-core measured-commit: 5833cdae98c0cfe3c2523c7f17e33bcfd3d7292f -measured-utc: 2026-11-17 +measured-utc: 2026-11-18 --- # Coverage Evidence - `torrust-tracker-core` -Baseline for the sub-issue spec of #2902. Measured on 2026-11-17 at `develop` commit `5833cdae9` +Baseline for the sub-issue spec of #2902. Measured at `develop` commit `5833cdae9` (full SHA `5833cdae98c0cfe3c2523c7f17e33bcfd3d7292f`) (`Merge torrust/torrust-tracker#2900: chore(issues): [#2873] archive the closed spec and mark it DONE in EPIC #2003`), -with `cargo-llvm-cov 0.6.16` and stable Rust 1.99.1, from a clean workspace and a separate -`CARGO_LLVM_COV_TARGET_DIR`. Every figure is filtered to `packages/tracker-core/src/` (62 files, 51 with executable lines). The -totals include the in-file `#[cfg(test)]` modules (most unit tests live in the files they test), so +with `cargo-llvm-cov 0.9.1` and stable Rust 1.100.0, from a clean workspace and a separate +`CARGO_LLVM_COV_TARGET_DIR`. Every figure is filtered to `packages/tracker-core/src/` (62 files, 50 with executable lines). The +totals include the helper functions of the in-file `#[cfg(test)]` modules (most unit tests live in the files they test), so they are not production-only coverage; `tests/` is not counted. The package has no benches or examples. +**Re-measured on 2026-11-18.** The first measurement (2026-11-17) used `cargo-llvm-cov 0.6.16` and +Rust 1.99.1. After `stable` moved to Rust 1.100.0, `cargo-llvm-cov 0.6.16` reported 0% for every +file: Cargo 1.100.0 writes test binaries under `target/debug/build///out/`, and +0.6.16 still read a stale binary from `target/debug/deps/`. At the maintainer's request every figure +of this issue was measured again with `cargo-llvm-cov 0.9.1` and Rust 1.100.0, from a clean +coverage target directory, at the same commits; the 1.99.1 figures are superseded and kept only in +the append-only progress logs. Two counting changes come with the new toolchain: `#[test]` +functions are not counted (so `peer_tests.rs`, which holds only tests, has no measured lines, and +test assertions no longer appear as uncovered lines), and each `tracing` macro adds a region for +its log-level check, which a test run with logging disabled leaves uncovered. + ```console cargo llvm-cov clean --workspace cargo llvm-cov -p torrust-tracker-core --all-features --lib --json --output-path .tmp/cov/unit.json @@ -27,13 +38,10 @@ cargo llvm-cov clean --workspace cargo llvm-cov -p torrust-tracker-core --lib --json --output-path .tmp/cov/unit-default.json ``` -The container-gated row (T1b) was measured afterwards on the S0 branch, at its commit -`docs(issues): [#2902] specify the tracker-core package tests`. That commit changes no file -under `packages/`, so the measured source is that of `develop` at -`5833cdae98c0cfe3c2523c7f17e33bcfd3d7292f`: `git diff --stat 5833cdae9 -- packages`, with -`` from `git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests'`, -prints nothing. The run followed `docker pull mysql:8.0` and `docker pull postgres:16` (the tests' default tags, -`mysql/mod.rs:115` and `postgres/mod.rs:102`), with the same separate target directory: +The container-gated row (T1b) is measured at the same commit, with the images `mysql:8.0` and +`postgres:16` (the tests' default tags, `mysql/mod.rs:115` and `postgres/mod.rs:102`; pulled with +the maintainer's permission on 2026-11-17 and reused from the local Docker cache) and the same +separate target directory: ```console cargo llvm-cov clean --workspace @@ -43,11 +51,11 @@ TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true TORRUST_TRACKER_CORE_RUN_POSTGRE | Scope | Tests | Lines | Regions | Functions | | --- | ---: | ---: | ---: | ---: | -| Unit-only (`--all-features --lib`) | 157 unit | 4,099 / 5,104 (80.31%) | 5,716 / 7,127 (80.20%) | 687 / 954 (72.01%) | -| Integration-only (`--all-features --test integration`) | 12 integration | 841 / 1,909 (44.05%) | 936 / 2,506 (37.35%) | 145 / 484 (29.96%) | -| Aggregate (`--all-features`, all targets) | 157 unit + 12 integration | 4,230 / 5,149 (82.15%) | 5,834 / 7,182 (81.23%) | 703 / 958 (73.38%) | -| Unit-only without the `db-compatibility-tests` feature (`--lib`) | 155 unit (the two driver tests are not compiled) | 4,085 / 4,780 (85.46%) | 5,700 / 6,691 (85.19%) | 683 / 916 (74.56%) | -| Container-gated aggregate (`--all-features`, both `TORRUST_TRACKER_CORE_RUN_*_DRIVER_TEST=true`, Docker `mysql:8.0` and `postgres:16`) | 157 unit + 12 integration, both driver suites run | 4,830 / 5,149 (93.80%) | 6,723 / 7,182 (93.61%) | 809 / 958 (84.45%) | +| Unit-only (`--all-features --lib`) | 157 unit | 4,009 / 5,054 (79.32%) | 4,338 / 5,518 (78.62%) | 686 / 953 (71.98%) | +| Integration-only (`--all-features --test integration`) | 12 integration | 827 / 1,931 (42.83%) | 712 / 2,033 (35.02%) | 145 / 484 (29.96%) | +| Aggregate (`--all-features`, all targets) | 157 unit + 12 integration | 4,138 / 5,099 (81.15%) | 4,433 / 5,570 (79.59%) | 702 / 957 (73.35%) | +| Unit-only without the `db-compatibility-tests` feature (`--lib`) | 155 unit (the two driver tests are not compiled) | 3,995 / 4,730 (84.46%) | 4,324 / 5,210 (82.99%) | 682 / 915 (74.54%) | +| Container-gated aggregate (`--all-features`, both `TORRUST_TRACKER_CORE_RUN_*_DRIVER_TEST=true`, Docker `mysql:8.0` and `postgres:16`) | 157 unit + 12 integration, both driver suites run | 4,725 / 5,099 (92.67%) | 4,979 / 5,570 (89.39%) | 808 / 957 (84.43%) | Reading the scopes: @@ -58,19 +66,19 @@ Reading the scopes: compiled by `--all-features` but **skip themselves and pass** unless `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST` / `TORRUST_TRACKER_CORE_RUN_POSTGRES_DRIVER_TEST` is set, and they then need Docker and the `mysql` / `postgres` images. So the four default rows above do - **not** include them: the two drivers (728 measured lines in ten files, 0-4% covered) are measured here as - uncovered. The fifth row above measures them with the suites running (T1b, 2026-11-17, images - `mysql:8.0` and `postgres:16`, the tests' defaults): the drivers' `mod.rs` files reach 95.8%, the - schema migrators 83-88%, and each store 58-64%: the same failure branches (malformed row, + **not** include them: the two drivers (746 measured lines in ten files, 0-4% covered) are measured here as + uncovered. The fifth row above measures them with the suites running (T1b, images + `mysql:8.0` and `postgres:16`, the tests' defaults): the drivers' `mod.rs` files reach 94%, the + schema migrators 83-84%, and each store 53-59%: the same failure branches (malformed row, failed query) that the SQLite stores leave uncovered. So the container-gated suite already protects the server drivers' happy path; the remaining gap there is the failure branches (F2). - Aggregate and unit-only lines differ in five files only, all under `statistics/` - (`event/handler.rs` 179 → 198 of 203 lines, `event/listener.rs` 357 → 419 of 421, `metrics.rs` - 11 → 20 of 45, `persisted/mod.rs` 0 → 26 of 32, `repository.rs` 86 → 101 of 149). That is the + (`event/handler.rs` 175 / 196 → 191 / 196 lines, `event/listener.rs` 360 / 411 → 423 / 426, + `metrics.rs` 11 → 20 of 45, `persisted/mod.rs` 0 / 11 → 26 / 32, `repository.rs` 85 / 139 → 100 / 148). That is the one area where the integration binary protects code no unit test reaches; the EPIC rule says it still needs focused unit tests (slice S1). The aggregate must not be used to claim unit coverage. - The EPIC tables for the other packages use `--all-features --lib`; the same command is the - unit-only baseline here (80.31%). The scope without the feature (85.46%) is the one that matches + unit-only baseline here (79.32%). The scope without the feature (84.46%) is the one that matches what a contributor's plain `cargo test -p torrust-tracker-core` runs. ## Per-File Inventory @@ -81,52 +89,51 @@ means the file is not reached). | File | Unit-only lines | Integration-only lines | Aggregate lines | Container-gated aggregate lines | | --- | ---: | ---: | ---: | ---: | -| `announce_handler.rs` | 400 / 401 (99.75%) | 80 / 92 (86.96%) | 400 / 401 (99.75%) | 400 / 401 (99.75%) | -| `authentication/handler.rs` | 371 / 371 (100.00%) | 6 / 90 (6.67%) | 371 / 371 (100.00%) | 371 / 371 (100.00%) | +| `announce_handler.rs` | 388 / 389 (99.74%) | 80 / 92 (86.96%) | 388 / 389 (99.74%) | 388 / 389 (99.74%) | +| `authentication/handler.rs` | 366 / 366 (100.00%) | 6 / 90 (6.67%) | 366 / 366 (100.00%) | 366 / 366 (100.00%) | | `authentication/key/mod.rs` | 77 / 77 (100.00%) | 0 / 31 (0.00%) | 77 / 77 (100.00%) | 77 / 77 (100.00%) | -| `authentication/key/peer_key.rs` | 100 / 101 (99.01%) | 0 / 45 (0.00%) | 100 / 101 (99.01%) | 100 / 101 (99.01%) | -| `authentication/key/repository/in_memory.rs` | 92 / 92 (100.00%) | 0 / 21 (0.00%) | 92 / 92 (100.00%) | 92 / 92 (100.00%) | +| `authentication/key/peer_key.rs` | 99 / 100 (99.00%) | 0 / 44 (0.00%) | 99 / 100 (99.00%) | 99 / 100 (99.00%) | +| `authentication/key/repository/in_memory.rs` | 91 / 91 (100.00%) | 0 / 20 (0.00%) | 91 / 91 (100.00%) | 91 / 91 (100.00%) | | `authentication/key/repository/persisted.rs` | 73 / 74 (98.65%) | 5 / 20 (25.00%) | 73 / 74 (98.65%) | 73 / 74 (98.65%) | -| `authentication/mod.rs` | 123 / 123 (100.00%) | - | 123 / 123 (100.00%) | 123 / 123 (100.00%) | -| `authentication/service.rs` | 144 / 144 (100.00%) | 6 / 30 (20.00%) | 144 / 144 (100.00%) | 144 / 144 (100.00%) | -| `container.rs` | 143 / 144 (99.31%) | 72 / 73 (98.63%) | 143 / 144 (99.31%) | 143 / 144 (99.31%) | -| `databases/driver/mod.rs` | 185 / 188 (98.40%) | - | 185 / 188 (98.40%) | 187 / 188 (99.47%) | -| `databases/driver/mysql/auth_key_store.rs` | 0 / 50 (0.00%) | 0 / 50 (0.00%) | 0 / 50 (0.00%) | 29 / 50 (58.00%) | -| `databases/driver/mysql/mod.rs` | 7 / 212 (3.30%) | 0 / 38 (0.00%) | 7 / 212 (3.30%) | 203 / 212 (95.75%) | -| `databases/driver/mysql/schema_migrator.rs` | 0 / 75 (0.00%) | 0 / 75 (0.00%) | 0 / 75 (0.00%) | 66 / 75 (88.00%) | -| `databases/driver/mysql/torrent_metrics_store.rs` | 0 / 45 (0.00%) | 0 / 45 (0.00%) | 0 / 45 (0.00%) | 29 / 45 (64.44%) | -| `databases/driver/mysql/whitelist_store.rs` | 0 / 28 (0.00%) | 0 / 28 (0.00%) | 0 / 28 (0.00%) | 17 / 28 (60.71%) | -| `databases/driver/postgres/auth_key_store.rs` | 0 / 50 (0.00%) | 0 / 50 (0.00%) | 0 / 50 (0.00%) | 29 / 50 (58.00%) | -| `databases/driver/postgres/mod.rs` | 7 / 189 (3.70%) | 0 / 39 (0.00%) | 7 / 189 (3.70%) | 181 / 189 (95.77%) | +| `authentication/mod.rs` | 114 / 114 (100.00%) | - | 114 / 114 (100.00%) | 114 / 114 (100.00%) | +| `authentication/service.rs` | 143 / 143 (100.00%) | 6 / 29 (20.69%) | 143 / 143 (100.00%) | 143 / 143 (100.00%) | +| `container.rs` | 136 / 138 (98.55%) | 71 / 73 (97.26%) | 136 / 138 (98.55%) | 136 / 138 (98.55%) | +| `databases/driver/mod.rs` | 186 / 189 (98.41%) | - | 186 / 189 (98.41%) | 188 / 189 (99.47%) | +| `databases/driver/mysql/auth_key_store.rs` | 0 / 55 (0.00%) | 0 / 55 (0.00%) | 0 / 55 (0.00%) | 29 / 55 (52.73%) | +| `databases/driver/mysql/mod.rs` | 7 / 211 (3.32%) | 0 / 37 (0.00%) | 7 / 211 (3.32%) | 199 / 211 (94.31%) | +| `databases/driver/mysql/schema_migrator.rs` | 0 / 77 (0.00%) | 0 / 77 (0.00%) | 0 / 77 (0.00%) | 65 / 77 (84.42%) | +| `databases/driver/mysql/torrent_metrics_store.rs` | 0 / 46 (0.00%) | 0 / 46 (0.00%) | 0 / 46 (0.00%) | 27 / 46 (58.70%) | +| `databases/driver/mysql/whitelist_store.rs` | 0 / 31 (0.00%) | 0 / 31 (0.00%) | 0 / 31 (0.00%) | 17 / 31 (54.84%) | +| `databases/driver/postgres/auth_key_store.rs` | 0 / 55 (0.00%) | 0 / 55 (0.00%) | 0 / 55 (0.00%) | 29 / 55 (52.73%) | +| `databases/driver/postgres/mod.rs` | 7 / 188 (3.72%) | 0 / 38 (0.00%) | 7 / 188 (3.72%) | 177 / 188 (94.15%) | | `databases/driver/postgres/schema_migrator.rs` | 0 / 6 (0.00%) | 0 / 6 (0.00%) | 0 / 6 (0.00%) | 5 / 6 (83.33%) | -| `databases/driver/postgres/torrent_metrics_store.rs` | 0 / 45 (0.00%) | 0 / 45 (0.00%) | 0 / 45 (0.00%) | 29 / 45 (64.44%) | -| `databases/driver/postgres/whitelist_store.rs` | 0 / 28 (0.00%) | 0 / 28 (0.00%) | 0 / 28 (0.00%) | 17 / 28 (60.71%) | -| `databases/driver/sqlite/auth_key_store.rs` | 29 / 50 (58.00%) | 0 / 50 (0.00%) | 29 / 50 (58.00%) | 29 / 50 (58.00%) | -| `databases/driver/sqlite/mod.rs` | 85 / 92 (92.39%) | 32 / 37 (86.49%) | 85 / 92 (92.39%) | 85 / 92 (92.39%) | -| `databases/driver/sqlite/schema_migrator.rs` | 145 / 155 (93.55%) | 22 / 73 (30.14%) | 145 / 155 (93.55%) | 145 / 155 (93.55%) | -| `databases/driver/sqlite/torrent_metrics_store.rs` | 29 / 45 (64.44%) | 29 / 45 (64.44%) | 29 / 45 (64.44%) | 29 / 45 (64.44%) | -| `databases/driver/sqlite/whitelist_store.rs` | 17 / 28 (60.71%) | 0 / 28 (0.00%) | 17 / 28 (60.71%) | 17 / 28 (60.71%) | +| `databases/driver/postgres/torrent_metrics_store.rs` | 0 / 46 (0.00%) | 0 / 46 (0.00%) | 0 / 46 (0.00%) | 27 / 46 (58.70%) | +| `databases/driver/postgres/whitelist_store.rs` | 0 / 31 (0.00%) | 0 / 31 (0.00%) | 0 / 31 (0.00%) | 17 / 31 (54.84%) | +| `databases/driver/sqlite/auth_key_store.rs` | 29 / 55 (52.73%) | 0 / 55 (0.00%) | 29 / 55 (52.73%) | 29 / 55 (52.73%) | +| `databases/driver/sqlite/mod.rs` | 81 / 91 (89.01%) | 28 / 36 (77.78%) | 81 / 91 (89.01%) | 81 / 91 (89.01%) | +| `databases/driver/sqlite/schema_migrator.rs` | 136 / 149 (91.28%) | 20 / 73 (27.40%) | 136 / 149 (91.28%) | 136 / 149 (91.28%) | +| `databases/driver/sqlite/torrent_metrics_store.rs` | 27 / 46 (58.70%) | 27 / 46 (58.70%) | 27 / 46 (58.70%) | 27 / 46 (58.70%) | +| `databases/driver/sqlite/whitelist_store.rs` | 17 / 31 (54.84%) | 0 / 31 (0.00%) | 17 / 31 (54.84%) | 17 / 31 (54.84%) | | `databases/error.rs` | 28 / 35 (80.00%) | 0 / 23 (0.00%) | 28 / 35 (80.00%) | 35 / 35 (100.00%) | -| `databases/setup.rs` | 34 / 44 (77.27%) | 18 / 29 (62.07%) | 34 / 44 (77.27%) | 34 / 44 (77.27%) | +| `databases/setup.rs` | 33 / 41 (80.49%) | 17 / 26 (65.38%) | 33 / 41 (80.49%) | 33 / 41 (80.49%) | | `databases/traits/whitelist.rs` | 2 / 2 (100.00%) | 0 / 2 (0.00%) | 2 / 2 (100.00%) | 2 / 2 (100.00%) | | `error.rs` | 38 / 50 (76.00%) | 0 / 12 (0.00%) | 38 / 50 (76.00%) | 38 / 50 (76.00%) | -| `lib.rs` | 58 / 58 (100.00%) | - | 58 / 58 (100.00%) | 58 / 58 (100.00%) | -| `peer_tests.rs` | 30 / 30 (100.00%) | - | 30 / 30 (100.00%) | 30 / 30 (100.00%) | -| `scrape_handler.rs` | 190 / 190 (100.00%) | 43 / 44 (97.73%) | 190 / 190 (100.00%) | 190 / 190 (100.00%) | -| `statistics/event/handler.rs` | 179 / 203 (88.18%) | 92 / 99 (92.93%) | 198 / 203 (97.54%) | 198 / 203 (97.54%) | -| `statistics/event/listener.rs` | 357 / 406 (87.93%) | 156 / 168 (92.86%) | 419 / 421 (99.52%) | 419 / 421 (99.52%) | +| `lib.rs` | 57 / 57 (100.00%) | - | 57 / 57 (100.00%) | 57 / 57 (100.00%) | +| `scrape_handler.rs` | 184 / 184 (100.00%) | 41 / 42 (97.62%) | 184 / 184 (100.00%) | 184 / 184 (100.00%) | +| `statistics/event/handler.rs` | 175 / 196 (89.29%) | 88 / 94 (93.62%) | 191 / 196 (97.45%) | 191 / 196 (97.45%) | +| `statistics/event/listener.rs` | 360 / 411 (87.59%) | 155 / 167 (92.81%) | 423 / 426 (99.30%) | 423 / 426 (99.30%) | | `statistics/metrics.rs` | 11 / 45 (24.44%) | 20 / 45 (44.44%) | 20 / 45 (44.44%) | 20 / 45 (44.44%) | -| `statistics/mod.rs` | 40 / 40 (100.00%) | 40 / 40 (100.00%) | 40 / 40 (100.00%) | 40 / 40 (100.00%) | +| `statistics/mod.rs` | 42 / 43 (97.67%) | 42 / 43 (97.67%) | 42 / 43 (97.67%) | 42 / 43 (97.67%) | | `statistics/persisted/downloads.rs` | 77 / 77 (100.00%) | 39 / 39 (100.00%) | 77 / 77 (100.00%) | 77 / 77 (100.00%) | | `statistics/persisted/mod.rs` | 0 / 11 (0.00%) | 26 / 32 (81.25%) | 26 / 32 (81.25%) | 26 / 32 (81.25%) | -| `statistics/repository.rs` | 86 / 140 (61.43%) | 60 / 115 (52.17%) | 101 / 149 (67.79%) | 101 / 149 (67.79%) | -| `test_helpers.rs` | 109 / 123 (88.62%) | - | 109 / 123 (88.62%) | 109 / 123 (88.62%) | -| `torrent/manager.rs` | 153 / 153 (100.00%) | 15 / 48 (31.25%) | 153 / 153 (100.00%) | 153 / 153 (100.00%) | +| `statistics/repository.rs` | 85 / 139 (61.15%) | 61 / 116 (52.59%) | 100 / 148 (67.57%) | 100 / 148 (67.57%) | +| `test_helpers.rs` | 110 / 124 (88.71%) | - | 110 / 124 (88.71%) | 110 / 124 (88.71%) | +| `torrent/manager.rs` | 150 / 156 (96.15%) | 15 / 54 (27.78%) | 150 / 156 (96.15%) | 150 / 156 (96.15%) | | `torrent/persisted_downloads.rs` | 22 / 22 (100.00%) | 22 / 22 (100.00%) | 22 / 22 (100.00%) | 22 / 22 (100.00%) | | `torrent/repository/in_memory.rs` | 56 / 60 (93.33%) | 30 / 60 (50.00%) | 56 / 60 (93.33%) | 56 / 60 (93.33%) | -| `torrent/services.rs` | 267 / 267 (100.00%) | 0 / 1 (0.00%) | 267 / 267 (100.00%) | 267 / 267 (100.00%) | -| `whitelist/authorization.rs` | 74 / 74 (100.00%) | 12 / 16 (75.00%) | 74 / 74 (100.00%) | 74 / 74 (100.00%) | -| `whitelist/manager.rs` | 99 / 99 (100.00%) | 6 / 26 (23.08%) | 99 / 99 (100.00%) | 99 / 99 (100.00%) | +| `torrent/services.rs` | 272 / 272 (100.00%) | 0 / 1 (0.00%) | 272 / 272 (100.00%) | 272 / 272 (100.00%) | +| `whitelist/authorization.rs` | 71 / 71 (100.00%) | 12 / 16 (75.00%) | 71 / 71 (100.00%) | 71 / 71 (100.00%) | +| `whitelist/manager.rs` | 97 / 97 (100.00%) | 6 / 26 (23.08%) | 97 / 97 (100.00%) | 97 / 97 (100.00%) | | `whitelist/mod.rs` | 18 / 18 (100.00%) | - | 18 / 18 (100.00%) | 18 / 18 (100.00%) | | `whitelist/repository/in_memory.rs` | 51 / 51 (100.00%) | 0 / 17 (0.00%) | 51 / 51 (100.00%) | 51 / 51 (100.00%) | | `whitelist/repository/persisted.rs` | 74 / 74 (100.00%) | 3 / 25 (12.00%) | 74 / 74 (100.00%) | 74 / 74 (100.00%) | @@ -139,7 +146,7 @@ Line numbers are those of `5833cdae9`. Each row covers one file, or one family o class; where a file has a `#[cfg(test)]` module, the lines column labels its `production:` lines and its `test module:` lines separately. A test-module line is never a decision to test. Classes: **3A** unit-testable now; **3B** needs a boundary above a unit test (a container, a real database); **owned** by a collaborator or another issue; -**no decision** (logging-only code, code-region artifacts); **test code** (lines in a `#[cfg(test)]` +**no decision** (logging-only code, logging-macro regions, code-region artifacts); **test code** (lines in a `#[cfg(test)]` module or in test support). A "hypothesis" is not a decision: each group is re-challenged per file in the decision records (hard to test, owned elsewhere, or merely unselected?). @@ -150,31 +157,29 @@ module or in test support). A | `databases/driver/sqlite/auth_key_store.rs` | 18-100, 124-126 | Row-parse failure branches (`MalformedDatabaseRecord` for a bad key or a negative `valid_until`), `sqlx` failures, `parse_valid_until` negative case | 3A | Test through a temp SQLite file with a malformed row inserted by raw `sqlx`; the same helper is copied in three drivers (finding F2) | | `databases/driver/sqlite/torrent_metrics_store.rs` | 15-124 (16 of 45 lines uncovered) | Aggregate metric load/save error branches, `u32` conversion failure (`MalformedDatabaseRecord`) | 3A | Same technique | | `databases/driver/sqlite/whitelist_store.rs` | 18-75 (11 of 28) | Row-parse and query failure branches | 3A | Same technique | -| `databases/driver/sqlite/mod.rs` | production: 54, 58, 60, 62, 79; test module: 103, 119 | Production: the error branches of the aggregate-metric helpers (`load_torrent_aggregate_metric`: query failure, `try_get` failure, the `u32` conversion to `MalformedDatabaseRecord`; `save_torrent_aggregate_metric`: query failure). Test module: lines 103 and 119 are `unreachable!` arms of the test helpers | 3A (production), test code (test module) | A row with an out-of-range value inserted by raw `sqlx`; a dropped table. `Sqlite::new` (lines 38-47) is fully covered | +| `databases/driver/sqlite/mod.rs` | production: 54, 58, 60-62, 79; test module: 103, 119 | Production: the error branches of the aggregate-metric helpers (`load_torrent_aggregate_metric`: query failure, `try_get` failure, the `u32` conversion to `MalformedDatabaseRecord`; `save_torrent_aggregate_metric`: query failure). Test module: lines 103 and 119 are `unreachable!` arms of the test helpers | 3A (production), test code (test module) | A row with an out-of-range value inserted by raw `sqlx`; a dropped table. `Sqlite::new` (lines 38-47) is fully covered | | `databases/driver/sqlite/schema_migrator.rs` | production: 38, 56, 90, 103, 122-123, 136, 139, 152; test module: 275 | Production: `?` error regions of the legacy bootstrap and `drop_database_tables`. Test module: line 275 is an assertion | mostly no decision (production), test code (test module) | Legacy partial-state and migrated paths are already tested; challenge each `?` region | | `databases/driver/mod.rs` | test module: 67-68, 70 | Retry loop of the test-only `create_database_tables` helper | test support | No-change | -| `databases/error.rs` | production: 140-147; test module: 160, 173 | Production: `From<(MigrateError, Driver)>` (the `MigrationError` mapping). Test module: lines 160 and 173 are assertions | 3A (production), test code (test module) | One test of the migration-error mapping; the `sqlx::Error` arms are already tested | +| `databases/error.rs` | production: 140-141, 143-147 | `From<(MigrateError, Driver)>` (the `MigrationError` mapping) | 3A | One test of the migration-error mapping; the `sqlx::Error` arms are already tested | | `databases/setup.rs` | production: 114-128 | `initialize_database_from_configuration` for MySQL and PostgreSQL | 3B (success path) or 3A (unreachable endpoint) | Unreachable-endpoint error test is 3A; the success path is container-gated | | `error.rs` | production: 47-49, 53-55, 59-61, 65-67 | The four `From` conversions into `TrackerCoreError` | 3A | Trivial but package-owned wiring; one table test | | `statistics/repository.rs` | production: 104, 114-120, 139-146, 148-154, 157-158, 164-206 | `set_counter`, `set_gauge`, `increment_gauge`, `decrement_gauge` and their error-logging arms | 3A | Covered only by the integration binary today; direct unit tests (success and metric-type-mismatch error) | | `statistics/metrics.rs` | 36-44, 49-57, 62-69, 74-81 | `Metrics::set_counter`, `set_gauge`, `increment_gauge`, `decrement_gauge` | 3A | Same | | `statistics/persisted/mod.rs` | 21-25, 59-61, 65-67 | `load_persisted_metrics` (startup load into the in-memory counters) | 3A | Unit test with the `testing` feature's `TorrentMetricsStore` mock (ADR on test support) or a temp SQLite store | | `statistics/persisted/downloads.rs` | production: 133 | Production: the `?` of `increase_global_downloads` when `load_global_downloads` fails | 3A (medium) | Failing-`Database` case | -| `statistics/event/listener.rs` | production: 19-83; test module: 283-284 | Production: the two spawning wrappers (`run_*_event_listener`) and the `*_unspawned` entry points. Test module: lines 283-284 belong to the test `ScriptedReceiver` | 3A (production), test code (test module) | Spawn, send an event, cancel, await the handle; drain behavior is owned by the `events` package | -| `statistics/event/handler.rs` | production: 19-58, 129 | Logging-only handlers (`handle_torrent_added`, `_removed`, `handle_peer_*`) and one error arm | no decision (logging-only arms), 3A (line 129) | The logging-only arms carry no state change; decide whether a log-assertion test (ADR on log identifiers) is worth it; line 129 is a metric-increment error arm | +| `statistics/event/listener.rs` | production: 19-83; logging-macro regions: 106, 134, 168, 186, 227, 231; test module: 283-284 | Production: the two spawning wrappers (`run_*_event_listener`) and the `*_unspawned` entry points. Test module: lines 283-284 belong to the test `ScriptedReceiver` | 3A (production), no decision (logging-macro regions), test code (test module) | Spawn, send an event, cancel, await the handle; drain behavior is owned by the `events` package | +| `statistics/event/handler.rs` | production: 19-58, 129; logging-macro regions: 66, 106, 108, 120 | Logging-only handlers (`handle_torrent_added`, `_removed`, `handle_peer_*`) and one error arm | no decision (logging-only arms and logging-macro regions), 3A (line 129) | The logging-only arms carry no state change; decide whether a log-assertion test (ADR on log identifiers) is worth it; line 129 is a metric-increment error arm | | `statistics/mod.rs` | 49 | Production: the implicit `else` of `if tracker_usage_statistics_enabled` (the in-session counter is not described when usage statistics are disabled) | 3A | A metrics test with usage statistics disabled | -| `container.rs` | production: 86; test module: 193 | Production: the `Persistence` error mapping when the database cannot initialize. Test module: line 193 is an assertion | 3A (production), test code (test module) | Container built over an invalid SQLite path | -| `authentication/handler.rs` | production: 252, 280; test module: 424, 479, 493, 531, 604, 656, 690 | Production: the `?` regions of `remove_peer_key` and `load_peer_keys_from_database` (database failure). Test module: the other seven lines are assertions | 3A (production), test code (test module) | Fake the `Database` failing | +| `container.rs` | production: 86 | The `Persistence` error mapping when the database cannot initialize | 3A | Container built over an invalid SQLite path | +| `authentication/handler.rs` | production: 252, 280 | The `?` regions of `remove_peer_key` and `load_peer_keys_from_database` (database failure) | 3A | Fake the `Database` failing | | `authentication/key/repository/persisted.rs` | production: 57, 71; test module: 96 | Production: the `?` regions of `remove` and `load_keys`. Test module: line 96 is an `unreachable!` arm of a test helper | 3A (production), test code (test module) | Same fake | | `authentication/key/peer_key.rs` | production: 64 | The `_ => false` arm of `PeerKey`'s `PartialEq` (one key expiring, the other permanent) | 3A | One equality case | -| `authentication/key/mod.rs` | test module: 304 | An assertion | test code | No-change | +| `authentication/key/mod.rs` | production: 113, 120 | The log-level regions of the two `tracing::debug!` calls in `generate_key` | no decision (logging-macro regions) | No-change | | `announce_handler.rs` | production: 184, 189; test module: 634 | Production: the `?` regions of the announce (whitelist failure, downloads load failure). Test module: line 634 is an assertion | 3A (production), test code (test module) | Whitelist and database failure cases may exist elsewhere; challenge | -| `scrape_handler.rs` | test module: 350 | Test module: an assertion | test code | No-change | -| `torrent/manager.rs` | production: 66 | Production: the `?` of `load_torrents_from_database` when the database fails | 3A (medium) | Failing-`Database` case | +| `torrent/manager.rs` | production: 66; logging-macro regions: 120-123, 131-132 | Production: the `?` of `load_torrents_from_database` when the database fails | 3A (medium), no decision (logging-macro regions) | Failing-`Database` case | | `torrent/repository/in_memory.rs` | 177-179 | `get_torrent_peers` delegating to the swarm registry | owned (swarm-coordination-registry) | A thin delegation test is cheap; decide per file | | `whitelist/manager.rs` | production: 53, 66, 79 | The `?` regions of `add`, `remove` and `load` (database failure) | 3A | Same failing-`Database` fake | | `whitelist/repository/persisted.rs` | production: 30, 36, 46, 52 | The `?` regions of the read and the write in `add` and `remove` | 3A | Same fake (finding F4 check) | -| `whitelist/authorization.rs` | test module: 139 | An assertion | test code | No-change | | `test_helpers.rs` | test module: 144-156, 209 | Test-support builder branch for persistent completed statistics | test support | Not package-owned behavior; no test by decision, unless a slice uses it | Counts are by line class, not by decision: a "region" group can disappear when its neighbors are diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 3c9283a39c..c8de7de36a 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -78,7 +78,10 @@ Each file goes through the same two phases, with a maintainer gate after each: ## Commands Use stable Rust for tests and coverage and the nightly toolchain for formatting only; record the -toolchain with every result. The S1 baseline used stable Rust 1.99.1 and `cargo-llvm-cov 0.6.16`. +toolchain with every result. Every figure of this issue uses stable Rust 1.100.0 and +`cargo-llvm-cov 0.9.1` (re-measured on 2026-11-18; the first figures used Rust 1.99.1 and +`cargo-llvm-cov 0.6.16`, which cannot read the test-binary layout of Cargo 1.100.0). Measure from a +clean coverage target directory: a stale binary there is merged into the report. ```bash # Focused tests diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md index 75dc42929a..5d5a6e95c5 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-metrics-tests.md @@ -19,8 +19,8 @@ Follow the shared [guidance](README.md). This record covers only ## Current State - **Unit-only coverage:** 11 / 45 lines at the S1 baseline; 45 / 45 after the - [repository tests](statistics-repository-tests.md) (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, - `--all-features --lib`, 2026-11-17). The baseline left 36-44, 49-57, 62-69 and 74-81 uncovered: + [repository tests](statistics-repository-tests.md) (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, + `--all-features --lib`; re-measured on 2026-11-18, the same figures). The baseline left 36-44, 49-57, 62-69 and 74-81 uncovered: `set_counter`, `set_gauge`, `increment_gauge` and `decrement_gauge`. - **What the file decides:** nothing of its own. `Metrics` holds a `MetricCollection`; its accessor returns it and its five write methods pass their arguments to the method of the same name and diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md index 421b44dc92..2882a09a3f 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-mod-tests.md @@ -20,8 +20,7 @@ Follow the shared [guidance](README.md). This plan covers only ## Current State -- **Unit-only coverage:** 0 / 11 lines, at the S1 baseline and after rows 1 and 2 (stable Rust - 1.99.1, `cargo-llvm-cov 0.6.16`, `--all-features --lib`). Uncovered: 21-46 +- **Unit-only coverage:** 0 / 11 lines, at the S1 baseline and after rows 1 and 2 (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, `--all-features --lib`; re-measured on 2026-11-18). Uncovered: 21-46 (`load_persisted_metrics`) and 58-68 (the two `From` conversions into `Error`). - **Callers:** the tracker start-up (`src/app.rs:385`) and the integration test environment (`tests/common/test_env.rs:138`), which unwraps the result on a real SQLite database with no @@ -86,9 +85,10 @@ a runtime per case for no extra mutant. ## Results -- **Coverage:** the file's production lines 0 / 11 to 11 / 11 (`--all-features --lib`, stable Rust - 1.99.1, 2026-11-18); the package's unit-only lines 4,351 / 5,266 (82.62%) to 4,474 / 5,378 - (83.19%), where the denominator grows with the 112 lines of the new test module. One region stays +- **Coverage:** the file's production lines 0 / 11 to 11 / 11 (`--all-features --lib`, + stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, re-measured on 2026-11-18; 124 / 124 lines with the test module's + helpers); the package's unit-only lines 4,256 / 5,211 (81.67%) to 4,380 / 5,324 (82.27%), where + the denominator grows with the 113 measured lines of the new test module. One region stays uncovered: the `?` error arm of the first write (line 34), which cannot be reached because `describe_metrics` always registers the persistent total as a counter. - **Tests:** five added, all passing; 172 unit tests in the package. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md index 2d42fb2350..9d23638e7c 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md @@ -21,10 +21,10 @@ Follow the shared [guidance](README.md). This plan covers only ## Current State -- **Unit-only coverage:** 86 / 140 lines (61.43%), 117 / 172 regions, 22 / 29 functions, at the S1 - baseline (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, clean workspace, - `--all-features --lib`, 2026-11-17). It is the T1 figure: no file under `packages/` changed - between the measured commit and the S1 branch point. +- **Unit-only coverage:** 85 / 139 lines (61.15%), 92 / 138 regions, 22 / 29 functions, at the S1 + baseline (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, clean workspace, `--all-features --lib`; re-measured on + 2026-11-18, see [coverage-evidence.md](../coverage-evidence.md)). It is the T1 figure: this file + did not change between the measured commit and the S1 branch point. - **Uncovered lines** (as `cargo-llvm-cov` reports them): 104 (the error arm of `increment_counter`), 114-120 (the entry of `set_counter`), 139-158 (`set_gauge`), 164-182 (`increment_gauge`) and 188-206 (`decrement_gauge`). The async bodies make the per-line split @@ -152,11 +152,13 @@ Gauges are compared as `Option` (`Gauge` derives `PartialEq`), which keep ## Results -- **Unit-only coverage** (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, clean workspace, - `--all-features --lib`): `statistics/repository.rs` 86 / 140 lines at the S1 baseline; 277 / 277 - lines (100.00%), 394 / 394 regions and 57 / 57 functions after (the counts include the test - module). Package unit-only lines after this file: 4,324 / 5,241 (82.50%), regions 6,023 / 7,349 - (81.96%), functions 726 / 982 (73.93%), 167 unit tests (157 before). +- **Unit-only coverage** (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, clean workspace, `--all-features --lib`; + re-measured on 2026-11-18): `statistics/repository.rs` 85 / 139 lines at the S1 baseline; + 275 / 275 lines (100.00%), 342 / 347 regions and 57 / 57 functions after (the counts include the + test module's helpers). The five uncovered regions are the log-level checks of the + `tracing::error!` calls in the error arms (lines 104, 129, 154, 178 and 202); the arms themselves + run in the refusal tests. Package unit-only lines after this file: 4,256 / 5,211 (81.67%), + regions 4,624 / 5,739 (80.57%), functions 716 / 972 (73.66%), 167 unit tests (157 before). - **Covered but not asserted:** `statistics/metrics.rs` (row 2) is now 45 / 45 lines, because every repository write calls its `Metrics` wrapper. Row 2 decides whether that needs its own tests. - **Tests:** 10 added, 1 changed (R1), 1 unchanged. No integration test was added or changed. From 00d79fd5897ef52f36ef5ad7199679bd3f1eccbb Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 09:36:43 +0000 Subject: [PATCH 13/40] test(tracker-core): [#2902] cover the public statistics listener entry points The tests covered only the private dispatch loops. Four tests run the two `*_unspawned` functions the application supervises and the two spawn wrappers over a real event bus: send one event, cancel, await the listener within a 5-second deadline, and check the counted or persisted download and, for the unspawned functions, the `Cancelled` completion. Co-Authored-By: Claude Opus 5.5 --- .../src/statistics/event/listener.rs | 139 +++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/packages/tracker-core/src/statistics/event/listener.rs b/packages/tracker-core/src/statistics/event/listener.rs index c7ae8a2892..548ab3856a 100644 --- a/packages/tracker-core/src/statistics/event/listener.rs +++ b/packages/tracker-core/src/statistics/event/listener.rs @@ -250,8 +250,13 @@ mod tests { use torrust_tracker_events::receiver::{RecvError, TryRecvError}; use torrust_tracker_events::shutdown::Completion; use torrust_tracker_swarm_coordination_registry::event::Event; + use torrust_tracker_swarm_coordination_registry::event::bus::EventBus; - use super::{dispatch_in_memory_events, dispatch_persistent_completed_statistics_events}; + use super::{ + dispatch_in_memory_events, dispatch_persistent_completed_statistics_events, run_in_memory_event_listener, + run_in_memory_event_listener_unspawned, run_persistent_completed_statistics_event_listener, + run_persistent_completed_statistics_event_listener_unspawned, + }; use crate::databases::setup::initialize_database; use crate::statistics::persisted::downloads::DatabaseDownloadsMetricRepository; use crate::statistics::repository::Repository; @@ -616,4 +621,136 @@ mod tests { "an expired drain must still return Cancelled" ); } + + /// The deadline for every wait on a listener (spec: Asynchronous Work, Cleanup and Test Fixtures). + const LISTENER_DEADLINE: Duration = Duration::from_secs(5); + + /// Sends `event` on the bus; every receiver subscribed before the call queues it. + async fn send(event_bus: &EventBus, event: Event) { + let sender = event_bus.sender().expect("the default event bus has an enabled sender"); + sender + .send(event) + .await + .expect("an enabled sender returns a result") + .expect("the listener's receiver is subscribed, so the event is queued"); + } + + /// Awaits `listener` within [`LISTENER_DEADLINE`], failing with a message naming it. + async fn within_deadline(listener: impl Future, name: &str) -> T { + tokio::time::timeout(LISTENER_DEADLINE, listener) + .await + .unwrap_or_else(|_| panic!("{name} did not finish within {LISTENER_DEADLINE:?}")) + } + + #[tokio::test] + async fn it_should_handle_a_queued_event_and_return_cancelled_when_the_unspawned_in_memory_listener_is_cancelled() { + // Arrange + clock::Stopped::local_set_to_unix_epoch(); + let stats_repository = Arc::new(Repository::default()); + let event_bus = EventBus::default(); + let cancellation_token = CancellationToken::new(); + let listener = run_in_memory_event_listener_unspawned( + event_bus.receiver(), + cancellation_token.clone(), + stats_repository.clone(), + DEFAULT_DRAIN_TIMEOUT, + ); + send(&event_bus, peer_download_completed_event()).await; + + // Act + cancellation_token.cancel(); + let completion = within_deadline(listener, "the unspawned in-memory listener").await; + + // Assert + expect_in_memory_download_metrics_to_be(&stats_repository, 1).await; + assert_eq!( + completion, + Completion::Cancelled, + "a cancelled listener must return Cancelled" + ); + } + + #[tokio::test] + async fn it_should_persist_a_queued_event_and_return_cancelled_when_the_unspawned_persistent_listener_is_cancelled() { + // Arrange + clock::Stopped::local_set_to_unix_epoch(); + let stats_repository = Arc::new(Repository::new(true, true)); + let ephemeral = ephemeral_configuration(); + let downloads_repository = database_downloads_repository(&ephemeral.config).await; + let event_bus = EventBus::default(); + let cancellation_token = CancellationToken::new(); + let listener = run_persistent_completed_statistics_event_listener_unspawned( + event_bus.receiver(), + cancellation_token.clone(), + downloads_repository.clone(), + stats_repository.clone(), + DEFAULT_DRAIN_TIMEOUT, + ); + send(&event_bus, peer_download_completed_event()).await; + + // Act + cancellation_token.cancel(); + let completion = within_deadline(listener, "the unspawned persistent listener").await; + + // Assert + expect_persisted_download_metrics_to_be(&downloads_repository, &stats_repository, Some(1)).await; + assert_eq!( + completion, + Completion::Cancelled, + "a cancelled listener must return Cancelled" + ); + } + + #[tokio::test] + async fn it_should_handle_a_queued_event_then_finish_when_the_spawned_in_memory_listener_is_cancelled() { + // Arrange + clock::Stopped::local_set_to_unix_epoch(); + let stats_repository = Arc::new(Repository::default()); + let event_bus = EventBus::default(); + let cancellation_token = CancellationToken::new(); + let listener = run_in_memory_event_listener( + event_bus.receiver(), + cancellation_token.clone(), + &stats_repository, + DEFAULT_DRAIN_TIMEOUT, + ); + send(&event_bus, peer_download_completed_event()).await; + + // Act + cancellation_token.cancel(); + within_deadline(listener, "the spawned in-memory listener") + .await + .expect("the listener task must not panic"); + + // Assert + expect_in_memory_download_metrics_to_be(&stats_repository, 1).await; + } + + #[tokio::test] + async fn it_should_persist_a_queued_event_then_finish_when_the_spawned_persistent_listener_is_cancelled() { + // Arrange + clock::Stopped::local_set_to_unix_epoch(); + let stats_repository = Arc::new(Repository::new(true, true)); + let ephemeral = ephemeral_configuration(); + let downloads_repository = database_downloads_repository(&ephemeral.config).await; + let event_bus = EventBus::default(); + let cancellation_token = CancellationToken::new(); + let listener = run_persistent_completed_statistics_event_listener( + event_bus.receiver(), + cancellation_token.clone(), + &downloads_repository, + &stats_repository, + DEFAULT_DRAIN_TIMEOUT, + ); + send(&event_bus, peer_download_completed_event()).await; + + // Act + cancellation_token.cancel(); + within_deadline(listener, "the spawned persistent listener") + .await + .expect("the listener task must not panic"); + + // Assert + expect_persisted_download_metrics_to_be(&downloads_repository, &stats_repository, Some(1)).await; + } } From d48058796f38bfb82e535eaf1479072e1f295e21 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 09:37:18 +0000 Subject: [PATCH 14/40] docs(issues): [#2902] record the results of the statistics listener tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 7 +-- .../test-refactor-plans/README.md | 2 +- .../statistics-event-listener-tests.md | 48 +++++++++++++++---- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 8bef780bc2..2f5dbf5955 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 09:10" +last-updated-utc: "2026-11-18 09:37" semantic-links: skill-links: - create-issue @@ -281,7 +281,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`, `DEFERRED`. | T1 | DONE | Coverage evidence and complete module inventory | [coverage-evidence.md](coverage-evidence.md): baseline in four scopes, per-file uncovered groups, property candidacy, initial hypothesis for the 62 files. Delivered with this spec (S0). | | T1b | DONE | Measure the container-gated scope | The `--all-features` run with `TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST` and `TORRUST_TRACKER_CORE_RUN_POSTGRES_DRIVER_TEST` set (images pulled with the maintainer's permission, 2026-11-17): lines 92.67% (re-measured 2026-11-18 with Rust 1.100.0). Recorded in `coverage-evidence.md`; informs the scope of S3. | | T2 | DONE | Shared plan guidance | [`test-refactor-plans/README.md`](test-refactor-plans/README.md): two-phase sequence, guardrails, toolchain-pinned commands. First test slice (S1). | -| T2b | IN_PROGRESS | Design-review checkpoint | After the first listener test and the first `TempDir`-owned SQLite test pass in S1, the maintainer reviews the fixture shape (see [Asynchronous Work, Cleanup and Test Fixtures](#asynchronous-work-cleanup-and-test-fixtures)) before other files reuse it. The SQLite half is done: the fixture shape of the [temporary-database fix](test-refactor-plans/test-support-ephemeral-database-tests.md) was approved on 2026-11-17; the listener half comes with S1. | +| T2b | DONE | Design-review checkpoint | After the first listener test and the first `TempDir`-owned SQLite test pass in S1, the maintainer reviews the fixture shape (see [Asynchronous Work, Cleanup and Test Fixtures](#asynchronous-work-cleanup-and-test-fixtures)) before other files reuse it. The SQLite half is done: the fixture shape of the [temporary-database fix](test-refactor-plans/test-support-ephemeral-database-tests.md) was approved on 2026-11-17; the listener half (spawn, handle one event, cancel, join under a deadline) was approved on 2026-11-18 with the [listener tests](test-refactor-plans/statistics-event-listener-tests.md). | | T3 | IN_PROGRESS | Process every ledger row through the per-file workflow | Each row ends in exactly one of: test added, no-change with reason, deferred with owner. | | T4 | TODO | Bounded mutation assessment | `mutation-evidence.md`: configuration, survivors, reason for each unviable mutant. Last slice. | | T5 | TODO | Reconcile evidence and progress state | Ledger, records, slice table, acceptance rows and both EPIC coverage tables agree; grep for `status: proposed` and stray `TODO` labels in finished records. | @@ -354,7 +354,7 @@ rows are ordered by slice, then by risk. | 1 | `statistics/repository.rs` | S1 | 85 / 139 | Test candidate (four counter/gauge methods and error arms) | DONE | | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | -| 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers) | IN_PROGRESS | +| 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | | 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm | PENDING | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | | 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | @@ -422,6 +422,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-18 04:16 UTC - Claude Code (Opus 5.5) - Row 2 (`statistics/metrics.rs`) is done as no change, approved by the maintainer: the repository tests cover it 45 / 45 and kill all six hand-made mutants ([record](test-refactor-plans/statistics-metrics-tests.md)). - 2026-11-18 04:23 UTC - Claude Code (Opus 5.5) - Row 3 (`statistics/persisted/mod.rs`) done: five tests, 11 / 11 production lines, all eight named mutants killed; they pin that the load is not atomic ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)). Plan and completed file approved by the maintainer. - 2026-11-18 09:10 UTC - Claude Code (Opus 5.5) - Every coverage figure re-measured, at the maintainer's request, with stable Rust 1.100.0 and `cargo-llvm-cov 0.9.1`: after `rustup update` moved `stable` from 1.99.1, `cargo-llvm-cov 0.6.16` reported 0% for every file (it read a stale binary from the old `target/debug/deps/` layout), and the maintainer upgraded it for everyone. Same commits as before: the T1 baseline at `5833cdae9` in five scopes (unit-only now 79.32%, was 80.31%; container-gated 92.67%, was 93.80%), and the unit-only run after rows 1 and 3. [coverage-evidence.md](coverage-evidence.md), the ledger, the baseline section and the row records hold the new figures; the entries above keep the old ones. The new toolchain does not count `#[test]` functions and adds a region per `tracing` call, classified as no decision. +- 2026-11-18 09:37 UTC - Claude Code (Opus 5.5) - Row 4 (`statistics/event/listener.rs`) done: four tests of the public entry points over a real event bus, 538 / 542 lines, all seven named mutants killed; the maintainer approved the plan, the completed file and the listener fixture shape, so checkpoint T2b is done ([plan](test-refactor-plans/statistics-event-listener-tests.md)). ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index c8de7de36a..809aa44fd1 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -29,7 +29,7 @@ approves it. A group of declaration-only files may share one plan. | 2 | [test-support-ephemeral-database-tests.md](test-support-ephemeral-database-tests.md) | DONE | F5 fix and the SQLite half of checkpoint T2b; shape, scope and guard owner decided and the completed change approved 2026-11-17; merged in #2923 | | 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | | 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | -| 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | IN_PROGRESS | Plan approved 2026-11-18; listener half of checkpoint T2b | +| 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md index 691b19d2e2..fc61cc852b 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/event/listener.rs -status: approved +status: done semantic-links: related-artifacts: - packages/tracker-core/src/statistics/event/listener.rs @@ -23,11 +23,13 @@ event, cancels it and joins it under a deadline. ## Current State -- **Unit-only coverage:** 357 / 406 lines at the S1 baseline, 362 / 411 after rows 1 to 3 - (stable Rust 1.99.1, `cargo-llvm-cov 0.6.16`, `--all-features --lib`, 2026-11-18). Uncovered: - 19-54 (the spawn wrappers `run_in_memory_event_listener` and - `run_persistent_completed_statistics_event_listener`), 62-91 (the public `*_unspawned` - functions), and 284-285 (the `Lagged` arm of the test receiver's `try_recv`, test code). +- **Unit-only coverage:** 360 / 411 lines at the T1 baseline; 365 / 416 at the S1 branch point + (the F5 fix changed the test module) and after rows 1 to 3 (stable Rust 1.100.0, + `cargo-llvm-cov 0.9.1`, `--all-features --lib`, 2026-11-18). Uncovered: 19-55 (the spawn + wrappers `run_in_memory_event_listener` and `run_persistent_completed_statistics_event_listener`), + 62-67 and 77-83 (the public `*_unspawned` functions), the log-level regions of six `tracing` + calls (106, 134, 168, 186, 227, 231), and 284-285 (the `Lagged` arm of the test receiver's + `try_recv`, test code). - **Callers:** the application runs the two `*_unspawned` functions under its own supervision (`src/bootstrap/jobs/tracker_core.rs`) and uses the `Completion` they return. The spawn wrappers are used only by the integration test environment (`tests/common/test_env.rs`), which discards @@ -102,10 +104,36 @@ unhandled (`it_should_leave_the_queued_event_unprocessed_and_return_cancelled_wh | ID | Status | Work | Completion evidence | | --- | --- | --- | --- | -| L1 | TODO | Add the four tests and the deadline helper. | They pass; lines 19-91 covered. | -| L2 | TODO | Run M1-M7. | Each is killed by its expected test. | -| L3 | TODO | Stop for the T2b fixture-shape review and the completed-file review. | The maintainer's decision recorded here. | +| L1 | DONE | Add the four tests and the deadline helper. | They pass; lines 19-91 covered. | +| L2 | DONE | Run M1-M7. | Each is killed by its expected test. | +| L3 | DONE | Stop for the T2b fixture-shape review and the completed-file review. | The maintainer's decision recorded here. | ## Results -To be filled in after L3. +- **Coverage** (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, `--all-features --lib`, clean + coverage target directory, 2026-11-18): the file 365 / 416 lines to 538 / 542, regions 386 / 424 + to 555 / 568, functions 50 / 56 to 70 / 71 (the counts include the test module's helpers). The + package's unit-only lines 4,380 / 5,324 (82.27%) to 4,553 / 5,450 (83.54%), regions 4,932 / 6,016 + (81.98%), functions 755 / 1,003 (75.27%). Every production line runs. What stays uncovered: + - the log-level regions of the `tracing` calls (lines 29, 53, 68, 84, 106, 134, 168, 186, 227 and + 231): no decision; + - the test receiver's `Closed` and `Lagged` arms of `try_recv` (289-290) and the timeout message + of `within_deadline` (642), which runs only when a listener misses the deadline: test code. +- **Tests:** four added, all passing; 176 unit tests in the package. The four passed 20 runs in a + row (`cargo test -p torrust-tracker-core --all-features --lib statistics::event::listener`); no + test sleeps, and every wait on a listener is bounded by the 5-second deadline. +- **Mutations** (each applied alone and reverted; the file compared with its copy afterwards): + + | ID | Result | + | --- | --- | + | M1 | Killed by the spawned in-memory test | + | M2 | Killed by the spawned persistent test | + | M3 | Killed by the unspawned in-memory test | + | M4 | Killed by the unspawned persistent test | + | M5 | Killed by both in-memory tests (the spawn wrapper runs the unspawned function) | + | M6 | Killed by both persistent tests | + | M7 | Killed by the spawned in-memory test | + +- **Review outcome:** the maintainer approved the completed file and the fixture shape (checkpoint T2b) on 2026-11-18. +- **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the + existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. From 572dd85402712a354bac30b65119e99c7f5ddaa8 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 10:03:03 +0000 Subject: [PATCH 15/40] docs(issues): [#2902] add the plan for the statistics event handler tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 2 +- .../test-refactor-plans/README.md | 1 + .../statistics-event-handler-tests.md | 86 +++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 2f5dbf5955..526ba4a247 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -355,7 +355,7 @@ rows are ordered by slice, then by risk. | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | | 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | -| 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm | PENDING | +| 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm | IN_PROGRESS | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | | 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | | 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 809aa44fd1..35c88d0a77 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -30,6 +30,7 @@ approves it. A group of declaration-only files may share one plan. | 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | | 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | | 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | +| 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md new file mode 100644 index 0000000000..68ae527531 --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md @@ -0,0 +1,86 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/event/handler.rs +status: approved +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/event/handler.rs + - packages/tracker-core/src/statistics/persisted/downloads.rs + - packages/tracker-core/src/statistics/repository.rs + - packages/swarm-coordination-registry/src/event.rs +--- + +# Statistics Event Handler File Test Plan + +Follow the shared [guidance](README.md). This plan covers only +`packages/tracker-core/src/statistics/event/handler.rs`, ledger row 5. + +## Current State + +- **Unit-only coverage:** 175 / 196 lines at the T1 baseline and after rows 1 to 4 (stable Rust + 1.100.0, `cargo-llvm-cov 0.9.1`, `--all-features --lib`, 2026-11-18). Uncovered: + - 19-20, 24 and 29: the `TorrentAdded`, `TorrentRemoved`, `PeerRemoved` and `PeerUpdated` arms of + `handle_in_memory_event`; + - 36-58: the five logging-only handlers (`handle_torrent_added`, `_removed`, `handle_peer_added`, + `_removed`, `_updated`), reached only through those arms (`PeerAdded` runs in a test, but its + `tracing::debug!` region does not); + - 66, 106, 108 and 120: log-level regions of `tracing` calls; + - 129: the error arm of `increase_global_downloads`. +- **Existing tests:** 5. A completion increments both in-memory totals; `PeerAdded` changes no + in-memory total; a completion is persisted (torrent row, global row, persisted total); `PeerAdded` + persists nothing; a failed torrent write still persists the global total. +- **Module-owned decisions not yet tested:** + - Only `PeerDownloadCompleted` changes a total: the other five event kinds only log. One of the + five is tested, for each handler. + - The persisted total follows the database: when the global write fails, the in-memory persisted + total is not incremented (line 129), even though the torrent row was written. + +## Maintainer Decision + +Plan approved on 2026-11-18, including replacing the two `PeerAdded`-only tests by the tables. + +## Test Design + +| Test | Arrange | Assert | +| --- | --- | --- | +| `it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download` | each of `TorrentAdded`, `TorrentRemoved`, `PeerAdded`, `PeerRemoved` and `PeerUpdated`, in a table, on a fresh repository | the persistent and in-session totals read 0, with the event's name in the message | +| `it_should_persist_nothing_for_an_event_other_than_a_completed_download` | the same table, on a fresh `TempDir` database | no torrent row, no global row, persisted total 0 | +| `it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_saved` | `MockTorrentMetricsStore`: the torrent write succeeds (`load_torrent_downloads` → `None`, `save_torrent_downloads` → `Ok`), `load_global_downloads` fails | the persisted total reads 0 | + +The two table tests replace the two existing `PeerAdded`-only tests +(`it_should_not_increment_in_memory_completion_metrics_when_an_event_is_not_a_completion` and +`it_should_not_persist_completion_statistics_when_an_event_is_not_a_completion`), which become one +case of each table. The other three existing tests stay as they are. + +**Not tested:** the log output of the five handlers. A log line is not a contract of this package, +and asserting it would need a tracing subscriber in the tests; the table tests run the handlers, so +a panic in one would fail them. + +## Property-Test Decision + +No `quickcheck`: the input is an enum of six cases, all listed in the table. + +## Named Mutations + +| ID | Mutation | Expected killer | +| --- | --- | --- | +| M1 | The `PeerRemoved` arm counts a completed download (`handle_peer_download_completed(info_hash, peer, ...)`) | the in-memory table (`PeerRemoved` case) | +| M2 | The `PeerUpdated` arm counts a completed download (with `new_peer`) | the in-memory table (`PeerUpdated` case) | +| M3 | The error arm of `increase_global_downloads` also increments the persisted total | the global-failure test | +| M4 | The persistent handler persists every event (`if let` replaced by an unconditional call with a sample info-hash) | the persistence table | + +M1 and M2 survive today: the only non-completion event under test is `PeerAdded`. + +## Steps + +| ID | Status | Work | Completion evidence | +| --- | --- | --- | --- | +| H1 | TODO | Add the three tests and remove the two replaced ones. | They pass; lines 19-58 and 129 run. | +| H2 | TODO | Run M1-M4. | Each is killed by its expected test. | +| H3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | + +## Results + +To be filled in after H3. From aa1d6311f3bbafa756cc9e1cd7aab3e993bad8ce Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 11:08:26 +0000 Subject: [PATCH 16/40] test(tracker-core): [#2902] cover every event kind and the global save failure of the statistics handlers Only `PeerAdded` stood for the events that must not count as a completed download, so counting `PeerRemoved` or `PeerUpdated` went unnoticed. Two table tests run all five such events through the in-memory and the persistent handler and replace the two `PeerAdded`-only tests. A third test pins that the persisted total does not move when the global downloads cannot be saved. Co-Authored-By: Claude Opus 5.5 --- .../src/statistics/event/handler.rs | 158 ++++++++++++++---- 1 file changed, 122 insertions(+), 36 deletions(-) diff --git a/packages/tracker-core/src/statistics/event/handler.rs b/packages/tracker-core/src/statistics/event/handler.rs index d93cee024d..bcba295150 100644 --- a/packages/tracker-core/src/statistics/event/handler.rs +++ b/packages/tracker-core/src/statistics/event/handler.rs @@ -148,11 +148,45 @@ mod tests { use crate::statistics::repository::Repository; use crate::test_helpers::tests::{ephemeral_configuration, sample_info_hash, sample_peer}; - fn peer_added_event() -> Event { - Event::PeerAdded { - info_hash: sample_info_hash(), - peer: sample_peer(), - } + /// Every event kind except `PeerDownloadCompleted`, named for the assertion messages. + fn events_other_than_a_completed_download() -> [(&'static str, Event); 5] { + [ + ( + "TorrentAdded", + Event::TorrentAdded { + info_hash: sample_info_hash(), + announcement: sample_peer(), + }, + ), + ( + "TorrentRemoved", + Event::TorrentRemoved { + info_hash: sample_info_hash(), + }, + ), + ( + "PeerAdded", + Event::PeerAdded { + info_hash: sample_info_hash(), + peer: sample_peer(), + }, + ), + ( + "PeerRemoved", + Event::PeerRemoved { + info_hash: sample_info_hash(), + peer: sample_peer(), + }, + ), + ( + "PeerUpdated", + Event::PeerUpdated { + info_hash: sample_info_hash(), + old_peer: sample_peer(), + new_peer: sample_peer(), + }, + ), + ] } fn peer_download_completed_event() -> Event { @@ -183,17 +217,25 @@ mod tests { } #[tokio::test] - async fn it_should_not_increment_in_memory_completion_metrics_when_an_event_is_not_a_completion() { - // Arrange - let stats_repository = Arc::new(Repository::default()); - let now = DurationSinceUnixEpoch::new(1, 0); - - // Act - handle_in_memory_event(peer_added_event(), &stats_repository, now).await; - - // Assert - assert_eq!(stats_repository.get_torrents_downloads_total().await, 0); - assert_eq!(stats_repository.get_torrents_downloads_in_session_total().await, 0); + async fn it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download() { + for (name, event) in events_other_than_a_completed_download() { + // Arrange + let stats_repository = Arc::new(Repository::default()); + let now = DurationSinceUnixEpoch::new(1, 0); + + // Act + handle_in_memory_event(event, &stats_repository, now).await; + + // Assert + assert_eq!( + ( + stats_repository.get_torrents_downloads_total().await, + stats_repository.get_torrents_downloads_in_session_total().await + ), + (0, 0), + "{name} must not count as a completed download" + ); + } } #[tokio::test] @@ -226,26 +268,31 @@ mod tests { } #[tokio::test] - async fn it_should_not_persist_completion_statistics_when_an_event_is_not_a_completion() { - // Arrange - let stats_repository = Arc::new(Repository::new(true, true)); - let ephemeral = ephemeral_configuration(); - let downloads_repository = database_downloads_repository(&ephemeral.config).await; - let now = DurationSinceUnixEpoch::new(1, 0); - - // Act - handle_persistent_completed_statistics_event(peer_added_event(), &downloads_repository, &stats_repository, now).await; - - // Assert - assert_eq!( - downloads_repository - .load_torrent_downloads(&sample_info_hash()) - .await - .unwrap(), - None - ); - assert_eq!(downloads_repository.load_global_downloads().await.unwrap(), None); - assert_eq!(stats_repository.get_torrents_downloads_persisted_total().await, 0); + async fn it_should_persist_nothing_for_an_event_other_than_a_completed_download() { + for (name, event) in events_other_than_a_completed_download() { + // Arrange + let stats_repository = Arc::new(Repository::new(true, true)); + let ephemeral = ephemeral_configuration(); + let downloads_repository = database_downloads_repository(&ephemeral.config).await; + let now = DurationSinceUnixEpoch::new(1, 0); + + // Act + handle_persistent_completed_statistics_event(event, &downloads_repository, &stats_repository, now).await; + + // Assert + assert_eq!( + ( + downloads_repository + .load_torrent_downloads(&sample_info_hash()) + .await + .unwrap(), + downloads_repository.load_global_downloads().await.unwrap(), + stats_repository.get_torrents_downloads_persisted_total().await + ), + (None, None, 0), + "{name} must not persist a completed download" + ); + } } #[tokio::test] @@ -281,4 +328,43 @@ mod tests { // Assert assert_eq!(stats_repository.get_torrents_downloads_persisted_total().await, 1); } + + #[tokio::test] + async fn it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_saved() { + // Arrange + let stats_repository = Arc::new(Repository::new(true, true)); + let mut store = MockTorrentMetricsStore::new(); + store + .expect_load_torrent_downloads() + .returning(|_| Box::pin(std::future::ready(Ok(None)))); + store + .expect_save_torrent_downloads() + .times(1) + .returning(|_, _| Box::pin(std::future::ready(Ok(())))); + store.expect_load_global_downloads().times(1).returning(|| { + Box::pin(std::future::ready(Err(Error::MalformedDatabaseRecord { + message: "corrupt global downloads".to_string(), + driver: Driver::Sqlite3, + }))) + }); + let store: Arc = Arc::new(store); + let downloads_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&store)); + let now = DurationSinceUnixEpoch::new(1, 0); + + // Act + handle_persistent_completed_statistics_event( + peer_download_completed_event(), + &downloads_repository, + &stats_repository, + now, + ) + .await; + + // Assert + assert_eq!( + stats_repository.get_torrents_downloads_persisted_total().await, + 0, + "the persisted total must follow the database, which did not save the global downloads" + ); + } } From 75a4439b13f58ec9fe83f1bbbf27bc819619ce4b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 11:09:15 +0000 Subject: [PATCH 17/40] docs(issues): [#2902] record the results of the statistics event handler tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 5 +-- .../test-refactor-plans/README.md | 2 +- .../statistics-event-handler-tests.md | 31 ++++++++++++++++--- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 526ba4a247..e879cd443f 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 09:37" +last-updated-utc: "2026-11-18 11:09" semantic-links: skill-links: - create-issue @@ -355,7 +355,7 @@ rows are ordered by slice, then by risk. | 2 | `statistics/metrics.rs` | S1 | 11 / 45 | Test candidate; no change, covered 45 / 45 by the repository tests ([record](test-refactor-plans/statistics-metrics-tests.md)) | DONE | | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | | 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | -| 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm | IN_PROGRESS | +| 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm; 311 / 311 with two event tables and a failure test ([plan](test-refactor-plans/statistics-event-handler-tests.md)) | DONE | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | | 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | | 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | @@ -423,6 +423,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-18 04:23 UTC - Claude Code (Opus 5.5) - Row 3 (`statistics/persisted/mod.rs`) done: five tests, 11 / 11 production lines, all eight named mutants killed; they pin that the load is not atomic ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)). Plan and completed file approved by the maintainer. - 2026-11-18 09:10 UTC - Claude Code (Opus 5.5) - Every coverage figure re-measured, at the maintainer's request, with stable Rust 1.100.0 and `cargo-llvm-cov 0.9.1`: after `rustup update` moved `stable` from 1.99.1, `cargo-llvm-cov 0.6.16` reported 0% for every file (it read a stale binary from the old `target/debug/deps/` layout), and the maintainer upgraded it for everyone. Same commits as before: the T1 baseline at `5833cdae9` in five scopes (unit-only now 79.32%, was 80.31%; container-gated 92.67%, was 93.80%), and the unit-only run after rows 1 and 3. [coverage-evidence.md](coverage-evidence.md), the ledger, the baseline section and the row records hold the new figures; the entries above keep the old ones. The new toolchain does not count `#[test]` functions and adds a region per `tracing` call, classified as no decision. - 2026-11-18 09:37 UTC - Claude Code (Opus 5.5) - Row 4 (`statistics/event/listener.rs`) done: four tests of the public entry points over a real event bus, 538 / 542 lines, all seven named mutants killed; the maintainer approved the plan, the completed file and the listener fixture shape, so checkpoint T2b is done ([plan](test-refactor-plans/statistics-event-listener-tests.md)). +- 2026-11-18 11:09 UTC - Claude Code (Opus 5.5) - Row 5 (`statistics/event/handler.rs`) done: two table tests over the five events that are not a completed download (replacing the two `PeerAdded`-only tests) and a global-save failure test; 311 / 311 lines, all four named mutants killed, one of which survived the old tests ([plan](test-refactor-plans/statistics-event-handler-tests.md)). Plan and completed file approved by the maintainer. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 35c88d0a77..6cd4e79a75 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -30,7 +30,7 @@ approves it. A group of declaration-only files may share one plan. | 3 | [statistics-metrics-tests.md](statistics-metrics-tests.md) | DONE | No change: covered by the repository tests, all six mutants killed; approved 2026-11-18 | | 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | | 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | -| 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 | +| 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | DONE | Plan approved 2026-11-18; completed file approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md index 68ae527531..cb15d991ad 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/event/handler.rs -status: approved +status: done semantic-links: related-artifacts: - packages/tracker-core/src/statistics/event/handler.rs @@ -77,10 +77,31 @@ M1 and M2 survive today: the only non-completion event under test is `PeerAdded` | ID | Status | Work | Completion evidence | | --- | --- | --- | --- | -| H1 | TODO | Add the three tests and remove the two replaced ones. | They pass; lines 19-58 and 129 run. | -| H2 | TODO | Run M1-M4. | Each is killed by its expected test. | -| H3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | +| H1 | DONE | Add the three tests and remove the two replaced ones. | They pass; lines 19-58 and 129 run. | +| H2 | DONE | Run M1-M4. | Each is killed by its expected test. | +| H3 | DONE | Record the results and ask for the completed-file review. | This record and the ledger. | ## Results -To be filled in after H3. +- **Coverage** (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, `--all-features --lib`, clean + coverage target directory, 2026-11-18): the file 175 / 196 lines to 311 / 311, regions 204 / 249 + to 264 / 289, functions 30 / 34 to 39 / 39 (the counts include the test module's helpers, which + grew with the event table). The package's unit-only lines 4,553 / 5,450 (83.54%) to + 4,688 / 5,564 (84.26%), regions 4,993 / 6,056 (82.45%), functions 764 / 1,008 (75.79%). Every + line runs; the regions left are the log-level checks of the `tracing` calls (lines 37, 41, 45, + 49, 57, 66, 106, 108, 120 and 129; at 129 the error arm runs, its log call does not): no decision. +- **Tests:** three added, two replaced by the tables (their `PeerAdded` case is kept as one row), + three unchanged: six in the file, 177 unit tests in the package. +- **Mutations** (each applied alone and reverted; a mutant that did not compile was rewritten to + keep calling the logging handler, which the `unused` lint requires): + + | ID | Result | + | --- | --- | + | M1 | Killed by the in-memory table: "PeerRemoved must not count as a completed download". It survived the tests before this change (checked against the committed file). | + | M2 | Killed by the in-memory table: "PeerUpdated must not count as a completed download" | + | M3 | Killed by the global-failure test | + | M4 | Killed by the persistence table and by the existing completion test | + +- **Review outcome:** the maintainer approved the completed file on 2026-11-18. +- **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the + existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. From 8b1f8fa8b87ccb01755ac4dc6305d8ca930f1928 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 11:33:17 +0000 Subject: [PATCH 18/40] docs(issues): [#2902] add the plan for the persisted downloads repository tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 2 +- .../test-refactor-plans/README.md | 1 + .../statistics-persisted-downloads-tests.md | 79 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index e879cd443f..cc5511c6a4 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -356,7 +356,7 @@ rows are ordered by slice, then by risk. | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | | 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | | 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm; 311 / 311 with two event tables and a failure test ([plan](test-refactor-plans/statistics-event-handler-tests.md)) | DONE | -| 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | PENDING | +| 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | IN_PROGRESS | | 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | | 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | | 9 | `databases/driver/sqlite/torrent_metrics_store.rs` | S2 | 27 / 46 | Test candidate | PENDING | diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 6cd4e79a75..6d62a11340 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -31,6 +31,7 @@ approves it. A group of declaration-only files may share one plan. | 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | | 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | | 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | DONE | Plan approved 2026-11-18; completed file approved 2026-11-18 | +| 7 | [statistics-persisted-downloads-tests.md](statistics-persisted-downloads-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 (a surviving mutant despite full coverage) | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md new file mode 100644 index 0000000000..4521e7d44a --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md @@ -0,0 +1,79 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/persisted/downloads.rs +status: approved +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/persisted/downloads.rs + - packages/tracker-core/src/databases/traits/torrent_metrics.rs + - packages/tracker-core/src/statistics/event/handler.rs +--- + +# Statistics Persisted Downloads File Test Plan + +Follow the shared [guidance](README.md). This plan covers only +`packages/tracker-core/src/statistics/persisted/downloads.rs`, ledger row 6. + +## Current State + +- **Unit-only coverage:** 77 / 77 lines at the T1 baseline, with the `?` of + `increase_global_downloads` (line 133) as the only uncovered region. After row 5 the file is + 79 / 79 lines and 114 / 114 regions (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, + `--all-features --lib`, 2026-11-18): the global-save failure test of the handler reaches line 133. +- **Existing tests:** 3 in the file, over a `TempDir` SQLite database: save a torrent's downloads, + increase a torrent's downloads once from nothing, load all torrents' downloads. +- **Module-owned decisions:** `increase_downloads_for_torrent` and `increase_global_downloads` each + read the stored value first; with none they save 1, with one they increment it; a failed read is + returned as the error, and nothing is written. + +## Mutation Probe + +Coverage is complete, so six hand-made mutants were run against the whole unit suite before +planning (2026-11-18): + +| ID | Mutation | Result | +| --- | --- | --- | +| P1 | The `?` of the global read swallowed (`.ok().flatten()`) | Killed by the handler's global-save failure test | +| P2 | The `?` of the torrent read swallowed | Killed by the handler's torrent-failure test | +| P3 | A stored global total is overwritten with 1 instead of incremented | Killed only by a listener test that drains two events | +| P4 | A stored torrent total is overwritten with 1 instead of incremented | **Survived** | +| P5 | The first global total is saved as 0 | Killed by the handler and listener tests | +| P6 | The first torrent total is saved as 0 | Killed, also by this file's increase test | + +P4 is a gap: no test increases the same torrent's downloads twice. P3 is caught only far from this +file. + +## Maintainer Decision + +Plan approved on 2026-11-18, without direct error-propagation tests. + +## Test Design + +Both tests use the file's `TempDir` SQLite fixture (`ephemeral_configuration()`, kept by the test). + +| Test | Act | Assert | +| --- | --- | --- | +| `it_should_increment_the_stored_downloads_of_a_torrent` | `increase_downloads_for_torrent` twice for the same info-hash | the torrent's stored downloads are 2 | +| `it_should_save_then_increment_the_global_downloads` | `increase_global_downloads` twice | `load_global_downloads` gives `Some(1)` after the first call and `Some(2)` after the second | + +**Not added:** direct error-propagation tests for the two reads (P1, P2). The handler tests already +kill both mutants with a mocked failing store, and the handler is the only caller. + +## Property-Test Decision + +No `quickcheck`: the rule is "first save 1, then add 1", which two examples pin; the counter's +overflow belongs to the drivers (S2). + +## Steps + +| ID | Status | Work | Completion evidence | +| --- | --- | --- | --- | +| D1 | TODO | Add the two tests. | They pass. | +| D2 | TODO | Rerun P3 and P4. | Both are killed by the new tests in this file. | +| D3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | + +## Results + +To be filled in after D3. From f4bf930f8abc87566be403d6e43a0450fdb0883a Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 13:23:27 +0000 Subject: [PATCH 19/40] test(tracker-core): [#2902] pin that the persisted downloads are incremented, not overwritten Every test increased a torrent's downloads once from nothing, so overwriting a stored total with 1 passed them all. Two tests on a temporary SQLite database increase the same torrent twice and the global total twice and expect 2. Co-Authored-By: Claude Opus 5.5 --- .../src/statistics/persisted/downloads.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/tracker-core/src/statistics/persisted/downloads.rs b/packages/tracker-core/src/statistics/persisted/downloads.rs index a147a3108e..dae7b9671e 100644 --- a/packages/tracker-core/src/statistics/persisted/downloads.rs +++ b/packages/tracker-core/src/statistics/persisted/downloads.rs @@ -210,4 +210,43 @@ mod tests { assert_eq!(torrents, expected_torrents); } + + #[tokio::test] + async fn it_should_increment_the_stored_downloads_of_a_torrent() { + // Arrange + let ephemeral = ephemeral_configuration(); + let repository = initialize_db_persistent_torrent_repository(&ephemeral.config).await; + let infohash = sample_info_hash(); + repository.increase_downloads_for_torrent(&infohash).await.unwrap(); + + // Act + repository.increase_downloads_for_torrent(&infohash).await.unwrap(); + + // Assert + assert_eq!( + repository.load_torrent_downloads(&infohash).await.unwrap(), + Some(2), + "a second download of the same torrent should add to the stored total" + ); + } + + #[tokio::test] + async fn it_should_save_then_increment_the_global_downloads() { + // Arrange + let ephemeral = ephemeral_configuration(); + let repository = initialize_db_persistent_torrent_repository(&ephemeral.config).await; + + // Act + repository.increase_global_downloads().await.unwrap(); + let after_the_first = repository.load_global_downloads().await.unwrap(); + repository.increase_global_downloads().await.unwrap(); + let after_the_second = repository.load_global_downloads().await.unwrap(); + + // Assert + assert_eq!( + (after_the_first, after_the_second), + (Some(1), Some(2)), + "the first download should save 1 and the next should add to it" + ); + } } From 74fdef83c5a80e6bfe9710efeac1f41861f5d643 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 13:24:08 +0000 Subject: [PATCH 20/40] docs(issues): [#2902] record the results of the persisted downloads repository tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 5 +++-- .../test-refactor-plans/README.md | 2 +- .../statistics-persisted-downloads-tests.md | 21 ++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index cc5511c6a4..dcb4f67349 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 11:09" +last-updated-utc: "2026-11-18 13:24" semantic-links: skill-links: - create-issue @@ -356,7 +356,7 @@ rows are ordered by slice, then by risk. | 3 | `statistics/persisted/mod.rs` | S1 | 0 / 11 | Test candidate (`load_persisted_metrics`); 11 / 11 with five tests ([plan](test-refactor-plans/statistics-persisted-mod-tests.md)) | DONE | | 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | | 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm; 311 / 311 with two event tables and a failure test ([plan](test-refactor-plans/statistics-event-handler-tests.md)) | DONE | -| 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`) | IN_PROGRESS | +| 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`), covered by row 5; two increment tests kill a surviving mutant ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)) | DONE | | 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | | 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | | 9 | `databases/driver/sqlite/torrent_metrics_store.rs` | S2 | 27 / 46 | Test candidate | PENDING | @@ -424,6 +424,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-18 09:10 UTC - Claude Code (Opus 5.5) - Every coverage figure re-measured, at the maintainer's request, with stable Rust 1.100.0 and `cargo-llvm-cov 0.9.1`: after `rustup update` moved `stable` from 1.99.1, `cargo-llvm-cov 0.6.16` reported 0% for every file (it read a stale binary from the old `target/debug/deps/` layout), and the maintainer upgraded it for everyone. Same commits as before: the T1 baseline at `5833cdae9` in five scopes (unit-only now 79.32%, was 80.31%; container-gated 92.67%, was 93.80%), and the unit-only run after rows 1 and 3. [coverage-evidence.md](coverage-evidence.md), the ledger, the baseline section and the row records hold the new figures; the entries above keep the old ones. The new toolchain does not count `#[test]` functions and adds a region per `tracing` call, classified as no decision. - 2026-11-18 09:37 UTC - Claude Code (Opus 5.5) - Row 4 (`statistics/event/listener.rs`) done: four tests of the public entry points over a real event bus, 538 / 542 lines, all seven named mutants killed; the maintainer approved the plan, the completed file and the listener fixture shape, so checkpoint T2b is done ([plan](test-refactor-plans/statistics-event-listener-tests.md)). - 2026-11-18 11:09 UTC - Claude Code (Opus 5.5) - Row 5 (`statistics/event/handler.rs`) done: two table tests over the five events that are not a completed download (replacing the two `PeerAdded`-only tests) and a global-save failure test; 311 / 311 lines, all four named mutants killed, one of which survived the old tests ([plan](test-refactor-plans/statistics-event-handler-tests.md)). Plan and completed file approved by the maintainer. +- 2026-11-18 13:24 UTC - Claude Code (Opus 5.5) - Row 6 (`statistics/persisted/downloads.rs`) done: coverage was already complete after row 5, but a mutation probe found a stored torrent total could be overwritten with 1 unnoticed; two increment tests kill it ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)). Plan and completed file approved by the maintainer. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 6d62a11340..db5f30f4de 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -31,7 +31,7 @@ approves it. A group of declaration-only files may share one plan. | 4 | [statistics-persisted-mod-tests.md](statistics-persisted-mod-tests.md) | DONE | Plan approved 2026-11-18 (pins the non-atomic load); completed file approved 2026-11-18 | | 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | | 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | DONE | Plan approved 2026-11-18; completed file approved 2026-11-18 | -| 7 | [statistics-persisted-downloads-tests.md](statistics-persisted-downloads-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 (a surviving mutant despite full coverage) | +| 7 | [statistics-persisted-downloads-tests.md](statistics-persisted-downloads-tests.md) | DONE | Plan approved 2026-11-18 (a surviving mutant despite full coverage); completed file approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md index 4521e7d44a..70bb99649e 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-persisted-downloads-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/persisted/downloads.rs -status: approved +status: done semantic-links: related-artifacts: - packages/tracker-core/src/statistics/persisted/downloads.rs @@ -70,10 +70,21 @@ overflow belongs to the drivers (S2). | ID | Status | Work | Completion evidence | | --- | --- | --- | --- | -| D1 | TODO | Add the two tests. | They pass. | -| D2 | TODO | Rerun P3 and P4. | Both are killed by the new tests in this file. | -| D3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | +| D1 | DONE | Add the two tests. | They pass. | +| D2 | DONE | Rerun P3 and P4. | Both are killed by the new tests in this file. | +| D3 | DONE | Record the results and ask for the completed-file review. | This record and the ledger. | ## Results -To be filled in after D3. +- **Mutations:** P3 is now killed by `it_should_save_then_increment_the_global_downloads` and P4 by + `it_should_increment_the_stored_downloads_of_a_torrent`, each run against this file's tests only + (`statistics::persisted::downloads`); P1, P2, P5 and P6 stay killed as in the probe. +- **Coverage** (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, `--all-features --lib`, clean coverage + target directory, 2026-11-18): the file 79 / 79 lines to 112 / 112, regions 114 / 114 to + 148 / 148, functions 23 / 23 to 27 / 27 (the growth is the new tests). The package's unit-only + lines 4,688 / 5,564 (84.26%) to 4,721 / 5,597 (84.35%), regions 5,027 / 6,090 (82.55%), + functions 768 / 1,012 (75.89%). +- **Tests:** two added, three unchanged; 179 unit tests in the package. +- **Review outcome:** the maintainer approved the completed file on 2026-11-18. +- **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the + existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. From 95499faa07df9da5d342b4a54a22d9f5a54af16b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 13:41:24 +0000 Subject: [PATCH 21/40] docs(issues): [#2902] add the plan for the statistics module tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 2 +- .../test-refactor-plans/README.md | 1 + .../statistics-mod-tests.md | 75 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index dcb4f67349..69080dbdb1 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -357,7 +357,7 @@ rows are ordered by slice, then by risk. | 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | | 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm; 311 / 311 with two event tables and a failure test ([plan](test-refactor-plans/statistics-event-handler-tests.md)) | DONE | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`), covered by row 5; two increment tests kill a surviving mutant ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)) | DONE | -| 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | PENDING | +| 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | IN_PROGRESS | | 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | | 9 | `databases/driver/sqlite/torrent_metrics_store.rs` | S2 | 27 / 46 | Test candidate | PENDING | | 10 | `databases/driver/sqlite/whitelist_store.rs` | S2 | 17 / 31 | Test candidate | PENDING | diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index db5f30f4de..4b0eccaebd 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -32,6 +32,7 @@ approves it. A group of declaration-only files may share one plan. | 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | | 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | DONE | Plan approved 2026-11-18; completed file approved 2026-11-18 | | 7 | [statistics-persisted-downloads-tests.md](statistics-persisted-downloads-tests.md) | DONE | Plan approved 2026-11-18 (a surviving mutant despite full coverage); completed file approved 2026-11-18 | +| 8 | [statistics-mod-tests.md](statistics-mod-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md new file mode 100644 index 0000000000..badff12ae6 --- /dev/null +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md @@ -0,0 +1,75 @@ +--- +doc-type: file-test-plan +issue: 2902 +package: torrust-tracker-core +target-file: packages/tracker-core/src/statistics/mod.rs +status: approved +semantic-links: + related-artifacts: + - packages/tracker-core/src/statistics/mod.rs + - packages/tracker-core/src/statistics/event/mod.rs + - packages/tracker-core/src/statistics/repository.rs + - docs/adrs/20260901113500_define_completed_download_metric_retention_names.md +--- + +# Statistics Module File Test Plan + +Follow the shared [guidance](README.md). This plan covers ledger row 7: +`packages/tracker-core/src/statistics/mod.rs` and `packages/tracker-core/src/statistics/event/mod.rs`, +the last row of S1. + +## Current State + +- **Unit-only coverage:** `statistics/mod.rs` 42 / 43 lines, 32 / 33 regions, 2 / 2 functions, at + the T1 baseline and after rows 1 to 6 (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, + `--all-features --lib`, 2026-11-18). Uncovered: line 49, the implicit `else` of + `if tracker_usage_statistics_enabled`. `statistics/event/mod.rs` has no measured lines: it only + declares the `handler` and `listener` modules. +- **Existing tests:** none in the file. `describe_metrics` runs through `Repository::new`; the + repository tests (row 1) pin that the persisted total is absent when persisted statistics are + disabled and present at zero when they are enabled. No test builds a repository with usage + statistics disabled. +- **Module-owned decisions:** `describe_metrics(usage, persisted)` registers the persistent total + (deprecated name) always, the in-session total only when `usage` is on, and the persisted total + only when `persisted` is on, each at zero. + +## Maintainer Decision + +Plan approved on 2026-11-18, with the four-case table. + +## Test Design + +One table test in a new `tests` module of `statistics/mod.rs`: + +| Test | Cases | Assert | +| --- | --- | --- | +| `it_should_register_each_downloads_total_only_when_its_statistics_are_enabled` | the four combinations of `(usage, persisted)` | for each case, the persistent total is `Some(0)`; the in-session total is `Some(0)` only with `usage`; the persisted total is `Some(0)` only with `persisted`; read with `metric_collection().get_counter_value(.., &LabelSet::default())`, and the message names the case | + +`statistics/event/mod.rs`: no change, declarations only. + +## Property-Test Decision + +No `quickcheck`: the input is two booleans, all four cases listed. + +## Named Mutations + +| ID | Mutation | Expected killer | +| --- | --- | --- | +| M1 | The in-session total is registered whatever `usage` says (the `if` removed) | the `usage = false` cases | +| M2 | The in-session condition reads `persisted` instead of `usage` | the mixed cases | +| M3 | The persistent total is registered only when `usage` is on | the `usage = false` cases | +| M4 | The persisted condition is negated | the table (and the row 1 repository tests) | + +M1 and M2 survive today: no test disables usage statistics. + +## Steps + +| ID | Status | Work | Completion evidence | +| --- | --- | --- | --- | +| C1 | TODO | Add the table test. | It passes; line 49 runs. | +| C2 | TODO | Run M1-M4. | Each is killed by the table. | +| C3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | + +## Results + +To be filled in after C3. From cf80a032ae1f00da5ccbe9fce074e1c590e93d9d Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 13:47:25 +0000 Subject: [PATCH 22/40] test(tracker-core): [#2902] pin which downloads totals each statistics setting registers No test disabled usage statistics, so registering the in-session total regardless passed. One table test over the four combinations of usage and persisted statistics pins that the persistent total is always registered and the other two only with their setting, each at zero. Co-Authored-By: Claude Opus 5.5 --- packages/tracker-core/src/statistics/mod.rs | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/tracker-core/src/statistics/mod.rs b/packages/tracker-core/src/statistics/mod.rs index 9403e9dd75..7c94b18a6d 100644 --- a/packages/tracker-core/src/statistics/mod.rs +++ b/packages/tracker-core/src/statistics/mod.rs @@ -73,3 +73,42 @@ fn set_counter_to_zero(metrics: &mut Metrics, metric_name: &str) { ) .expect("described counters accept an initial zero value"); } + +#[cfg(test)] +mod tests { + use torrust_metrics::label::LabelSet; + use torrust_metrics::metric_name; + + use super::metrics::Metrics; + use super::{ + TRACKER_CORE_IN_SESSION_TORRENTS_DOWNLOADS_TOTAL, TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL, + TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL, describe_metrics, + }; + + /// The value of an unlabeled counter, or `None` when it is not registered. + fn counter(metrics: &Metrics, name: &str) -> Option { + metrics + .metric_collection() + .get_counter_value(&metric_name!(name), &LabelSet::default()) + .map(|counter| counter.value()) + } + + #[test] + fn it_should_register_each_downloads_total_only_when_its_statistics_are_enabled() { + for (usage, persisted) in [(false, false), (false, true), (true, false), (true, true)] { + // Act + let metrics = describe_metrics(usage, persisted); + + // Assert + assert_eq!( + ( + counter(&metrics, TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + counter(&metrics, TRACKER_CORE_IN_SESSION_TORRENTS_DOWNLOADS_TOTAL), + counter(&metrics, TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL) + ), + (Some(0), usage.then_some(0), persisted.then_some(0)), + "(persistent, in-session, persisted) totals with usage statistics {usage} and persisted statistics {persisted}" + ); + } + } +} From adf964a0b36c338513bda31bd0afda1123d3759e Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Wed, 18 Nov 2026 13:48:23 +0000 Subject: [PATCH 23/40] docs(issues): [#2902] record the results of the statistics module tests Co-Authored-By: Claude Opus 5.5 --- .../2902-1347-add-tests-tracker-core/ISSUE.md | 5 ++-- .../test-refactor-plans/README.md | 2 +- .../statistics-mod-tests.md | 29 +++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 69080dbdb1..72fb8a0343 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 13:24" +last-updated-utc: "2026-11-18 13:48" semantic-links: skill-links: - create-issue @@ -357,7 +357,7 @@ rows are ordered by slice, then by risk. | 4 | `statistics/event/listener.rs` | S1 | 360 / 411 | Test candidate (spawn wrappers); 538 / 542 with four tests ([plan](test-refactor-plans/statistics-event-listener-tests.md)) | DONE | | 5 | `statistics/event/handler.rs` | S1 | 175 / 196 | Mostly logging-only; one error arm; 311 / 311 with two event tables and a failure test ([plan](test-refactor-plans/statistics-event-handler-tests.md)) | DONE | | 6 | `statistics/persisted/downloads.rs` | S1 | 77 / 77 | Failing-`Database` case (line 133, `increase_global_downloads`), covered by row 5; two increment tests kill a surviving mutant ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)) | DONE | -| 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only | IN_PROGRESS | +| 7 | `statistics/mod.rs`, `statistics/event/mod.rs` | S1 | 42 / 43, no entries | Test candidate (`statistics/mod.rs:49`, usage statistics disabled); `event/mod.rs` declarations only; 60 / 60 with one table test, `event/mod.rs` no change ([plan](test-refactor-plans/statistics-mod-tests.md)) | DONE | | 8 | `databases/driver/sqlite/auth_key_store.rs` | S2 | 29 / 55 | Test candidate | PENDING | | 9 | `databases/driver/sqlite/torrent_metrics_store.rs` | S2 | 27 / 46 | Test candidate | PENDING | | 10 | `databases/driver/sqlite/whitelist_store.rs` | S2 | 17 / 31 | Test candidate | PENDING | @@ -425,6 +425,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-18 09:37 UTC - Claude Code (Opus 5.5) - Row 4 (`statistics/event/listener.rs`) done: four tests of the public entry points over a real event bus, 538 / 542 lines, all seven named mutants killed; the maintainer approved the plan, the completed file and the listener fixture shape, so checkpoint T2b is done ([plan](test-refactor-plans/statistics-event-listener-tests.md)). - 2026-11-18 11:09 UTC - Claude Code (Opus 5.5) - Row 5 (`statistics/event/handler.rs`) done: two table tests over the five events that are not a completed download (replacing the two `PeerAdded`-only tests) and a global-save failure test; 311 / 311 lines, all four named mutants killed, one of which survived the old tests ([plan](test-refactor-plans/statistics-event-handler-tests.md)). Plan and completed file approved by the maintainer. - 2026-11-18 13:24 UTC - Claude Code (Opus 5.5) - Row 6 (`statistics/persisted/downloads.rs`) done: coverage was already complete after row 5, but a mutation probe found a stored torrent total could be overwritten with 1 unnoticed; two increment tests kill it ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)). Plan and completed file approved by the maintainer. +- 2026-11-18 13:48 UTC - Claude Code (Opus 5.5) - Row 7 (`statistics/mod.rs`, `statistics/event/mod.rs`) done: one table test pins which downloads totals each statistics setting registers; 60 / 60 lines, all four named mutants killed; `event/mod.rs` no change ([plan](test-refactor-plans/statistics-mod-tests.md)). Plan and completed file approved by the maintainer. All S1 rows are done. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md index 4b0eccaebd..3344525c87 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/README.md @@ -32,7 +32,7 @@ approves it. A group of declaration-only files may share one plan. | 5 | [statistics-event-listener-tests.md](statistics-event-listener-tests.md) | DONE | Plan approved 2026-11-18; completed file and the T2b fixture shape approved 2026-11-18 | | 6 | [statistics-event-handler-tests.md](statistics-event-handler-tests.md) | DONE | Plan approved 2026-11-18; completed file approved 2026-11-18 | | 7 | [statistics-persisted-downloads-tests.md](statistics-persisted-downloads-tests.md) | DONE | Plan approved 2026-11-18 (a surviving mutant despite full coverage); completed file approved 2026-11-18 | -| 8 | [statistics-mod-tests.md](statistics-mod-tests.md) | IN_PROGRESS | Plan approved 2026-11-18 | +| 8 | [statistics-mod-tests.md](statistics-mod-tests.md) | DONE | Plan approved 2026-11-18; completed file approved 2026-11-18 | Add a row when a plan is created; the remaining files and their order are in the ledger. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md index badff12ae6..7bfe685aa8 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md @@ -3,7 +3,7 @@ doc-type: file-test-plan issue: 2902 package: torrust-tracker-core target-file: packages/tracker-core/src/statistics/mod.rs -status: approved +status: done semantic-links: related-artifacts: - packages/tracker-core/src/statistics/mod.rs @@ -66,10 +66,29 @@ M1 and M2 survive today: no test disables usage statistics. | ID | Status | Work | Completion evidence | | --- | --- | --- | --- | -| C1 | TODO | Add the table test. | It passes; line 49 runs. | -| C2 | TODO | Run M1-M4. | Each is killed by the table. | -| C3 | TODO | Record the results and ask for the completed-file review. | This record and the ledger. | +| C1 | DONE | Add the table test. | It passes; line 49 runs. | +| C2 | DONE | Run M1-M4. | Each is killed by the table. | +| C3 | DONE | Record the results and ask for the completed-file review. | This record and the ledger. | ## Results -To be filled in after C3. +- **Mutations** (each applied alone and reverted, run against the `statistics::` tests): + + | ID | Result | + | --- | --- | + | M1 | Killed by the table | + | M2 | Killed by the table and by the row 1 test `it_should_omit_persisted_metric_when_persisted_completed_statistics_are_disabled` | + | M3 | Killed by the table | + | M4 | Killed by the table, the two row 1 persisted-metric tests and a row 3 test | + + Correction to the plan: only M1 survived before this change; M2 was already killed by the row 1 + repository test, which builds a repository with usage statistics on and persisted statistics off. +- **Coverage** (stable Rust 1.100.0, `cargo-llvm-cov 0.9.1`, `--all-features --lib`, clean coverage + target directory, 2026-11-18): `statistics/mod.rs` 42 / 43 lines to 60 / 60, regions 32 / 33 to + 56 / 56, functions 2 / 2 to 5 / 5. The package's unit-only lines 4,721 / 5,597 (84.35%) to + 4,739 / 5,614 (84.41%), regions 5,051 / 6,113 (82.63%), functions 771 / 1,015 (75.96%). +- **Tests:** one added; 180 unit tests in the package. `statistics/event/mod.rs`: no change + (declarations only). +- **Review outcome:** the maintainer approved the completed file on 2026-11-18. +- **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the + existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. From f9a370271d668a6076e03f67246d01a8b8e9c78b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sat, 21 Nov 2026 13:26:32 +0000 Subject: [PATCH 24/40] docs(issues): [#2902] close slice S1 with its coverage measurement The S1 branch, rebased on `develop` `44ce734fe`, is measured in the four default scopes next to its base: unit-only lines 79.45% to 84.41%, aggregate 81.27% to 84.41%. The aggregate now equals unit-only, so the integration binary no longer reaches any `tracker-core` line the unit tests miss. The EPIC's #2902 rows hold the latest values and row 14 is in progress. Co-Authored-By: Claude Opus 5.5 --- .../1347-overhaul-packages-testing/EPIC.md | 9 +++--- .../2902-1347-add-tests-tracker-core/ISSUE.md | 3 +- .../coverage-evidence.md | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md index b2bbee4f98..baf5b52363 100644 --- a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md +++ b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md @@ -6,7 +6,7 @@ epic: null github-issue: 1347 spec-path: docs/issues/open/1347-overhaul-packages-testing/EPIC.md epic-owner: josecelano -last-updated-utc: "2026-11-18 10:20" +last-updated-utc: "2026-11-21 13:24" semantic-links: skill-links: - create-issue @@ -99,7 +99,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | 11 | #2824 - Add tests to the primitives package | `docs/issues/closed/2824-1347-add-tests-primitives/ISSUE.md` | DONE | S0 (the spec, #2828), S1 (the `PeerRole` JSON casing fix, #2834), S2 (the `peer.rs` tests, #2841), S3 (the configuration defaults and bounded values, #2852) and S4 (`swarm_metadata.rs`, the no-change files, the mutation run, the manual checks, #2864) are merged; the issue is closed. Unit-only lines 60.56% → 94.07%. Findings F1 (fixed through #2811), F2 (fixed in S1), F3 (#2804), F4 (#2823), F6 (#2838, #2850) and F5 (#2876, drafted through #2865) have owners. | | 12 | #2838 - UDP tracker accepts announces with a negative left, uploaded or downloaded | `docs/issues/closed/2838-1347-udp-reject-negative-announce-bytes/ISSUE.md` | DONE | Bug found by the #2824 primitives tests work. Fixed by the standalone issue #2850 (`docs/issues/closed/2850-non-negative-number-of-bytes/ISSUE.md`): its implementation PR #2872 merged on 2026-11-16 and closed this issue. The patch of PR #2839 was not merged; its tests were taken over by PR #2872. | | 13 | #2876 - Move `peer::Id::new` to a realistic test helper and decide whether `peer::fixture` goes behind a `testing` feature | `docs/issues/closed/2876-1347-peer-id-test-helper/ISSUE.md` | DONE | Finding F5 of #2824. Spec through #2878, implementation through #2888: `Id::new` removed, `qbittorrent_peer_id` helper, `peer::fixture` behind the new `testing` feature of `primitives`, test-support ADR amended. Breaking for the published `primitives` 3.0.0; adds to the 4.0.0 it owes (#2583). | -| 14 | #2902 - Add tests to the tracker-core package | `docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md` | TODO | Lowest unit-only lines of the packages in the EPIC coverage table: 79.32% (MySQL/PostgreSQL drivers 0-4%, SQLite failure branches, `statistics/` reached only by the integration binary). Slices S0-S5 proposed; S0 is the spec-only PR. | +| 14 | #2902 - Add tests to the tracker-core package | `docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md` | IN_PROGRESS | Lowest unit-only lines of the packages in the EPIC coverage table: 79.32% (MySQL/PostgreSQL drivers 0-4%, SQLite failure branches, `statistics/` reached only by the integration binary). Slices S0-S5 proposed; S0 is the spec-only PR. | | 15 | Additional package-testing subissues | Create a folder-style spec when a concrete package need is identified | TODO | Permitted but not required upfront; retain scope in this EPIC. | **Publishing gate (maintainer decision of 2026-11-18).** A workspace crate may be published @@ -134,7 +134,7 @@ level or determine whether unit coverage is adequate. | `torrust-tracker-http-core` | [#1349](../../closed/1349-1347-add-tests-http-core/ISSUE.md) | Lines: 88.88%; regions: 90.41%; functions: 84.29% | Lines: 99.28%; regions: 99.25%; functions: 99.74% | Lines: +10.40 pp; regions: +8.84 pp; functions: +15.45 pp | [Coverage evidence](../../closed/1349-1347-add-tests-http-core/coverage-evidence.md) | | `torrust-tracker-axum-rest-api-server` | [#2637](../../closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md) | Lines: 87.98%; regions: 84.10%; functions: 83.42% | Lines: 97.67%; regions: 97.13%; functions: 95.48% | Lines: +9.69 pp; regions: +13.03 pp; functions: +12.06 pp | [Coverage evidence](../../closed/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md) | | `torrust-tracker-primitives` | [#2824](../../closed/2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 94.07%; regions: 95.30%; functions: 94.17% | Lines: +33.51 pp; regions: +27.36 pp; functions: +36.94 pp | [Coverage evidence](../../closed/2824-1347-add-tests-primitives/coverage-evidence.md) | -| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 81.15%; regions: 79.59%; functions: 73.35% | Not yet measured | Not yet measured | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | +| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 81.15%; regions: 79.59%; functions: 73.35% | Lines: 84.41%; regions: 82.63%; functions: 75.96% (after S1) | Lines: +3.26 pp; regions: +3.04 pp; functions: +2.61 pp | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | ### Unit-Only Coverage @@ -150,7 +150,7 @@ weak unit-only result with aggregate, integration, example, or end-to-end covera | `torrust-tracker-http-core` | [#1349](../../closed/1349-1347-add-tests-http-core/ISSUE.md) | Lines: 88.88%; regions: 90.41%; functions: 84.29% | Lines: 99.28%; regions: 99.25%; functions: 99.74% | Lines: +10.40 pp; regions: +8.84 pp; functions: +15.45 pp | [Coverage evidence](../../closed/1349-1347-add-tests-http-core/coverage-evidence.md) | | `torrust-tracker-axum-rest-api-server` | [#2637](../../closed/2637-1347-add-tests-axum-rest-api-server/ISSUE.md) | Lines: 63.87%; regions: 63.98%; functions: 51.34% | Lines: 96.67%; regions: 96.38%; functions: 93.97% | Lines: +32.80 pp; regions: +32.40 pp; functions: +42.63 pp | [Coverage evidence](../../closed/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md) | | `torrust-tracker-primitives` | [#2824](../../closed/2824-1347-add-tests-primitives/ISSUE.md) | Lines: 60.56%; regions: 67.94%; functions: 57.23% | Lines: 94.07%; regions: 95.30%; functions: 94.17% | Lines: +33.51 pp; regions: +27.36 pp; functions: +36.94 pp | [Coverage evidence](../../closed/2824-1347-add-tests-primitives/coverage-evidence.md) | -| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 79.32%; regions: 78.62%; functions: 71.98% | Not yet measured | Not yet measured | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | +| `torrust-tracker-core` | [#2902](../2902-1347-add-tests-tracker-core/ISSUE.md) | Lines: 79.32%; regions: 78.62%; functions: 71.98% | Lines: 84.41%; regions: 82.63%; functions: 75.96% (after S1) | Lines: +5.09 pp; regions: +4.01 pp; functions: +3.98 pp | [Coverage evidence](../2902-1347-add-tests-tracker-core/coverage-evidence.md) | ## Delivery Strategy @@ -411,6 +411,7 @@ For each subissue implementation, the completion policy is: - GitHub EPIC: https://github.com/torrust/torrust-tracker/issues/1347 - Related issues: #1348, #1349, #2136, #2149, #2637, #2824, #2902 - 2026-11-09 12:10 UTC - Claude Code - #2637 S6 merged through #2772 (2026-11-09 12:08 UTC) and issue #2637 closed: the `axum-rest-api-server` package is DONE. Final figures (unchanged): unit-only lines 96.67%, aggregate 97.67%. The spec was archived to `docs/issues/closed/` and the subissue row is `DONE`. +- 2026-11-21 13:24 UTC - Claude Code (Opus 5.5) - #2902 S1 (`statistics/`) closed, measured on its `develop` base `44ce734fe`: `tracker-core` unit-only lines 84.41% (79.45% on the base), aggregate 84.41% (81.27% on the base); the aggregate now equals unit-only, so the integration binary covers no line the unit tests miss. Row 14 is `IN_PROGRESS`. - Package inventory: `docs/packages.md` - Reference package: `packages/tracker-core/` - Coverage tooling: `cargo llvm-cov` diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index 72fb8a0343..bfed530995 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" related-pr: null -last-updated-utc: "2026-11-18 13:48" +last-updated-utc: "2026-11-21 13:24" semantic-links: skill-links: - create-issue @@ -426,6 +426,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-18 11:09 UTC - Claude Code (Opus 5.5) - Row 5 (`statistics/event/handler.rs`) done: two table tests over the five events that are not a completed download (replacing the two `PeerAdded`-only tests) and a global-save failure test; 311 / 311 lines, all four named mutants killed, one of which survived the old tests ([plan](test-refactor-plans/statistics-event-handler-tests.md)). Plan and completed file approved by the maintainer. - 2026-11-18 13:24 UTC - Claude Code (Opus 5.5) - Row 6 (`statistics/persisted/downloads.rs`) done: coverage was already complete after row 5, but a mutation probe found a stored torrent total could be overwritten with 1 unnoticed; two increment tests kill it ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)). Plan and completed file approved by the maintainer. - 2026-11-18 13:48 UTC - Claude Code (Opus 5.5) - Row 7 (`statistics/mod.rs`, `statistics/event/mod.rs`) done: one table test pins which downloads totals each statistics setting registers; 60 / 60 lines, all four named mutants killed; `event/mod.rs` no change ([plan](test-refactor-plans/statistics-mod-tests.md)). Plan and completed file approved by the maintainer. All S1 rows are done. +- 2026-11-21 13:24 UTC - Claude Code (Opus 5.5) - S1 closed: the branch was rebased on `develop` `44ce734fe` (one EPIC log conflict, both entries kept) and measured in the four scopes with the base: unit-only lines 79.45% to 84.41%, aggregate 81.27% to 84.41%, so the integration binary no longer reaches any line the unit tests miss ([slice measurements](coverage-evidence.md#slice-measurements)). The EPIC's #2902 rows hold the latest values. Next: the S1 PR. ## Open Design Questions diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md b/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md index 7a426f7886..2ec852af62 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md @@ -185,6 +185,37 @@ module or in test support). A Counts are by line class, not by decision: a "region" group can disappear when its neighbors are tested. The grouping above is the T1 hypothesis the decision records revisit. +## Slice Measurements + +Each slice closes with the four default scopes, measured at the slice's branch head and at the +`develop` commit it is based on, so the slice's own change is the difference between the two. Stable +Rust 1.100.0, `cargo-llvm-cov 0.9.1`, a clean coverage target directory, filtered to +`packages/tracker-core/src/`. + +### S1 (`statistics/`) + +Measured on 2026-11-21. Base: `develop` at `44ce734fe`, which also changed the integration tests (15 +instead of 12). Head: the S1 branch at its commit +`docs(issues): [#2902] record the results of the statistics module tests` (the slice-close commit +changes documentation only). + +| Scope | Tests | Lines | Regions | Functions | +| --- | ---: | ---: | ---: | ---: | +| Unit-only, base | 157 unit | 4,032 / 5,075 (79.45%) | 4,352 / 5,530 (78.70%) | 677 / 944 (71.72%) | +| Unit-only, S1 | 180 unit | 4,739 / 5,614 (84.41%) | 5,051 / 6,113 (82.63%) | 771 / 1,015 (75.96%) | +| Integration-only, base and S1 | 15 integration | 827 / 1,683 (49.14%) | 712 / 1,711 (41.61%) | 145 / 442 (32.81%) | +| Aggregate, base | 157 unit + 15 integration | 4,161 / 5,120 (81.27%) | 4,447 / 5,582 (79.67%) | 693 / 948 (73.10%) | +| Aggregate, S1 | 180 unit + 15 integration | 4,739 / 5,614 (84.41%) | 5,051 / 6,113 (82.63%) | 771 / 1,015 (75.96%) | +| Unit-only without `db-compatibility-tests`, base | 155 unit | 4,018 / 4,751 (84.57%) | 4,338 / 5,222 (83.07%) | 673 / 906 (74.28%) | +| Unit-only without `db-compatibility-tests`, S1 | 178 unit | 4,725 / 5,290 (89.32%) | 5,037 / 5,805 (86.77%) | 767 / 977 (78.51%) | + +At the S1 head the aggregate equals the unit-only figure line for line: the integration binary no +longer reaches any line of the package that the unit tests miss. Before S1 it added 129 lines, all +in the five `statistics/` files (see the baseline above). Every `statistics/` file is now fully +covered by lines; the regions left are the log-level checks of `tracing` calls, the unreachable +error arm of `load_persisted_metrics` (line 34) and test code. The per-file decisions are in the +[test-refactor plans](test-refactor-plans/README.md). + ## Test-Technique Assessment (initial) | Technique | Applicability | Initial decision | From 09b91fe3e6db7b7f96e2190a0d8529e036ec65da Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sat, 21 Nov 2026 13:34:02 +0000 Subject: [PATCH 25/40] docs(issues): [#2902] record the S1 pull request and close the F20 follow-up Co-Authored-By: Claude Opus 5.5 --- .../open/2902-1347-add-tests-tracker-core/ISSUE.md | 7 ++++--- docs/pr-reviews/pr-2903-review/PR-REVIEW.md | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md index bfed530995..b508a2dc2f 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md @@ -8,8 +8,8 @@ epic: 1347 github-issue: 2902 spec-path: docs/issues/open/2902-1347-add-tests-tracker-core/ISSUE.md branch: "2902-1347-add-tests-tracker-core-statistics" -related-pr: null -last-updated-utc: "2026-11-21 13:24" +related-pr: 2988 +last-updated-utc: "2026-11-21 13:33" semantic-links: skill-links: - create-issue @@ -297,7 +297,7 @@ is the proposal for the maintainer's approval (questions Q5, Q6): | Slice | Content | Ledger rows | Branch | PR | Status | | --- | --- | --- | --- | --- | --- | | S0 | This specification, the T1 evidence, and the EPIC registration with the baseline | - | `2902-1347-add-tests-tracker-core-spec` | #2903 | DONE | -| S1 | T2, then `statistics/`: `repository.rs`, `metrics.rs`, `persisted/mod.rs`, `persisted/downloads.rs`, `event/listener.rs`, `event/handler.rs`, `mod.rs` (the only area reached just by the integration binary) | 1-7 | `2902-1347-add-tests-tracker-core-statistics` | TBD | IN_PROGRESS | +| S1 | T2, then `statistics/`: `repository.rs`, `metrics.rs`, `persisted/mod.rs`, `persisted/downloads.rs`, `event/listener.rs`, `event/handler.rs`, `mod.rs` (the only area reached just by the integration binary) | 1-7 | `2902-1347-add-tests-tracker-core-statistics` | #2988 | IN_PROGRESS | | S2 | The SQLite persistence boundary: `sqlite/{auth_key_store,torrent_metrics_store,whitelist_store,mod,schema_migrator}.rs`, `databases/{error,setup}.rs`, `error.rs`, the extraction of `parse_valid_until` (Q4), plus the `databases/traits` and `driver/mod.rs` no-change decisions | 8-17 | `2902-1347-add-tests-tracker-core-sqlite` | TBD | TODO | | S3 | MySQL and PostgreSQL drivers: Docker-free error-path tests if non-flaky, otherwise no-change rows with the `db-compatibility` workflow as owner (Q3); the README and `packages/AGENTS.md` driver-test commands (Q2) | 18-27 | `2902-1347-add-tests-tracker-core-server-drivers` | TBD | TODO | | S4 | Authentication and whitelist: failing-`Database` propagation, `Key` property decision (F3, F4 checks) | 28-39 | `2902-1347-add-tests-tracker-core-auth-whitelist` | TBD | TODO | @@ -427,6 +427,7 @@ The first slice's record checks the grouping against `find packages/tracker-core - 2026-11-18 13:24 UTC - Claude Code (Opus 5.5) - Row 6 (`statistics/persisted/downloads.rs`) done: coverage was already complete after row 5, but a mutation probe found a stored torrent total could be overwritten with 1 unnoticed; two increment tests kill it ([plan](test-refactor-plans/statistics-persisted-downloads-tests.md)). Plan and completed file approved by the maintainer. - 2026-11-18 13:48 UTC - Claude Code (Opus 5.5) - Row 7 (`statistics/mod.rs`, `statistics/event/mod.rs`) done: one table test pins which downloads totals each statistics setting registers; 60 / 60 lines, all four named mutants killed; `event/mod.rs` no change ([plan](test-refactor-plans/statistics-mod-tests.md)). Plan and completed file approved by the maintainer. All S1 rows are done. - 2026-11-21 13:24 UTC - Claude Code (Opus 5.5) - S1 closed: the branch was rebased on `develop` `44ce734fe` (one EPIC log conflict, both entries kept) and measured in the four scopes with the base: unit-only lines 79.45% to 84.41%, aggregate 81.27% to 84.41%, so the integration binary no longer reaches any line the unit tests miss ([slice measurements](coverage-evidence.md#slice-measurements)). The EPIC's #2902 rows hold the latest values. Next: the S1 PR. +- 2026-11-21 13:33 UTC - Claude Code (Opus 5.5) - Opened the S1 PR #2988 (`Related to #2902`); it also carries the fix of finding F20 of #2903, whose thread is now resolved. ## Open Design Questions diff --git a/docs/pr-reviews/pr-2903-review/PR-REVIEW.md b/docs/pr-reviews/pr-2903-review/PR-REVIEW.md index 987eccc812..c866585c28 100644 --- a/docs/pr-reviews/pr-2903-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2903-review/PR-REVIEW.md @@ -77,7 +77,7 @@ and F19. | F17 | review-finding:pr-2903-f17 | Copilot | Minor | metadata | ORIGINAL | FIXED | RESOLVED | | F18 | review-finding:pr-2903-f18 | Human | Nit | correctness | ORIGINAL | FIXED | RESOLVED | | F19 | review-finding:pr-2903-f19 | Human | Nit | metadata | RE_RAISE_OF:F17 | NO_ACTION | SUPERSEDED | -| F20 | review-finding:pr-2903-f20 | Human | Nit | correctness | ORIGINAL | FOLLOW_UP | OPEN | +| F20 | review-finding:pr-2903-f20 | Human | Nit | correctness | ORIGINAL | FOLLOW_UP | RESOLVED | ## Finding Details @@ -335,10 +335,10 @@ and F19. - Reviewer finding ID: F20 - Source URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4600527629 - Concern: the merge commit of #2903 has the same subject as the S0 commit, so `git log --fixed-strings --grep='specify the tracker-core package tests'` lists it first and the verifications that take `-1` compare with the merge commit instead of the S0 commit. -- Solution: the maintainer merged #2903 with the nit open (2026-11-17); the S1 branch of #2902 adds `--no-merges` to the lookup in `coverage-evidence.md` and in the F8 and F18 verifications. -- Current-tree verification: on the S1 branch, `git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests'` prints one id, the S0 commit's, and `git diff --stat 5833cdae9 -- packages | wc -l` prints 0. +- Solution: the maintainer merged #2903 with the nit open (2026-11-17); the S1 branch of #2902 adds `--no-merges` to the lookup in the F8 and F18 verifications. It also added it in `coverage-evidence.md`, but the re-measurement of 2026-11-18 removed the lookup from that file: the container-gated scope is now measured at `5833cdae9` itself. +- Current-tree verification: on the S1 branch, `git log --no-merges --format=%H --fixed-strings --grep='specify the tracker-core package tests'` prints one id, the S0 commit's, and `git diff --stat 5833cdae9 -- packages | wc -l` prints 0; `grep -c 'specify the tracker-core package tests' docs/issues/open/2902-1347-add-tests-tracker-core/coverage-evidence.md` prints 0. - Resolution reference: docs(issues): [#2902] skip merge commits in the S0 commit lookup -- Follow-up PR URL: pending, the S1 PR of #2902 (branch `2902-1347-add-tests-tracker-core-statistics`) +- Follow-up PR URL: https://github.com/torrust/torrust-tracker/pull/2988 - Reply URL: https://github.com/torrust/torrust-tracker/pull/2903#discussion_r4602399913 ## Processing Log @@ -352,6 +352,7 @@ and F19. - 2026-11-17 13:31 UTC - Round 5 (Copilot's review `5939369230`, 13:30:51 UTC, F17) was about the head before the round 4 replies were recorded; replied at 13:31:57 UTC and resolved the thread. - 2026-11-17 13:41 UTC - Round 6 (da2ce7's review `5939412622`, 13:33:52 UTC, F18-F19): F18 fixed in its own commit and pushed; replied to both threads at 13:41:03 and 13:41:07 UTC and resolved each after its reply (F19 superseded by F17). - 2026-11-17 16:18 UTC - Round 7 (da2ce7's review `5939722814`, 13:55:00 UTC, approval with F20): the maintainer merged #2903 with F20 open. The fix is the first commit of the S1 branch of #2902; replied at 16:18:25 UTC and left the thread open until the S1 PR exists. +- 2026-11-21 13:33 UTC - F20 follow-up: the S1 PR #2988 is open with the fix; replied on the thread at 13:32:38 UTC (edited at 13:32:56 UTC to say the `coverage-evidence.md` lookup was removed by the re-measurement) and resolved it. ## Completion Rules From 7c64de59bef508acee5cb3d09b259ec598873a45 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:27:29 +0000 Subject: [PATCH 26/40] test(tracker-core): [#2902] turn the statistics table tests into rstest cases The two event tables of the statistics handler and the registration table of the statistics module looped over their cases, so the first broken case stopped the test and hid the others. Each case is now an `rstest` case with its own name, as the `write-unit-test` skill prescribes; `rstest` 0.28.0, already in the lock file, becomes a dev-dependency of the package. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + packages/tracker-core/Cargo.toml | 1 + .../src/statistics/event/handler.rs | 169 +++++++++--------- packages/tracker-core/src/statistics/mod.rs | 38 ++-- 4 files changed, 110 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0cdb9d2731..e038932063 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5188,6 +5188,7 @@ dependencies = [ "derive_more 2.1.1", "mockall", "rand 0.9.5", + "rstest", "secrecy", "serde", "serde_json", diff --git a/packages/tracker-core/Cargo.toml b/packages/tracker-core/Cargo.toml index 795df2e140..c3552fdefc 100644 --- a/packages/tracker-core/Cargo.toml +++ b/packages/tracker-core/Cargo.toml @@ -47,6 +47,7 @@ tracing = "0" [dev-dependencies] mockall = "0" +rstest = "0.28.0" secrecy = "0.10.3" testcontainers = "0" tempfile = "3.27.0" diff --git a/packages/tracker-core/src/statistics/event/handler.rs b/packages/tracker-core/src/statistics/event/handler.rs index bcba295150..dda57eee68 100644 --- a/packages/tracker-core/src/statistics/event/handler.rs +++ b/packages/tracker-core/src/statistics/event/handler.rs @@ -135,6 +135,7 @@ mod tests { use std::panic::Location; use std::sync::Arc; + use rstest::rstest; use torrust_clock::DurationSinceUnixEpoch; use torrust_tracker_configuration::v3_0_0::core::Core; use torrust_tracker_primitives::Driver; @@ -148,45 +149,39 @@ mod tests { use crate::statistics::repository::Repository; use crate::test_helpers::tests::{ephemeral_configuration, sample_info_hash, sample_peer}; - /// Every event kind except `PeerDownloadCompleted`, named for the assertion messages. - fn events_other_than_a_completed_download() -> [(&'static str, Event); 5] { - [ - ( - "TorrentAdded", - Event::TorrentAdded { - info_hash: sample_info_hash(), - announcement: sample_peer(), - }, - ), - ( - "TorrentRemoved", - Event::TorrentRemoved { - info_hash: sample_info_hash(), - }, - ), - ( - "PeerAdded", - Event::PeerAdded { - info_hash: sample_info_hash(), - peer: sample_peer(), - }, - ), - ( - "PeerRemoved", - Event::PeerRemoved { - info_hash: sample_info_hash(), - peer: sample_peer(), - }, - ), - ( - "PeerUpdated", - Event::PeerUpdated { - info_hash: sample_info_hash(), - old_peer: sample_peer(), - new_peer: sample_peer(), - }, - ), - ] + fn torrent_added_event() -> Event { + Event::TorrentAdded { + info_hash: sample_info_hash(), + announcement: sample_peer(), + } + } + + fn torrent_removed_event() -> Event { + Event::TorrentRemoved { + info_hash: sample_info_hash(), + } + } + + fn peer_added_event() -> Event { + Event::PeerAdded { + info_hash: sample_info_hash(), + peer: sample_peer(), + } + } + + fn peer_removed_event() -> Event { + Event::PeerRemoved { + info_hash: sample_info_hash(), + peer: sample_peer(), + } + } + + fn peer_updated_event() -> Event { + Event::PeerUpdated { + info_hash: sample_info_hash(), + old_peer: sample_peer(), + new_peer: sample_peer(), + } } fn peer_download_completed_event() -> Event { @@ -216,26 +211,30 @@ mod tests { assert_eq!(stats_repository.get_torrents_downloads_in_session_total().await, 1); } + #[rstest] + #[case::torrent_added(torrent_added_event())] + #[case::torrent_removed(torrent_removed_event())] + #[case::peer_added(peer_added_event())] + #[case::peer_removed(peer_removed_event())] + #[case::peer_updated(peer_updated_event())] #[tokio::test] - async fn it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download() { - for (name, event) in events_other_than_a_completed_download() { - // Arrange - let stats_repository = Arc::new(Repository::default()); - let now = DurationSinceUnixEpoch::new(1, 0); - - // Act - handle_in_memory_event(event, &stats_repository, now).await; - - // Assert - assert_eq!( - ( - stats_repository.get_torrents_downloads_total().await, - stats_repository.get_torrents_downloads_in_session_total().await - ), - (0, 0), - "{name} must not count as a completed download" - ); - } + async fn it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download(#[case] event: Event) { + // Arrange + let stats_repository = Arc::new(Repository::default()); + let now = DurationSinceUnixEpoch::new(1, 0); + + // Act + handle_in_memory_event(event, &stats_repository, now).await; + + // Assert + assert_eq!( + ( + stats_repository.get_torrents_downloads_total().await, + stats_repository.get_torrents_downloads_in_session_total().await + ), + (0, 0), + "an event other than a completed download must not change the persistent or in-session total" + ); } #[tokio::test] @@ -267,32 +266,36 @@ mod tests { assert_eq!(stats_repository.get_torrents_downloads_persisted_total().await, 1); } + #[rstest] + #[case::torrent_added(torrent_added_event())] + #[case::torrent_removed(torrent_removed_event())] + #[case::peer_added(peer_added_event())] + #[case::peer_removed(peer_removed_event())] + #[case::peer_updated(peer_updated_event())] #[tokio::test] - async fn it_should_persist_nothing_for_an_event_other_than_a_completed_download() { - for (name, event) in events_other_than_a_completed_download() { - // Arrange - let stats_repository = Arc::new(Repository::new(true, true)); - let ephemeral = ephemeral_configuration(); - let downloads_repository = database_downloads_repository(&ephemeral.config).await; - let now = DurationSinceUnixEpoch::new(1, 0); - - // Act - handle_persistent_completed_statistics_event(event, &downloads_repository, &stats_repository, now).await; - - // Assert - assert_eq!( - ( - downloads_repository - .load_torrent_downloads(&sample_info_hash()) - .await - .unwrap(), - downloads_repository.load_global_downloads().await.unwrap(), - stats_repository.get_torrents_downloads_persisted_total().await - ), - (None, None, 0), - "{name} must not persist a completed download" - ); - } + async fn it_should_persist_nothing_for_an_event_other_than_a_completed_download(#[case] event: Event) { + // Arrange + let stats_repository = Arc::new(Repository::new(true, true)); + let ephemeral = ephemeral_configuration(); + let downloads_repository = database_downloads_repository(&ephemeral.config).await; + let now = DurationSinceUnixEpoch::new(1, 0); + + // Act + handle_persistent_completed_statistics_event(event, &downloads_repository, &stats_repository, now).await; + + // Assert + assert_eq!( + ( + downloads_repository + .load_torrent_downloads(&sample_info_hash()) + .await + .unwrap(), + downloads_repository.load_global_downloads().await.unwrap(), + stats_repository.get_torrents_downloads_persisted_total().await + ), + (None, None, 0), + "an event other than a completed download must not persist a download" + ); } #[tokio::test] diff --git a/packages/tracker-core/src/statistics/mod.rs b/packages/tracker-core/src/statistics/mod.rs index 7c94b18a6d..88f385598f 100644 --- a/packages/tracker-core/src/statistics/mod.rs +++ b/packages/tracker-core/src/statistics/mod.rs @@ -76,6 +76,7 @@ fn set_counter_to_zero(metrics: &mut Metrics, metric_name: &str) { #[cfg(test)] mod tests { + use rstest::rstest; use torrust_metrics::label::LabelSet; use torrust_metrics::metric_name; @@ -93,22 +94,27 @@ mod tests { .map(|counter| counter.value()) } - #[test] - fn it_should_register_each_downloads_total_only_when_its_statistics_are_enabled() { - for (usage, persisted) in [(false, false), (false, true), (true, false), (true, true)] { - // Act - let metrics = describe_metrics(usage, persisted); + #[rstest] + #[case::both_disabled(false, false)] + #[case::only_persisted_statistics(false, true)] + #[case::only_usage_statistics(true, false)] + #[case::both_enabled(true, true)] + fn it_should_register_each_downloads_total_only_when_its_statistics_are_enabled( + #[case] usage: bool, + #[case] persisted: bool, + ) { + // Act + let metrics = describe_metrics(usage, persisted); - // Assert - assert_eq!( - ( - counter(&metrics, TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), - counter(&metrics, TRACKER_CORE_IN_SESSION_TORRENTS_DOWNLOADS_TOTAL), - counter(&metrics, TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL) - ), - (Some(0), usage.then_some(0), persisted.then_some(0)), - "(persistent, in-session, persisted) totals with usage statistics {usage} and persisted statistics {persisted}" - ); - } + // Assert + assert_eq!( + ( + counter(&metrics, TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL), + counter(&metrics, TRACKER_CORE_IN_SESSION_TORRENTS_DOWNLOADS_TOTAL), + counter(&metrics, TRACKER_CORE_PERSISTED_TORRENTS_DOWNLOADS_TOTAL) + ), + (Some(0), usage.then_some(0), persisted.then_some(0)), + "(persistent, in-session, persisted) totals with usage statistics {usage} and persisted statistics {persisted}" + ); } } From 1b6b3506c85fa6e6d057a71d31093dfeb0a638eb Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:28:51 +0000 Subject: [PATCH 27/40] test(tracker-core): [#2902] check that no torrent row is persisted for an event other than a completion The persistence cases looked up only the sample info-hash, so a row written under another info-hash went unnoticed. They now expect no torrent row at all. Co-Authored-By: Claude Opus 5.5 --- packages/tracker-core/src/statistics/event/handler.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/tracker-core/src/statistics/event/handler.rs b/packages/tracker-core/src/statistics/event/handler.rs index dda57eee68..642bd2c109 100644 --- a/packages/tracker-core/src/statistics/event/handler.rs +++ b/packages/tracker-core/src/statistics/event/handler.rs @@ -286,15 +286,12 @@ mod tests { // Assert assert_eq!( ( - downloads_repository - .load_torrent_downloads(&sample_info_hash()) - .await - .unwrap(), + downloads_repository.load_all_torrents_downloads().await.unwrap().len(), downloads_repository.load_global_downloads().await.unwrap(), stats_repository.get_torrents_downloads_persisted_total().await ), - (None, None, 0), - "an event other than a completed download must not persist a download" + (0, None, 0), + "an event other than a completed download must not persist a download for any torrent" ); } From 18fdd8913a100c776760951b8f037b32ffd67979 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:29:57 +0000 Subject: [PATCH 28/40] test(tracker-core): [#2902] name the global downloads failure test after the read it fails The test fails `load_global_downloads`, so `increase_global_downloads` stops before any save. Its name and message said the global downloads could not be saved; they now say they cannot be increased, which is what the mock arranges. Co-Authored-By: Claude Opus 5.5 --- .../test-refactor-plans/statistics-event-handler-tests.md | 4 ++-- packages/tracker-core/src/statistics/event/handler.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md index cb15d991ad..458c6cb8aa 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md @@ -34,7 +34,7 @@ Follow the shared [guidance](README.md). This plan covers only - **Module-owned decisions not yet tested:** - Only `PeerDownloadCompleted` changes a total: the other five event kinds only log. One of the five is tested, for each handler. - - The persisted total follows the database: when the global write fails, the in-memory persisted + - The persisted total follows the database: when the global downloads cannot be increased (the test fails their read), the in-memory persisted total is not incremented (line 129), even though the torrent row was written. ## Maintainer Decision @@ -47,7 +47,7 @@ Plan approved on 2026-11-18, including replacing the two `PeerAdded`-only tests | --- | --- | --- | | `it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download` | each of `TorrentAdded`, `TorrentRemoved`, `PeerAdded`, `PeerRemoved` and `PeerUpdated`, in a table, on a fresh repository | the persistent and in-session totals read 0, with the event's name in the message | | `it_should_persist_nothing_for_an_event_other_than_a_completed_download` | the same table, on a fresh `TempDir` database | no torrent row, no global row, persisted total 0 | -| `it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_saved` | `MockTorrentMetricsStore`: the torrent write succeeds (`load_torrent_downloads` → `None`, `save_torrent_downloads` → `Ok`), `load_global_downloads` fails | the persisted total reads 0 | +| `it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_increased` | `MockTorrentMetricsStore`: the torrent write succeeds (`load_torrent_downloads` → `None`, `save_torrent_downloads` → `Ok`), `load_global_downloads` fails | the persisted total reads 0 | The two table tests replace the two existing `PeerAdded`-only tests (`it_should_not_increment_in_memory_completion_metrics_when_an_event_is_not_a_completion` and diff --git a/packages/tracker-core/src/statistics/event/handler.rs b/packages/tracker-core/src/statistics/event/handler.rs index 642bd2c109..5446cb38dd 100644 --- a/packages/tracker-core/src/statistics/event/handler.rs +++ b/packages/tracker-core/src/statistics/event/handler.rs @@ -330,7 +330,7 @@ mod tests { } #[tokio::test] - async fn it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_saved() { + async fn it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_increased() { // Arrange let stats_repository = Arc::new(Repository::new(true, true)); let mut store = MockTorrentMetricsStore::new(); @@ -364,7 +364,7 @@ mod tests { assert_eq!( stats_repository.get_torrents_downloads_persisted_total().await, 0, - "the persisted total must follow the database, which did not save the global downloads" + "the persisted total must follow the database, which could not read the global downloads to increase them" ); } } From 7dd2f1856faae744270971baec253500427ce6be Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:31:00 +0000 Subject: [PATCH 29/40] docs(issues): [#2902] move the S1 close entry into the EPIC progress log The entry went under `## References`, after an older stray log line, so the Progress Log never said that S1 closed or that row 14 moved to `IN_PROGRESS`. Co-Authored-By: Claude Opus 5.5 --- docs/issues/open/1347-overhaul-packages-testing/EPIC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md index baf5b52363..9d0f6e7791 100644 --- a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md +++ b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md @@ -371,6 +371,7 @@ For each subissue implementation, the completion policy is: - 2026-11-17 12:43 UTC - Claude Code (Opus 5.5) - #2902 T1b, measured on 2026-11-17 after the maintainer allowed pulling the `mysql:8.0` and `postgres:16` images: with both driver suites running, the `tracker-core` aggregate is lines 93.80% (4,830 / 5,149). Correction: the commit that recorded T1b edited the 10:57 entry above in place; its original text is restored (review finding F9 of #2903). - 2026-11-18 09:10 UTC - Claude Code (Opus 5.5) - #2902 re-measured its baseline with stable Rust 1.100.0 and `cargo-llvm-cov 0.9.1` (Rust 1.99.1 with `cargo-llvm-cov 0.6.16` cannot measure after the Cargo 1.100.0 test-binary layout change): `tracker-core` unit-only lines 79.32% (was 80.31%), aggregate 81.15% (was 82.15%), container-gated 92.67% (was 93.80%), at the same commit. The other packages' rows keep their own toolchains. - 2026-11-18 10:20 UTC - Claude Code (Claude Fable 5.2) - Added the "Publishing gate" paragraph under the `Subissues` table through PR torrust/torrust-tracker#2935 (issue #2583): by the maintainer's decision of 2026-11-18, a crate may be published under #2583 once its own package-testing subissues are closed, and EPIC #1669 no longer waits for this EPIC to close as a whole. No subissue was created or changed. +- 2026-11-21 13:24 UTC - Claude Code (Opus 5.5) - #2902 S1 (`statistics/`) closed, measured on its `develop` base `44ce734fe`: `tracker-core` unit-only lines 84.41% (79.45% on the base), aggregate 84.41% (81.27% on the base); the aggregate now equals unit-only, so the integration binary covers no line the unit tests miss. Row 14 is `IN_PROGRESS`. ## Acceptance Criteria @@ -411,7 +412,6 @@ For each subissue implementation, the completion policy is: - GitHub EPIC: https://github.com/torrust/torrust-tracker/issues/1347 - Related issues: #1348, #1349, #2136, #2149, #2637, #2824, #2902 - 2026-11-09 12:10 UTC - Claude Code - #2637 S6 merged through #2772 (2026-11-09 12:08 UTC) and issue #2637 closed: the `axum-rest-api-server` package is DONE. Final figures (unchanged): unit-only lines 96.67%, aggregate 97.67%. The spec was archived to `docs/issues/closed/` and the subissue row is `DONE`. -- 2026-11-21 13:24 UTC - Claude Code (Opus 5.5) - #2902 S1 (`statistics/`) closed, measured on its `develop` base `44ce734fe`: `tracker-core` unit-only lines 84.41% (79.45% on the base), aggregate 84.41% (81.27% on the base); the aggregate now equals unit-only, so the integration binary covers no line the unit tests miss. Row 14 is `IN_PROGRESS`. - Package inventory: `docs/packages.md` - Reference package: `packages/tracker-core/` - Coverage tooling: `cargo llvm-cov` From f788cb0aa117cd7ee918b5d7aa9356d8f4b70b1b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:31:48 +0000 Subject: [PATCH 30/40] docs(issues): [#2902] return a stray #2637 entry to the EPIC progress log The 2026-11-09 entry for #2637 S6 sat under `## References` since the #2637 archive commit. It now sits in the Progress Log between the 2026-11-06 and 2026-11-11 entries. Co-Authored-By: Claude Opus 5.5 --- docs/issues/open/1347-overhaul-packages-testing/EPIC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md index 9d0f6e7791..46e1e7bd80 100644 --- a/docs/issues/open/1347-overhaul-packages-testing/EPIC.md +++ b/docs/issues/open/1347-overhaul-packages-testing/EPIC.md @@ -356,6 +356,7 @@ For each subissue implementation, the completion policy is: - 2026-11-06 09:06 UTC - Claude Code - #2637 S5 (the `server.rs` lifecycle) pull request #2744 opened. - 2026-11-06 10:31 UTC - Claude Code - #2637 S5 merged through #2744 (2026-11-06 10:26 UTC). S6 (rows 19-31, then the final tasks) started; its baseline is the S5 re-measurement (unit-only lines 96.71%, aggregate 97.71%). - 2026-11-06 16:37 UTC - Claude Code - #2637 S6 (crate root, wiring and final tasks) finished: ledger rows 19-31 done, one test added (`authenticate` with a duplicated token value, found by the mutation run), manual scenarios M1-M5 passed. Final figures: unit-only lines 96.67% (170 unit tests), aggregate 97.67%; both "Latest" tables carry them. +- 2026-11-09 12:10 UTC - Claude Code - #2637 S6 merged through #2772 (2026-11-09 12:08 UTC) and issue #2637 closed: the `axum-rest-api-server` package is DONE. Final figures (unchanged): unit-only lines 96.67%, aggregate 97.67%. The spec was archived to `docs/issues/closed/` and the subissue row is `DONE`. - 2026-11-11 11:22 UTC - Claude Code - Created #2824 (`primitives`) as a subissue of this EPIC (the link under #1347 is set by the maintainer). Clean baseline at `eaae0e487`, filtered to the package source: unit-only = aggregate lines 60.56% (453/748), regions 67.94% (712/1,048), functions 57.23% (91/159), 47 unit tests, no integration tests. Delivered in slices S0-S4; the row stays `TODO` until the first implementation slice starts. - 2026-11-11 14:32 UTC - Claude Code - #2824 S1 (PR #2834) re-measured `primitives` unit-only (= aggregate) at lines 62.73% (468 / 746), regions 70.29%, functions 59.49%, 49 unit tests. The figures include the changes merged to `develop` since the baseline (`Peer` lost `Ord`, the unused `AddAssign` was deleted), not only the slice. Both "Latest" tables carry them; the row is `IN_PROGRESS`. - 2026-11-12 13:40 UTC - Claude Code - #2824 S2 (`peer.rs` tests, 31 added) re-measured `primitives` unit-only (= aggregate) at lines 84.86% (824 / 971), regions 88.93%, functions 82.90%, 80 unit tests; the figures include the added in-file test code. Both "Latest" tables carry them; the row stays `IN_PROGRESS`. @@ -411,7 +412,6 @@ For each subissue implementation, the completion policy is: - GitHub EPIC: https://github.com/torrust/torrust-tracker/issues/1347 - Related issues: #1348, #1349, #2136, #2149, #2637, #2824, #2902 -- 2026-11-09 12:10 UTC - Claude Code - #2637 S6 merged through #2772 (2026-11-09 12:08 UTC) and issue #2637 closed: the `axum-rest-api-server` package is DONE. Final figures (unchanged): unit-only lines 96.67%, aggregate 97.67%. The spec was archived to `docs/issues/closed/` and the subissue row is `DONE`. - Package inventory: `docs/packages.md` - Reference package: `packages/tracker-core/` - Coverage tooling: `cargo llvm-cov` From 0a746a5f494342fc003cfc936fa4101c5361208b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:32:45 +0000 Subject: [PATCH 31/40] docs(issues): [#2902] reconcile the listener and repository plans with their tests The listener plan named one helper, `join_within_deadline`; the tests add `LISTENER_DEADLINE`, `send` and `within_deadline`. The repository plan said gauges are compared as `Option`; they are compared as `Option`, as its Results section already says. Co-Authored-By: Claude Opus 5.5 --- .../test-refactor-plans/statistics-event-listener-tests.md | 3 ++- .../test-refactor-plans/statistics-repository-tests.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md index fc61cc852b..792e3d6365 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-listener-tests.md @@ -72,7 +72,8 @@ Plan approved on 2026-11-18, with all four tests (the spawned pair keeps the T2b The tests reuse the module's existing helpers (`peer_download_completed_event`, `database_downloads_repository`, `expect_in_memory_download_metrics_to_be`, -`expect_persisted_download_metrics_to_be`) and add one: a 5-second `join_within_deadline` helper. +`expect_persisted_download_metrics_to_be`) and add three: the 5-second `LISTENER_DEADLINE`, `send` (one event on the bus) and +`within_deadline` (awaits a listener under the deadline, with a message naming it). ## Property-Test Decision diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md index 9d23638e7c..c2cdef85ac 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-repository-tests.md @@ -92,7 +92,7 @@ on the tuple against `(true, true, false)`, which prints all three values on fai Arrange with its own message instead of pretending to be a counter failure. - **Fixed time:** `DurationSinceUnixEpoch::from_secs(0)`, a literal; no clock. - **Reading back:** the counter readers for counters; `read_metrics` with - `metric_collection().get_gauge_value(...)` for gauges, compared as `Option`. + `metric_collection().get_gauge_value(...)` for gauges, compared as `Option` (see below). - **Error assertion:** `matches!(result, Err(Error::MetricNameCollisionAdding { metric_name }) if metric_name == metric_name!("..."))`, the pattern of the `torrust-metrics` tests. - **Shape:** one test per operation and outcome, about ten small tests, no loops and no table From f9c1ea320644a08da03a9db96a37383019de1ac2 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:33:41 +0000 Subject: [PATCH 32/40] docs(issues): [#2902] record the review changes of the statistics table tests Co-Authored-By: Claude Opus 5.5 --- .../statistics-event-handler-tests.md | 15 +++++++++++++++ .../test-refactor-plans/statistics-mod-tests.md | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md index 458c6cb8aa..e51110a6b8 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md @@ -105,3 +105,18 @@ M1 and M2 survive today: the only non-completion event under test is `PeerAdded` - **Review outcome:** the maintainer approved the completed file on 2026-11-18. - **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. + +## Changes After Review (#2988) + +- **`rstest` cases (finding F2 of #2988, maintainer decision of 2026-11-22):** the two tables loop + no longer. Each event kind is an `rstest` case with its own name (`case_1_torrent_added` to + `case_5_peer_updated`), as the `write-unit-test` skill prescribes, so each broken event kind fails + under its own name: with M1 applied, only `case_4_peer_removed` fails. `rstest` 0.28.0, already in + the lock file, became a dev-dependency of the package. The ten cases replace the two table tests: + 191 unit test cases in the package. +- **Any torrent row (Copilot, #2988):** the persistence cases expect no torrent row at all + (`load_all_torrents_downloads()` is empty), not only no row for the sample info-hash; a mutant + that writes a row under another info-hash fails all five cases. +- **Name (finding F3 of #2988):** the global failure test is + `it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_increased`: its + mock fails the read of the global downloads, before any save. diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md index 7bfe685aa8..74980ffeb7 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md @@ -92,3 +92,10 @@ M1 and M2 survive today: no test disables usage statistics. - **Review outcome:** the maintainer approved the completed file on 2026-11-18. - **Validation:** `cargo clippy -p torrust-tracker-core --all-targets --all-features` (only the existing `axum::serve` warning) and `cargo +nightly fmt --all -- --check` pass. + +## Changes After Review (#2988) + +- **`rstest` cases (finding F2 of #2988, maintainer decision of 2026-11-22):** the table loops no + longer. Each `(usage, persisted)` combination is an `rstest` case with its own name + (`case_1_both_disabled` to `case_4_both_enabled`), as the `write-unit-test` skill prescribes, so + each broken combination fails under its own name. From a05b5a02f62dc25a175923390b2be91dbc593fd2 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:36:20 +0000 Subject: [PATCH 33/40] docs(pr-reviews): [#2902] record the first review round of #2988 Co-Authored-By: Claude Opus 5.5 --- docs/pr-reviews/pr-2988-review/PR-REVIEW.md | 175 ++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 docs/pr-reviews/pr-2988-review/PR-REVIEW.md diff --git a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md new file mode 100644 index 0000000000..463ba41807 --- /dev/null +++ b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md @@ -0,0 +1,175 @@ +--- +semantic-links: + skill-links: + - process-pr-review + related-artifacts: + - .claude/skills/process-pr-review/SKILL.md +--- + + + +# PR #2988 Review Audit + +Source: pull-request reviews and inline review threads for https://github.com/torrust/torrust-tracker/pull/2988. + +## Ownership + +The PR author owns this tracked audit record. Reviewers, including repository review agents, +deliver findings through GitHub and have no repository-artifact obligation. + +- Post-merge workflow approval: N/A + +## Status Values + +- Relationship: `ORIGINAL`, `RE_RAISE_OF:` +- Disposition: `FIXED`, `NO_ACTION`, `SUPERSEDED`, `FOLLOW_UP` +- Thread state: `OPEN`, `RESOLVED`, `NON_RESOLVABLE`, `SUPERSEDED`. `OPEN` applies prospectively + to audits created or updated for approved follow-up work; historical audits remain valid without + bulk migration. +- Severity: `Blocker`, `Major`, `Minor`, `Nit`, `Suggestion`; append `(inferred)` when derived + from free prose. +- Author class: `Copilot`, `Human`, `Unknown` +- Category: `link-integrity`, `formatting`, `metadata`, `testing`, `correctness`, + `documentation`, `maintainability`, `security`, `other` +- An outdated thread whose concern was fixed is `FIXED`/`RESOLVED`, even when GitHub marks the + original thread outdated after the push. For in-PR feedback, use `NO_ACTION`/`SUPERSEDED` only + for a duplicate, superseded, or no-change concern. A post-merge `NO_ACTION` requires maintainer + approval to decline the follow-up work. +- When the current identity cannot resolve a thread (`viewerCanResolve` is `false`), keep the + disposition established from the current tree and record `Thread state=OPEN`. The reviewer or PR + author resolves it; permission says nothing about whether the concern was fixed. + +## Findings + +Round 1 is two reviews of the head whose last commit is +`docs(issues): [#2902] record the S1 pull request and close the F20 follow-up`: Copilot's review +`6006223766` (2026-11-21 15:13:36 UTC, comment, three inline comments without IDs, recorded as F5 +to F7 with the severity of its overview, two Medium and one Low) and da2ce7's review `6006307330` +(2026-11-21 15:32:08 UTC, approval, inline findings F1 to F4 with the reviewer's IDs). + +| Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | +| ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | +| F1 | review-finding:pr-2988-f1 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F2 | review-finding:pr-2988-f2 | Human | Minor | testing | ORIGINAL | FIXED | RESOLVED | +| F3 | review-finding:pr-2988-f3 | Human | Nit | testing | ORIGINAL | FIXED | RESOLVED | +| F4 | review-finding:pr-2988-f4 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | +| F5 | review-finding:pr-2988-f5 | Copilot | Minor (inferred) | testing | ORIGINAL | FIXED | RESOLVED | +| F6 | review-finding:pr-2988-f6 | Copilot | Minor (inferred) | testing | ORIGINAL | NO_ACTION | SUPERSEDED | +| F7 | review-finding:pr-2988-f7 | Copilot | Nit (inferred) | maintainability | ORIGINAL | NO_ACTION | SUPERSEDED | + +## Finding Details + +### F1 - The S1 close entry landed under References + +- PR number: 2988 +- Source review ID: 6006307330 +- Reviewer finding ID: F1 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653399821 +- Concern: The 2026-11-21 13:24 EPIC entry followed a stray 2026-11-09 line into `## References`, so the Progress Log never said that S1 closed. +- Solution: The entry ends the Progress Log; the stray #2637 entry moved, in its own commit, between the 2026-11-06 and 2026-11-11 entries. +- Current-tree verification: `sed -n '/^## References/,$p' docs/issues/open/1347-overhaul-packages-testing/EPIC.md | grep -c '^- 2026'` prints 0. +- Resolution reference: docs(issues): [#2902] move the S1 close entry into the EPIC progress log +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542178 + +### F2 - The table tests looped over their cases + +- PR number: 2988 +- Source review ID: 6006307330 +- Reviewer finding ID: F2 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653399827 +- Concern: Three table tests iterated in a `for` loop, where the `write-unit-test` skill prescribes `rstest` cases; the first broken case hid the others. +- Solution: By the maintainer's decision of 2026-11-22, the three tables are 14 named `rstest` cases; `rstest` 0.28.0 is a dev-dependency of the package. The row 5 and row 7 plans record the change. +- Current-tree verification: `cargo test -p torrust-tracker-core --all-features --lib statistics:: -- --list` lists the 14 `case_` tests; with the `PeerRemoved` mutant only `case_4_peer_removed` fails. +- Resolution reference: test(tracker-core): [#2902] turn the statistics table tests into rstest cases +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542313 + +### F3 - The test name said save where the mock fails the read + +- PR number: 2988 +- Source review ID: 6006307330 +- Reviewer finding ID: F3 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653399830 +- Concern: The global failure test failed `load_global_downloads`, so no save ran, but its name and message said the global downloads could not be saved. +- Solution: The test is `it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_increased`, with a matching message; the plan uses the new name. +- Current-tree verification: `grep -rn 'cannot_be_saved' packages/tracker-core docs/issues/open/2902-1347-add-tests-tracker-core` prints nothing. +- Resolution reference: test(tracker-core): [#2902] name the global downloads failure test after the read it fails +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542399 + +### F4 - Plan text not reconciled with the code + +- PR number: 2988 +- Source review ID: 6006307330 +- Reviewer finding ID: F4 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653399836 +- Concern: The listener plan named one helper, `join_within_deadline`, and the repository plan said gauges are compared as `Option`. +- Solution: The listener plan names `LISTENER_DEADLINE`, `send` and `within_deadline`; the repository plan says `Option`. +- Current-tree verification: `grep -rn 'join_within_deadline\|Option' docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans` prints nothing. +- Resolution reference: docs(issues): [#2902] reconcile the listener and repository plans with their tests +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542502 + +### F5 - The persistence check looked up one info-hash only + +- PR number: 2988 +- Source review ID: 6006223766 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653330510 +- Concern: The persistence table asserted no row for `sample_info_hash()`, which would miss a row written under the event's own info-hash if the helper were not deterministic. +- Solution: The helper parses a fixed literal, so the old check was sound; it is still widened: each case expects no torrent row at all (`load_all_torrents_downloads()` is empty). A mutant writing a row under another info-hash fails all five cases. +- Current-tree verification: `grep -n 'load_all_torrents_downloads().await.unwrap().len()' packages/tracker-core/src/statistics/event/handler.rs` shows the assertion. +- Resolution reference: test(tracker-core): [#2902] check that no torrent row is persisted for an event other than a completion +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542603 + +### F6 - The same comment on the persistence table + +- PR number: 2988 +- Source review ID: 6006223766 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653330553 +- Concern: The F5 comment, repeated at the persistence table. +- Solution: Superseded by F5, fixed by the same commit. +- Current-tree verification: As for F5. +- Resolution reference: test(tracker-core): [#2902] check that no torrent row is persisted for an event other than a completion +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542683 + +### F7 - One database per case + +- PR number: 2988 +- Source review ID: 6006223766 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4653330586 +- Concern: The persistence table built a fresh temporary database for each of its five cases, which may be slow. +- Solution: Superseded by F2: each case is its own `rstest` test, run in parallel; one database per test keeps the cases isolated, as the spec's ownership map requires. The five cases take 0.01 s. +- Current-tree verification: `cargo test -p torrust-tracker-core --all-features --lib it_should_persist_nothing` runs five tests. +- Resolution reference: test(tracker-core): [#2902] turn the statistics table tests into rstest cases +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542783 + +## Processing Log + +- 2026-11-22 09:22 UTC - Read both round 1 reviews; the maintainer chose `rstest` cases for F2. Fixed F2, F5, F3, F1 (and the stray #2637 line) and F4 in their own commits, then recorded the review changes in the row 5 and row 7 plans. +- 2026-11-22 09:34 UTC - Replied on all seven threads (09:34:44 to 09:34:57 UTC), before pushing the fixes and this record together; the threads are resolved after the push. + +## Completion Rules + +- Re-derive the reply claim against the current tree before replying or resolving a thread. +- Reply on every resolvable thread before resolving it. +- For an outdated thread whose concern was fixed, record `Disposition=FIXED` and + `Thread state=RESOLVED`, even if GitHub marks the thread outdated after the push. For a + duplicate, superseded, or no-change in-PR thread, reply exactly + `Superseded by : .`, record `Disposition=NO_ACTION` and + `Thread state=SUPERSEDED`, then resolve it. A post-merge `NO_ACTION` requires maintainer + approval to decline the follow-up work. When the current identity cannot resolve a thread + (`viewerCanResolve` is `false`), still reply, keep the disposition established from the current + tree, and record `Thread state=OPEN`; the reviewer or PR author resolves it. +- A consolidated PR conversation response may cover multiple review rounds only when it names + every review ID and every finding ID with its disposition and resolution reference. Record its + durable URL in each related row. +- Cite a fix by its unique Conventional Commit subject or durable reply URL, never by a branch SHA + that can change after a rebase. +- Refresh review threads using GraphQL and confirm that no unresolved actionable thread remains. From 5ccaef5ae68c99a778b5b95ce4666197df30813d Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:57:20 +0000 Subject: [PATCH 34/40] docs(issues): [#2902] point the table test designs at their rstest cases The handler plan still promised the event's name in each assertion message and called its two tests tables; each event is now an `rstest` case whose name carries the event. The module plan gets the same pointer. Co-Authored-By: Claude Opus 5.5 --- .../test-refactor-plans/statistics-event-handler-tests.md | 4 ++-- .../test-refactor-plans/statistics-mod-tests.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md index e51110a6b8..c5fb37b1b6 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md @@ -45,8 +45,8 @@ Plan approved on 2026-11-18, including replacing the two `PeerAdded`-only tests | Test | Arrange | Assert | | --- | --- | --- | -| `it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download` | each of `TorrentAdded`, `TorrentRemoved`, `PeerAdded`, `PeerRemoved` and `PeerUpdated`, in a table, on a fresh repository | the persistent and in-session totals read 0, with the event's name in the message | -| `it_should_persist_nothing_for_an_event_other_than_a_completed_download` | the same table, on a fresh `TempDir` database | no torrent row, no global row, persisted total 0 | +| `it_should_change_no_in_memory_total_for_an_event_other_than_a_completed_download` | each of `TorrentAdded`, `TorrentRemoved`, `PeerAdded`, `PeerRemoved` and `PeerUpdated`, one `rstest` case each (see Changes After Review), on a fresh repository | the persistent and in-session totals read 0; the case name names the event | +| `it_should_persist_nothing_for_an_event_other_than_a_completed_download` | the same five `rstest` cases, on a fresh `TempDir` database | no torrent row for any info-hash, no global row, persisted total 0 | | `it_should_not_increment_the_persisted_total_when_the_global_downloads_cannot_be_increased` | `MockTorrentMetricsStore`: the torrent write succeeds (`load_torrent_downloads` → `None`, `save_torrent_downloads` → `Ok`), `load_global_downloads` fails | the persisted total reads 0 | The two table tests replace the two existing `PeerAdded`-only tests diff --git a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md index 74980ffeb7..a126a539d3 100644 --- a/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md +++ b/docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-mod-tests.md @@ -39,7 +39,7 @@ Plan approved on 2026-11-18, with the four-case table. ## Test Design -One table test in a new `tests` module of `statistics/mod.rs`: +One table test in a new `tests` module of `statistics/mod.rs` (now one `rstest` case per combination; see Changes After Review): | Test | Cases | Assert | | --- | --- | --- | From d2749722eb0f17c345ff6ce259b8e39ec92125a0 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 09:59:01 +0000 Subject: [PATCH 35/40] docs(pr-reviews): [#2902] record the second review round of #2988 Co-Authored-By: Claude Opus 5.5 --- docs/pr-reviews/pr-2988-review/PR-REVIEW.md | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md index 463ba41807..31382642b0 100644 --- a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md @@ -46,6 +46,9 @@ Round 1 is two reviews of the head whose last commit is `6006223766` (2026-11-21 15:13:36 UTC, comment, three inline comments without IDs, recorded as F5 to F7 with the severity of its overview, two Medium and one Low) and da2ce7's review `6006307330` (2026-11-21 15:32:08 UTC, approval, inline findings F1 to F4 with the reviewer's IDs). +Round 2 is da2ce7's review `6011586262` (2026-11-22 09:55:05 UTC, approval) of the head whose last +commit is `docs(pr-reviews): [#2902] record the first review round of #2988`; its inline findings +keep the reviewer's IDs F21 and F22. | Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | | ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | @@ -56,6 +59,8 @@ to F7 with the severity of its overview, two Medium and one Low) and da2ce7's re | F5 | review-finding:pr-2988-f5 | Copilot | Minor (inferred) | testing | ORIGINAL | FIXED | RESOLVED | | F6 | review-finding:pr-2988-f6 | Copilot | Minor (inferred) | testing | ORIGINAL | NO_ACTION | SUPERSEDED | | F7 | review-finding:pr-2988-f7 | Copilot | Nit (inferred) | maintainability | ORIGINAL | NO_ACTION | SUPERSEDED | +| F21 | review-finding:pr-2988-f21 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | +| F22 | review-finding:pr-2988-f22 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | ## Finding Details @@ -150,10 +155,37 @@ to F7 with the severity of its overview, two Medium and one Low) and da2ce7's re - Follow-up PR URL: N/A - Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657542783 +### F21 - The description reported the round 1 test count + +- PR number: 2988 +- Source review ID: 6011586262 +- Reviewer finding ID: F21 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657607454 +- Concern: The description still said 180 unit tests and "Test code and documentation only", without the `rstest` dev-dependency that round 1 added; the merge commit copies the description. +- Solution: The Validation line gives 191 unit test cases at the head after round 1, the summary names the `rstest` dev-dependency, rows 5 and 7 say `rstest` tables, and a bullet lists round 1; the coverage sentence keeps 180 "at the measured commit". +- Current-tree verification: `gh pr view 2988 --json body --jq .body | grep -c '191 unit test cases'` prints 1. +- Resolution reference: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657617124 +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657617124 + +### F22 - A Test Design row still promised the event's name in the message + +- PR number: 2988 +- Source review ID: 6011586262 +- Reviewer finding ID: F22 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657607460 +- Concern: The handler plan's Test Design rows still said "in a table" and "with the event's name in the message", although each event is now an `rstest` case sharing one message. +- Solution: Both rows say one `rstest` case per event, with the case name naming the event; the module plan got the same pointer. +- Current-tree verification: `grep -c "the event's name in the message" docs/issues/open/2902-1347-add-tests-tracker-core/test-refactor-plans/statistics-event-handler-tests.md` prints 0. +- Resolution reference: docs(issues): [#2902] point the table test designs at their rstest cases +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657617254 + ## Processing Log - 2026-11-22 09:22 UTC - Read both round 1 reviews; the maintainer chose `rstest` cases for F2. Fixed F2, F5, F3, F1 (and the stray #2637 line) and F4 in their own commits, then recorded the review changes in the row 5 and row 7 plans. - 2026-11-22 09:34 UTC - Replied on all seven threads (09:34:44 to 09:34:57 UTC), before pushing the fixes and this record together; the threads are resolved after the push. +- 2026-11-22 09:58 UTC - Round 2 (approval with F21 and F22): F21 fixed in the description, F22 in its own commit; replied at 09:58:21 and 09:58:23 UTC, before pushing the fix and this record together; the threads are resolved after the push. ## Completion Rules From 97e9699c59646cf0bee99219cf37757c49e79823 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 10:05:02 +0000 Subject: [PATCH 36/40] test(tracker-core): [#2902] expect one torrent read in the global downloads failure test The mock of `load_torrent_downloads` allowed any number of calls, so a redundant read went unnoticed. Like the other expectations of the test, it now expects exactly one. Co-Authored-By: Claude Opus 5.5 --- packages/tracker-core/src/statistics/event/handler.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tracker-core/src/statistics/event/handler.rs b/packages/tracker-core/src/statistics/event/handler.rs index 5446cb38dd..5fc4a24e08 100644 --- a/packages/tracker-core/src/statistics/event/handler.rs +++ b/packages/tracker-core/src/statistics/event/handler.rs @@ -336,6 +336,7 @@ mod tests { let mut store = MockTorrentMetricsStore::new(); store .expect_load_torrent_downloads() + .times(1) .returning(|_| Box::pin(std::future::ready(Ok(None)))); store .expect_save_torrent_downloads() From 31342ce9ad2fa852fc2028a8ace808d7908a4df4 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 10:06:05 +0000 Subject: [PATCH 37/40] chore(tracker-core): [#2902] build rstest without its default features The `add-rust-dependency` skill prefers `default-features = false`. The statistics tests use neither default feature of `rstest` (`async-timeout`, `crate-name`), so they are off, as in `axum-rest-api-server`. The version stays 0.28.0, the latest stable release. Co-Authored-By: Claude Opus 5.5 --- packages/tracker-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tracker-core/Cargo.toml b/packages/tracker-core/Cargo.toml index c3552fdefc..cb599182c4 100644 --- a/packages/tracker-core/Cargo.toml +++ b/packages/tracker-core/Cargo.toml @@ -47,7 +47,7 @@ tracing = "0" [dev-dependencies] mockall = "0" -rstest = "0.28.0" +rstest = { version = "0.28.0", default-features = false } secrecy = "0.10.3" testcontainers = "0" tempfile = "3.27.0" From 71c0a0f5ce6f9ea2e559327c55572c048de93d0b Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 10:07:30 +0000 Subject: [PATCH 38/40] docs(pr-reviews): [#2902] record the third review round of #2988 Co-Authored-By: Claude Opus 5.5 --- docs/pr-reviews/pr-2988-review/PR-REVIEW.md | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md index 31382642b0..365a2c86a6 100644 --- a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md @@ -49,6 +49,9 @@ to F7 with the severity of its overview, two Medium and one Low) and da2ce7's re Round 2 is da2ce7's review `6011586262` (2026-11-22 09:55:05 UTC, approval) of the head whose last commit is `docs(pr-reviews): [#2902] record the first review round of #2988`; its inline findings keep the reviewer's IDs F21 and F22. +Round 3 is Copilot's review `6011613619` (2026-11-22 10:03:41 UTC, comment) of the head whose last +commit is `docs(pr-reviews): [#2902] record the first review round of #2988`; its two inline comments +have no IDs and are recorded as F23 and F24. | Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | | ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | @@ -61,6 +64,8 @@ keep the reviewer's IDs F21 and F22. | F7 | review-finding:pr-2988-f7 | Copilot | Nit (inferred) | maintainability | ORIGINAL | NO_ACTION | SUPERSEDED | | F21 | review-finding:pr-2988-f21 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | | F22 | review-finding:pr-2988-f22 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | +| F23 | review-finding:pr-2988-f23 | Copilot | Nit (inferred) | testing | ORIGINAL | FIXED | RESOLVED | +| F24 | review-finding:pr-2988-f24 | Copilot | Nit (inferred) | maintainability | ORIGINAL | FIXED | RESOLVED | ## Finding Details @@ -181,11 +186,38 @@ keep the reviewer's IDs F21 and F22. - Follow-up PR URL: N/A - Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657617254 +### F23 - The torrent read of the failure test had no call count + +- PR number: 2988 +- Source review ID: 6011613619 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657632841 +- Concern: `expect_load_torrent_downloads()` in the global downloads failure test allowed any number of calls, so a redundant read would pass. +- Solution: It now has `.times(1)`, like the test's other two expectations. +- Current-tree verification: `grep -n -A1 'expect_load_torrent_downloads()' packages/tracker-core/src/statistics/event/handler.rs` shows `.times(1)` after the last occurrence. +- Resolution reference: test(tracker-core): [#2902] expect one torrent read in the global downloads failure test +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657642560 + +### F24 - The rstest requirement style + +- PR number: 2988 +- Source review ID: 6011613619 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657632867 +- Concern: `rstest = "0.28.0"` differs from the `"0"` style of nearby dev-dependencies. +- Solution: The requirement stays `0.28.0`: the `add-rust-dependency` skill starts from the latest stable version, which `"0"` does not select, and three sibling packages use the same requirement. The skill's other rule, `default-features = false`, had been missed and is applied; `Cargo.lock` is unchanged. +- Current-tree verification: `grep -n '^rstest' packages/tracker-core/Cargo.toml` shows `rstest = { version = "0.28.0", default-features = false }`. +- Resolution reference: chore(tracker-core): [#2902] build rstest without its default features +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657642714 + ## Processing Log - 2026-11-22 09:22 UTC - Read both round 1 reviews; the maintainer chose `rstest` cases for F2. Fixed F2, F5, F3, F1 (and the stray #2637 line) and F4 in their own commits, then recorded the review changes in the row 5 and row 7 plans. - 2026-11-22 09:34 UTC - Replied on all seven threads (09:34:44 to 09:34:57 UTC), before pushing the fixes and this record together; the threads are resolved after the push. - 2026-11-22 09:58 UTC - Round 2 (approval with F21 and F22): F21 fixed in the description, F22 in its own commit; replied at 09:58:21 and 09:58:23 UTC, before pushing the fix and this record together; the threads are resolved after the push. +- 2026-11-22 10:06 UTC - Round 3 (Copilot comment with F23 and F24): each fixed in its own commit, F24 keeping the version and turning off the default features; replied at 10:06:48 and 10:06:51 UTC, before pushing the fixes and this record together; the threads are resolved after the push. ## Completion Rules From 2da9871a55874fc5baef748c1927ea6041054cd6 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 10:25:43 +0000 Subject: [PATCH 39/40] docs(pr-reviews): [#2902] map the F23 severity from the Copilot overview The overview of review `6011613619` marks F23 Medium, which the record maps to `Minor (inferred)` as it does for F5 and F6; the row said `Nit (inferred)`. The round 3 sentence now names both overview severities, as the round 1 sentence does. Co-Authored-By: Claude Opus 5.5 --- docs/pr-reviews/pr-2988-review/PR-REVIEW.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md index 365a2c86a6..17b4ba6b5c 100644 --- a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md @@ -51,7 +51,7 @@ commit is `docs(pr-reviews): [#2902] record the first review round of #2988`; it keep the reviewer's IDs F21 and F22. Round 3 is Copilot's review `6011613619` (2026-11-22 10:03:41 UTC, comment) of the head whose last commit is `docs(pr-reviews): [#2902] record the first review round of #2988`; its two inline comments -have no IDs and are recorded as F23 and F24. +have no IDs and are recorded as F23 and F24 with the severity of its overview (F23 Medium, F24 Low). | Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | | ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | @@ -64,7 +64,7 @@ have no IDs and are recorded as F23 and F24. | F7 | review-finding:pr-2988-f7 | Copilot | Nit (inferred) | maintainability | ORIGINAL | NO_ACTION | SUPERSEDED | | F21 | review-finding:pr-2988-f21 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | | F22 | review-finding:pr-2988-f22 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | -| F23 | review-finding:pr-2988-f23 | Copilot | Nit (inferred) | testing | ORIGINAL | FIXED | RESOLVED | +| F23 | review-finding:pr-2988-f23 | Copilot | Minor (inferred) | testing | ORIGINAL | FIXED | RESOLVED | | F24 | review-finding:pr-2988-f24 | Copilot | Nit (inferred) | maintainability | ORIGINAL | FIXED | RESOLVED | ## Finding Details From 51865117852673d00812bbaba7329b2773706dd1 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Sun, 22 Nov 2026 10:26:56 +0000 Subject: [PATCH 40/40] docs(pr-reviews): [#2902] record the fourth review round of #2988 Co-Authored-By: Claude Opus 5.5 --- docs/pr-reviews/pr-2988-review/PR-REVIEW.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md index 17b4ba6b5c..f389249eb7 100644 --- a/docs/pr-reviews/pr-2988-review/PR-REVIEW.md +++ b/docs/pr-reviews/pr-2988-review/PR-REVIEW.md @@ -52,6 +52,9 @@ keep the reviewer's IDs F21 and F22. Round 3 is Copilot's review `6011613619` (2026-11-22 10:03:41 UTC, comment) of the head whose last commit is `docs(pr-reviews): [#2902] record the first review round of #2988`; its two inline comments have no IDs and are recorded as F23 and F24 with the severity of its overview (F23 Medium, F24 Low). +Round 4 is da2ce7's review `6011697342` (2026-11-22 10:23:39 UTC, approval) of the head whose last +commit is `docs(pr-reviews): [#2902] record the third review round of #2988`; its inline finding keeps +the reviewer's ID F25. | Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | | ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | @@ -66,6 +69,7 @@ have no IDs and are recorded as F23 and F24 with the severity of its overview (F | F22 | review-finding:pr-2988-f22 | Human | Nit | documentation | ORIGINAL | FIXED | RESOLVED | | F23 | review-finding:pr-2988-f23 | Copilot | Minor (inferred) | testing | ORIGINAL | FIXED | RESOLVED | | F24 | review-finding:pr-2988-f24 | Copilot | Nit (inferred) | maintainability | ORIGINAL | FIXED | RESOLVED | +| F25 | review-finding:pr-2988-f25 | Human | Nit | metadata | ORIGINAL | FIXED | RESOLVED | ## Finding Details @@ -212,12 +216,26 @@ have no IDs and are recorded as F23 and F24 with the severity of its overview (F - Follow-up PR URL: N/A - Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657642714 +### F25 - The F23 severity did not follow the overview mapping + +- PR number: 2988 +- Source review ID: 6011697342 +- Reviewer finding ID: F25 +- Source URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657693257 +- Concern: The record maps the automated reviewer's Medium to `Minor (inferred)` (F5, F6), but the F23 row, whose overview severity is Medium, read `Nit (inferred)`; the round 3 sentence did not name the overview severities. +- Solution: The F23 row reads `Minor (inferred)`, and the round 3 sentence names both overview severities (F23 Medium, F24 Low). +- Current-tree verification: `grep -n '^| F23 ' docs/pr-reviews/pr-2988-review/PR-REVIEW.md` shows `Minor (inferred)`. +- Resolution reference: docs(pr-reviews): [#2902] map the F23 severity from the Copilot overview +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2988#discussion_r4657701374 + ## Processing Log - 2026-11-22 09:22 UTC - Read both round 1 reviews; the maintainer chose `rstest` cases for F2. Fixed F2, F5, F3, F1 (and the stray #2637 line) and F4 in their own commits, then recorded the review changes in the row 5 and row 7 plans. - 2026-11-22 09:34 UTC - Replied on all seven threads (09:34:44 to 09:34:57 UTC), before pushing the fixes and this record together; the threads are resolved after the push. - 2026-11-22 09:58 UTC - Round 2 (approval with F21 and F22): F21 fixed in the description, F22 in its own commit; replied at 09:58:21 and 09:58:23 UTC, before pushing the fix and this record together; the threads are resolved after the push. - 2026-11-22 10:06 UTC - Round 3 (Copilot comment with F23 and F24): each fixed in its own commit, F24 keeping the version and turning off the default features; replied at 10:06:48 and 10:06:51 UTC, before pushing the fixes and this record together; the threads are resolved after the push. +- 2026-11-22 10:26 UTC - Round 4 (approval with the Nit F25): fixed in its own commit; replied at 10:26:21 UTC, before pushing the fix and this record together; the thread is resolved after the push. ## Completion Rules