test(error_classifier): cover Qwen applyPromptTemplate vs llama.cpp grammar

Add regressions for the Discord-shaped applyPromptTemplate 400 that embeds
"No user query found", bare no-user-query on a large session, and the genuine
llama.cpp unable-to-generate-parser grammar path that must stay recoverable.
This commit is contained in:
xxxigm
2026-08-12 23:24:52 +07:00
committed by kshitij
parent a768a6c1a2
commit 847cc47cdb
+46
View File
@@ -483,9 +483,55 @@ class TestClassifyApiError:
# ── Provider-specific: llama.cpp grammar-parse ──
def test_llama_cpp_unable_to_generate_parser_template(self):
e = MockAPIError(
"Unable to generate parser for this template. "
"Automatic parser generation failed: error parsing grammar",
status_code=400,
)
result = classify_api_error(e, provider="custom", model="local-llama")
assert result.reason == FailoverReason.llama_cpp_grammar_pattern
assert result.retryable is True
assert result.should_compress is False
def test_qwen_apply_prompt_template_no_user_query_not_llama_cpp_grammar(self):
"""Local engines wrap Qwen raise_exception as applyPromptTemplate 400.
Must NOT classify as llama_cpp_grammar_pattern (which strips tool
schema keywords and retries). Fail fast as format_error so the user
sees a request-shape failure instead of a misleading template/parser
loop — typical after context overflow + failed compression.
"""
e = MockAPIError(
"Engine protocol applyPromptTemplate request returned 400: "
'{"error":{"code":400,"message":"Unable to generate parser for '
"this template. Automatic parser generation failed: "
"While executing CallExpression ... multi_step_tool %} "
"{{- raise_exception('No user query found in messages')",
status_code=400,
)
result = classify_api_error(
e,
provider="custom",
model="qwen/qwen3.6-35b-a3b",
approx_tokens=226_000,
context_length=100_864,
)
assert result.reason == FailoverReason.format_error
assert result.retryable is False
assert result.should_compress is False
assert result.should_fallback is True
def test_bare_no_user_query_found_is_format_error_even_on_large_session(self):
e = MockAPIError("No user query found in messages", status_code=400)
result = classify_api_error(
e,
approx_tokens=226_000,
context_length=100_864,
)
assert result.reason == FailoverReason.format_error
assert result.retryable is False
assert result.should_compress is False
# ── Provider-specific: Anthropic long-context tier ──