Skip to content

test(node): cover prefetch record_served through the live cdn/client/v1 serve loop (#900) - #909

Merged
thiras merged 1 commit into
mainfrom
test/900-prefetch-served-serve-loop
Jun 15, 2026
Merged

thiras merged 1 commit into
mainfrom
test/900-prefetch-served-serve-loop

Conversation

@thiras

@thiras thiras commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

Closes #900. Adds an end-to-end test that pins the previously-uncovered wiring: a real paid cdn/client/v1 serve of a prefetch-acquired blob drives PrefetchEngine::note_served_if_prefetched from inside the live collect_voucher loop (crates/node/src/handlers/client.rs), feeding the demand-quality served / acquired numerator.

Until now both halves of the credit contract were tested only in isolation:

  • tag-on-acquire — e2e prefetch_acquire_pulls_and_records_spend
  • tag→credit — unit note_served_credits_only_prefetched_hashes

Neither exercised the real serve loop, so a refactor dropping the attach_prefetch_engine call, the prefetch_engine.get() guard, or the note_served_if_prefetched call would have gone uncaught.

How

Three loopback endpoints:

  • Node A holds the blob(s), serves probe + client (the prefetch upstream).
  • Node B prefetch-acquires the blob from A (tagging it), then runs a live ClientHandler over the same cache with the engine attached.
  • Client C does a real stream_fetch paid pull from B.

Positive: after the pull, the ratio moves from a 0.0 baseline to exactly 1.0 (whole blob acquired = denominator, whole blob served back = numerator over both voucher intervals). Asserting the precise value — not just > 0 — catches partial-credit bugs (e.g. crediting only the first 1 MiB interval → ~0.67).

Negative control: B reactively pulls a second, untagged blob (plain cache-miss populate, never prefetch-acquired) and C serves it through the same live handler; the ratio must stay at 1.0. This pins the acquired.contains gate through the real serve path, not just that some credit fires.

Verification

  • New test passes deterministically (multiple runs); full node_origin_pull binary 23/23 pass.
  • Falsification-checked both directions: disabling the production note_served_if_prefetched call fails the positive assertion; removing the acquired.contains gate (so every served blob credits) drives the ratio to 2.0 and fails the negative control.
  • cargo fmt --check, cargo clippy -p decdn-node --tests, and all pre-commit hooks (fmt/clippy/doc/deny) clean.

Test-only; no production code changed.

🤖 Generated with Claude Code

…v1 serve loop (#900)

The demand-quality auto-throttle's served-bytes numerator is fed by
PrefetchEngine::note_served_if_prefetched, called from the accepted-voucher
branch of collect_voucher in the client serve handler. Until now both halves of
the credit contract were tested only in isolation (tag-on-acquire e2e +
tag->credit unit); the wiring through the real serve loop had no coverage.

Add an e2e test: node B prefetch-acquires a blob from upstream A (tagging it as
prefetch content), then a separate client C performs a real paid cdn/client/v1
pull of that blob from B. The pull drives note_served_if_prefetched from the
live ClientHandler, moving the served/acquired demand-quality ratio from a zero
baseline to exactly 1.0 (the whole blob acquired and served back).

A negative control then serves an untagged blob (one B reactively pulled on a
cache miss, never prefetch-acquired) through the same live handler and asserts
the ratio is unchanged, pinning the acquired.contains gate through the real
serve path rather than just that some credit fires.

Both directions were falsification-checked: disabling the production
note_served_if_prefetched call fails the positive assertion, and removing the
acquired.contains gate fails the negative control.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 15, 2026 00:30

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new integration test prefetch_acquired_blob_credits_served_through_serve_loop and a helper function cache_with_blobs in crates/node/tests/node_origin_pull.rs to verify that serving a prefetch-acquired blob correctly updates the demand-quality ratio, while serving an untagged blob does not. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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 an end-to-end integration test to ensure prefetch-acquired blobs are credited as “served” via the real cdn/client/v1 serve loop (i.e., the production ClientHandler path), covering the previously untested wiring for demand-quality metrics.

Changes:

  • Adds a new multi-node loopback test that prefetch-acquires a blob and then performs a paid stream_fetch through the live client handler, asserting served/acquired moves from 0.0 to exactly 1.0.
  • Adds a negative-control flow that serves an untagged (reactively populated) blob and asserts the ratio remains unchanged.
  • Introduces a small helper to seed a cache with multiple blobs for the upstream node fixture.

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

Comment thread crates/node/tests/node_origin_pull.rs Resolved
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 85.71% (was 85.66%, ▲ +0.05%) — 37080/43262 lines

No coverage data for changed Rust files.

History
Commit Total Δ vs base
3d3f2b6 (HEAD) 85.71% ▲ +0.05%

@thiras
thiras merged commit 3c82993 into main Jun 15, 2026
21 checks passed
@thiras
thiras deleted the test/900-prefetch-served-serve-loop branch June 15, 2026 01: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.

test(node): cover prefetch record_served through the live cdn/client/v1 serve loop

2 participants