Skip to content

Windows: C++ minja outputs fewer newlines than Python Jinja2 #16

@ochafik

Description

@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.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:

  1. Add diagnostic output to the test to print exact bytes on Windows CI
  2. Trace through the template parser to find where the newline is lost
  3. Check if std::regex or file reading behaves differently on Windows

/cc @ochafik

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions