Files
leleka/control-plane/tests/chat_template_oracle.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

64 lines
2.1 KiB
Rust

//! The native Jinja renderer against the Python server's `ChatTemplate` (jinja2) on generated conversations.
//!
//! `tests/fixtures/offline/chat_template_oracle.json` was recorded from the Original's Python code (Strata 41cf05a0):
//! 90 renders (every role incl. developer and tool, list content with image/video parts, assistant `tool_calls`
//! with mapping arguments, tools, `enable_thinking` / `reasoning_effort` / `preserve_thinking`, no generation
//! prompt) and 25 conversations the template refuses, with the exact `raise_exception` message.
use leleka_control_plane::prompt::{ChatInput, Json, pinned};
use serde::Deserialize;
#[derive(Deserialize)]
struct Case {
messages: Vec<Json>,
tools: Option<Json>,
add_generation_prompt: bool,
kwargs: Json,
rendered: Option<String>,
error: Option<String>,
}
#[derive(Deserialize)]
struct Golden {
ok: Vec<Case>,
raised: Vec<Case>,
}
fn render(case: &Case) -> Result<String, String> {
let tools = match &case.tools {
Some(Json::Array(items)) => Some(items.as_slice()),
_ => None, // null, or a mapping the template ignores
};
let kwargs = match &case.kwargs {
Json::Object(fields) => fields.iter().map(|(k, v)| (k.as_str(), v.clone())).collect(),
_ => Vec::new(),
};
pinned().render(&ChatInput {
messages: &case.messages,
tools,
add_generation_prompt: case.add_generation_prompt,
kwargs,
})
}
fn golden() -> Golden {
serde_json::from_str(include_str!("fixtures/offline/chat_template_oracle.json")).unwrap()
}
#[test]
fn renders_are_byte_identical_to_jinja2() {
let golden = golden();
assert!(golden.ok.len() >= 90);
for (at, case) in golden.ok.iter().enumerate() {
assert_eq!(render(case), Ok(case.rendered.clone().unwrap()), "case {at}");
}
}
#[test]
fn refusals_carry_the_templates_own_message() {
let golden = golden();
assert!(golden.raised.len() >= 25);
for (at, case) in golden.raised.iter().enumerate() {
assert_eq!(render(case), Err(case.error.clone().unwrap()), "case {at}");
}
}