Skip to content

test(http-core): [#1349] pin the event contract and the container composition with unit tests - #2593

Merged
josecelano merged 7 commits into
torrust:developfrom
josecelano:1349-1347-add-tests-http-core-events-container
Oct 21, 2026
Merged

josecelano merged 7 commits into
torrust:developfrom
josecelano:1349-1347-add-tests-http-core-events-container

Conversation

@josecelano

@josecelano josecelano commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Slice S4 of #1349 (tests for the torrust-tracker-http-core package, EPIC #1347): the unit tests for the HTTP core events and for the container that composes the services. It changes test code and documentation only. Production code is unchanged: everything before the #[cfg(test)] module of event.rs is byte-identical to develop, container.rs only gains an appended test module, and there is no manifest change. The remaining files follow in the slices S5-S6 of the specification, each starting after the previous one merges.

Related to #1349
Parent EPIC: #1347

What this slice adds

  • event.rs. The 7 existing tests are refactored onto small in-file builders and rstest tables, and the approved plan adds the rest: 29 cases in 10 test functions. They pin the full metric label set of a connection context as literal strings (IPv4, IPv6, an IPv4-mapped client, a configured public URL, an HTTPS server on another port and a server bound to an IPv4-mapped address), the client IP family and type derived from the client and not the server binding, the public URL and instance id accessors, equality over every part of a context, and the four public accessors that have no caller in the repository, which are pinned as public API by maintainer decision. The dead announce_events_match helper is removed and the public test module becomes a private tests module.
  • container.rs. The file had no tests. It now has 27: the always-enabled statistics event bus and its sender (with usage statistics enabled and disabled), the collaborators the container exposes, the instance id, public URL, reverse-proxy policy and query-string IP policy that reach the announce and scrape services, the tracker-core authentication, whitelist and torrent repository those services use, how initialize_from_tracker_core exposes its own event bus, and initialize over a real SQLite file in the temp directory, including its documented panic. The tracker-core container is built by hand, so no test calls a production container factory.
  • Records. The S3 merge record, the two file plans with their prose-first Arrange, Act and Assert reviews and mutation results, the per-file evidence, the ledger, the independent review report, the audit of Copilot's review of this pull request, and the EPIC Overhaul: Packages Testing #1347 rows and both coverage tables.

Evidence

  • Coverage (cargo-llvm-cov 0.6.16, stable Rust 1.99.0, clean unit-only runs). The S3 merge brought Drain listener queues on shutdown #2414 into statistics/event/listener.rs, so the baseline was measured again at the S3 merge: lines 2,040 / 2,197 (92.85%), regions 93.64%, functions 93.85%, 95 unit tests. Now: lines 2,536 / 2,592 (97.84%), regions 3,264 / 3,324 (98.19%), functions 309 / 315 (98.10%), and 144 unit tests. event.rs goes from 83.96% to 100% of lines, and every production line of container.rs (73) is covered; the uncovered regions are failure branches of matches! assertions in the test module. The totals include the test modules, and llvm-cov does not count the body lines of a test that is both an rstest table and a #[tokio::test], so the counted totals fell by 80 lines when four tests became tables; no production line lost coverage. The mutation results below are the stronger signal.
  • Mutations. Each named mutation was applied by hand, run and reverted, and each made the tests named for it fail: four on the event label projection and client IP classification, and seven on the container wiring (the bus status, the sender, the instance id, the HTTP tracker config and the core config). Eight more probes on initialize, the key store, the whitelist and the statistics repository were killed too. The independent review then found two label mutants that survived (the protocol and address-type labels hard-coded) and an unvaried port; an HTTPS case on port 443 and a case with a server bound to an IPv4-mapped address now kill them. Copilot's review of this pull request found a mutant nobody had hunted: a bus gated on the usage-statistics policy passed the delivery test, because the default configuration enables usage statistics. Four tests are now tables over the policy and three new mutations are killed only by the disabled cases. One mutation survives by design: initialize always creating the swarm registry with usage statistics disabled, which nothing in this package can observe because the container does not expose the registry. The plan records it with its owner.
  • No bug found, so no hand-off was needed.
  • Process notes. The plan gates the R1 refactor of event.rs on a maintainer review before the new tests. R1 and R2 were coded together and the maintainer approved the completed file; the plan and the specification log say so. The specification log also carries a correction: the S4 start entry claimed that http-core did not change after S3, which was wrong because of Drain listener queues on shutdown #2414. Three mutation forms did not compile under the workspace lints and were redone in a compiling form before they counted.

Review guidance

The production diff is empty, so review the tests, not the behavior. Each plan lists every test with the Arrange, Act and Assert it was written from, the mutation that proves it, and the maintainer's approvals. The commits are the S3 merge record, one commit per file, and the fixes from the independent Task Reviewer, kept as separate steps.

Files

  • packages/http-core/src/event.rs (test module only)
  • packages/http-core/src/container.rs (test module appended)
  • docs/issues/open/1349-1347-add-tests-http-core/ (ISSUE.md, coverage-evidence.md, agent-review-reports.md, test-refactor-plans/README.md, test-refactor-plans/event-tests.md (new), test-refactor-plans/container-tests.md (new))
  • docs/issues/open/1347-overhaul-packages-testing/EPIC.md
  • docs/pr-reviews/pr-2593-review/PR-REVIEW.md (new)

Validation

  • cargo test -p torrust-tracker-http-core: 144 unit tests and the doc tests pass.
  • cargo +nightly fmt --all -- --check, cargo clippy -p torrust-tracker-http-core --all-targets --all-features -- -D warnings, cargo machete --with-metadata, git diff --check, linter markdown and linter cspell pass.
  • Pre-commit (./contrib/dev-tools/git/hooks/pre-commit.sh) passed for every commit.
  • Pre-push (./contrib/dev-tools/git/hooks/pre-push.sh: nightly Rust format, check and docs, then the stable Rust 1.99.0 test suite) passed on the final head.
  • The independent Task Reviewer passed the slice with four LOW findings and no required change; all four are fixed, and the report is in agent-review-reports.md.
  • The commit-id citation check from the open-pull-request skill prints nothing (no branch commit ids cited).
  • The branch is not rebased onto the latest develop: it changed only documentation outside packages/http-core since this branch was cut, and git merge-tree against it reports no conflict.

josecelano and others added 4 commits October 20, 2026 20:51
Mark slice S3 done after the merge of torrust#2586, point the specification at the S4
branch, and log that the baseline for S4 is the final S3 measurement because
packages/http-core did not change on develop after the S3 head. Update the EPIC
row.

Related to torrust#1349

Co-authored-by: Copilot <[email protected]>
…ection context

Refactor the 7 tests of event.rs into 27 cases in 10 test functions with
an in-file builder, AAA markers and it_should_* names. Add whole label-set
tables, the public URL and instance id accessors, and pin the four
accessors that have no caller as public API. Remove the dead
announce_events_match helper and make the test module private.

event.rs goes from 157/187 to 135/135 lines. Mutations L1-L4 and six
extra probes are killed. The S4 baseline is re-measured because the S3
merge brought torrust#2414 into the listener. Add the file plan, its results and
the coverage evidence.

Co-authored-by: Copilot <[email protected]>
…TP services

Add 20 unit tests for container.rs, which had none: the always-enabled
event bus and its sender, the collaborators the container exposes, the
instance id, public URL, reverse proxy and IP-override policy that reach
the announce and scrape services, the tracker-core authentication,
whitelist and torrent repository they use, and the initialize entry
point over a real SQLite file. The tracker-core container is built by
hand, so no test calls a production container factory.

All 73 production lines are covered. Mutations M1-M7 and eight extra
probes are killed; one survives, the swarm registry's usage-statistics
flag, which this package cannot observe. Add the file plan, its results
and the coverage evidence.

Co-authored-by: Copilot <[email protected]>
Add an HTTPS case on port 443 and a case with a server bound to an
IPv4-mapped IPv6 address to the event label table, which kills three
surviving label mutants. Replace a match that computed an expected value
with a case parameter, split the tests that had several reasons to fail or
a split Act, and take the missing database directory of the panic test
from a random name.

Record the review report and the final S4 figures: 140 unit tests, lines
97.90%, regions 98.26% and functions 98.14%, with the EPIC rows.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 07:34
…ication

Record the S4 pull request, its branch state and the pre-push result in
the slice table, the frontmatter and the progress log.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The always-enabled event-publication contract still needs a test with usage statistics disabled.

1 open issue
What changed in this PR

Adds S4 test coverage for HTTP core event contracts and service composition under #1349, without changing production code.

Changes:

  • Expands event tests to 29 cases covering labels, accessors, and equality.
  • Adds 23 container tests covering wiring, configuration, and initialization.
  • Records coverage, mutation evidence, and review outcomes.
File Description
packages/​http-core/​src/​event.rs Refactors and expands event contract tests.
packages/​http-core/​src/​container.rs Adds service composition and initialization tests.
docs/​issues/​open/​1349-1347-add-tests-http-core/​test-refactor-plans/​README.md Registers completed file plans.
docs/​issues/​open/​1349-1347-add-tests-http-core/​test-refactor-plans/​event-tests.md Documents event tests and mutation evidence.
docs/​issues/​open/​1349-1347-add-tests-http-core/​test-refactor-plans/​container-tests.md Documents composition tests and coverage boundaries.
docs/​issues/​open/​1349-1347-add-tests-http-core/​ISSUE.md Updates slice progress and implementation ledger.
docs/​issues/​open/​1349-1347-add-tests-http-core/​coverage-evidence.md Records refreshed baseline and S4 coverage.
docs/​issues/​open/​1349-1347-add-tests-http-core/​agent-review-reports.md Records independent review and follow-up fixes.
docs/​issues/​open/​1347-overhaul-packages-testing/​EPIC.md Updates package progress and coverage tables.

Review effort: Balanced

Comment thread packages/http-core/src/container.rs Resolved
…atistics disabled

The delivery test of the HTTP core services ran with the default core
configuration, whose usage statistics are enabled, so a bus gated on that
policy would have passed it. Turn it and the three container publication
tests into tables over the usage-statistics policy of the tracker core and
of the HTTP tracker, each with an enabled and a disabled case.

Three new mutations that gate the bus or a service sender on the policy
are killed only by the disabled cases. Record the round and the figures:
27 container tests, 144 unit tests, lines 97.84%, regions 98.19%,
functions 98.10%.

Co-authored-by: Copilot <[email protected]>
Record Copilot's finding on the event-delivery test, its fix and the
resolved thread.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No blocking defects remain in the test-only changes, and the prior event-publication coverage gap is addressed.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@josecelano

Copy link
Copy Markdown
Member Author

ACK 580b592

@josecelano
josecelano merged commit b5ab35a into torrust:develop Oct 21, 2026
20 checks passed
@da2ce7

da2ce7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Post-merge note: this pull request requested a review from this account and was closed without one at its final head. A post-merge review will not be done: All 1,015 executable lines it added are tests, benchmarks or test support with no production behaviour, and 1,013 of them are still present.

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants