Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ python3 scripts/canonical_review.py report --check # 0 current, 1 stale. Read-

`record` writes the ledger and rewrites the burn-down together, since a ledger and a report that disagree are two answers about one coverage. Both are tracked, so both have to be committed before the push, [`.husky/pre-push`][pre-push] refusing a tree that differs from HEAD before it runs either gate. The receipt above is not tracked and is recorded after the last commit instead, so the two records sit on opposite sides of it, and recording this one first, then committing it with the change, is the shortest order that satisfies both. `record` binds the digest to the read for `--expect-digest`'s reason above: recording a unit by name alone would stamp whatever the file holds at record time, so an edit between the review and the record would be attested to by a reviewer who never saw it. It refuses an unknown unit, a digest the content has moved past, and a reviewer outside `local_review.py`'s own backend vocabulary, since two spellings of one reviewer make the two records impossible to read together. A pass is recorded whatever it found, including nothing, for the same reason a receipt is: the record says a review ran over exactly this text, never that the text is clean.

Each entry's `hubCommit` is stamped as the merge-base against the target (`--target`, default `develop`) rather than `HEAD`. A branch's own tip is exactly what a squash merge discards and an amend moves, so stamping it leaves the field resolving nowhere once the branch that recorded it is gone. The merge-base is ordinarily a commit the target's remote-tracking ref already holds, so it survives both ([ptr727/ProjectTemplate#1222][hubcommit-issue], [#1210][hubcommit-eight-issue]). A pass recorded before that fix can still name a commit unreachable from wherever a reader's own checkout stands. Those entries are left as recorded rather than rewritten, since inventing a commit for one would fabricate provenance nothing supports. Checking one by hand is `git merge-base --is-ancestor <hubCommit> HEAD`, which exits `0` when it resolves as an ancestor here and nonzero otherwise, whether the object is entirely absent from the checkout or exists but sits off this branch. Because `record` now resolves the target the same way `check` does, an unresolvable target refuses the record too, where naming no target at all previously never could.
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved

The exit code is three-valued on the same contract as its sibling. The boundaries it reports rather than answers are a manifest it cannot read, a ledger it cannot parse, a ledger holding two entries for one unit, a canonical that is not UTF-8, a document carrying two level-two sections of one name, and a target ref that does not resolve. That last one matters more than it looks: every path of an unresolvable ref reads as absent from `git cat-file --batch`, so reading it as a verdict would report a branch that introduced the entire canonical set and demand a pass over all of it.

## `build_dist.py`
Expand Down Expand Up @@ -309,6 +311,8 @@ Installs the fleet's Skills for the current machine, cross-platform and idempote
[governance]: ../GOVERNANCE.md
[host-setup]: ../docs/host-setup.md
[host-tools]: ../spec/host-tools.json
[hubcommit-eight-issue]: https://github.com/ptr727/ProjectTemplate/issues/1210
[hubcommit-issue]: https://github.com/ptr727/ProjectTemplate/issues/1222
[marketplace]: ../.claude-plugin/marketplace.json
[operations]: ../OPERATIONS.md
[pre-push]: ../.husky/pre-push
Expand Down
19 changes: 15 additions & 4 deletions scripts/canonical_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,16 +697,19 @@ def cmd_record(args: argparse.Namespace) -> int:
return EXIT_CANNOT_RUN
ledger = read_ledger(root)
stamp = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
# The hub commit the engine itself ran from, per GOVERNANCE.md "Hub-Hosted Tooling": a verdict carrying no commit cannot be re-run, and two runs that disagree cannot be attributed to the tree or to the tool.
# It locates the tooling rather than the text, since a pass legitimately runs over content that is not committed yet, and the digest above is what locates the text.
head = git("rev-parse", "HEAD", root=root).strip()
# A stable anchor a reader can resolve later, per GOVERNANCE.md "Hub-Hosted Tooling": a verdict carrying no commit cannot be re-run.
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
# It is deliberately not the exact tree the pass read: the digest above locates that text, and checking out this commit can show the unit before this pass's own edit.
# Stamped as the merge-base against the target rather than HEAD: HEAD is this branch's own tip, which a squash merge discards and an amend moves, so either leaves the stamp resolving nowhere on the branch that receives the pass.
# The merge-base is ordinarily a commit the target's remote-tracking ref already holds, so it survives both.
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
# See #1222 and #1210.
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
_, base = resolve_base(args.target, root)
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
for unit, value in wanted.items():
ledger[unit] = {
"unit": unit,
"digest": value,
"reviewer": args.reviewer,
"findings": args.findings,
"hubCommit": head,
"hubCommit": base,
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
"stamp": stamp,
}
write_ledger(root, ledger)
Expand Down Expand Up @@ -877,6 +880,14 @@ def main(argv: list[str] | None = None) -> int:
help="a unit key and the digest the reviewer read, repeatable",
)
p_record.add_argument("--findings", type=int, default=None, help="how many findings it raised")
p_record.add_argument(
"--target",
default=None,
help=(
f"target branch (default {DEFAULT_TARGET})"
", whose merge-base against this branch is stamped as hubCommit"
),
)
p_record.set_defaults(handler=cmd_record)

p_report = sub.add_parser("report", help=f"write {REPORT}")
Expand Down
42 changes: 40 additions & 2 deletions scripts/tests/test_canonical_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,24 @@ def test_an_unresolvable_target_cannot_run_rather_than_reporting_everything_new(
self.assertEqual(code, cr.EXIT_CANNOT_RUN)
self.assertIn("no-such-branch", output)

def test_record_refuses_an_unresolvable_target(self) -> None:
"""`record` now resolves a merge-base against `--target` the same way `check` does, so a
target that does not resolve is a new refusal `record` did not have when it stamped `HEAD`."""
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
code, output = self.loud(
[
"record",
"--reviewer",
"agent-skill",
"--target",
"no-such-branch",
"--unit",
f"DOC.md > Alpha={self.units()['DOC.md > Alpha']}",
]
)
self.assertEqual(code, cr.EXIT_CANNOT_RUN)
self.assertIn("no-such-branch", output)
self.assertFalse((self.tmp / cr.LEDGER).exists(), "a refused record still wrote a ledger")

def test_a_path_holding_a_line_ending_cannot_run(self) -> None:
"""git cat-file --batch is line-delimited, so such a path would shift every later answer
onto the wrong request and read as content rather than as a failure."""
Expand Down Expand Up @@ -499,13 +517,33 @@ def test_recording_twice_keeps_one_entry_per_unit(self) -> None:
self.assertEqual(len(entries), 1)
self.assertEqual(entries["DOC.md > Alpha"]["digest"], self.units()["DOC.md > Alpha"])

def test_a_recorded_pass_names_the_hub_commit_it_ran_from(self) -> None:
"""A verdict carrying no commit cannot be re-run, per GOVERNANCE.md "Hub-Hosted Tooling"."""
def test_a_recorded_pass_names_a_hub_commit(self) -> None:
"""A verdict carrying no commit cannot be re-run, per GOVERNANCE.md "Hub-Hosted Tooling".

The fixture's `task` branch has made no commit of its own yet, so its merge-base against
`origin/develop` and its own `HEAD` are the same commit here. That coincidence is why this
much still holds against `HEAD`. The case where they diverge, and only the merge-base is
what gets stamped, is `test_a_recorded_pass_names_the_merge_base_not_the_branch_tip` below.
"""
self.record("DOC.md > Alpha")
entry = cr.read_ledger(self.tmp)["DOC.md > Alpha"]
self.assertEqual(entry["hubCommit"], run(self.tmp, "rev-parse", "HEAD").strip())
self.assertEqual(entry["reviewer"], "agent-skill")

def test_a_recorded_pass_names_the_merge_base_not_the_branch_tip(self) -> None:
"""A branch's own tip is squashed away on merge and stops resolving. The merge-base against
the target is a commit the target already holds, so it survives the squash. #1222, #1210."""
self.write("DOC.md", "intro\n\n## Alpha\n\nedited\n\n## Beta\n\nb body\n")
run(self.tmp, "add", "-A")
run(self.tmp, "commit", "-m", "advance the branch tip past the merge base")
base = run(self.tmp, "rev-parse", "refs/remotes/origin/develop").strip()
tip = run(self.tmp, "rev-parse", "HEAD").strip()
self.assertNotEqual(base, tip, "the fixture needs a tip that has moved past the base")
self.record("DOC.md > Alpha")
entry = cr.read_ledger(self.tmp)["DOC.md > Alpha"]
self.assertEqual(entry["hubCommit"], base)
self.assertNotEqual(entry["hubCommit"], tip)

def test_record_refuses_a_digest_the_content_has_moved_past(self) -> None:
"""The guard against a format-on-save between the review and the record."""
code, output = self.loud(
Expand Down