Skip to content

Commit b8ffc43

Browse files
fix(test): replace git-describe submodule check with CHANGELOG parse
The git-describe-based submodule check from the previous commit passed locally but failed in CI because actions/checkout pins the submodule to its recorded SHA without fetching the spec repo's tags. `git describe --tags --exact-match` then finds nothing and the test fails with "submodule HEAD is not at any tag." Switching to parsing openarmature-spec/CHANGELOG.md: the spec follows Keep a Changelog, so the first non-[Unreleased] `## [X.Y.Z]` heading is the version at the pinned commit. This works regardless of CI tag-fetch state and catches the same drift class (submodule moved to a different release). Skips cleanly when CHANGELOG.md isn't present (installed-package lanes that don't ship the submodule checkout).
1 parent 4c12add commit b8ffc43

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

tests/test_smoke.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import subprocess
1+
import re
22
import tomllib
33
from pathlib import Path
44

@@ -16,37 +16,39 @@ def test_spec_version_matches_pyproject() -> None:
1616
# AGENTS.md flags __spec_version__, pyproject.toml's
1717
# [tool.openarmature].spec_version, and the submodule pin as
1818
# required to stay in sync. This test catches the pyproject ↔
19-
# runtime drift class; test_spec_version_matches_submodule_pin
19+
# runtime drift class; test_spec_version_matches_submodule_changelog
2020
# below catches the submodule side.
2121
pyproject_path = Path(__file__).resolve().parent.parent / "pyproject.toml"
2222
config = tomllib.loads(pyproject_path.read_text())
2323
pyproject_spec_version = config["tool"]["openarmature"]["spec_version"]
2424
assert openarmature.__spec_version__ == pyproject_spec_version
2525

2626

27-
def test_spec_version_matches_submodule_pin() -> None:
28-
# The submodule's git HEAD must be at the v{__spec_version__}
29-
# tag, completing the three-place drift check from AGENTS.md.
30-
# Skips cleanly when the submodule isn't a git checkout (e.g.,
31-
# installed-package CI lanes pulling from PyPI sdists).
32-
spec_dir = Path(__file__).resolve().parent.parent / "openarmature-spec"
33-
if not (spec_dir / ".git").exists():
34-
pytest.skip("openarmature-spec is not a git checkout")
35-
try:
36-
result = subprocess.run(
37-
["git", "-C", str(spec_dir), "describe", "--tags", "--exact-match", "HEAD"],
38-
capture_output=True,
39-
text=True,
40-
check=True,
41-
)
42-
except subprocess.CalledProcessError:
43-
pytest.fail(
44-
"submodule HEAD is not at any tag; bump it to "
45-
f"v{openarmature.__spec_version__} or update __spec_version__"
46-
)
47-
submodule_tag = result.stdout.strip()
48-
expected = f"v{openarmature.__spec_version__}"
49-
assert submodule_tag == expected, (
50-
f"submodule pinned at {submodule_tag}, but __spec_version__ is "
51-
f"{openarmature.__spec_version__} (expected tag {expected})"
27+
# Keep a Changelog heading: ``## [0.15.0]`` (with optional trailing
28+
# date). The ``[Unreleased]`` entry uses a non-numeric tag and is
29+
# skipped by this pattern.
30+
_CHANGELOG_VERSION_RE = re.compile(r"^## \[(\d+\.\d+\.\d+)\]")
31+
32+
33+
def test_spec_version_matches_submodule_changelog() -> None:
34+
# Third value AGENTS.md flags: the submodule pin (the spec
35+
# checkout the parent repo records). We verify by reading the
36+
# spec's CHANGELOG.md at the pinned commit and asserting the
37+
# latest versioned entry equals __spec_version__. CHANGELOG
38+
# parsing is more robust than ``git describe`` (no tag-fetch
39+
# dependency, works in any checkout shape) and the spec follows
40+
# Keep a Changelog so the format is stable.
41+
changelog_path = Path(__file__).resolve().parent.parent / "openarmature-spec" / "CHANGELOG.md"
42+
if not changelog_path.exists():
43+
pytest.skip("openarmature-spec/CHANGELOG.md is not present")
44+
for line in changelog_path.read_text().splitlines():
45+
match = _CHANGELOG_VERSION_RE.match(line)
46+
if match:
47+
submodule_latest = match.group(1)
48+
break
49+
else:
50+
pytest.fail("could not find a versioned heading in openarmature-spec/CHANGELOG.md")
51+
assert openarmature.__spec_version__ == submodule_latest, (
52+
f"submodule's CHANGELOG latest is {submodule_latest}, but "
53+
f"__spec_version__ is {openarmature.__spec_version__}"
5254
)

0 commit comments

Comments
 (0)