From 0af739fd6cf61140a0036680181f4d02c6732569 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Sat, 14 Nov 2026 04:26:21 -0600 Subject: [PATCH] fix(id-core): correct frames byte-refusal test to the crate oversize semantics (#8354) --- pkgs/id/crates/id-core/src/frames.rs | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pkgs/id/crates/id-core/src/frames.rs b/pkgs/id/crates/id-core/src/frames.rs index e0a98d6bb4..3c775ad068 100644 --- a/pkgs/id/crates/id-core/src/frames.rs +++ b/pkgs/id/crates/id-core/src/frames.rs @@ -400,11 +400,18 @@ mod tests { let endpoint = [8; 32]; let mut abuse = AbuseEvaluator::new(policy, [9; 32]); + // A 5-byte frame exceeds the byte bucket's burst capacity + // (4): the cost can never be admitted, so the crate's design + // (abuse module docs; the #3927 oversize oracle) makes the + // refusal a permanent RequestTooLarge with no retry offered + // (#8354 — this test previously expected BudgetExhausted, + // which is the within-capacity refusal; see below). let refusal = charge_frame(&mut abuse, endpoint, true, 5, 0).unwrap_err(); assert_eq!( refusal.0.reason, - crate::abuse::RefusalReason::BudgetExhausted + crate::abuse::RefusalReason::RequestTooLarge ); + assert!(refusal.0.retry_after_ms.is_none()); assert!(abuse.counters().get(&[9; 32], &endpoint).is_none()); // The refused frame did not consume the frame allowance. @@ -416,6 +423,26 @@ mod tests { bytes: 4, }) ); + + // A within-capacity byte refusal — the bucket is momentarily + // empty but the cost fits its burst capacity — is the + // retryable BudgetExhausted, and it likewise spends neither + // the frame token nor the counters. + let mut abuse = AbuseEvaluator::new(policy, [9; 32]); + charge_frame(&mut abuse, endpoint, true, 4, 0).unwrap(); + let refusal = charge_frame(&mut abuse, endpoint, true, 1, 0).unwrap_err(); + assert_eq!( + refusal.0.reason, + crate::abuse::RefusalReason::BudgetExhausted + ); + assert!(refusal.0.retry_after_ms.is_some()); + assert_eq!( + abuse.counters().get(&[9; 32], &endpoint), + Some(crate::abuse::Counters { + frames: 1, + bytes: 4, + }) + ); } #[test]