From f242290ca595b34944f189839a498ba3e02dc443 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 1 Nov 2026 03:17:08 +0100 Subject: [PATCH] usage-meter-poll: pin what the production client is built with (finding new-client-timeout-unpinned) UsageClient carries its timeout and url; UsageClient::production() is what start() builds, and the test asserts that client's url and 10 s timeout as spec r2 says, replacing a 1..=60 s bound no rule names. Co-Authored-By: Claude Sonnet 5.5 --- crates/claude-connector/src/usage_poll.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/claude-connector/src/usage_poll.rs b/crates/claude-connector/src/usage_poll.rs index ff61482..94b23ec 100644 --- a/crates/claude-connector/src/usage_poll.rs +++ b/crates/claude-connector/src/usage_poll.rs @@ -141,13 +141,20 @@ fn parse_usage(body: &str) -> Option> { /// The blocking HTTPS client: 10 s end to end, no redirects (the token must /// not follow one anywhere). -struct UsageClient { +pub(crate) struct UsageClient { agent: ureq::Agent, url: String, + timeout: Duration, } impl UsageClient { - fn new(url: impl Into) -> Self { + /// The client that asks the provider's usage endpoint. + pub(crate) fn production() -> Self { + Self::new(ENDPOINT) + } + + /// A client for another endpoint: a test's fake server. + pub(crate) fn new(url: impl Into) -> Self { Self::with_timeout(url, TIMEOUT) } @@ -158,6 +165,7 @@ impl UsageClient { .redirects(0) .build(), url: url.into(), + timeout, } } @@ -392,7 +400,7 @@ pub fn start( let poller = Poller::new( cell, tokens, - UsageClient::new(ENDPOINT), + UsageClient::production(), Box::new(|line| eprintln!("claude-connector: {line}")), ); std::thread::Builder::new() @@ -962,8 +970,11 @@ mod tests { } #[test] - fn the_real_timeout_frees_the_thread_within_a_minute() { - assert!(TIMEOUT >= secs(1) && TIMEOUT <= secs(60), "{TIMEOUT:?}"); + fn the_production_client_asks_the_provider_and_gives_up_after_ten_seconds() { + let client = UsageClient::production(); + assert_eq!(client.url, "https://api.anthropic.com/api/oauth/usage"); + assert_eq!(client.timeout, secs(10)); + assert_eq!(TIMEOUT, secs(10)); } /// Answers one connection after `delay`, as a slow endpoint does.