fix(dsl): add JSON double-quotes to string literals inside container types#1821
fix(dsl): add JSON double-quotes to string literals inside container types#1821giulio-leone wants to merge 2 commits intodottxt-ai:mainfrom
Conversation
737936a to
d98d45e
Compare
|
Friendly ping — CI is green and this is ready for review. Happy to address any feedback. Thanks! |
d98d45e to
a28d431
Compare
RobinPicard
left a comment
There was a problem hiding this comment.
Thanks for opening a PR. The update of the uv.lock seems accidental, let's remove it. Also, I think we need unit tests to be sure the fix proposed actually works, there are a bunch of edge cases that should be covered.
Add _ensure_json_quoted helper that wraps bare String terms in double-quote delimiters when they appear inside container types (List, Tuple, Dict). This ensures Literal and Enum string values produce valid JSON-matching regexes. Remove accidental uv.lock changes. Add comprehensive unit tests for _ensure_json_quoted and its integration with _handle_list, _handle_tuple, and _handle_dict. Refs: dottxt-ai#1630
a28d431 to
4a7851c
Compare
|
Hi @RobinPicard — both items addressed:
Ready for re-review! |
|
Hi! Gentle ping — this PR is rebased, CI passes, and ready for review. Happy to address any feedback. Thanks! |
Add 10 additional tests covering edge cases per reviewer request: - Sequence/Regex passthrough (already structured terms unchanged) - Single-variant Literal in list - Dict with literal string values (not just keys) - Variable-length Tuple (ellipsis) with Literal - Boolean/int types unchanged in containers - Nested Alternatives recursion - Literal strings with special characters (spaces, punctuation) All 42 DSL tests pass. Signed-off-by: Giulio Leone <6887247+giulio-leone@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks for the review @RobinPicard!
Unit tests: Added 10 additional edge-case tests (total of 17 new tests covering
All 42 DSL tests pass locally on Python 3.13. |
|
@RobinPicard I've addressed both review items:
All 42 tests pass. Ready for re-review! |
Summary
Fixes #1630
String literal values from
Literal[]andEnuminside container types (List,Tuple,Dict) were emitted as bare words in the generated regex. This made the output inconsistent with howList[str]works (which correctly produces quoted JSON strings).Problem
Fix
Add
_ensure_json_quoted()helper that wraps bareStringterms in double-quote delimiters. Applied in_handle_list,_handle_tuple, and_handle_dict.Design decisions
Stringinstances are quoted —Regexterms (liketypes.string) already include their own patterns and are left unchangedLiteralis unaffected —Literal['Paris', 'London']still produces(Paris|London)without quotesList[Literal['a', 1]]produces("a"|(1))(only the string value is quoted)List[MyEnum]where members are strings gets proper quotingTests
All existing tests pass (26 DSL tests + 2 to_regex tests).