Skip to content

The agent that grows with you

fix: round-trip checkpoint path bytes without text translation

Tekniumf8c9e93dadae
diff --git a/tests/tools/test_checkpoint_path_roundtrip.py b/tests/tools/test_checkpoint_path_roundtrip.py
index d3435a1dd5d..9a4cf625ca5 100644
--- a/tests/tools/test_checkpoint_path_roundtrip.py
+++ b/tests/tools/test_checkpoint_path_roundtrip.py
@@ -1,14 +1,27 @@
"""Checkpoint file names must survive Git's machine-readable path output."""
+import os
+
+import pytest
+
from tools import checkpoint_manager as checkpoints
-def test_safe_restore_preserves_exact_paths_and_user_edits(tmp_path, monkeypatch):
+ [" leading.txt", "报告.txt", "ordinary.txt"],
+ pytest.param(
+ [b" raw-\xff.txt", b"carriage\rreturn.txt", b"crlf\r\nname.txt"],
+ marks=pytest.mark.linux_only,
+ id="posix-byte-paths",
+ ),
+])
+def test_safe_restore_preserves_exact_paths_and_user_edits(tmp_path, monkeypatch, names):
+ names = [os.fsdecode(name) for name in names]
monkeypatch.setattr(checkpoints, "CHECKPOINT_BASE", tmp_path / "checkpoints")
work = tmp_path / "project"
work.mkdir()
(work / "AGENTS.md").write_text("Project instructions\n", encoding="utf-8")
- names = [" leading.txt", "报告.txt", "ordinary.txt"]
+
for name in names:
(work / name).write_text("original\n", encoding="utf-8")
preserved = work / " 用户修改.txt"
@@ -33,12 +46,17 @@ def test_safe_restore_preserves_exact_paths_and_user_edits(tmp_path, monkeypatch
assert preserved.read_text(encoding="utf-8") == "user edit\n"
-def test_size_cap_applies_to_leading_space_paths(tmp_path, monkeypatch):
+ " oversized.bin",
+ pytest.param(b" oversized-\xff.bin", marks=pytest.mark.linux_only, id="posix-byte-path"),
+])
+def test_size_cap_applies_to_leading_space_paths(tmp_path, monkeypatch, name):
+ name = os.fsdecode(name)
monkeypatch.setattr(checkpoints, "CHECKPOINT_BASE", tmp_path / "checkpoints")
work = tmp_path / "project"
work.mkdir()
(work / "small.txt").write_text("keep\n", encoding="utf-8")
- name = " oversized.bin"
+
(work / name).write_bytes(b"x" * (1024 * 1024 + 1))
manager = checkpoints.CheckpointManager(enabled=True, max_file_size_mb=1)
assert manager.ensure_checkpoint(str(work))
diff --git a/tools/checkpoint_manager.py b/tools/checkpoint_manager.py
index f3e341845ed..2aa89236e54 100644
--- a/tools/checkpoint_manager.py
+++ b/tools/checkpoint_manager.py
@@ -203,8 +203,14 @@ def _git_env(store: Path, working_dir: str, index_file: Optional[Path] = None) -
def _git_subprocess(cmd: List[str], env: dict, timeout: int, cwd: Optional[str] = None):
# creationflags suppresses the per-call conhost flash on Windows (no-op on POSIX).
- return subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=timeout,
- env=env, cwd=cwd, stdin=subprocess.DEVNULL, creationflags=windows_hide_flags())
+ # Text mode both replaces undecodable path bytes and normalizes CR/CRLF.
+ text_options = {} if "-z" in cmd else {"text": True, "encoding": "utf-8", "errors": "replace"}
+ result = subprocess.run(cmd, capture_output=True, timeout=timeout, **text_options,
+ env=env, cwd=cwd, stdin=subprocess.DEVNULL, creationflags=windows_hide_flags())
+ if "-z" in cmd:
+ result.stdout = os.fsdecode(result.stdout)
+ result.stderr = result.stderr.decode("utf-8", errors="replace")
+ return result
def _repair_bare_repo_dirs(store: Path) -> None: