Repository navigation
feat(primitives): move AnnouncePolicy from configuration to primitives (#1795) - #1796
Conversation
Move AnnouncePolicy from torrust-tracker-configuration to torrust-tracker-primitives (SI-04 of EPIC torrust#1669). - Move spec from drafts/ to open/ with issue number prefix - Update EPIC torrust#1669 subissues table with torrust#1795 issue link - Link torrust#1795 as subissue of torrust#1669 on GitHub
torrust#1795) Fixes the inverted dependency where torrust-tracker-primitives depended on torrust-tracker-configuration for AnnouncePolicy. After this change: - Before: primitives -> configuration (inverted dep) - After: configuration -> primitives (natural direction) Changes: - Move AnnouncePolicy struct+impls into packages/primitives/src/announce.rs - Export AnnouncePolicy from torrust_tracker_primitives lib.rs - Remove torrust-tracker-configuration dep from primitives/Cargo.toml - Add torrust-tracker-primitives dep to configuration/Cargo.toml - Replace AnnouncePolicy definition in configuration/src/lib.rs with a #[deprecated] re-export for external consumer backwards compatibility - Update configuration/src/v2_0_0/core.rs to import from torrust_tracker_primitives - Update bittorrent-http-tracker-protocol test import + remove unused torrust-tracker-configuration dep from its Cargo.toml - Update bittorrent-tracker-core integration test import - Update announce_handler.rs doc comment import path All acceptance criteria verified: - cargo build --workspace: clean - cargo test --workspace: all pass - linter all: exit code 0 - cargo machete: no unused deps - grep torrust_tracker_configuration::AnnouncePolicy: zero matches Closes torrust#1795 Part of torrust#1669 (SI-04)
Add a note to the run-pre-push-checks skill warning agents that git push is a long-running command (~5 minutes with the pre-push hook installed). Agents must wait for the terminal-completion notification before acting, and should redirect push output to .tmp/ to avoid parsing shared terminal history that may contain unrelated commands.
|
ACK 0bcb28e |
There was a problem hiding this comment.
Pull request overview
Moves AnnouncePolicy from torrust-tracker-configuration to torrust-tracker-primitives to fix an inverted dependency where primitives depended on configuration. A #[deprecated] re-export is kept in configuration for external backwards compatibility.
Changes:
- Moved
AnnouncePolicystruct + impls intopackages/primitives/src/announce.rsand exported fromprimitives/lib.rs. - Flipped the dependency direction: removed
torrust-tracker-configurationfromprimitives/Cargo.toml, addedtorrust-tracker-primitivestoconfiguration/Cargo.toml, and droppedconfigurationfromhttp-protocol/Cargo.toml. - Updated all in-workspace imports (
configuration/v2_0_0/core.rs,tracker-coreintegration test,http-protocoltest, and a doc-comment inannounce_handler.rs) and updated spec/EPIC docs.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/primitives/src/announce.rs | New definition of AnnouncePolicy with serde defaults and Default/Constructor impls. |
| packages/primitives/src/lib.rs | Re-export AnnouncePolicy alongside AnnounceData/AnnounceEvent. |
| packages/primitives/Cargo.toml | Dropped inverted torrust-tracker-configuration dependency. |
| packages/configuration/src/lib.rs | Replaced struct definition with a #[deprecated] pub use re-export. |
| packages/configuration/src/v2_0_0/core.rs | Imports AnnouncePolicy from torrust_tracker_primitives. |
| packages/configuration/Cargo.toml | Adds torrust-tracker-primitives dependency. |
| packages/http-protocol/Cargo.toml | Removes now-unused torrust-tracker-configuration dependency. |
| packages/http-protocol/src/v1/responses/announce.rs | Test import switched to torrust_tracker_primitives. |
| packages/tracker-core/tests/integration.rs | Test import switched to torrust_tracker_primitives. |
| packages/tracker-core/src/announce_handler.rs | Doc-comment import path updated. |
| Cargo.lock | Reflects the dependency flip. |
| docs/issues/open/1795-1669-04-...md | Spec moved from draft to open and marked completed. |
| docs/issues/open/1669-overhaul-packages/EPIC.md | EPIC table updated with issue #1795 links. |
| .github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md | Unrelated guidance for AI agents on long-running git push. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1796 +/- ##
===========================================
- Coverage 77.73% 77.64% -0.09%
===========================================
Files 378 379 +1
Lines 28602 28602
Branches 28602 28602
===========================================
- Hits 22233 22209 -24
- Misses 6063 6080 +17
- Partials 306 313 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of #1796 as it stands at e170b9620 on the default branch.
What still runs: AnnouncePolicy is defined in packages/primitives/src/announce.rs:21 and exported at packages/primitives/src/lib.rs:30. torrust-tracker-primitives no longer depends on torrust-tracker-configuration, and the configuration crate now depends on primitives, so the dependency direction this change set out to fix still holds. Later changes widened the struct: max_peers_per_announce was added, and both intervals became AnnounceIntervalInSecs. Both configuration schemas use the struct as the [core.announce_policy] table (packages/configuration/src/v3_0_0/core.rs:21, packages/configuration/src/v2_0_0/core.rs:17). The deprecated re-export at packages/configuration/src/lib.rs:289-294 is unchanged since this change.
[Minor] [core.announce_policy] accepts unknown keys without an error. AnnouncePolicy (packages/primitives/src/announce.rs:20) has no #[serde(deny_unknown_fields)], and the same attribute on the enclosing v3 Core (packages/configuration/src/v3_0_0/core.rs:17) does not reach nested tables. packages/configuration/AGENTS.md requires the attribute on every v3 configuration struct, so that typos and stale keys fail at load. The struct left the configuration package in this change, before the v3 schema existed (cce0aba), so that rule never covered it. A v3 file with interval_minimum = 600 under [core.announce_policy], or the override variable TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__ANNOUNCE_POLICY__INTERVAL_MINIMUM=600, loads without complaint, and the HTTP tracker sends the default min interval of 120 seconds. No test covers an unknown key in this table: neither the v3 announce-policy load tests (packages/configuration/src/v3_0_0/mod.rs:1742-1840) nor the unit tests in packages/primitives/src/announce.rs:120-173. The draft specification docs/issues/drafts/2387-si-4-configuration-keys-with-units/ISSUE.md:71 records the missing attribute but has no issue yet. The smallest fix is to add #[serde(deny_unknown_fields)] to AnnouncePolicy, plus a v3 load test that rejects a misspelled key. Because the v2 Core does not deny unknown keys, the fix also tightens the v2 announce table; nothing in the workspace loads the v2 schema at this commit.
[Minor] The #[deprecated] attribute on the re-export at packages/configuration/src/lib.rs:289-294 produces no warning, so no consumer learns of the move before the re-export is removed. The compiler does not apply #[deprecated] on a pub use to paths that resolve through it, and the workspace shows this. packages/rest-api-runtime-adapter/src/v1/conversion.rs:6 imports PeerId through the equally deprecated re-export at packages/primitives/src/lib.rs:58-63 with no allow(deprecated). That crate inherits the workspace lints, which deny warnings (Cargo.toml:233), and it still builds. A downstream crate that keeps use torrust_tracker_configuration::AnnouncePolicy; therefore builds silently today and breaks only when the re-export goes away. The smallest fix is a deprecated type alias, #[deprecated(...)] pub type AnnouncePolicy = torrust_tracker_primitives::AnnouncePolicy;. Use sites of an alias do warn, and struct literals, new and default keep working through the old path. This crate already used the alias form for Driver (docs/issues/open/1669-overhaul-packages/DECISIONS.md:195).
[Nit] The doc comment at packages/configuration/src/lib.rs:286-288 says removal is tracked as a follow-up cleanup subissue of EPIC #1669. The EPIC specification at this commit (docs/issues/open/1669-overhaul-packages/EPIC.md) lists no subissue for removing this re-export. The same sentence appears on the deprecated re-exports in packages/primitives/src/lib.rs:43-78. Either link the issue that tracks the removal, or drop the sentence.
[Nit] The doc example whose import this change updated (packages/tracker-core/src/announce_handler.rs:61-85) still describes structs that do not exist. It shows peers: Vec<peer::Peer>, a swarm_stats field with completed, seeders and leechers, and an AnnounceInterval type. The real AnnounceData has Vec<Arc<peer::Peer>> and stats: SwarmMetadata with downloaded, complete and incomplete, and AnnouncePolicy has three fields. The mismatch predates this change, which only moved the import. Replacing the hand-written copy with intra-doc links to torrust_tracker_primitives::AnnounceData and torrust_tracker_primitives::AnnouncePolicy would stop it drifting.
Checked and found sound:
- At merge, the move kept the derives, field defaults and serde attributes exactly as they were.
- No crate in the workspace still imports
AnnouncePolicythrough the configuration path. - Primitives has no dependency on configuration, so there is no cycle.
- The later
AnnounceIntervalInSecsbound rejects intervals abovei32::MAXwhile deserializing, so no configured interval can overflow a protocol encoding or panic. - The description's file-by-file list matches the diff, except for one documentation change in
.github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md, which sits in its own commit (3643296) and is not listed.
This review did not build the code or run the tests.
Summary
Moves
AnnouncePolicyfromtorrust-tracker-configurationintotorrust-tracker-primitives, fixing an inverted dependency where aprimitivespackage depended on aconfigurationpackage.primitives→configuration(forAnnouncePolicy)configuration→primitives(natural direction)Changes
AnnouncePolicystruct + impls intopackages/primitives/src/announce.rsAnnouncePolicyfromtorrust_tracker_primitiveslib.rstorrust-tracker-configurationdep fromprimitives/Cargo.tomltorrust-tracker-primitivesdep toconfiguration/Cargo.tomlAnnouncePolicydefinition inconfiguration/src/lib.rswith a#[deprecated]re-export for external consumer backwards compatibilityconfiguration/src/v2_0_0/core.rsto import fromtorrust_tracker_primitivesbittorrent-http-tracker-protocoltest import + remove unusedtorrust-tracker-configurationdep from itsCargo.tomlbittorrent-tracker-coreintegration test importannounce_handler.rsdoc comment import pathVerification
cargo build --workspace: cleancargo test --workspace: all passlinter all: exit code 0cargo machete: no unused depsCloses #1795
Part of #1669 (SI-04)