Skip to content
Merged
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
5 changes: 4 additions & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/loopzero/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/loopzero/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
eowca marked this conversation as resolved.
Resolved
return diff.encode("utf-8", errors="surrogateescape")


Expand Down
6 changes: 6 additions & 0 deletions tests/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Exercise the command that diff_since actually emits

The test hand-copies the Git options, so it will still pass if diff_since adds an option that _inspection_commands rejects. Capture the arguments from diff_since and pass their shell-quoted form to the parser so the test catches future drift.

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"
Expand Down
31 changes: 31 additions & 0 deletions tests/test_worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Keep the runner imports at module scope

The inline comment says the local import preserves the shared import block, but this delta edits that block too. Import render_patch and split_diff there and remove the local import and its comment.

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)
Expand Down
Loading