Repository: ggml-org/llama.cpp
Pull request: tests: Fix test-jinja-py Windows failures by bypassing command-line args

Current `test-jinja-py` execution on Windows show 12 failures which is caused by two issues:

1. JSON string is first converted to ANSI code page on Windows causing misinterpretation in python side.

```
  ASSERTION FAILED : Template render mismatch
    Template: "{{ data|tojson(ensure_ascii=true) }}"
    Expected: "\"\\u2713\""
    Python  : "\"\\u00e2\\u0153\\u201c\""
```
1. Expected output is assuming LF for new line where Windows defaults to CRLF.

```
  ASSERTION FAILED : Template render mismatch
    Template: "{% if true %}\nhello\n{% endif %}\n"
    Expected: "hello\n"
    Python  : "hello\r\n"

```

This PR fixes the first issue while #20365 addresses the second issue.

Full log with the 12 failures is the following:
[test-jinja-py_log_57819b8d.txt](https://github.com/user-attachments/files/25963521/test-jinja-py_log_57819b8d.txt)



Changed files:
filename: tests/test-jinja.cpp
patch: @@ -1897,8 +1897,9 @@ import sys
 from datetime import datetime
 from jinja2.sandbox import SandboxedEnvironment
 
-tmpl = json.loads(sys.argv[1])
-vars_json = json.loads(sys.argv[2])
+merged_input = json.loads(sys.stdin.buffer.read().decode("utf-8"))
+tmpl = merged_input["tmpl"]
+vars_json = merged_input["vars"]
 
 env = SandboxedEnvironment(
     trim_blocks=True,
@@ -1921,16 +1922,17 @@ sys.stdout.buffer.write(result.encode())
 static void test_template_py(testing & t, const std::string & name, const std::string & tmpl, const json & vars, const std::string & expect) {
     t.test(name, [&tmpl, &vars, &expect](testing & t) {
         // Prepare arguments
-        std::string tmpl_json = json(tmpl).dump();
-        std::string vars_json = vars.dump();
+        json merged;
+        merged["tmpl"] = json(tmpl);
+        merged["vars"] = vars;
 
 #ifdef _WIN32
         const char * python_executable = "python.exe";
 #else
         const char * python_executable = "python3";
 #endif
 
-        const char * command_line[] = {python_executable, "-c", py_script.c_str(), tmpl_json.c_str(), vars_json.c_str(), NULL};
+        const char * command_line[] = {python_executable, "-c", py_script.c_str(), NULL};
 
         struct subprocess_s subprocess;
         int options = subprocess_option_combined_stdout_stderr
@@ -1944,6 +1946,20 @@ static void test_template_py(testing & t, const std::string & name, const std::s
             t.assert_true("subprocess creation", false);
             return;
         }
+        FILE * p_stdin = subprocess_stdin(&subprocess);
+
+        // Write input
+        std::string input = merged.dump();
+        auto written = fwrite(input.c_str(), 1, input.size(), p_stdin);
+        if (written != input.size()) {
+            t.log("Failed to write complete input to subprocess stdin");
+            t.assert_true("subprocess stdin write", false);
+            subprocess_destroy(&subprocess);
+            return;
+        }
+        fflush(p_stdin);
+        fclose(p_stdin); // Close stdin to signal EOF to the Python process
+        subprocess.stdin_file = nullptr;
 
         // Read output
         std::string output;