Repository navigation
refactor(node): gate the Direct*Sink test fakes behind a test-support feature - #1875
Merged
Merged
Conversation
… 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
There was a problem hiding this comment.
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-supportfeature and gate bothDirect*Sinktest fakes behind#[cfg(any(test, feature = "test-support"))]. - Introduce
NoopWarmingCreditSinkand switchClientHandlerDeps::newto default to it instead ofDirectWarmingCreditSink. - Add a self dev-dependency enabling
test-supportso integration tests intests/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.
…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
Coverage reportTotal: 82.11% (was 82.11%, ● 0.00%) — 68318/83199 lines
History
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1852.
Problem
DirectWarmingCreditSink(warming_allowance.rs) andDirectReceiptSink(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 werepub,#[doc(hidden)], so a contract-violating implementation was linkable into a production build, guarded only by a doc sentence. They werepubonly because the cross-crate integration tests intests/cannot see#[cfg(test)]items.Change
Gate both types (and their impls) behind a new
test-supportfeature via#[cfg(any(test, feature = "test-support"))], turning the "never in production" rule from a doc promise into a build-time property — a normalcargo build -p decdn-nodeno longer compiles either type.#[cfg(test)]unit tests reach the fakes through theany(test, …)arm.decdn-node = { path = ".", features = ["test-support"] }) that enables the feature for the lib they link — mirroring the existingtest-utildev-dep pattern already documented in this crate'sCargo.toml.ClientHandlerDeps::newdefaultedwarming_credittoDirectWarmingCreditSink, which the gate would have pulled out of the production build (this is the contradiction the issue points at). AddedNoopWarmingCreditSink— an inert, always-compiled no-op sink — and use it as that default. The runtime always overwrites it with the channel sink fromspawn_warming_creditor; a handler left with the default simply applies no warming credit, the same safe/conservative direction a full aggregator queue takes.receipt_sinkis 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 onesighup_signalfailure is a pre-existing in-process signal-ordering flake; it reproduces identically onmainand 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