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
20 changes: 15 additions & 5 deletions scripts/handoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
Exit codes
0 the command did what it says.
1 a refusal the caller can act on: the label is missing from the repository, no handoff is
open on the track, a track is ambiguous, an open handoff carries no metadata block, a body
is over the hard cap, or the command line itself was wrong. A usage error is a refusal, so
open on the track, a track is ambiguous, a handoff carries no metadata block, a body is
over the hard cap, or the command line itself was wrong. A usage error is a refusal, so
`Parser` below moves it here off argparse's own 2.
2 the command did not run to an answer: `gh` failed, a write did not confirm, or an exception
nobody modeled reached the top. A refusal and a failure to reach one never share a code,
Expand Down Expand Up @@ -838,6 +838,7 @@ def successor_of(repo: str, track: str, number: int, ignore: int) -> dict | None
"link at it would fork the chain there unseen."
)
unreadable: list[str] = []
bare: list[str] = []
for row in [*open_handoffs(repo), *closed]:
if row["number"] == ignore:
continue
Expand All @@ -848,12 +849,21 @@ def successor_of(repo: str, track: str, number: int, ignore: int) -> dict | None
except Refusal as exc:
unreadable.append(str(exc))
continue
if marker and marker["track"] == track and marker["previous"] == str(number):
if marker is None:
# `newest_closed` holds these two to be the same hazard, and so does this.
# An absent block leaves what the link succeeds unknown, as an unreadable one does.
# Reading either as "not the successor" is a guess.
bare.append(
f"#{row['number']} carries the `{LABEL}` label and no metadata block, so what it "
"succeeds cannot be read. Add one to its body by hand, or take the label off it."
)
continue
if marker["track"] == track and marker["previous"] == str(number):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
row["marker"] = marker
return row
if unreadable:
if unreadable or bare:
raise Refusal(
cut(" ".join(unreadable))
cut(" ".join([*unreadable, *bare]))
+ f" One of those could already succeed #{number}, so whether pointing a second link "
"at it forks the chain cannot be read."
)
Expand Down
51 changes: 51 additions & 0 deletions scripts/tests/test_handoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,37 @@ def test_new_refuses_an_open_head_that_already_has_a_successor(self) -> None:
self.assertIn("#21 already succeeds #20", err)
self.assertNotIn(1001, fake.issues)

def test_new_refuses_over_a_bare_closed_row(self) -> None:
"""An open head keeps `newest_closed` from ever running, so nothing else reads #50.

`on_track` takes precedence unconditionally, and the closed side is scanned only when it
returns nothing. So `successor_of` is the one read that meets a bare closed row on this
path, and reading it as "nothing succeeds #11" is the guess that forks the lane.
"""
fake = FakeGh(
{
10: link(10, "lane", 1, None, state="CLOSED"),
11: link(11, "lane", 2, 10),
50: link(50, "lane", 3, 11, state="CLOSED", body="the block was edited out"),
}
)
code, _, err = run(
fake,
"new",
"--repo",
"o/r",
"--track",
"lane",
"--title",
"T",
"--body-file",
self.body_file("w"),
)
self.assertEqual(code, 1)
self.assertIn("#50", err)
self.assertIn("no metadata block", err)
self.assertNotIn(1001, fake.issues)

def test_new_files_onto_a_head_nothing_succeeds(self) -> None:
"""The guard must not refuse the ordinary case it sits in front of."""
fake = FakeGh(
Expand Down Expand Up @@ -1576,6 +1607,26 @@ def test_an_unreadable_link_refuses_rather_than_reading_as_no_successor(self) ->
self.assertIn("could already succeed #10", err)
self.assertEqual(read_marker(fake.issues[13]["body"], 13)["previous"], "none")

def test_a_bare_link_refuses_rather_than_reading_as_no_successor(self) -> None:
"""The successor is real and its block was stripped, so nothing says it succeeds #10.

Reading that as "#10 has no successor" lets a second link name #10 as well, which forks
the lane and strands #11 while the run exits 0.
"""
fake = FakeGh(
{
10: link(10, "lane", 1, None, state="CLOSED"),
11: link(11, "lane", 2, 10, body="the block was edited out"),
13: link(13, "lane", 3, None, body=marked("an orphan", "lane", 3, None)),
}
)
code, _, err = run(fake, "link", "--repo", "o/r", "--new", "13", "--previous", "10")
self.assertEqual(code, 1)
self.assertIn("#11", err)
self.assertIn("no metadata block", err)
self.assertIn("could already succeed #10", err)
self.assertEqual(read_marker(fake.issues[13]["body"], 13)["previous"], "none")

def test_a_successor_with_no_block_refuses(self) -> None:
fake = FakeGh(
{
Expand Down