Skip to content

feat(ci): configure cargo deny for workspace layer boundary enforcement - #1932

Merged
josecelano merged 3 commits into
torrust:developfrom
josecelano:1925-configure-cargo-deny-for-layer-boundary-enforcement
Jun 23, 2026
Merged

feat(ci): configure cargo deny for workspace layer boundary enforcement#1932
josecelano merged 3 commits into
torrust:developfrom
josecelano:1925-configure-cargo-deny-for-layer-boundary-enforcement

Conversation

@josecelano

Copy link
Copy Markdown
Member

Description

Install and configure cargo deny to programmatically enforce the workspace's layered architecture rules, preventing accidental dependency edges between layers from being introduced.

Closes #1925

Changes

  • deny.toml (new): workspace root configuration with [bans] section using the wrappers mechanism to restrict which packages can depend on server-layer, protocol, and core crates
  • .github/workflows/testing.yaml: added new layer-bans CI job that runs cargo deny check bans
  • .github/workflows/copilot-setup-steps.yml: added Install cargo-deny step (setup workflow for Copilot agent VM infrastructure)
  • contrib/dev-tools/git/hooks/pre-commit.sh: added cargo deny check bans as a pre-commit step (0.57s runtime)
  • docs/packages.md: added "Layer Boundary Enforcement" section documenting forbidden edges, wrapper mechanism, known exceptions, and maintenance instructions
  • packages/AGENTS.md: added step 7 in "Adding or Modifying a Package" referencing deny enforcement
  • packages/udp-server/Cargo.toml: fixed wildcard path dependency (added missing version)
  • packages/persistence-benchmark/Cargo.toml: fixed wildcard path dependency (added missing version)
  • docs/issues/open/1925-...md: updated implementation tracking and verification results

Verification

  • cargo deny check bans — ✅ (exit 0, zero errors)
  • Forbidden edge test (core -> server) — ✅ detected as error[banned]
  • cargo build --workspace — ✅
  • linter all — ✅
  • cargo test --doc --workspace — ✅
  • Pre-commit hook — ✅ (all steps pass)

@josecelano
josecelano requested a review from a team as a code owner June 22, 2026 18:04
Copilot AI review requested due to automatic review settings June 22, 2026 18:04

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

Adds automated enforcement of the workspace’s layered architecture by introducing cargo deny bans (via wrappers) and wiring the check into local and CI workflows, plus updating documentation and fixing internal dependency metadata needed to satisfy wildcard bans.

Changes:

  • Added deny.toml with [bans] rules to prevent forbidden cross-layer dependency edges.
  • Integrated cargo deny check bans into CI (testing.yaml) and the local pre-commit hook.
  • Documented the enforcement mechanism and updated internal path dependencies to include explicit versions (to satisfy wildcard bans).

Reviewed changes

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

Show a summary per file
File Description
deny.toml New cargo-deny bans configuration to enforce layer boundaries via wrappers.
.github/workflows/testing.yaml Adds layer-bans job to run cargo deny check bans in CI.
.github/workflows/copilot-setup-steps.yml Installs cargo-deny in the Copilot setup workflow so agent VMs can run the new checks.
contrib/dev-tools/git/hooks/pre-commit.sh Adds a pre-commit step to run cargo deny check bans.
docs/packages.md Documents layer boundary enforcement, forbidden edges, and maintenance guidance.
packages/AGENTS.md Adds contributor guidance referencing the deny-based enforcement.
packages/udp-server/Cargo.toml Adds missing version for an internal path dependency (avoid wildcard bans failure).
packages/persistence-benchmark/Cargo.toml Adds missing version for an internal path dependency (avoid wildcard bans failure).
docs/issues/open/1925-1669-si-31-configure-cargo-deny-for-layer-boundary-enforcement.md Updates implementation tracking and verification status for the issue spec.

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

Comment thread deny.toml Outdated
Comment thread deny.toml Outdated
Comment thread .github/workflows/copilot-setup-steps.yml Outdated
@josecelano josecelano self-assigned this Jun 22, 2026
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.46%. Comparing base (cefc37f) to head (97b37fb).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1932      +/-   ##
===========================================
- Coverage    79.49%   79.46%   -0.03%     
===========================================
  Files          324      324              
  Lines        23116    23116              
  Branches     23116    23116              
===========================================
- Hits         18375    18370       -5     
- Misses        4465     4476      +11     
+ Partials       276      270       -6     

☔ View full report in Codecov by Harness.
📢 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.

Install and configure cargo-deny with bans + wrappers to enforce the
workspace layered architecture, preventing accidental dependency edges
between layers.

- Create deny.toml with deny entries for server, core, and protocol crates
- Add layer-bans CI job to testing.yaml workflow
- Add Install cargo-deny to copilot-setup-steps workflow
- Add cargo deny check bans to pre-commit hook
- Document forbidden edges and wrapper rules in docs/packages.md
- Fix two wildcard path dependencies (udp-server, persistence-benchmark)
- Make multiple-versions rationale self-contained in deny.toml
- Tighten protocol crate comment to match actual rule
- Add --locked flag to copilot setup workflow install step
- Mark M4 verification as PASS in issue spec
@josecelano
josecelano force-pushed the 1925-configure-cargo-deny-for-layer-boundary-enforcement branch from 5518180 to e1b01da Compare June 22, 2026 20:41
@josecelano
josecelano requested a review from Copilot June 23, 2026 08:46

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

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

Comment thread .github/workflows/testing.yaml
Comment thread .github/workflows/copilot-setup-steps.yml Outdated
- Pin cargo-deny to v0.19.9 in testing.yaml and copilot-setup-steps.yml
- Update proposed config example in issue spec to match actual deny.toml
- Clean up duplicate notes block in issue spec
@josecelano

Copy link
Copy Markdown
Member Author

All 7 Copilot review comments have been addressed in commits a478b63c and 97b37fb:

  1. multiple-versions rationale — Made self-contained with example crate names
  2. protocol comment wording — Tightened to "directly by torrust-tracker-core"
  3. --locked flag — Added to copilot-setup-steps.yml install step
  4. M4 pending→PASS — Updated in issue spec
  5. Stale example config — Updated udp-protocol wrappers to match actual deny.toml
  6. Version pin in testing.yaml — Pinned to cargo-deny@0.19.9
  7. Version pin in copilot-setup-steps.yml — Pinned to cargo-deny@0.19.9

(These thread IDs don't expose GraphQL node IDs via the REST API, so I can't use the resolve_thread API — but the fixes are pushed to the branch.)

@josecelano

Copy link
Copy Markdown
Member Author

ACK 97b37fb

@josecelano
josecelano merged commit 94427f3 into torrust:develop Jun 23, 2026
22 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.

SI-31: Configure cargo deny for workspace layer boundary enforcement

2 participants