The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(release): abandon only the approved attempt, and only after the new cut is viable
etherneta12c3417c82d
diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.pyindex 49e4dea8440..bf358016af1 100644--- a/scripts/releases/entrypoint.py+++ b/scripts/releases/entrypoint.py@@ -193,6 +193,26 @@ def _changelog(repo: Path, repository: str, *, commit: str, tag: str, version: s)+def _abandon_confirmed(outstanding: tuple[str, int, str], confirm_abandon: Callable[[str], bool],+ refusal: ReleaseRefused, *, repo: Path, remote: str, repository: str,+ execute, inspect) -> None:+ """Abandon exactly the attempt the person approved, or raise ``refusal``.++ The prompt can sit open while another operator abandons it and cuts the+ next one; ``abandon`` would then clear that new attempt too. So the remote+ is read again after the answer and anything but the same single attempt+ is refused.+ """+ version, attempt, ref = outstanding+ if not confirm_abandon(ref):+ raise refusal+ if _outstanding_attempt(repo, remote) != outstanding:+ raise ReleaseRefused(f"{ref} changed while waiting for an answer — nothing was abandoned")+ print(abandon_steps([_abandon_attempt(version, attempt, ref, repo=repo, remote=remote,+ repository=repository, execute=execute, inspect=inspect)]),+ file=sys.stderr)++def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,execute, autopublish: bool = False, no_changelog: bool = False,skip_bundles: bool = False, skip_tests: bool = False,@@ -210,20 +230,20 @@ def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,``run_wait`` is how many seconds to keep looking for the dispatched run;GitHub lists it a moment after the dispatch returns.``confirm_abandon`` is asked about an outstanding attempt's ref; only a- caller with a person at the terminal passes one. A yes abandons the attempt- through ``abandon`` (so it needs ``inspect``, which cancels runs and deletes- the draft) and the cut goes on; no confirmer, or a no, is the refusal.+ caller with a person at the terminal passes one. It is asked only after the+ new cut has passed every check that can refuse it. A yes abandons that one+ attempt (so it needs ``inspect``, which cancels runs and deletes the draft)+ and the cut goes on; no confirmer, or a no, is the refusal."""_refresh_claims(repo, remote)_require_remote_main(repo, commit)outstanding = _outstanding_attempt(repo, remote)+ refusal = Noneif outstanding is not None:refusal = _refuse_outstanding(outstanding, repo=repo, remote=remote,repository=repository, execute=execute)- if confirm_abandon is None or not confirm_abandon(outstanding[2]):+ if confirm_abandon is None:raise refusal- print(abandon_steps(abandon(outstanding[0], repo=repo, remote=remote, repository=repository,- execute=execute, inspect=inspect)), file=sys.stderr)published_version, published_commit = published_require_ancestry(repo, commit, published_commit)version = derive_next_version(published=published_version, bump=bump)@@ -251,6 +271,12 @@ def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str," Do this before step 2: once the retry claims this attempt, changelog numbers the next one.\n"" 2. Re-run the same release command with --no-changelog.\n"" 3. Edit changelog.md down in your editor and paste it into the draft release body.")+ if refusal is not None:+ # Everything that can refuse the new cut has run, so a yes cannot+ # destroy the old attempt and then fail to replace it. The attempt+ # number ignores markers, so abandoning does not change ``tag``.+ _abandon_confirmed(outstanding, confirm_abandon, refusal, repo=repo, remote=remote,+ repository=repository, execute=execute, inspect=inspect)claim_epoch = _next_claim_epoch(repo, claims)claim = json.dumps({"schema": 1,diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.pyindex f453f648c6f..3abd4643163 100644--- a/tests/scripts/test_release_entrypoint.py+++ b/tests/scripts/test_release_entrypoint.py@@ -243,19 +243,57 @@ def test_an_unconfirmed_abandon_refuses_as_before(source, confirm_abandon):assert git(source, "tag", "--list", "*rc.*") == "rc.1-v0.21.5"[email protected](("tty", "answer", "expected"), [- (True, "y", True), (True, "YES", True), (True, "", False), (True, "n", False),- (True, EOFError, False), (False, "y", None),+def test_a_yes_never_clears_a_cut_that_would_be_refused_anyway(source):+ from scripts.releases.entrypoint import ReleaseRefused++ earlier = git(source, "rev-parse", "HEAD")+ published = _advance(source, "published")+ _claim(source, "0.21.5", published)+ asked = []++ with pytest.raises(ReleaseRefused, match="does not descend from the published stable head"):+ _release(source, earlier, published=("0.21.4", published), execute=_must_not_execute,+ confirm_abandon=lambda ref: asked.append(ref) or True)++ assert asked == []+ assert "abandoned-rc" not in git(source, "ls-remote", "origin", "refs/tags/*")+++def test_a_yes_abandons_only_the_attempt_it_was_asked_about(source):+ from scripts.releases.entrypoint import ReleaseRefused++ commit = git(source, "rev-parse", "HEAD")+ _claim(source, "0.21.5", commit)++ def another_operator_replaces_the_attempt(_ref):+ _mark(source, "0.21.5")+ _claim(source, "0.21.5", commit, attempt=2)+ return True++ with pytest.raises(ReleaseRefused, match="changed while waiting"):+ _release(source, _advance(source, "later"), execute=_must_not_execute,+ confirm_abandon=another_operator_replaces_the_attempt)++ assert "abandoned-rc.2-v0.21.5" not in git(source, "ls-remote", "origin", "refs/tags/*")++[email protected](("stdin_tty", "stdout_tty", "answer", "expected"), [+ (True, True, "y", True), (True, True, "YES", True), (True, True, "", False),+ (True, True, "n", False), (True, True, EOFError, False),+ (False, True, "y", None), (True, False, "y", None), (False, False, "y", None),])-def test_the_abandon_prompt_exists_only_on_a_terminal_and_defaults_to_no(monkeypatch, tty, answer, expected):+def test_the_abandon_prompt_needs_both_streams_on_a_terminal_and_defaults_to_no(+ monkeypatch, stdin_tty, stdout_tty, answer, expected):import sysfrom scripts.releases.entrypoint import _abandon_prompt- monkeypatch.setattr(sys.stdin, "isatty", lambda: tty)- monkeypatch.setattr(sys.stdout, "isatty", lambda: tty)+ monkeypatch.setattr(sys.stdin, "isatty", lambda: stdin_tty)+ monkeypatch.setattr(sys.stdout, "isatty", lambda: stdout_tty)+ prompts = []- def fake_input(_prompt):+ def fake_input(prompt):+ prompts.append(prompt)if answer is EOFError:raise EOFErrorreturn answer@@ -263,7 +301,11 @@ def test_the_abandon_prompt_exists_only_on_a_terminal_and_defaults_to_no(monkeypmonkeypatch.setattr("builtins.input", fake_input)confirm = _abandon_prompt()- assert (confirm is None) if expected is None else (confirm("rc.1-v0.21.5") is expected)+ if expected is None:+ assert confirm is None+ assert prompts == []+ else:+ assert confirm("rc.1-v0.21.5") is expecteddef test_second_cut_after_abandon_is_attempt_two_of_the_same_version(source):