Fix test mock HTTP body read in router and parallel_tool_calls in messages tests

This commit is contained in:
Meta Vens 2026-12-04 01:00:12 +01:00
commit 4796f917ac
2 changed files with 34 additions and 5 deletions

View file

@ -678,6 +678,7 @@ fn model_row_policies_gate_forced_tool_choice_output_schema_and_efforts() {
// Thinking inactive (unset_effort is None and request effort is None) -> accepted.
without_thinking.unset_effort = None;
asked.parallel_tool_calls = true;
let body = super::render(&asked, PROVIDER, &without_thinking).unwrap();
assert_eq!(body["tool_choice"], json!({"type": "any"}));

View file

@ -288,11 +288,39 @@ mod tests {
let seen_clone = seen_body.clone();
std::thread::spawn(move || {
let (mut stream, _) = listener.accept().unwrap();
let mut buf = [0u8; 8192];
let n = stream.read(&mut buf).unwrap();
let text = std::str::from_utf8(&buf[..n]).unwrap();
let body_str = text.split("\r\n\r\n").nth(1).unwrap();
*seen_clone.lock().unwrap() = Some(serde_json::from_str(body_str).unwrap());
let mut buf = Vec::new();
let mut chunk = [0u8; 4096];
let mut header_end = None;
let mut content_len = 0usize;
loop {
let n = stream.read(&mut chunk).unwrap_or(0);
if n == 0 {
break;
}
buf.extend_from_slice(&chunk[..n]);
if header_end.is_none()
&& let Some(pos) = buf.windows(4).position(|w| w == b"\r\n\r\n")
{
let end = pos + 4;
header_end = Some(end);
let headers = String::from_utf8_lossy(&buf[..pos]);
for line in headers.lines().skip(1) {
if let Some((k, v)) = line.split_once(':')
&& k.eq_ignore_ascii_case("content-length")
{
content_len = v.trim().parse().unwrap_or(0);
}
}
}
if let Some(end) = header_end
&& buf.len() >= end + content_len
{
break;
}
}
let end = header_end.unwrap_or(buf.len());
*seen_clone.lock().unwrap() =
Some(serde_json::from_slice(&buf[end..end + content_len]).unwrap());
let resp = serde_json::json!({
"id": "msg_router_1",
"content": [{"type": "text", "text": "ok"}],