Skip to content

refactor(env): narrow EnvContainer::initialize to accept per-service config slices - #1866

Merged
josecelano merged 1 commit into
torrust:developfrom
josecelano:1861-1669-narrow-envcontainer-initialize-config-slices
Jun 2, 2026
Merged

josecelano merged 1 commit into
torrust:developfrom
josecelano:1861-1669-narrow-envcontainer-initialize-config-slices

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Closes #1861.

Implements DEC-09 from EPIC #1669: narrows the initialization API of EnvContainer (and related server environment types) to accept specific config slices instead of the full Configuration aggregate.

What changed

packages/udp-server/src/environment.rs

  • Environment::new and EnvContainer::initialize now accept (&Arc<Core>, &Arc<UdpTracker>) instead of &Arc<Configuration>
  • initialize_global_services call removed (callers manage logging/clock setup independently)

packages/axum-http-server/src/environment.rs

  • Same narrowing: (&Arc<Core>, &Arc<HttpTracker>) instead of &Arc<Configuration>

Call sites updated

  • packages/udp-server/tests/server/contract.rs — 6 call sites
  • packages/axum-http-server/tests/server/v1/contract.rs — 50 call sites
  • packages/axum-health-check-api-server/tests/server/contract.rs — 4 call sites

Examples rewritten

  • packages/udp-server/examples/udp_only_public_tracker.rs — now uses Core + UdpTracker directly; Configuration aggregate is not imported
  • packages/axum-http-server/examples/http_only_public_tracker.rs — now uses Core + HttpTracker directly

Docs

  • docs/issues/open/1669-overhaul-packages/DECISIONS.md — DEC-09 added
  • docs/issues/open/1861-1669-narrow-envcontainer-initialize-config-slices/ISSUE.md — closed, all acceptance criteria checked

Out of scope

  • axum-rest-api-server environment: intentionally not narrowed — it legitimately needs Core, HttpTracker, UdpTracker, and HttpApi to expose full tracker status via the REST API.
  • src/bootstrap/ (main binary): unaffected — uses AppContainer::initialize, not Environment::new directly.

Copilot AI review requested due to automatic review settings June 2, 2026 11:32
@josecelano josecelano self-assigned this Jun 2, 2026

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.

Pull request overview

Refactors the UDP and Axum HTTP server “environment” initialization APIs to accept only the configuration slices each service needs (Arc<Core> + per-service config), reducing cross-package configuration coupling as described in DEC-09 / issue #1861.

Changes:

  • Narrowed Environment::new / EnvContainer::initialize for UDP and HTTP servers to take (&Arc<Core>, &Arc<UdpTracker|HttpTracker>) instead of &Arc<Configuration>.
  • Updated test call sites to extract and pass the per-service config slices.
  • Rewrote UDP/HTTP example binaries to construct Core + per-service config directly (no Configuration aggregate), and documented DEC-09 / closed the issue spec.

Reviewed changes

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

Show a summary per file
File Description
packages/udp-server/src/environment.rs Narrows environment/container initialization to Core + UdpTracker and removes bundled global logging init.
packages/axum-http-server/src/environment.rs Narrows environment/container initialization to Core + HttpTracker and removes bundled global logging init.
packages/udp-server/tests/server/contract.rs Updates UDP contract tests to pass Arc<Core> + Arc<UdpTracker>.
packages/axum-http-server/tests/server/v1/contract.rs Updates HTTP v1 contract tests to pass Arc<Core> + Arc<HttpTracker> (many call sites).
packages/axum-health-check-api-server/tests/server/contract.rs Updates health-check tests to construct and pass config slices to UDP/HTTP servers.
packages/udp-server/examples/udp_only_public_tracker.rs Updates example to build Core + UdpTracker directly and use the narrowed API.
packages/axum-http-server/examples/http_only_public_tracker.rs Updates example to build Core + HttpTracker directly and use the narrowed API.
docs/issues/open/1669-overhaul-packages/DECISIONS.md Adds DEC-09 documenting the decision/rationale and artifacts.
docs/issues/open/1861-1669-narrow-envcontainer-initialize-config-slices/ISSUE.md Marks issue closed and checks acceptance criteria (but has a future last-updated-utc).

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

@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.78%. Comparing base (0e672e6) to head (cf67dea).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1866      +/-   ##
===========================================
- Coverage    77.79%   77.78%   -0.02%     
===========================================
  Files          382      382              
  Lines        28648    28637      -11     
  Branches     28648    28637      -11     
===========================================
- Hits         22288    22275      -13     
- Misses        6051     6054       +3     
+ Partials       309      308       -1     

☔ 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.

…config slices

Instead of accepting the full `&Arc<Configuration>` aggregate, the
`EnvContainer::initialize` and `Environment::new` constructors for the
UDP and HTTP server environments now accept only the config slices they
actually need:

- `UdpTrackerEnvironment::new` now takes `(&Arc<Core>, &Arc<UdpTracker>)`
- `HttpTrackerEnvironment::new` now takes `(&Arc<Core>, &Arc<HttpTracker>)`

This prevents idle config types (`HttpTracker`, `UdpTracker`, `HttpApi`,
`HealthCheckApi`, `TslConfig`, `AccessTokens`) from being compiled into
binaries that do not use them.

Updated all call sites: 6 in udp-server tests, 50 in axum-http-server tests,
4 in axum-health-check-api-server tests, and both Cargo examples.

Decision recorded as DEC-09 in docs/issues/open/1669-overhaul-packages/DECISIONS.md.
Issue torrust#1861 closed.

Closes torrust#1861
@josecelano
josecelano force-pushed the 1861-1669-narrow-envcontainer-initialize-config-slices branch from bd5499e to cf67dea Compare June 2, 2026 12:12
@josecelano

Copy link
Copy Markdown
Member Author

ACK cf67dea

@josecelano
josecelano merged commit 455257c into torrust:develop Jun 2, 2026
18 checks passed

This branch was previously deployed

1 inactive deployment
coverage — cf67dea0 Deployed Jun 2, 2026 by josecelano via Generate Coverage Report #1348
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.

Revisit EnvContainer::initialize to accept narrower config slices instead of &Configuration

2 participants