feat(build-time-versioning): xceadmin committed fallback stub and CLI version wiring

Commits a fallback src/xceadmin/src/xceadmin/_build_info.py (GIT_COMMIT/
BUILD_TIME both "unknown") for install paths that never run meson-build.sh
(e.g. `pip install -e .`), and wires click.version_option() on cli.py's
top-level group. cli.py imports _build_info defensively (try/except
ImportError with an inline fallback) and composes the version string from
importlib.metadata.version("xceadmin") plus both build-info fields.

Verified independently by review: editable install shows "unknown" for
both fields with no import error; the meson-built wheel shows real,
matching commit id + build time; full xceadmin suite 261 passed/3 skipped
(258 baseline + 3 new tests); ruff clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-08-20 14:47:20 +00:00
parent e1cd9d257c
commit 7f5c87ce9d
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
4 changed files with 114 additions and 5 deletions

View file

@ -70,6 +70,57 @@ def test_xcecommon_is_importable_independent_of_xceadmin() -> None:
import xcecommon # noqa: F401 - import success is the assertion
# ---------------------------------------------------------------------------
# --version (build-time-versioning task 5.2): click.version_option() wired on
# the top-level group, composing pyproject.toml's static semantic version
# with the two _build_info fields (task 5.1's meson-generated real values, or
# task 5.2's committed "unknown"-only fallback stub for a non-meson `pip
# install -e .`). Observable: `xceadmin --version` prints and exits 0, never
# an import error, regardless of which _build_info variant is installed.
# ---------------------------------------------------------------------------
def test_cli_version_flag_exits_zero_and_shows_package_version() -> None:
"""`xceadmin --version` must exit 0 and print pyproject.toml's static
semantic version (0.1.0) plus build-info fields -- Requirements 1.1,
1.2, 2.1."""
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0, result.output
assert "0.1.0" in result.output # pyproject.toml's static [project].version
assert "version" in result.output.lower()
def test_cli_version_flag_includes_build_info_fields() -> None:
"""The printed --version string must include BOTH _build_info fields
(whichever variant -- "unknown" fallback or meson-generated real values
-- is currently installed), not just the bare package version, so
--version and the eventual startup log line (out of this task's scope)
can never disagree (Requirement 2.2)."""
from xceadmin import _build_info
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0, result.output
assert _build_info.GIT_COMMIT in result.output
assert _build_info.BUILD_TIME in result.output
def test_build_info_module_is_importable_with_string_fields() -> None:
"""xceadmin._build_info must always be importable with both fields
present as non-empty strings -- whether it's the committed "unknown"-only
fallback stub (task 5.2, a non-meson `pip install -e .`) or the
meson-generated real-value module (task 5.1) this test run happens to be
installed against. Never an import error (tasks.md 5.2's Observable
bullet, Requirement 1.4)."""
from xceadmin import _build_info
assert isinstance(_build_info.GIT_COMMIT, str) and _build_info.GIT_COMMIT
assert isinstance(_build_info.BUILD_TIME, str) and _build_info.BUILD_TIME
# ---------------------------------------------------------------------------
# config build
# ---------------------------------------------------------------------------