fix: publish tag guard - v<version> must be among git tag --points-at (v0.12.1)

The first live run of daedalus publish on the v0.12.0 release was
rejected by its own tag guard: git describe --exact-match returns
whichever name git picks (here: latest), not the version tag, when
several tags share the release commit. The guard now checks that
v<version> is among git tag --points-at HEAD; moving tags on the
same commit are fine (publish spec 3.3.2, reproduced by a new test).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
nvaldez
2026-11-19 10:33:56 +01:00
parent 7ebce2109e
commit 6145ae33e8
7 changed files with 65 additions and 24 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ def test_app_version_falls_back_to_pyproject(monkeypatch):
raise hello.importlib.metadata.PackageNotFoundError(_name)
monkeypatch.setattr(hello.importlib.metadata, "version", not_found)
assert hello.app_version() == "0.12.0"
assert hello.app_version() == "0.12.1"
def test_help_exits_zero(capsys):
+36 -11
View File
@@ -28,7 +28,7 @@ def clean_runner(version, calls=None):
py = publish.PY
return make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{version}\n"),
("git", "tag", "--points-at"): (0, f"v{version}\n"),
(py, "-m", "build", "--version"): (0, "build 1.6.1\n"),
(py, "-m", "twine", "--version"): (0, "twine 7.0.0\n"),
(py, "-m", "build"): (0, "Successfully built\n"),
@@ -61,7 +61,7 @@ def test_dirty_tree_stops_before_building():
args = publish.parse_args([])
assert publish.cmd_publish(args, runner,
lambda _u: 404) == 3
assert not any(cmd[0] == "git" and cmd[1] == "describe"
assert not any(cmd[:2] == ["git", "tag"]
or cmd[1:3] == ["-m", "build"]
for cmd, _cwd in calls)
@@ -71,7 +71,7 @@ def test_tag_mismatch_stops():
calls = []
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, "v0.0.1\n"),
("git", "tag", "--points-at"): (0, "v0.0.1\n"),
}, calls)
args = publish.parse_args([])
assert publish.cmd_publish(args, runner,
@@ -79,15 +79,40 @@ def test_tag_mismatch_stops():
def test_tag_probe_failure_stops():
"""An untagged HEAD (describe fails) is exit 4."""
"""An untagged HEAD (no tag points at it) is exit 4."""
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (128, "no tag\n"),
("git", "tag", "--points-at"): (1, ""),
})
assert publish.cmd_publish(publish.parse_args([]), runner,
lambda _u: 404) == 4
def test_moving_tags_on_the_same_commit_do_not_confuse_the_guard():
"""`latest` sharing the release commit is fine (item 3.3.2).
git's own name picking is not the contract; v<version>
among the tags that point at HEAD is. Live case: git
prints `latest` for a commit tagged both latest and
v<version>.
"""
calls = []
runner = make_runner({
("git", "status"): (0, ""),
("git", "tag", "--points-at"):
(0, f"latest\nv{repo_version()}\n"),
(publish.PY, "-m", "build", "--version"): (0, "build\n"),
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
(publish.PY, "-m", "build"): (0, "ok\n"),
(publish.PY, "-m", "twine", "check"): (0, "PASSED\n"),
}, calls)
assert publish.cmd_publish(publish.parse_args([]), runner,
lambda _u: 404) == 0
tag_calls = [cmd for cmd, _ in calls
if cmd[:2] == ["git", "tag"]]
assert tag_calls == [["git", "tag", "--points-at", "HEAD"]]
def repo_version():
"""The version the checkout's pyproject carries."""
_name, version = publish.read_project(
@@ -99,7 +124,7 @@ def test_tooling_missing_stops():
"""No build/twine in the interpreter is exit 5."""
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{repo_version()}\n"),
("git", "tag", "--points-at"): (0, f"v{repo_version()}\n"),
(publish.PY, "-m", "build", "--version"): (127, "no module"),
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
})
@@ -112,7 +137,7 @@ def test_already_on_pypi_stops():
calls = []
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{repo_version()}\n"),
("git", "tag", "--points-at"): (0, f"v{repo_version()}\n"),
(publish.PY, "-m", "build", "--version"): (0, "build\n"),
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
}, calls)
@@ -126,7 +151,7 @@ def test_pypi_unreachable_stops():
"""A blind publish is refused: unreachable PyPI is exit 6."""
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{repo_version()}\n"),
("git", "tag", "--points-at"): (0, f"v{repo_version()}\n"),
(publish.PY, "-m", "build", "--version"): (0, "build\n"),
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
})
@@ -175,7 +200,7 @@ def test_build_failure_is_7():
py = publish.PY
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{version}\n"),
("git", "tag", "--points-at"): (0, f"v{version}\n"),
(py, "-m", "build", "--version"): (0, "build\n"),
(py, "-m", "twine", "--version"): (0, "twine\n"),
(py, "-m", "build"): (1, "error\n"),
@@ -191,7 +216,7 @@ def test_check_failure_is_8():
py = publish.PY
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{version}\n"),
("git", "tag", "--points-at"): (0, f"v{version}\n"),
(py, "-m", "build", "--version"): (0, "build\n"),
(py, "-m", "twine", "--version"): (0, "twine\n"),
(py, "-m", "build"): (0, "ok\n"),
@@ -208,7 +233,7 @@ def test_upload_failure_is_9():
py = publish.PY
runner = make_runner({
("git", "status"): (0, ""),
("git", "describe"): (0, f"v{version}\n"),
("git", "tag", "--points-at"): (0, f"v{version}\n"),
(py, "-m", "build", "--version"): (0, "build\n"),
(py, "-m", "twine", "--version"): (0, "twine\n"),
(py, "-m", "build"): (0, "ok\n"),