Repository navigation
Preserve carriage returns in review diffs #1140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,6 +250,52 @@ def repo(tmp_path): | |
| # ----------------------------------------------------------------- prompt | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("legacy_encoding", [False, True]) | ||
| def test_committed_diff_preserves_git_bytes_for_native_evidence(git_repo, legacy_encoding): | ||
| import subprocess | ||
|
|
||
| from loopzero import runners, worktree | ||
|
|
||
| from .conftest import git | ||
|
|
||
| git(git_repo, "config", "core.autocrlf", "false") | ||
| path = git_repo / "README.md" | ||
| if legacy_encoding: | ||
| path.write_bytes(b"caf\xe9\n") | ||
| git(git_repo, "commit", "-am", "add Latin-1 text") | ||
| base = worktree.head(git_repo) | ||
| path.write_bytes(b"caf\xe8\r\n" if legacy_encoding else b"hello\r\n") | ||
| git(git_repo, "commit", "-am", "change line endings") | ||
| head = worktree.head(git_repo) | ||
| native = subprocess.check_output(["git", "diff", "--no-color", base, head], cwd=git_repo) | ||
| patch = worktree.diff_since(git_repo, base) | ||
| assert patch == native | ||
| diff = runners.render_patch(patch) | ||
| prompt = runners.build_prompt(kind="primary", head=head, task_text="", diff=diff) | ||
| if legacy_encoding: | ||
| assert "-caf\\xe9\n+caf\\xe8\r\n" in prompt | ||
| else: | ||
| assert b"-hello\n+hello\r\n" in native | ||
| assert prompt.split("\n", 1)[1].encode() == native | ||
| context = { | ||
| "cwd": str(git_repo), "head": head, "base": base, | ||
| "diff_sha256": hashlib.sha256(patch).hexdigest(), "diff_bytes": len(patch), | ||
| } | ||
| command = f"git -C {git_repo} rev-parse HEAD && git -C {git_repo} diff --no-color {base} {head}" | ||
| item = {"type": "command_execution", "id": "read-1", "command": command} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Native-inspection check uses a hand-built output, not real Codex output The test builds |
||
| output = head + "\n" + native.decode(errors="replace") | ||
| events = [ | ||
| {"type": "item.started", "item": item}, | ||
| {"type": "item.completed", | ||
| "item": dict(item, status="completed", exit_code=0, aggregated_output=output)}, | ||
| ] | ||
| inspection = runners._native_inspection({"events": events}, context) | ||
| if legacy_encoding: | ||
| assert not inspection | ||
| else: | ||
| assert inspection["diff_event"]["end"] == len(output) | ||
|
|
||
|
|
||
| def test_prompt_frames_exact_task_and_raw_diff() -> None: | ||
| prompt = build_prompt(kind="delta", head="deadbeef", task_text=" Objective ", diff="+line\n") | ||
| header, diff = prompt.split("\n", 1) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
preserve_newlinesswitches to binary I/O and strict decoding; the name only says newlinesThe flag does three things: it turns off newline translation, makes stdout decoding strict (raising
UnicodeDecodeErrorout ofrun), and changes stderr's default encoding from the locale to UTF-8. Any future caller that sets it to keep CRs will also get the strict-decode exception, whichrun's other callers don't expect. A clearer name such asexact_stdout/raw_utf8, or a docstring line sayingrunmay raiseUnicodeDecodeError, would make this explicit. Also, the stdin encoding branch at line 82 is never used, since the only caller passes no input. Removing it would keep the shim smaller.