From 6145ae33e8ac9cfb13a3354f570a87837bac2fac Mon Sep 17 00:00:00 2001 From: nvaldez Date: Thu, 19 Nov 2026 10:33:56 +0100 Subject: [PATCH] fix: publish tag guard - v 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 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 --- CHANGELOG.md | 12 +++++++++ daedalus/tests/test_cli.py | 2 +- pyproject.toml | 2 +- python/src/publish/publish.py | 13 +++++----- python/src/publish/spec.md | 11 +++++--- python/tests/test_hello.py | 2 +- python/tests/test_publish.py | 47 +++++++++++++++++++++++++++-------- 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 068f12e..14c4709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,18 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and - Nothing yet. +## [0.12.1] - 2026-11-19 + +### Fixed in 0.12.1 + +- `publish`'s tag guard rejected a correctly tagged release when + `latest` (or any other tag) shared the release commit: `git describe + --tags --exact-match` returns whichever name git picks, not the + version tag. The guard now checks that `v` is among + `git tag --points-at HEAD` (membership check, publish spec item + 3.3.2); moving tags on the same commit are fine. Found by the first + live run of `daedalus publish` on the v0.12.0 release. + ## [0.12.0] - 2026-11-19 ### Added in 0.12.0 diff --git a/daedalus/tests/test_cli.py b/daedalus/tests/test_cli.py index 80845f6..3b5728d 100644 --- a/daedalus/tests/test_cli.py +++ b/daedalus/tests/test_cli.py @@ -150,7 +150,7 @@ def test_path_with_extra_words_is_a_usage_error(fake_registry, plain, capsys): assert "usage: daedalus --path " in capsys.readouterr().err -@pytest.mark.parametrize("installed, expected", [(True, "daedalus 1.2.3"), (False, "daedalus 0.12.0")]) +@pytest.mark.parametrize("installed, expected", [(True, "daedalus 1.2.3"), (False, "daedalus 0.12.1")]) def test_version(monkeypatch, capsys, installed, expected): """--version uses metadata or pyproject.toml in a checkout.""" def fake_version(_name): diff --git a/pyproject.toml b/pyproject.toml index b455833..254f186 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "daedalus" -version = "0.12.0" +version = "0.12.1" description = "Template for daedalus: loose scripts in one repo, run with: daedalus [args...]" readme = "README.md" requires-python = ">=3.11" diff --git a/python/src/publish/publish.py b/python/src/publish/publish.py index 4b9b921..04d23df 100644 --- a/python/src/publish/publish.py +++ b/python/src/publish/publish.py @@ -118,12 +118,13 @@ def cmd_publish(args: argparse.Namespace, run_cmd=None, "or stash first - what ships must be committed " "(item 3.3.1)") return EXIT_DIRTY - code, output = run_cmd(["git", "describe", "--tags", "--exact-match", - "HEAD"], cwd=root) - if code != 0 or output.strip() != f"v{version}": - LOGGER.error("HEAD is not exactly tagged v%s; tag the release " - "first: git tag -a v%s -m \"...\" (item 3.3.2)", - version, version) + code, output = run_cmd(["git", "tag", "--points-at", "HEAD"], cwd=root) + tags = [line.strip() for line in output.splitlines() if line.strip()] + if code != 0 or f"v{version}" not in tags: + LOGGER.error("v%s is not among the tags pointing at HEAD " + "(found: %s); tag the release first: git tag -a " + "v%s -m \"...\" (item 3.3.2)", + version, tags or "none", version) return EXIT_TAG for module in ("build", "twine"): code, _output = run_cmd([PY, "-m", module, "--version"], cwd=root) diff --git a/python/src/publish/spec.md b/python/src/publish/spec.md index 2097ff9..0afa44d 100644 --- a/python/src/publish/spec.md +++ b/python/src/publish/spec.md @@ -39,9 +39,11 @@ are cited as `publish spec item N.M`. - **3.3.1** Dirty working tree (`git status --porcelain` in the repo root, any output) is exit 3 - what ships must be what is committed, and the tag must cover the exact tree. - - **3.3.2** HEAD not exactly tagged `v` - (`git describe --tags --exact-match HEAD`) is exit 4 - tag - first: `git tag -a v -m ...`. + - **3.3.2** `v` not among the tags that point at HEAD + (`git tag --points-at HEAD`) is exit 4 - tag the release + first: `git tag -a v -m ...`. Other tags on the + same commit (`latest`, `stable`) are fine; the guard checks + membership, not the name git happens to pick. - **3.3.3** The interpreter must provide `python -m build` and `python -m twine` (`--version` probe each); a failure is exit 5 with the inject hint (`pipx inject daedalus build twine`, or @@ -108,4 +110,5 @@ are cited as `publish spec item N.M`. - **7.1** Packaging truth: SPEC items 9.1-9.5, 9.2.1. - **7.2** Repository rules: SPEC items 6.6 (tests), 9.8 (version bump). -- **7.3** History: `CHANGELOG.md` entry 0.12.0. +- **7.3** History: `CHANGELOG.md` entries 0.12.0 (script), + 0.12.1 (tag-guard fix, found by the first live run). diff --git a/python/tests/test_hello.py b/python/tests/test_hello.py index 7caf736..e829dc6 100644 --- a/python/tests/test_hello.py +++ b/python/tests/test_hello.py @@ -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): diff --git a/python/tests/test_publish.py b/python/tests/test_publish.py index 2f170ce..98adfc7 100644 --- a/python/tests/test_publish.py +++ b/python/tests/test_publish.py @@ -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 + among the tags that point at HEAD is. Live case: git + prints `latest` for a commit tagged both latest and + v. + """ + 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"),