From e5ea698b4273b1e2d6f99a8691ae08ad90892453 Mon Sep 17 00:00:00 2001 From: "Slai.life" Date: Tue, 13 Oct 2026 18:12:31 +0800 Subject: [PATCH] Normalize Linux evaluator patch files on Windows hosts --- launch/core/platforms/linux.py | 11 ++++++++--- tests/runtime_test.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/launch/core/platforms/linux.py b/launch/core/platforms/linux.py index bd87786..8b22d80 100644 --- a/launch/core/platforms/linux.py +++ b/launch/core/platforms/linux.py @@ -26,6 +26,7 @@ import docker from docker.models.containers import Container + class LinuxRuntime(BaseRuntime): def __init__( @@ -205,9 +206,13 @@ def apply_patch(self, patch: str, verbose: bool = False) -> bool: filename = f"{uuid.uuid4()}.diff" hostpath = os.path.join(self.mnt_host, filename) - with open(hostpath, "w") as f: - f.write(patch) - containerpath = os.path.join(self.mnt_container, filename) + # Patch text may originate from a Windows-hosted model output. Keep + # the mounted file UTF-8 and LF-only so Linux git apply sees stable + # patch context bytes inside the evaluation container. + normalized_patch = patch.lstrip("\ufeff").replace("\r\n", "\n").replace("\r", "\n") + with open(hostpath, "w", encoding="utf-8", newline="\n") as f: + f.write(normalized_patch) + containerpath = os.path.join(self.mnt_container, filename) cmd = f"""git apply --reject --whitespace=nowarn {containerpath} """ res = self.send_command(cmd) diff --git a/tests/runtime_test.py b/tests/runtime_test.py index 809ec3d..f4077e6 100644 --- a/tests/runtime_test.py +++ b/tests/runtime_test.py @@ -41,6 +41,7 @@ import os import platform as host_platform +from types import SimpleNamespace import warnings import docker @@ -170,6 +171,26 @@ def test_runtime_constructor_attributes(runtime_cls, expected_attrs, patch_runti +def test_linux_runtime_writes_utf8_lf_patch_without_bom(monkeypatch, tmp_path): + runtime = LinuxRuntime.__new__(LinuxRuntime) + runtime.stopped = True + runtime.mnt_host = str(tmp_path) + runtime.mnt_container = "/mnt_tmp" + + def send_command(command, timeout=None): + return SimpleNamespace(metadata=SimpleNamespace(exit_code=0), output="") + + monkeypatch.setattr(runtime, "send_command", send_command) + patch = "\ufeffdiff --git a/a b/a\r\n--- a/a\r\n+++ b/a\r\n" + assert runtime.apply_patch(patch) is True + + patch_files = list(tmp_path.glob("*.diff")) + assert len(patch_files) == 1 + assert patch_files[0].read_bytes() == ( + b"diff --git a/a b/a\n--- a/a\n+++ b/a\n" + ) + + def supported_integration_platforms() -> set[str]: system = host_platform.system().lower() if system == "windows":