Summary
On Windows, C++ minja produces output with one fewer newline than Python Jinja2 for certain templates, specifically around blank lines.
Reproduction
The zai-org/GLM-4.6 template with tool_use context fails on Windows:
- Expected (Python Jinja2):
# Tools\n\nYou may call... (blank line)
- Actual (C++ minja):
# Tools\nYou may call... (no blank line)
The test passes on macOS and Linux.
Investigation
- Template from HuggingFace has pure LF line endings (
0a 0a = \n\n)
- No CRLF (
\r\n) in the source template
- The
normalize_newlines() function correctly handles CRLF→LF conversion
- The issue appears to be Windows-specific behavior in either:
- Template parsing
std::regex behavior
- File I/O handling
Current Workaround
tests/test-supported-template.cpp uses collapse_blank_lines() on Windows to normalize consecutive newlines before comparison. This masks the real difference but allows CI to pass.
Next Steps
To properly debug this, we need to:
- Add diagnostic output to the test to print exact bytes on Windows CI
- Trace through the template parser to find where the newline is lost
- Check if
std::regex or file reading behaves differently on Windows
/cc @ochafik
Summary
On Windows, C++ minja produces output with one fewer newline than Python Jinja2 for certain templates, specifically around blank lines.
Reproduction
The
zai-org/GLM-4.6template withtool_usecontext fails on Windows:# Tools\n\nYou may call...(blank line)# Tools\nYou may call...(no blank line)The test passes on macOS and Linux.
Investigation
0a 0a=\n\n)\r\n) in the source templatenormalize_newlines()function correctly handles CRLF→LF conversionstd::regexbehaviorCurrent Workaround
tests/test-supported-template.cppusescollapse_blank_lines()on Windows to normalize consecutive newlines before comparison. This masks the real difference but allows CI to pass.Next Steps
To properly debug this, we need to:
std::regexor file reading behaves differently on Windows/cc @ochafik