Files
leleka/crates/serving-policy/tests/golden_timings.rs
T
Pavlo Ratushnyi da8c974f68 Drop the stale engine/strata paths and retired generator names from comments, doc strings and generated fixtures (STRA-407)
Rust comments that named scripts/offline/*, gen_goldens.py, oracle/gen_*.{sh,cpp,py}, build_oracle.sh and similar retired generators now say where the data
came from (the Original's code, Strata 41cf05a0) or drop the sentence. The path/generator text of seven generated fixtures (sampler_oracle.json, sampling_keys.json,
memory_plan_golden.json, rope_golden.json, cvec_oracle.json, stra161 fixtures.json, commentary-tool-prompt.json) is reworded; no test reads those fields and no pin
covers their bytes. cmd_time/doc.rs: the two path texts in the format string; its lines are re-broken so they stay within 120 columns (the string is unchanged
otherwise). Comment-only except those data/string spots; no behaviour change.
2026-11-23 22:37:17 +01:00

51 lines
1.9 KiB
Rust

//! `request_timings` and `Service.set_aliases` against the Original's real Python
//! (fixture recorded from the Original's Python code).
use leleka_serving_policy::shared::normalize_aliases;
use leleka_serving_policy::timings::{Last, request_timings};
use serde_json::Value;
fn fixture() -> Value {
serde_json::from_str(include_str!("fixtures/timings.json")).unwrap()
}
#[test]
fn timings_equal_python() {
let fixture = fixture();
let cases = fixture["timings"].as_array().unwrap();
assert!(cases.len() > 30);
for case in cases {
let last = &case["last"];
let prompt_tokens = case["prompt_tokens"].as_u64().unwrap();
let generated = case["generated"].as_u64().unwrap();
if last.as_object().is_some_and(|o| o.is_empty()) {
continue; // MockEngine keeps no clock: Python answers None and the caller shows null
}
let got = request_timings(
&Last {
prompt_tokens,
generated: last["generated"].as_u64().unwrap_or(0),
prompt_ms: last["prompt_ms"].as_f64().unwrap(),
decode_ms: last["decode_ms"].as_f64().unwrap_or(0.0),
reused: last["reused"].as_u64(),
drafts_offered: last["drafts_offered"].as_u64(),
drafts_accepted: last["drafts_accepted"].as_u64(),
},
generated,
);
assert_eq!(got, case["timings"], "{case}");
}
}
#[test]
fn aliases_equal_python() {
for case in fixture()["aliases"].as_array().unwrap() {
let got = normalize_aliases(&case["input"], "m");
match (case.get("ok"), case.get("error")) {
(Some(ok), None) => assert_eq!(serde_json::json!(got.unwrap()), *ok, "{case}"),
(None, Some(error)) => assert_eq!(got.unwrap_err(), error.as_str().unwrap(), "{case}"),
_ => unreachable!(),
}
}
}