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.
78 lines
2.9 KiB
Rust
78 lines
2.9 KiB
Rust
//! `clean_shared_defaults` / `sampling_defaults_from_config` against the Original's real Python output
|
|
//! (fixture recorded from the Original's Python code).
|
|
|
|
use leleka_serving_policy::shared::{ConfigSampling, clean_shared_defaults, sampling_defaults_from_config};
|
|
use serde_json::{Value, json};
|
|
|
|
fn fixture() -> Value {
|
|
serde_json::from_str(include_str!("fixtures/shared.json")).unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn settings_cleaning_equals_python() {
|
|
let fixture = fixture();
|
|
let mut agreed_errors = 0;
|
|
for case in fixture["clean"].as_array().unwrap() {
|
|
let input = &case["input"];
|
|
let got = clean_shared_defaults(input);
|
|
match (case.get("ok"), case.get("error")) {
|
|
(Some(ok), None) => {
|
|
let got = got.unwrap_or_else(|e| panic!("{input}: unexpected error {e}"));
|
|
assert_eq!(&got.to_json(), ok, "{input}");
|
|
}
|
|
(None, Some(error)) => {
|
|
assert_eq!(got.unwrap_err(), error.as_str().unwrap(), "{input}");
|
|
agreed_errors += 1;
|
|
}
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
assert!(agreed_errors >= 20);
|
|
}
|
|
|
|
/// Python returns the dict of accepted keys: compare through the same names.
|
|
fn accepted_keys(got: &ConfigSampling) -> Value {
|
|
let s = &got.sampling;
|
|
let mut mine = serde_json::Map::new();
|
|
let mut put = |k: &str, v: Option<Value>| {
|
|
if let Some(v) = v {
|
|
mine.insert(k.into(), v);
|
|
}
|
|
};
|
|
put("temperature", s.temperature.map(|v| json!(v)));
|
|
put("top_p", s.top_p.map(|v| json!(v)));
|
|
put("min_p", s.min_p.map(|v| json!(v)));
|
|
put("top_k", s.top_k.map(|v| json!(v)));
|
|
put("presence_penalty", s.presence_penalty.map(|v| json!(v)));
|
|
put("frequency_penalty", s.frequency_penalty.map(|v| json!(v)));
|
|
put("repetition_penalty", s.repetition_penalty.map(|v| json!(v)));
|
|
put("penalty_last_n", s.penalty_last_n.map(|v| json!(v)));
|
|
put("seed", s.seed.map(|v| json!(v)));
|
|
put("experimental_speed_projection", got.experimental_speed_projection.map(|v| json!(v)));
|
|
Value::Object(mine)
|
|
}
|
|
|
|
#[test]
|
|
fn config_sampling_block_equals_python() {
|
|
let fixture = fixture();
|
|
let mut agreed_errors = 0;
|
|
for case in fixture["config"].as_array().unwrap() {
|
|
let input = case["input"].clone();
|
|
let got = sampling_defaults_from_config(&input);
|
|
match (case.get("ok"), case.get("error")) {
|
|
(Some(ok), None) => {
|
|
let got = got.unwrap_or_else(|e| panic!("{input}: unexpected error {e}"));
|
|
let mine = accepted_keys(&got);
|
|
assert_eq!(&mine, ok, "{input}");
|
|
assert_eq!(got.ignored.len(), case["ignored"].as_array().unwrap().len(), "{input}");
|
|
}
|
|
(None, Some(error)) => {
|
|
assert_eq!(got.unwrap_err(), error.as_str().unwrap(), "{input}");
|
|
agreed_errors += 1;
|
|
}
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
assert!(agreed_errors >= 14);
|
|
}
|