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.
65 lines
2.4 KiB
Rust
65 lines
2.4 KiB
Rust
//! `BudgetTracker` and `parse_budget` against the Original's real `Detokenizer` + `OutputParser` loop and
|
|
//! `Service.reasoning_budget` (fixture recorded from the Original's Python code).
|
|
|
|
use leleka_serving_policy::reasoning::{BudgetTracker, Verdict, WRAP_UP, parse_budget};
|
|
use serde_json::Value;
|
|
|
|
fn fixture() -> Value {
|
|
serde_json::from_str(include_str!("fixtures/reasoning.json")).unwrap()
|
|
}
|
|
|
|
fn unhex(text: &str) -> Vec<u8> {
|
|
(0..text.len() / 2).map(|i| u8::from_str_radix(&text[2 * i..2 * i + 2], 16).unwrap()).collect()
|
|
}
|
|
|
|
#[test]
|
|
fn wrap_up_text_is_the_originals() {
|
|
assert_eq!(fixture()["wrap_up"].as_str().unwrap(), WRAP_UP);
|
|
}
|
|
|
|
/// The index of the piece after which the tracker asks to wrap up, if any.
|
|
fn first_wrap(budget: u64, pieces: &[Vec<u8>]) -> Option<u64> {
|
|
let mut tracker = BudgetTracker::new(budget);
|
|
for (index, piece) in pieces.iter().enumerate() {
|
|
if tracker.push(piece) == Verdict::WrapUp {
|
|
return Some(index as u64);
|
|
}
|
|
}
|
|
None
|
|
}
|
|
|
|
#[test]
|
|
fn wrap_up_points_equal_python_for_every_sequence_and_budget() {
|
|
let fixture = fixture();
|
|
let mut wrapped = 0;
|
|
let mut unwrapped = 0;
|
|
for case in fixture["cases"].as_array().unwrap() {
|
|
let pieces: Vec<Vec<u8>> =
|
|
case["pieces_hex"].as_array().unwrap().iter().map(|v| unhex(v.as_str().unwrap())).collect();
|
|
for (budget, want) in case["wrap_at"].as_object().unwrap() {
|
|
let got = first_wrap(budget.parse().unwrap(), &pieces);
|
|
assert_eq!(got, want.as_u64(), "budget {budget} pieces {:?}", case["pieces_hex"]);
|
|
if got.is_some() {
|
|
wrapped += 1;
|
|
} else {
|
|
unwrapped += 1;
|
|
}
|
|
}
|
|
}
|
|
assert!(wrapped > 100 && unwrapped > 50, "{wrapped} {unwrapped}");
|
|
}
|
|
|
|
#[test]
|
|
fn budget_parsing_equals_python() {
|
|
for case in fixture()["parse"].as_array().unwrap() {
|
|
let request = case["request"].get("reasoning_budget_tokens");
|
|
let default = case["default"].clone();
|
|
let got = parse_budget(request, Some(&default));
|
|
match (case.get("ok"), case.get("error")) {
|
|
(Some(ok), None) => assert_eq!(got.unwrap().map(Value::from).unwrap_or(Value::Null), *ok, "{case}"),
|
|
(None, Some(error)) => assert_eq!(got.unwrap_err(), error.as_str().unwrap(), "{case}"),
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
}
|