review: docs section, 1 MiB grammar pre-check, negative tests, measured compile overhead

Addresses the #192 review: server usage documented in docs/grammar-draft.md
(incl. back-compat statement for the additive SUBMIT field and the #100-class
near-tie caveat); gateway pre-checks grammar payloads at 1 MiB (matching the
engine's gbytes bound); negative tests for non-dict response_format, empty and
oversized grammars, plus an explicit test that malformed GBNF passes the
gateway by design (engine fail-soft, draft-source semantics). Measured compile
overhead: 7.8 us/request typical schema, 17.9 us at the 32-level nesting cap.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
FABIOTESS
2026-07-14 15:44:17 +01:00
parent d7b855f43f
commit 84514a5f39
3 changed files with 37 additions and 0 deletions
+10
View File
@@ -99,6 +99,16 @@ class TemplateTest(unittest.TestCase):
generation_options({"response_format": {"type": "yaml"}}, 8)
with self.assertRaises(APIError):
generation_options({"response_format": {"type": "json_schema", "json_schema": {}}}, 8)
with self.assertRaises(APIError): # non-dict response_format
generation_options({"response_format": "json"}, 8)
with self.assertRaises(APIError): # empty gbnf
generation_options({"response_format": {"type": "gbnf", "grammar": " "}}, 8)
with self.assertRaises(APIError): # oversized grammar (> 1 MiB pre-check)
generation_options({"response_format": {"type": "gbnf", "grammar": "x" * ((1 << 20) + 1)}}, 8)
# malformed GBNF passes the gateway by design: the ENGINE fail-softs it
# (draft source only — bad grammar costs the speedup, never the request)
opts = generation_options({"response_format": {"type": "gbnf", "grammar": "not a grammar ::="}}, 8)
self.assertEqual(opts[3], "not a grammar ::=")
class ProtocolTest(unittest.TestCase):