]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
tests : fix test-jinja-py Windows failures by bypassing command-line args [no ci...
authorMasato Nakasaka <redacted>
Wed, 18 Mar 2026 09:43:31 +0000 (02:43 -0700)
committerGitHub <redacted>
Wed, 18 Mar 2026 09:43:31 +0000 (10:43 +0100)
* Fix errors occurring on Windows

* Reverted fix

#20365 will take care of CRLF isue

* Changed to write to directly to stdin

* Prevent fclose to happen twice

tests/test-jinja.cpp

index 23af1ec8278f96b9b746a977f0653c859978ab97..ef9c8f73c8b99fa7762753b501d185c9f33fde78 100644 (file)
@@ -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,8 +1922,9 @@ 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";
@@ -1930,7 +1932,7 @@ static void test_template_py(testing & t, const std::string & name, const std::s
         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;