Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions launch/core/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import docker
from docker.models.containers import Container


class LinuxRuntime(BaseRuntime):

def __init__(
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions tests/runtime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import os
import platform as host_platform
from types import SimpleNamespace
import warnings

import docker
Expand Down Expand Up @@ -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":
Expand Down