diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index c474e6e7..bf8ae655 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -185,7 +185,10 @@ commit identity stays in the JSON material header. Explicit UTF-8 stdin carries that header, a newline and the Git patch, including carriage returns and the final newline. UTF-8 patches are supplied verbatim. For other patches, the prompt escapes invalid bytes and literal backslashes so the changes stay -visible. The native inspection digest always binds the original Git bytes. +visible. The native inspection digest always binds the original Git bytes. Git forces +text hunks for every file (overriding `-diff`, `binary` and NUL detection) and +runs no external diff command or text conversion, so changed lines stay visible. +Chunked review summarizes only files whose Git header reports a deletion. The runner probes the selected Codex binary with `--version` and records its stdout in runner provenance and the saved review receipt. A failed probe uses RunnerBadOutput and existing family fallback before model input. Successful diff --git a/src/loopzero/runners.py b/src/loopzero/runners.py index 1fe9390a..340948c5 100644 --- a/src/loopzero/runners.py +++ b/src/loopzero/runners.py @@ -799,7 +799,8 @@ def _inspection_commands(command, cwd): args = [ part for part in group[1:] - if part not in {"--no-color", "--no-ext-diff", "--no-textconv"} + if part not in {"--no-color", "--no-ext-diff", "--no-textconv", "--text", + "--ignore-submodules=none", "--submodule=short"} ] if len(args) != 2 or not all(_hex(part, 40) for part in args): return [] @@ -1399,7 +1400,8 @@ def split_diff(diff: str, budget: int) -> list[str]: def _summarize_deleted(block: str) -> str: - if "\ndeleted file mode " not in block and "\n+++ /dev/null" not in block: + # Judge deletion from git's header lines only; hunk lines are the PR's own text. + if not re.search(r"(?m)^deleted file mode [0-7]{6}$", block.partition("\n@@")[0]): return block header = block.partition("\n")[0] match = re.fullmatch(r'diff --git ("?)a/(.*)\1 \1b/\2\1', header) diff --git a/src/loopzero/worktree.py b/src/loopzero/worktree.py index 008a7cde..aeffefda 100644 --- a/src/loopzero/worktree.py +++ b/src/loopzero/worktree.py @@ -250,7 +250,10 @@ def is_dirty(wt: Path) -> bool: def diff_since(wt: Path, sha: str) -> bytes: - diff = _git(Path(wt), "diff", "--no-color", sha, "HEAD", preserve_newlines=True) + # Show every file as text, whatever attributes or NUL bytes the reviewed head adds, + # without diff drivers, and keep submodule pointers even if .gitmodules ignores them. + diff = _git(Path(wt), "diff", "--no-color", "--no-ext-diff", "--no-textconv", "--text", + "--ignore-submodules=none", "--submodule=short", sha, "HEAD", preserve_newlines=True) return diff.encode("utf-8", errors="surrogateescape") diff --git a/tests/test_runners.py b/tests/test_runners.py index 6b864ba9..efbe346f 100644 --- a/tests/test_runners.py +++ b/tests/test_runners.py @@ -1186,6 +1186,12 @@ def timeout(*args, **kwargs): assert len(detail.splitlines()[-1]) <= runners.TAIL_CHARS and "waiting for proxy" not in fallback +def test_inspection_accepts_the_reviewer_patch_command() -> None: + command = (f"git -C /repo diff --no-color --no-ext-diff --no-textconv --text " + f"--ignore-submodules=none --submodule=short {'a' * 40} {'b' * 40}") + assert runners._inspection_commands(command, "/repo") == [("diff", "a" * 40, "b" * 40)] + + def test_split_diff_respects_budget_and_summarizes_deleted_file() -> None: deleted = ( "diff --git a/gone.py b/gone.py\n" diff --git a/tests/test_worktree.py b/tests/test_worktree.py index 1d5ee7ce..409267fd 100644 --- a/tests/test_worktree.py +++ b/tests/test_worktree.py @@ -205,6 +205,37 @@ def test_start_reports_git_failure_with_command(repo: Path) -> None: assert info.value.tail +def _commit_files(repo: Path, files: dict[str, bytes | None]) -> str: + for name, content in files.items(): + (repo / name).write_bytes(content) if content is not None else (repo / name).unlink() + git(repo, "add", "-A", "--", *files) + git(repo, "commit", "-q", "-m", "change") + return git(repo, "rev-parse", "HEAD").strip() + + +def test_diff_since_shows_changes_the_reviewed_files_try_to_hide(git_repo: Path) -> None: + base = _commit_files(git_repo, {"attr.py": b"old\n", "nul.py": b"old\n"}) + git(git_repo, "update-index", "--add", "--cacheinfo", f"160000,{base},a-sub") + _commit_files(git_repo, { + ".gitattributes": b"attr.py -diff\nnul.py binary\n", "attr.py": b"new = 'attr hunk'\n", + "nul.py": b"new = 'nul hunk'\x00\n", "image.png": b"\x89PNG\r\n\x1a\n\x00\xff\xfe", + ".gitmodules": b'[submodule "a-sub"]\n\tpath = a-sub\n\tignore = all\n'}) + diff = worktree.diff_since(git_repo, base) + assert b"Binary files" not in diff and f"+Subproject commit {base}".encode() in diff + assert b"+new = 'attr hunk'" in diff and b"+new = 'nul hunk'\x00" in diff and b"+\x89PNG\r" in diff + + +def test_split_diff_summarizes_only_files_git_reports_deleted(git_repo: Path) -> None: + from loopzero.runners import render_patch, split_diff # keeps the shared import block untouched + base = _commit_files(git_repo, {"gone.py": b"old\n", "padded.py": b"old\n", "carriage.py": b"old\n"}) + _commit_files(git_repo, {"gone.py": None, "padded.py": b"new = 'padded hunk'\n++ /dev/null\n" + b"x\n" * 300, + "carriage.py": b"new \rdiff --git a/carriage.py b/carriage.py\rdeleted file mode 100644\r" + + b"y\n" * 300}) + joined = "".join(split_diff(render_patch(worktree.diff_since(git_repo, base)), 1_000)) + assert "+++ /dev/null" in joined and "+new = 'padded hunk'" in joined and "+new \r" in joined + assert "gone.py: deleted, 1 lines" in joined and joined.count(": deleted, ") == 1 + + def test_dirty_head_and_diff(repo: Path) -> None: wt = worktree.start(repo, "work", "main") base = worktree.base_sha(wt)