[Rust Frontend] Speed up chat roundtrip tests (#47523)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>

Bugen Zhao committed Jul 4, 2026 at 02:25 UTC 8651f043b854b75c6dc875261073e2346290f4f5
2 files changed +34 -19
rust/Cargo.toml
+7
@@ -144,6 +144,13 @@ too_many_arguments = "allow"
144 [profile.dev]
145 panic = "abort"
146
147 +# Speed up cold tokenizer construction in tests.
148 +[profile.dev.package]
149 +fastokens = { opt-level = 3 }
150 +regex-automata = { opt-level = 3 }
151 +serde_json = { opt-level = 3 }
152 +tokenizers = { opt-level = 3 }
153 +
154 [profile.release]
155 lto = "thin"
156 panic = "abort"
rust/src/chat/tests/roundtrip.rs
+27 -19
@@ -214,14 +214,17 @@ macro_rules! roundtrip_tests {
214 ($($case:ident => [$($(#[$fixture_attr:meta])* $fixture:ident),* $(,)?]),+ $(,)?) => {
215 paste::paste! {
216 $(
217 - $(
218 - #[tokio::test]
219 - $(#[$fixture_attr])*
220 - #[file_serial([<hf_ $case>])]
221 - async fn [<roundtrip_ $case _ $fixture>]() -> Result<()> {
222 - [<run_roundtrip_ $fixture>](RoundtripCase::$case()).await
223 - }
224 - )*
217 + #[tokio::test]
218 + #[file_serial([<hf_ $case>])]
219 + async fn [<roundtrip_ $case>]() -> Result<()> {
220 + let case = RoundtripCase::$case();
221 + let backends = load_roundtrip_backends(&case).await?;
222 + $(
223 + $(#[$fixture_attr])*
224 + [<run_roundtrip_ $fixture>](&case, &backends).await?;
225 + )*
226 + Ok(())
227 + }
228 )+
229 }
230 };
@@ -241,18 +244,21 @@ roundtrip_tests! {
244 }
245
246 /// Run the fixed reasoning+content fixture for one model/parser case.
244 -async fn run_roundtrip_reasoning_and_content(case: RoundtripCase) -> Result<()> {
247 +async fn run_roundtrip_reasoning_and_content(
248 + case: &RoundtripCase,
249 + backends: &vllm_chat::LoadedModelBackends,
250 +) -> Result<()> {
251 for thinking in case.thinking_behavior.fixtures() {
246 - run_roundtrip_reasoning_and_content_inner(case.clone(), thinking).await?;
252 + run_roundtrip_reasoning_and_content_inner(case, backends, thinking).await?;
253 }
254 Ok(())
255 }
256
257 async fn run_roundtrip_reasoning_and_content_inner(
252 - case: RoundtripCase,
258 + case: &RoundtripCase,
259 + backends: &vllm_chat::LoadedModelBackends,
260 thinking: Option<bool>,
261 ) -> Result<()> {
255 - let backends = load_roundtrip_backends(&case).await?;
262 let request = roundtrip_request(
263 "roundtrip-reasoning-content",
264 vec![ChatMessage::text(ChatRole::User, "What is 2 + 2?")],
@@ -275,7 +281,7 @@ async fn run_roundtrip_reasoning_and_content_inner(
281 });
282 AssistantMessage { content }
283 };
278 - let result = run_roundtrip(&case, &backends, &request, assistant).await?;
284 + let result = run_roundtrip(case, backends, &request, assistant).await?;
285
286 assert_eq!(
287 result.parsed_message.reasoning().as_deref().map(str::trim),
@@ -293,8 +299,10 @@ async fn run_roundtrip_reasoning_and_content_inner(
299 }
300
301 /// Run the fixed reasoning+multiple-tools fixture for one model/parser case.
296 -async fn run_roundtrip_tool_call_mix(case: RoundtripCase) -> Result<()> {
297 - let backends = load_roundtrip_backends(&case).await?;
302 +async fn run_roundtrip_tool_call_mix(
303 + case: &RoundtripCase,
304 + backends: &vllm_chat::LoadedModelBackends,
305 +) -> Result<()> {
306 let request = roundtrip_request(
307 "roundtrip-reasoning-tools",
308 vec![ChatMessage::text(
@@ -308,8 +316,8 @@ async fn run_roundtrip_tool_call_mix(case: RoundtripCase) -> Result<()> {
316 let expected_text = "I will call the tools.";
317
318 let result = run_roundtrip(
311 - &case,
312 - &backends,
319 + case,
320 + backends,
321 &request,
322 AssistantMessage {
323 content: vec![
@@ -353,12 +361,12 @@ async fn run_roundtrip_tool_call_mix(case: RoundtripCase) -> Result<()> {
361 assert_eq!(tool_calls[0].name, "get_weather");
362 assert_eq!(
363 tool_calls[0].arguments,
356 - expected_arguments(&case, r#"{"location": "Shanghai"}"#)?,
364 + expected_arguments(case, r#"{"location": "Shanghai"}"#)?,
365 );
366 assert_eq!(tool_calls[1].name, "add");
367 assert_eq!(
368 tool_calls[1].arguments,
361 - expected_arguments(&case, r#"{"y": 1.0, "x": 2, "items": ["left", "right"]}"#)?,
369 + expected_arguments(case, r#"{"y": 1.0, "x": 2, "items": ["left", "right"]}"#)?,
370 );
371
372 assert_eq!(