test(model-connector): kill remaining 7 price.rs mutant survivors and harden spend validation tests

This commit is contained in:
Meta Vens 2026-12-06 04:28:08 +01:00
commit fb3ce4d21d
2 changed files with 129 additions and 2 deletions

View file

@ -212,6 +212,63 @@ mod tests {
);
assert_eq!(utc_month_string(0), "1970-01");
// All seven weekdays in order starting 1970-01-01 (Thu).
let expected_weekdays = [
Weekday::Thu,
Weekday::Fri,
Weekday::Sat,
Weekday::Sun,
Weekday::Mon,
Weekday::Tue,
Weekday::Wed,
];
for (offset, expected) in expected_weekdays.into_iter().enumerate() {
assert_eq!(
utc_parts((offset as u64) * 86_400 * 1_000).weekday,
expected
);
}
// 400-year leap boundary (2000-02-29, Tuesday) and 100-year non-leap boundary (2100-01-01, Friday).
assert_eq!(
utc_parts(11_016 * 86_400 * 1_000),
UtcParts {
year: 2000,
month: 2,
day: 29,
weekday: Weekday::Tue,
hour: 0,
}
);
assert_eq!(
utc_parts(47_482 * 86_400 * 1_000),
UtcParts {
year: 2100,
month: 1,
day: 1,
weekday: Weekday::Fri,
hour: 0,
}
);
// Non-zero cache_write rate and tokens.
let cache_write_rates = TokenRates {
input: 0,
cache_read: 0,
cache_write: 3_000,
output: 0,
};
assert_eq!(
cache_write_rates.cost_micro_usd(&Usage {
input_tokens: 0,
cache_read_tokens: 0,
cache_write_tokens: 500,
output_tokens: 0,
reasoning_tokens: None,
}),
2
);
// 2024-02-29T23:59:59Z (leap day, Thursday)
let leap_day_ms = (19_782 * 86_400 + 23 * 3_600 + 59 * 60 + 59) * 1_000;
assert_eq!(

View file

@ -3221,6 +3221,31 @@ mod tests {
assert_eq!(rc2.provider, STAND_IN_PROVIDER);
assert_eq!(rc2.cost_micro_usd, None);
// Priced model with Failed { usage: Some(...) } -> cost_micro_usd Some, does NOT increment calls_without_price.
let (c3_with_usage, inv3_with_usage) =
begin_model(&mut service, "priced", "failed-with-usage", tue_off_peak_ms);
let r3_with_usage = c3_with_usage.call().transported(
Vec::new(),
TransportOutcome::Failed {
kind: FailureKind::RateLimited,
message: "limited".to_string(),
usage: Some(usage.clone()),
},
);
let env3_with_usage = service
.complete(*c3_with_usage, r3_with_usage, FRAME)
.unwrap();
let TransportDisposition::Transported {
receipt: rc3_with_usage,
..
} = decrypt_result(&env3_with_usage, &security(KEY), &inv3_with_usage)
.unwrap()
.disposition
else {
panic!("expected transported failure with usage");
};
assert_eq!(rc3_with_usage.cost_micro_usd, Some(1_338));
// Priced model with Failed { usage: None } -> cost_micro_usd None, counts in calls_without_price.
let (c3, inv3) = begin_model(&mut service, "priced", "failed-no-usage", tue_off_peak_ms);
let r3 = c3.call().transported(
@ -3281,8 +3306,8 @@ mod tests {
caller: CALLER.to_string(),
model: "priced".to_string(),
month: "2026-12".to_string(),
calls: 3,
cost_micro_usd: 2_676 + 1_338,
calls: 4,
cost_micro_usd: 2_676 + 1_338 + 1_338,
calls_without_price: 1,
},
CallerModelSpend {
@ -3334,6 +3359,15 @@ mod tests {
0_u64,
0_u64,
),
(
spend_key(CALLER, "priced", "2026-00"),
CALLER,
"priced",
"2026-00",
1,
0,
0,
),
(
spend_key(CALLER, "priced", "2026-13"),
CALLER,
@ -3343,6 +3377,33 @@ mod tests {
0,
0,
),
(
spend_key(CALLER, "priced", "2026/12"),
CALLER,
"priced",
"2026/12",
1,
0,
0,
),
(
spend_key(CALLER, "priced", "202a-12"),
CALLER,
"priced",
"202a-12",
1,
0,
0,
),
(
spend_key(CALLER, "priced", "2026-1a"),
CALLER,
"priced",
"2026-1a",
1,
0,
0,
),
(
spend_key(CALLER, "priced", "2026-12"),
CALLER,
@ -3370,6 +3431,15 @@ mod tests {
0,
0,
),
(
spend_key(CALLER, "", "2026-12"),
CALLER,
"",
"2026-12",
1,
0,
0,
),
] {
let bad_store = TestStore::new();
let mut cache = CultCache::new();