Files
leleka/crates/serving-policy/tests/golden_host.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

67 lines
2.6 KiB
Rust

//! Stride selection and the stall watchdog against the Original's C++ host build
//! (fixture recorded from that build: `logits_selection.hpp` unmodified, the watchdog loop driven
//! by an injected clock).
use leleka_serving_policy::stride::{parse_stride, row_count, selected};
use leleka_serving_policy::watchdog::{Counters, StallWatchdog, Verdict};
use serde_json::Value;
fn fixture() -> Value {
serde_json::from_str(include_str!("fixtures/host_oracle.json")).unwrap()
}
#[test]
fn stride_parsing_equals_the_header() {
for case in fixture()["parse"].as_array().unwrap() {
let text = case["text"].as_str().unwrap();
let got = parse_stride(text);
if case["ok"].as_bool().unwrap() {
assert_eq!(got, case["value"].as_i64(), "{text:?}");
} else {
assert_eq!(got, None, "{text:?}");
}
}
}
#[test]
fn stride_selection_and_row_counts_equal_the_header() {
let fixture = fixture();
let cases = fixture["selected"].as_array().unwrap();
assert_eq!(cases.len(), 100);
for case in cases {
let total = case["total"].as_i64().unwrap();
let stride = case["stride"].as_i64().unwrap();
assert_eq!(row_count(total, stride), case["rows"].as_i64().unwrap());
let want: Vec<i64> = case["kept"].as_array().unwrap().iter().map(|v| v.as_i64().unwrap()).collect();
let got: Vec<i64> = (-2..total + 2).filter(|p| selected(*p, total, stride)).collect();
assert_eq!(got, want, "total {total} stride {stride}");
}
}
#[test]
fn watchdog_scenarios_equal_the_engine_loop() {
let fixture = fixture();
let mut fired = 0;
for scenario in fixture["watchdog"].as_array().unwrap() {
let limit = scenario["limit_s"].as_i64().unwrap();
let mut dog = StallWatchdog::new(limit, 0, Counters::default());
for step in scenario["steps"].as_array().unwrap() {
let counters = Counters {
beats: step["beats"].as_u64().unwrap(),
busy: step["busy"].as_bool().unwrap(),
ticks: step["ticks"].as_u64().unwrap(),
};
let verdict = dog.poll(step["at_ms"].as_u64().unwrap(), counters);
let want = step["layers_since"].as_i64().unwrap();
match verdict {
Verdict::Healthy => assert_eq!(want, -1, "limit {limit} step {step}"),
Verdict::Stalled { layers_since, .. } => {
assert_eq!(layers_since as i64, want, "limit {limit} step {step}");
fired += 1;
}
}
}
}
assert!(fired >= 6, "{fired}");
}