Skip to content

feat(clock): move DurationSinceUnixEpoch to torrust-tracker-clock (#1790)#1791

Merged
josecelano merged 4 commits into
torrust:developfrom
josecelano:1790-move-duration-since-unix-epoch
May 19, 2026
Merged

feat(clock): move DurationSinceUnixEpoch to torrust-tracker-clock (#1790)#1791
josecelano merged 4 commits into
torrust:developfrom
josecelano:1790-move-duration-since-unix-epoch

Conversation

@josecelano
Copy link
Copy Markdown
Member

Summary

Move the DurationSinceUnixEpoch type alias from torrust-tracker-primitives into torrust-tracker-clock, where it semantically belongs.

Closes #1790.

Motivation

DurationSinceUnixEpoch is a trivial alias for std::time::Duration with no tracker-specific logic. It lives in torrust-tracker-primitives only by historical accident. The primary user is torrust-tracker-clock (the Clock trait and conversion helpers), which had to carry a torrust-tracker-primitives dependency solely for this type. Moving it:

  • Removes the torrust-tracker-primitives dep from torrust-tracker-clock, making it dependency-lighter
  • Prepares torrust-tracker-clock for future extraction to a standalone repository (SI-09, SI-13 in EPIC Overhaul: packages #1669)

Changes

  • packages/clock/src/lib.rs — add pub type DurationSinceUnixEpoch = std::time::Duration
  • packages/clock/Cargo.toml — remove torrust-tracker-primitives dependency
  • packages/primitives/src/lib.rs — replace the type definition with #[deprecated] pub use torrust_tracker_clock::DurationSinceUnixEpoch (backward-compatible re-export; deprecated to guide consumers to the new path)
  • packages/primitives/src/peer.rs — import DurationSinceUnixEpoch directly from torrust_tracker_clock (bypasses the deprecated re-export to keep the build clean under -D deprecated)
  • packages/metrics/Cargo.toml — replace torrust-tracker-primitives dep with torrust-tracker-clock
  • 77 workspace .rs files — update import path from torrust_tracker_primitives::DurationSinceUnixEpoch to torrust_tracker_clock::DurationSinceUnixEpoch
  • Docs — issue spec and EPIC Overhaul: packages #1669 SI-02 row updated to DONE

Verification

  • cargo build --workspace — clean (zero errors, zero warnings)
  • cargo test --doc --workspace — all pass
  • cargo test --tests --benches --examples --workspace --all-targets --all-features — all pass
  • linter all — all linters pass (markdown, yaml, toml, cspell, clippy, rustfmt, shellcheck)
  • cargo machete — no unused dependencies
  • E2E tests (SQLite3) — pass

…rrust#1790)

Move the `DurationSinceUnixEpoch` type alias from `torrust-tracker-primitives`
into `torrust-tracker-clock`, where it semantically belongs as it measures
time relative to the Unix epoch — a clock-domain concept.

Changes:
- `torrust-tracker-clock`: add `pub type DurationSinceUnixEpoch = std::time::Duration`
- `torrust-tracker-clock/Cargo.toml`: remove `torrust-tracker-primitives` dependency
- `torrust-tracker-primitives/src/lib.rs`: replace type definition with
  `#[deprecated] pub use torrust_tracker_clock::DurationSinceUnixEpoch`
  for backward compatibility
- `torrust-tracker-primitives/src/peer.rs`: import `DurationSinceUnixEpoch`
  directly from `torrust_tracker_clock` to avoid triggering the deprecation
  warning internally
- `torrust-tracker-metrics/Cargo.toml`: replace `torrust-tracker-primitives`
  dep with `torrust-tracker-clock`
- All workspace consumers (77 files): update import path from
  `torrust_tracker_primitives::DurationSinceUnixEpoch` to
  `torrust_tracker_clock::DurationSinceUnixEpoch`
- Issue spec and EPIC updated

Resolves torrust#1790.
Copilot AI review requested due to automatic review settings May 18, 2026 19:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Moves the DurationSinceUnixEpoch type alias from torrust-tracker-primitives to torrust-tracker-clock, so torrust-tracker-clock no longer depends on torrust-tracker-primitives. A deprecated re-export is kept in torrust-tracker-primitives for backward compatibility, and all workspace consumers are updated to import from the new location.

Changes:

  • Define DurationSinceUnixEpoch in torrust-tracker-clock and drop its dep on torrust-tracker-primitives.
  • Add a deprecated re-export in torrust-tracker-primitives (which now depends on torrust-tracker-clock) and update peer.rs to import directly.
  • Update ~77 workspace files (and torrust-tracker-metrics Cargo.toml) to import the type from torrust_tracker_clock.

Reviewed changes

Copilot reviewed 90 out of 91 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/clock/src/lib.rs Adds pub type DurationSinceUnixEpoch
packages/clock/Cargo.toml Removes torrust-tracker-primitives dep
packages/clock/src/{clock,conv,clock/working,clock/stopped}/...rs Switch imports to local definition
packages/primitives/src/lib.rs Adds deprecated re-export from clock
packages/primitives/Cargo.toml Adds torrust-tracker-clock dep
packages/primitives/src/peer.rs Imports directly from clock to bypass deprecation
packages/metrics/Cargo.toml Swaps primitivesclock dep
packages/metrics/src/**.rs Import path updates
packages/{tracker-core,udp-tracker-core,udp-tracker-server,http-tracker-core,swarm-coordination-registry,torrent-repository-benchmarking,axum-rest-tracker-api-server}/...rs Import path updates
docs/issues/open/1790-...md New issue spec documenting the move
docs/issues/drafts/1669-02-...md Old draft spec deleted
docs/issues/open/1669-overhaul-packages/EPIC.md Marks SI-02 DONE and updates extraction table
Comments suppressed due to low confidence (3)

packages/primitives/src/lib.rs:1

  • Issue #1790 is this very PR's issue (the move itself), and its acceptance criteria mark it DONE without removing the re-export. The "Out of Scope" section of the spec explicitly defers removal to "a separate cleanup subissue." The deprecation note should point to a new (future) cleanup issue, or at minimum say "to be tracked in a follow-up subissue of #1669"; otherwise consumers chasing the link will find a closed/done issue with no actionable removal plan.
    packages/primitives/src/lib.rs:1
  • The since value "3.0.0-develop" is not a valid semver release identifier — since is intended to be the version in which the item became deprecated. Using a pre-release/develop marker here is misleading once the crate is published. Consider using the next planned crates.io version (e.g., the upcoming 3.x.y release) instead.
    packages/primitives/src/lib.rs:1
  • Because this is a pub use re-export marked #[deprecated], any downstream crate that still uses torrust_tracker_primitives::DurationSinceUnixEpoch will start getting a deprecated warning. If the workspace (or any downstream consumer) compiles with -D deprecated / #![deny(deprecated)], this will break their build. Consider documenting this consequence in the PR description / changelog, or gating the warning behind a feature flag during the transition period.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

---
doc-type: issue
issue-type: task
status: draft
Comment on lines +58 to +63
**Circular dep constraint**: `torrust-tracker-primitives` must **not** re-export the type
from `torrust-tracker-clock`. That would introduce a new `torrust-tracker-primitives` →
`torrust-tracker-clock` dependency edge. Instead, `torrust-tracker-primitives` retains its
own independent `pub type DurationSinceUnixEpoch = Duration` definition. Once all workspace
consumers have been migrated to `torrust_tracker_clock::DurationSinceUnixEpoch`, the copy
in `torrust-tracker-primitives` can be deprecated and removed in a future cleanup.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.72%. Comparing base (69f127b) to head (a6bd710).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1791      +/-   ##
===========================================
+ Coverage    77.67%   77.72%   +0.05%     
===========================================
  Files          378      378              
  Lines        28599    28599              
  Branches     28599    28599              
===========================================
+ Hits         22213    22229      +16     
+ Misses        6074     6060      -14     
+ Partials       312      310       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Fix spec status: draft -> open
- Rewrite obsolete 'Circular dep constraint' paragraph to describe
  the actual implementation (primitives -> clock dep, deprecated re-export)
- Fix deprecation note reference: torrust#1790 -> EPIC torrust#1669 (the correct
  place to track removal as a future cleanup subissue)
@josecelano josecelano self-assigned this May 18, 2026
@josecelano
Copy link
Copy Markdown
Member Author

ACK a6bd710

@josecelano josecelano merged commit 99bf2a5 into torrust:develop May 19, 2026
27 checks passed
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.

Move DurationSinceUnixEpoch from torrust-tracker-primitives to torrust-tracker-clock

2 participants