connector-usage-only: store-failure tests, README front door
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
af5da3dfaa
commit
dcb5f109f7
4 changed files with 62 additions and 26 deletions
|
|
@ -1438,7 +1438,8 @@ fn usage_sums_model_usage_across_models() {
|
|||
panic!("completed expected");
|
||||
};
|
||||
assert_eq!(*summed, usage(12, 37, 1083, 24, Some(8)));
|
||||
// The receipt is priced from usage alone: 12*3 + 37*0.3 + 1083*6 + 24*15 micro-USD, rounded up.
|
||||
// The receipt is the usage alone: the CLI's own total never reaches it.
|
||||
assert_eq!(parts(&cheap).1, parts(&dear).1);
|
||||
|
||||
// No model reported thinking tokens: none is claimed.
|
||||
let plain = r#"{"claude-haiku-5-5":{"inputTokens":1,"outputTokens":1,"cacheReadInputTokens":0,"cacheCreationInputTokens":0}}"#;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ impl PeerUnits for FakeUnits {
|
|||
struct Harness {
|
||||
dir: PathBuf,
|
||||
socket: PathBuf,
|
||||
service: Arc<Mutex<TransportService>>,
|
||||
_service: Arc<Mutex<TransportService>>,
|
||||
quota: Arc<QuotaCell>,
|
||||
tokens: Arc<FakeTokens>,
|
||||
/// The fake behind the listener, when it has one.
|
||||
|
|
@ -162,18 +162,6 @@ fn receive(stream: &UnixStream) -> (Vec<u8>, Vec<OwnedFd>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn connect(harness: &Harness) -> UnixStream {
|
||||
let stream = UnixStream::connect(&harness.socket).unwrap();
|
||||
stream
|
||||
.set_read_timeout(Some(Duration::from_secs(5)))
|
||||
.unwrap();
|
||||
stream
|
||||
}
|
||||
|
||||
fn send(stream: &mut UnixStream, message: &LeaseMessage) {
|
||||
stream.write_all(&encode_frame(message)).unwrap();
|
||||
}
|
||||
|
||||
fn request(ttl_ms: u64) -> LeaseMessage {
|
||||
LeaseMessage::ClaudeLeaseRequest(LeaseRequest {
|
||||
expires_at_unix_ms: now_ms() + ttl_ms,
|
||||
|
|
@ -182,7 +170,7 @@ fn request(ttl_ms: u64) -> LeaseMessage {
|
|||
|
||||
/// What one request to the listener came back with.
|
||||
struct Answer {
|
||||
stream: UnixStream,
|
||||
_stream: UnixStream,
|
||||
raw: Vec<u8>,
|
||||
message: Option<LeaseMessage>,
|
||||
fds: Vec<OwnedFd>,
|
||||
|
|
@ -202,7 +190,7 @@ fn ask_at(socket: &std::path::Path, ttl_ms: u64) -> Answer {
|
|||
let (raw, fds) = receive(&stream);
|
||||
let message = decode_frame(&raw);
|
||||
Answer {
|
||||
stream,
|
||||
_stream: stream,
|
||||
raw,
|
||||
message,
|
||||
fds,
|
||||
|
|
@ -316,7 +304,7 @@ fn start(setup: Setup) -> Harness {
|
|||
let harness = Harness {
|
||||
dir,
|
||||
socket,
|
||||
service,
|
||||
_service: service,
|
||||
quota,
|
||||
tokens,
|
||||
units: Some(units),
|
||||
|
|
|
|||
|
|
@ -2158,4 +2158,46 @@ mod tests {
|
|||
Some(Operation::UsageReadout)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_store_that_cannot_be_written_executes_nothing_and_holds_no_slot() {
|
||||
let store = FlakyStore::new(0);
|
||||
let allowance = store.allowance();
|
||||
let mut service =
|
||||
TransportService::with_store(store, "fixture-sse", [caller(CALLER, KEY, 1)], 5_000)
|
||||
.unwrap();
|
||||
let invocation = invocation_for(CALLER, "request-1");
|
||||
assert!(matches!(
|
||||
service.begin_unplanned(&raw_envelope(&invocation), 1_000, FRAME),
|
||||
Err(ServiceError::ReplayStore(_))
|
||||
));
|
||||
allowance.store(10, Ordering::SeqCst);
|
||||
assert!(matches!(
|
||||
service.begin_unplanned(&raw_envelope(&invocation), 1_000, FRAME),
|
||||
Ok(TransportAdmission::Execute(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_completion_write_answers_the_store_failure_and_frees_the_slot() {
|
||||
let store = FlakyStore::new(1);
|
||||
let allowance = store.allowance();
|
||||
let mut service =
|
||||
TransportService::with_store(store, "fixture-sse", [caller(CALLER, KEY, 1)], 5_000)
|
||||
.unwrap();
|
||||
let (claim, invocation) = claim_for(&mut service, "request-1");
|
||||
let result = text_result(claim.call(), "done");
|
||||
assert!(matches!(
|
||||
service.complete(*claim, result, FRAME),
|
||||
Err(ServiceError::ReplayStore(_))
|
||||
));
|
||||
// The slot is free (one concurrent request is admitted), and the retry
|
||||
// of the unfinished id is told it is indeterminate, not in flight.
|
||||
allowance.store(10, Ordering::SeqCst);
|
||||
let again = service
|
||||
.begin_unplanned(&raw_envelope(&invocation), 1_000, FRAME)
|
||||
.unwrap();
|
||||
assert_eq!(refusal_of(again, &invocation), Refusal::Indeterminate);
|
||||
let _ = claim_for(&mut service, "request-2");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue