From 5a8bb70d46d7b383336d3a123714a7ca178659c5 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:59:47 +0100 Subject: [PATCH 1/4] Review verified base merge resolutions in the available delta Co-Authored-By: Codex --- core/CONTRACT.md | 7 ++-- docs/ARCHITECTURE.md | 4 ++ src/loopzero/cli.py | 50 ++++++++++++---------- src/loopzero/eligibility.py | 46 +++++++++++++++----- tests/test_cli.py | 84 +++++++++++++++++++++++++++++-------- 5 files changed, 137 insertions(+), 54 deletions(-) diff --git a/core/CONTRACT.md b/core/CONTRACT.md index 62aa18b5..ac42bf19 100644 --- a/core/CONTRACT.md +++ b/core/CONTRACT.md @@ -204,9 +204,10 @@ version. Loop-zero serves internal projects only and does not target tamper resistance for outside users. Freeze new work on Codex evidence projections. Simplify or delete them when they break or obstruct delivery. -- One primary and at most one delta per PR. The delta reads only - changes since the primary; unresolved primary findings still count under - Blockers. +- One primary and at most one delta per PR. The delta receives the full patch + from the primary-reviewed commit to the current head, including resolution + edits in merges from the verified base. The reviewed commit must be on the + first-parent history. Unresolved primary findings still count under Blockers. - Default: one writing model family per PR, including delegates and repairs; another may advise read-only and review independently. Before committing imported work, record every actual writing delegate in truthful diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index c7180b3c..bd38b319 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -95,6 +95,10 @@ The [CLI](../src/loopzero/cli.py) implements the contract's the PR-wide cap of one primary and one delta across head rewrites, and the [owner-approved contributor-review exception](../core/CONTRACT.md#owner-approved-contributor-review-exception), which changes neither the selector nor the budget. + The delta requires the reviewed commit on the current head's first-parent + history and verifies merged parents against the live configured base. The + runner receives the full reviewed-to-current tree diff, including manual + merge resolutions. 5. `ready` derives readiness from the current head, its check receipt, an eligible review at that head or an eligible review covering an ancestor, blocking findings, target branch and required CI. The receipt must record a clean passing run diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index f52777d0..992de36b 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -810,11 +810,13 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: candidates = [family for family in config.reviewers if family not in authors] if result.fallback and not _published_fallback(result.fallback, candidates, excluded): raise CliError("saved fallback note is not in the published form; run without --repost") - allowed, _ = _decide_kind( + allowed, reviewed = _decide_kind( _pr_markers(reviews, head, config.review_publishers, repo=config.repo, number=pr.number), head ) if allowed != kind: raise CliError("saved review kind differs from the remaining review budget") + if reviewed is not None: + _verify_delta_history(wt, config, reviewed, head, pr.number) else: try: result = _run_review(wt, config, head, kind, reviewed, args.model, args.effort, @@ -963,12 +965,28 @@ def _confirm_review(wt: Path, config: Config, pr: github.PR, result: ReviewResul return True -def _delta_merge_recovery(wt: Path, reviewed: str, merge: str) -> str: - pre_merge = _git(wt, "rev-parse", f"{merge}^1") - if not _is_ancestor(wt, reviewed, pre_merge): - return f"replay the fixes on the reviewed head {reviewed[:12]}" - return (f"save the current tip on a backup branch, use `git reset --hard {pre_merge}`, " - "and cherry-pick any later fixes from the backup") +def _verify_delta_history(wt: Path, config: Config, since: str, head: str, number: int | None) -> None: + if not _is_ancestor(wt, since, head): + raise CliError( + f"reviewed head {since[:12]} is not an ancestor of this branch. Find the original " + "branch tip with `git reflog`. Save the current tip on a backup branch, then use " + "`git reset --hard ` and replay any later fixes. To publish the restored " + f"head, run `loopzero pr`, then `loopzero review` before merging {config.base_branch}, or open a new PR " + "from the current branch" + ) + if worktree.merges_since(wt, since): + try: + if number is None: + raise eligibility.BaseMergeError("missing PR identity") + with eligibility.base_merge_history(config.repo, number, since, head, config.base_branch): + pass + except eligibility.BaseMergeError as exc: + raise CliError( + f"could not verify merge history since {since[:12]} against {config.base_branch}: {exc}. " + "Restore the branch from the configured base and reviewed first-parent history, " + f"or replay the fixes on the reviewed head {since[:12]}, including resolution edits. " + "Push the recovered head with `loopzero pr` and run `loopzero review`, or open a new PR" + ) from exc def _run_review( @@ -978,22 +996,8 @@ def _run_review( ) -> ReviewResult: lineage_base = _primary_base(wt, config) since = reviewed if kind == "delta" else lineage_base - if kind == "delta" and not _is_ancestor(wt, since, head): - raise CliError( - f"reviewed head {since[:12]} is not an ancestor of this branch. Find the original " - "branch tip with `git reflog`. Save the current tip on a backup branch, then use " - "`git reset --hard ` and replay any later fixes. To publish the restored " - f"head, run `loopzero pr`, then `loopzero review` before merging {config.base_branch}, or open a new PR " - "from the current branch" - ) - if kind == "delta" and (merges := worktree.merges_since(wt, since)): - recovery = _delta_merge_recovery(wt, since, merges[0]) - raise CliError( - f"merge commit {merges[0][:12]} since the reviewed head {since[:12]} would put the " - f"merged-in changes in the delta material. To recover, {recovery}. " - f"To publish the recovered head, run `loopzero pr`, then `loopzero review` " - f"before merging {config.base_branch} again" - ) + if kind == "delta": + _verify_delta_history(wt, config, since, head, publication[1] if publication else None) diff = worktree.diff_since(wt, since) task = worktree.task_text(wt) authors = runners.author_families(wt, head, lineage_base) diff --git a/src/loopzero/eligibility.py b/src/loopzero/eligibility.py index 981c0bed..3cddeb19 100644 --- a/src/loopzero/eligibility.py +++ b/src/loopzero/eligibility.py @@ -9,6 +9,8 @@ import json import re import sys +from collections.abc import Callable, Iterator +from contextlib import contextmanager from pathlib import Path from loopzero import candidate, config, github, runners @@ -87,23 +89,46 @@ def eligible_review(reviews: list[dict], head: str, publishers: tuple[str, ...], return latest if verdict else None -def _clean_base_merges(repo: str, number: int, reviewed: str, head: str, base_branch: str) -> bool: - """Prove each intervening first-parent commit is an unmodified merge from the base.""" +class BaseMergeError(LoopZeroError): + """First-parent history or base provenance could not be established.""" + + +@contextmanager +def base_merge_history( + repo: str, number: int, reviewed: str, head: str, base_branch: str, +) -> Iterator[tuple[Callable[..., str], list[list[str]]]]: + """Verify the first-parent range and each merge's origin against the live PR base.""" try: pr = github.api_get(f"repos/{repo}/pulls/{number}") base = pr["base"]["sha"] if (pr["head"]["sha"] != head or pr["base"]["ref"] != base_branch or not re.fullmatch(r"[0-9a-f]{40}", base)): - return False + raise BaseMergeError("could not verify the configured PR base at this head") with candidate.fetched_git(repo, [reviewed, head, base]) as git: - history = git("rev-list", "--first-parent", "--parents", f"{reviewed}..{head}") + history = [row.split() for row in + git("rev-list", "--first-parent", "--parents", f"{reviewed}..{head}").splitlines()] cursor = head - for row in history.splitlines(): - commits = row.split() - if len(commits) != 3 or commits[0] != cursor: + for commits in history: + if len(commits) not in {2, 3} or commits[0] != cursor: + raise BaseMergeError("unverifiable first-parent history or merge parents") + cursor = commits[1] + if len(commits) == 3: + git("merge-base", "--is-ancestor", commits[2], base) + if cursor != reviewed: + raise BaseMergeError("reviewed head is absent from first-parent history") + yield git, history + except (candidate.CandidateError, github.GhError, KeyError, OSError, TypeError, ValueError) as exc: + raise BaseMergeError(str(exc)) from exc + + +def _clean_base_merges(repo: str, number: int, reviewed: str, head: str, base_branch: str) -> bool: + """Prove each intervening first-parent commit is an unmodified merge from the base.""" + try: + with base_merge_history(repo, number, reviewed, head, base_branch) as (git, history): + for commits in history: + if len(commits) != 3: return False merge, first, second = commits - git("merge-base", "--is-ancestor", second, base) merge_bases = git("merge-base", "--all", first, second).splitlines() # A shallow root outside the known merge bases could hide another base. if git("rev-list", "--max-parents=0", first, second, "--not", *merge_bases): @@ -111,9 +136,8 @@ def _clean_base_merges(repo: str, number: int, reviewed: str, head: str, base_br tree = git("merge-tree", "--write-tree", first, second) if tree != git("rev-parse", f"{merge}^{{tree}}"): return False - cursor = first - return cursor == reviewed - except (candidate.CandidateError, github.GhError, KeyError, OSError, TypeError, ValueError): + return True + except BaseMergeError: return False diff --git a/tests/test_cli.py b/tests/test_cli.py index 28242ab2..39addde0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -180,6 +180,21 @@ def head_of(path: Path) -> str: return git(path, "rev-parse", "HEAD").strip() +@pytest.fixture +def isolated_git(wt, monkeypatch, fake_tool): + """Use real isolated Git fetches against the test worktree.""" + fake_tool("prlimit", "exit 127\n") + popen = subprocess.Popen + + def fetch_from_worktree(argv, **kwargs): + if "fetch" in argv: + argv = [wt.as_uri() if arg == f"https://github.com/{REPO}.git" else arg for arg in argv] + return popen(argv, **kwargs) + + monkeypatch.setenv("GH_TOKEN", "test-token") + monkeypatch.setattr(subprocess, "Popen", fetch_from_worktree) + + @pytest.fixture def head(wt: Path) -> str: return head_of(wt) @@ -1600,36 +1615,71 @@ def test_review_delta_diffs_since_primary(wt: Path, gh: FakeGh, fake_bin: Path, assert marker(head, "delta") in payload["body"] -def test_review_delta_refuses_base_merge_since_primary(wt, repo, gh, fake_bin, capsys) -> None: - reviewed = head_of(wt) # intelflo#8393: primary-reviewed head, a merge of main, the delta - (repo / "upstream.py").write_text("y = 1\n") - git(repo, "add", "upstream.py") - git(repo, "commit", "-q", "-m", "landed on main") - git(wt, "merge", "-q", "--no-edit", "main") - merge = head_of(wt) - git(wt, "commit", "-q", "--allow-empty", "-m", "fix after review") - prepare_review(wt, gh, fake_bin, history=[rev(reviewed, "primary", state="CHANGES_REQUESTED")]) - code, out, err = run(capsys, "review") - assert code != 0 and out == "" and not (fake_bin / "claude.stdin").exists() - assert f"merge commit {merge[:12]} since the reviewed head {reviewed[:12]}" in err - assert f"`git reset --hard {reviewed}`" in err - assert "cherry-pick any later fixes" in err - assert "run `loopzero pr`, then `loopzero review` before merging main again" in err +def conflict_merge(wt, repo): + (wt / "README.md").write_text("branch edit\n") + git(wt, "commit", "-qam", "edit on branch") + reviewed = head_of(wt) + (repo / "README.md").write_text("base edit\n") + (repo / "upstream.py").write_text("upstream = 1\n") + git(repo, "add", "README.md", "upstream.py") + git(repo, "commit", "-qm", "landed on main") + with pytest.raises(subprocess.CalledProcessError) as exc: + git(wt, "merge", "--no-edit", "main") + assert "CONFLICT" in exc.value.stdout + (wt / "README.md").write_text("distinct resolution\n") + git(wt, "commit", "-qam", "resolve base merge") + return reviewed + + +@pytest.mark.parametrize("verified", [True, False]) +def test_review_delta_after_conflict_merge(wt, repo, gh, fake_bin, capsys, isolated_git, verified): + reviewed = conflict_merge(wt, repo) + history = [rev(reviewed, "primary")] + head = prepare_review(wt, gh, fake_bin, history=history) + detail = rest_pr_json(pr_json(headRefOid=head, isDraft=False)) + detail["base"]["sha"] = git(repo, "rev-parse", "main" if verified else "main^").strip() + gh.respond(f"api repos/{REPO}/pulls/7", detail) + + code, _, err = run(capsys, "review") + + if not verified: + assert code == 1 and not (fake_bin / "claude.stdin").exists() + assert "could not verify merge history" in err and "including resolution edits" in err + return + assert code == 0, err + header, diff = (fake_bin / "claude.stdin").read_bytes().split(b"\n", 1) + assert json.loads(header)["head"] == head + assert diff == git(wt, "diff", "--no-color", reviewed, head).strip().encode() + assert b"+distinct resolution" in diff and b"+upstream = 1" in diff + posted = posted_review(gh) + assert posted["commit_id"] == head and marker(head, "delta") in posted["body"] + + exact = rev(head, "delta") + exact["body"] = posted["body"] + for reviews, ready in ((history, False), ([*history, exact], True)): + arm_approved_pr_with_check_result(gh, head, wt, "success", reviews=reviews, isDraft=False) + gh.respond(f"api repos/{REPO}/pulls/7", detail) + assert run(capsys, "ready")[0] == (0 if ready else 1) + assert cli.eligibility.evaluate(REPO, 7, head, "main", (LOGIN,)).ready is ready def test_review_delta_replays_fixes_when_reviewed_head_is_second_parent( - wt: Path, gh: FakeGh, fake_bin: Path, capsys + wt: Path, gh: FakeGh, fake_bin: Path, capsys, isolated_git ) -> None: reviewed = head_of(wt) git(wt, "reset", "--hard", "main") git(wt, "commit", "-q", "--allow-empty", "-m", "independent branch work") git(wt, "merge", "-q", "--no-edit", reviewed) - prepare_review(wt, gh, fake_bin, history=[rev(reviewed, "primary", state="CHANGES_REQUESTED")]) + head = prepare_review(wt, gh, fake_bin, history=[rev(reviewed, "primary", state="CHANGES_REQUESTED")]) + detail = rest_pr_json(pr_json(headRefOid=head)) + detail["base"]["sha"] = reviewed # Even a verified base parent cannot substitute for the first parent. + gh.respond(f"api repos/{REPO}/pulls/7", detail) _fake_codex(fake_bin, json.dumps(APPROVE)) code, _, err = run(capsys, "review") assert code == 1 + assert "absent from first-parent history" in err assert f"replay the fixes on the reviewed head {reviewed[:12]}" in err assert "git reset --hard" not in err assert not (fake_bin / "claude.stdin").exists() From 0b6463e4eba31c345eaa861b9e7890419bd64c80 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:07:11 +0100 Subject: [PATCH 2/4] Reuse the base merge proof within the review size budget Architecture-Review: unchanged; the prior documentation update still describes delta validation and inherited coverage. Co-Authored-By: Codex --- src/loopzero/cli.py | 40 ++++++++++++--------------- src/loopzero/eligibility.py | 54 +++++++++++++------------------------ tests/test_cli.py | 4 +-- 3 files changed, 38 insertions(+), 60 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 69c3216c..da531f19 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -816,8 +816,7 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: ) if allowed != kind: raise CliError("saved review kind differs from the remaining review budget") - if reviewed is not None: - _verify_delta_history(wt, config, reviewed, head, pr.number) + _verify_delta_history(wt, config, reviewed, head, pr.number) else: try: result = _run_review(wt, config, head, kind, reviewed, args.model, args.effort, @@ -966,28 +965,24 @@ def _confirm_review(wt: Path, config: Config, pr: github.PR, result: ReviewResul return True -def _verify_delta_history(wt: Path, config: Config, since: str, head: str, number: int | None) -> None: +def _verify_delta_history(wt: Path, config: Config, since: str | None, head: str, number: int | None) -> None: + if since is None: + return if not _is_ancestor(wt, since, head): raise CliError( - f"reviewed head {since[:12]} is not an ancestor of this branch. Find the original " - "branch tip with `git reflog`. Save the current tip on a backup branch, then use " - "`git reset --hard ` and replay any later fixes. To publish the restored " - f"head, run `loopzero pr`, then `loopzero review` before merging {config.base_branch}, or open a new PR " - "from the current branch" + f"reviewed head {since[:12]} is not an ancestor of this branch. Find the original tip with `git reflog`. " + "Back up your branch, reset to that tip and replay later fixes. To publish the restored head, " + f"run `loopzero pr`, then `loopzero review` before merging {config.base_branch}, or open a new PR" + ) + if worktree.merges_since(wt, since) and (number is None or not eligibility.verified_base_merges( + config.repo, number, since, head, config.base_branch, clean=False, + )): + raise CliError( + f"could not verify merge history: {since[:12]} must be on the first-parent history and " + f"merged parents must come from {config.base_branch}. Save your work, then replay the fixes " + f"on the reviewed head {since[:12]}, including resolution edits. Push with `loopzero pr` " + "and run `loopzero review`, or open a new PR" ) - if worktree.merges_since(wt, since): - try: - if number is None: - raise eligibility.BaseMergeError("missing PR identity") - with eligibility.base_merge_history(config.repo, number, since, head, config.base_branch): - pass - except eligibility.BaseMergeError as exc: - raise CliError( - f"could not verify merge history since {since[:12]} against {config.base_branch}: {exc}. " - "Restore the branch from the configured base and reviewed first-parent history, " - f"or replay the fixes on the reviewed head {since[:12]}, including resolution edits. " - "Push the recovered head with `loopzero pr` and run `loopzero review`, or open a new PR" - ) from exc def _run_review( @@ -997,8 +992,7 @@ def _run_review( ) -> ReviewResult: lineage_base = _primary_base(wt, config) since = reviewed if kind == "delta" else lineage_base - if kind == "delta": - _verify_delta_history(wt, config, since, head, publication[1] if publication else None) + _verify_delta_history(wt, config, reviewed, head, publication[1] if publication else None) diff = worktree.diff_since(wt, since) task = worktree.task_text(wt) authors = runners.author_families(wt, head, lineage_base) diff --git a/src/loopzero/eligibility.py b/src/loopzero/eligibility.py index 3cddeb19..73f6f847 100644 --- a/src/loopzero/eligibility.py +++ b/src/loopzero/eligibility.py @@ -9,8 +9,6 @@ import json import re import sys -from collections.abc import Callable, Iterator -from contextlib import contextmanager from pathlib import Path from loopzero import candidate, config, github, runners @@ -89,46 +87,32 @@ def eligible_review(reviews: list[dict], head: str, publishers: tuple[str, ...], return latest if verdict else None -class BaseMergeError(LoopZeroError): - """First-parent history or base provenance could not be established.""" - - -@contextmanager -def base_merge_history( - repo: str, number: int, reviewed: str, head: str, base_branch: str, -) -> Iterator[tuple[Callable[..., str], list[list[str]]]]: - """Verify the first-parent range and each merge's origin against the live PR base.""" +def verified_base_merges( + repo: str, number: int, reviewed: str, head: str, base_branch: str, *, clean: bool, +) -> bool: + """Prove base provenance, requiring unmodified base merges alone for inheritance.""" try: pr = github.api_get(f"repos/{repo}/pulls/{number}") base = pr["base"]["sha"] if (pr["head"]["sha"] != head or pr["base"]["ref"] != base_branch or not re.fullmatch(r"[0-9a-f]{40}", base)): - raise BaseMergeError("could not verify the configured PR base at this head") + return False with candidate.fetched_git(repo, [reviewed, head, base]) as git: - history = [row.split() for row in - git("rev-list", "--first-parent", "--parents", f"{reviewed}..{head}").splitlines()] + history = git("rev-list", "--first-parent", "--parents", f"{reviewed}..{head}") cursor = head - for commits in history: + for row in history.splitlines(): + commits = row.split() if len(commits) not in {2, 3} or commits[0] != cursor: - raise BaseMergeError("unverifiable first-parent history or merge parents") - cursor = commits[1] - if len(commits) == 3: - git("merge-base", "--is-ancestor", commits[2], base) - if cursor != reviewed: - raise BaseMergeError("reviewed head is absent from first-parent history") - yield git, history - except (candidate.CandidateError, github.GhError, KeyError, OSError, TypeError, ValueError) as exc: - raise BaseMergeError(str(exc)) from exc - - -def _clean_base_merges(repo: str, number: int, reviewed: str, head: str, base_branch: str) -> bool: - """Prove each intervening first-parent commit is an unmodified merge from the base.""" - try: - with base_merge_history(repo, number, reviewed, head, base_branch) as (git, history): - for commits in history: - if len(commits) != 3: return False + cursor = commits[1] + if len(commits) == 2: + if clean: + return False + continue merge, first, second = commits + git("merge-base", "--is-ancestor", second, base) + if not clean: + continue merge_bases = git("merge-base", "--all", first, second).splitlines() # A shallow root outside the known merge bases could hide another base. if git("rev-list", "--max-parents=0", first, second, "--not", *merge_bases): @@ -136,8 +120,8 @@ def _clean_base_merges(repo: str, number: int, reviewed: str, head: str, base_br tree = git("merge-tree", "--write-tree", first, second) if tree != git("rev-parse", f"{merge}^{{tree}}"): return False - return True - except BaseMergeError: + return cursor == reviewed + except (candidate.CandidateError, github.GhError, KeyError, OSError, TypeError, ValueError): return False @@ -172,7 +156,7 @@ def readiness_review(reviews: list[dict], head: str, publishers: tuple[str, ...] return None elif not (verdict.startswith("approve** (") and state in {"APPROVED", "COMMENTED"}): return None - if not _clean_base_merges(repo, number, reviewed, head, base_branch): + if not verified_base_merges(repo, number, reviewed, head, base_branch, clean=True): return None return latest diff --git a/tests/test_cli.py b/tests/test_cli.py index 3ab23cb7..69094262 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1762,8 +1762,8 @@ def test_review_delta_replays_fixes_when_reviewed_head_is_second_parent( code, _, err = run(capsys, "review") assert code == 1 - assert "absent from first-parent history" in err - assert f"replay the fixes on the reviewed head {reviewed[:12]}" in err + assert f"{reviewed[:12]} must be on the first-parent history" in err + assert f"on the reviewed head {reviewed[:12]}, including resolution edits" in err assert "git reset --hard" not in err assert not (fake_bin / "claude.stdin").exists() assert not (fake_bin / "codex.stdin").exists() From 7b9c73c482da53c825860b29e624ba2620b183ff Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:32:40 +0100 Subject: [PATCH 3/4] Keep saved review validation within the complexity budget Architecture-Review: unchanged; the no-delta check moves inside delta patch construction. Co-Authored-By: Codex --- src/loopzero/cli.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 290c34cf..5aaacd8a 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -834,8 +834,7 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: ) if allowed != kind: raise CliError("saved review kind differs from the remaining review budget") - if reviewed is not None: - _delta_patch(wt, config, reviewed, head, pr.number) + _delta_patch(wt, config, reviewed, head, pr.number) else: try: result = _run_review(wt, config, head, kind, reviewed, args.model, args.effort, @@ -986,7 +985,9 @@ def _confirm_review(wt: Path, config: Config, pr: github.PR, result: ReviewResul return True -def _delta_patch(wt: Path, config: Config, since: str, head: str, number: int | None) -> bytes: +def _delta_patch(wt: Path, config: Config, since: str | None, head: str, number: int | None) -> bytes: + if since is None: + return b"" if not _is_ancestor(wt, since, head): raise CliError( f"reviewed head {since[:12]} is not an ancestor of this branch. Find the original tip with `git reflog`. " From 595b57fcbcb1eddf7131cea403d0da16264c0f39 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:36:21 +0100 Subject: [PATCH 4/4] Keep submodule pointer changes in merge deltas Architecture-Review: unchanged; the delta retains pointer changes just as the ordinary diff does. Co-Authored-By: Codex --- src/loopzero/eligibility.py | 3 ++- tests/test_cli.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/loopzero/eligibility.py b/src/loopzero/eligibility.py index f787db50..51ae5460 100644 --- a/src/loopzero/eligibility.py +++ b/src/loopzero/eligibility.py @@ -135,7 +135,8 @@ def base_merge_material( if clean: return b"" patch = git("log", "--first-parent", "--reverse", "--remerge-diff", "-p", "--format=", - "--no-ext-diff", "--no-textconv", "--text", "--submodule=short", + "--no-color", "--no-ext-diff", "--no-textconv", "--text", + "--ignore-submodules=none", "--submodule=short", f"{reviewed}..{head}", preserve_newlines=True) return patch.encode("utf-8", errors="surrogateescape") except (candidate.CandidateError, github.GhError, KeyError, OSError, TypeError, ValueError): diff --git a/tests/test_cli.py b/tests/test_cli.py index 7b4b58d2..e2772b0a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1866,6 +1866,9 @@ def conflict_merge(wt, repo): @pytest.mark.parametrize("verified", [True, False]) def test_review_delta_after_conflict_merge(wt, repo, gh, fake_bin, capsys, isolated_git, verified): reviewed = conflict_merge(wt, repo) + (wt / ".gitmodules").write_text('[submodule "dep"]\npath = dep\nurl = ../dep\nignore = all\n') + git(wt, "add", ".gitmodules") + git(wt, "update-index", "--add", "--cacheinfo", f"160000,{reviewed},dep") commit_file(wt, "topic.py", "topic = 2\n", "topic repair") history = [rev(reviewed, "primary")] head = prepare_review(wt, gh, fake_bin, history=history) @@ -1883,7 +1886,7 @@ def test_review_delta_after_conflict_merge(wt, repo, gh, fake_bin, capsys, isola header, diff = (fake_bin / "claude.stdin").read_bytes().split(b"\n", 1) assert json.loads(header)["head"] == head assert b"+distinct resolution" in diff and b"+topic = 2" in diff and b"upstream.py" not in diff - assert diff.endswith(b"+topic = 2\n") + assert f"+Subproject commit {reviewed}".encode() in diff and diff.endswith(b"+topic = 2\n") posted = posted_review(gh) assert posted["commit_id"] == head and marker(head, "delta") in posted["body"]