Skip to content

refactor(node): gate the Direct*Sink test fakes behind a test-support feature - #1875

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-1852-2jm0uw
Aug 30, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-1852-2jm0uw

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1852.

Problem

DirectWarmingCreditSink (warming_allowance.rs) and DirectReceiptSink (receipt_log.rs) are inline sink fakes that deliberately violate their trait's non-blocking contract — they take the ledger / receipt-log lock on the caller's thread. Both were pub, #[doc(hidden)], so a contract-violating implementation was linkable into a production build, guarded only by a doc sentence. They were pub only because the cross-crate integration tests in tests/ cannot see #[cfg(test)] items.

Change

Gate both types (and their impls) behind a new test-support feature via #[cfg(any(test, feature = "test-support"))], turning the "never in production" rule from a doc promise into a build-time property — a normal cargo build -p decdn-node no longer compiles either type.

  • The lib's own #[cfg(test)] unit tests reach the fakes through the any(test, …) arm.
  • The cross-crate integration tests reach them through a self dev-dependency (decdn-node = { path = ".", features = ["test-support"] }) that enables the feature for the lib they link — mirroring the existing test-util dev-dep pattern already documented in this crate's Cargo.toml.

ClientHandlerDeps::new defaulted warming_credit to DirectWarmingCreditSink, which the gate would have pulled out of the production build (this is the contradiction the issue points at). Added NoopWarmingCreditSink — an inert, always-compiled no-op sink — and use it as that default. The runtime always overwrites it with the channel sink from spawn_warming_creditor; a handler left with the default simply applies no warming credit, the same safe/conservative direction a full aggregator queue takes. receipt_sink is a required constructor parameter with no default, so no equivalent fix is needed there (as the issue notes).

Both fakes are gated together, as the issue asks — a half-applied gate would be worse than the current consistent state.

Validation

  • cargo build -p decdn-node (no features) — compiles; Direct* types absent from the production build.
  • cargo clippy -p decdn-node --all-targets — clean.
  • cargo test -p decdn-node — passes (the one sighup_signal failure is a pre-existing in-process signal-ordering flake; it reproduces identically on main and is unrelated to this change — CI's nextest isolates each test into its own process).
  • RUSTDOCFLAGS="-D warnings" cargo doc -p decdn-node --no-deps --document-private-items — clean (intra-doc links to the now-gated types were reworded to plain code spans so the featureless doc build stays warning-free).
  • cargo fmt -p decdn-node -- --check — clean.

🤖 Generated with Claude Code


Generated by Claude Code

… feature

`DirectWarmingCreditSink` and `DirectReceiptSink` deliberately violate their
trait's non-blocking contract (they take the ledger / receipt-log lock on the
caller's thread) and must never be wired onto the serve path. They were `pub`,
`#[doc(hidden)]` — linkable into a production build, guarded only by a doc
sentence — because the cross-crate integration tests in `tests/` cannot see
`#[cfg(test)]` items.

Gate both behind a new `test-support` feature (`#[cfg(any(test, feature =
"test-support"))]`), turning the "never in production" rule into a build-time
property: a normal `cargo build -p decdn-node` no longer compiles either type.
The lib's own `#[cfg(test)]` build reaches them through the `any(test, …)` arm;
the integration tests reach them through a self dev-dependency that enables the
feature for the lib they link.

`ClientHandlerDeps::new` defaulted `warming_credit` to `DirectWarmingCreditSink`,
which the gate would have pulled out of the production build. Add
`NoopWarmingCreditSink` — an inert, always-compiled no-op sink — and use it as
that default; the runtime overwrites it with the channel sink from
`spawn_warming_creditor`, and a handler left with the default simply applies no
warming credit (the same safe, conservative direction a full aggregator queue
takes). `receipt_sink` is a required constructor parameter with no default, so
it needs no equivalent change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_018XsS3hXsdSDrSrzDVgXmKi
Copilot AI lite review requested due to automatic review settings August 30, 2026 15:23

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

This PR makes the node crate’s contract-violating synchronous sink fakes (DirectWarmingCreditSink, DirectReceiptSink) impossible to link into normal production builds by gating them behind a new test-support feature, while keeping them available for unit tests and cross-crate integration tests.

Changes:

  • Add test-support feature and gate both Direct*Sink test fakes behind #[cfg(any(test, feature = "test-support"))].
  • Introduce NoopWarmingCreditSink and switch ClientHandlerDeps::new to default to it instead of DirectWarmingCreditSink.
  • Add a self dev-dependency enabling test-support so integration tests in tests/ can access the gated fakes.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/src/warming_allowance.rs Adds NoopWarmingCreditSink and gates DirectWarmingCreditSink behind test-support.
crates/node/src/receipt_log.rs Gates DirectReceiptSink behind test-support and updates prose to avoid featureless rustdoc link issues.
crates/node/src/handlers/client/mod.rs Switches ClientHandlerDeps::new default warming_credit to NoopWarmingCreditSink.
crates/node/Cargo.toml Defines test-support and enables it for integration tests via a self dev-dependency.
Cargo.lock Records the additional dev-dependency resolution changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/handlers/client/mod.rs Resolved
…itSink default

The field-level doc still described the default as an inline sink over a fresh
zero-budget allowance. Describe the actual default — the inert
`NoopWarmingCreditSink` the runtime overwrites with the channel sink from
`spawn_warming_creditor`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_018XsS3hXsdSDrSrzDVgXmKi
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.11% (was 82.11%, ● 0.00%) — 68318/83199 lines

File Coverage Lines Δ
crates/node/src/handlers/client/mod.rs 92.91% 1572/1692 ▲ +0.17%
crates/node/src/receipt_log.rs 91.48% 526/575 ● 0.00%
crates/node/src/warming_allowance.rs 98.03% 299/305 ▲ +0.01%
History
Commit Total Δ vs base
7e873ff (HEAD) 82.11% ● 0.00%

@alpergundogdu
alpergundogdu merged commit f869e80 into main Aug 30, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1852-2jm0uw branch August 30, 2026 16:12
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.

node: gate the Direct*Sink test impls behind a test-support feature

3 participants