usage-meter-poll: gate fixes: the timeout is read per request, serve has a refusal test, the RFC 850 guard is pinned

The timeout field was read only by a test (dead_code under -D warnings), so
ask() applies it to each request. The serve wrapper is reached by a
subprocess refusal test (no network); the serve test fails inside 30 s
instead of hanging; "Wednesday 21-Oct-26 ..." (no comma) is refused.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-01 03:30:55 +01:00
commit 7d4c1bf56e
3 changed files with 13 additions and 5 deletions

View file

@ -678,7 +678,7 @@ Connection: close
let served = std::thread::spawn(move || serve_config_with(&path, UsageClient::new(url)));
let request = request
.recv_timeout(Duration::from_secs(60))
.recv_timeout(Duration::from_secs(30))
.expect("the usage poll never asked the fake endpoint");
assert!(request.starts_with("GET /api/oauth/usage "), "{request}");
assert!(request.contains(&format!("Bearer {TOKEN}")), "{request}");

View file

@ -160,10 +160,7 @@ impl UsageClient {
fn with_timeout(url: impl Into<String>, timeout: Duration) -> Self {
Self {
agent: ureq::AgentBuilder::new()
.timeout(timeout)
.redirects(0)
.build(),
agent: ureq::AgentBuilder::new().redirects(0).build(),
url: url.into(),
timeout,
}
@ -177,6 +174,7 @@ impl UsageClient {
let sent = self
.agent
.get(&self.url)
.timeout(self.timeout)
.set("Authorization", bearer.as_str())
.set("anthropic-beta", "oauth-2025-04-20")
.call();
@ -911,6 +909,7 @@ mod tests {
"Wednesday, 21-Oct-26-1 07:28:00 GMT",
"Wednesday, 21-Oct-2026 07:28:00 GMT",
"Wednesday, 21-Foo-26 07:28:00 GMT",
"Wednesday 21-Oct-26 07:28:00 GMT",
"Wednesday, 21-Oct-26 07:28 GMT",
"Wed Oct 21 07:28:00:01 2026",
"Wed Oct 32 07:28:00 2026",

View file

@ -286,3 +286,12 @@ fn the_dollar_flags_are_not_flags() {
);
}
}
#[test]
fn serve_refuses_a_document_that_is_not_there() {
let scratch = Scratch::new();
let missing = scratch.path("missing.cc");
let served = run(&["serve", "--config", missing.to_str().unwrap()]);
assert!(!served.status.success(), "{served:?}");
assert!(!String::from_utf8_lossy(&served.stderr).is_empty());
}