Repository navigation
fix(api): report the installed or source package version - #203
cloudgpuapp wants to merge 1 commit into
Conversation
OkiriGabriel
left a comment
There was a problem hiding this comment.
Thanks @cloudgpuapp, this is a clean fix for #199, and the regression test is the right one. Two changes before merging:
-
Don't let a missing file stop the server from starting.
_app_version()runs at import time. If the package isn't installed andpyproject.tomlisn't next to the source (a slimmed image, or a vendored copy), theFileNotFoundErrororKeyErrorstopsapi.serverfrom importing at all. Please catchOSError,KeyErrorandValueErrorin the fallback and return"0.0.0+unknown"(or"unknown"). -
Prefer the source checkout's
pyproject.toml, then installed metadata. At the moment, an olderdevops-ai-agentinstalled in the same environment wins over the source you're actually running. For example,pip install devops-ai-agent==1.1.0in a venv followed by running from a checkout at 1.2.0 reports 1.1.0, andtest_api_version_matches_project_metadatafails in that environment. Installed wheels don't shippyproject.tomlbesideapi/, so this order is still correct for PyPI installs:def _app_version() -> str: source = Path(__file__).resolve().parents[1] / "pyproject.toml" if source.is_file(): try: with source.open("rb") as fh: return tomllib.load(fh)["project"]["version"] except (OSError, KeyError, ValueError): pass try: return version("devops-ai-agent") except PackageNotFoundError: return "0.0.0+unknown"
Then adjust
test_api_version_prefers_installed_distributionso it covers the no-pyproject.tomlcase, for example by monkeypatching the path, and add a test that neither source gives"0.0.0+unknown"instead of raising.
The tomli marker for Python 3.10 and the /health version field look good.
|
Heads-up @cloudgpuapp: #235 (fix for #225) makes the unauthenticated |
Description
Read the release version from installed package metadata or, when running directly from source, from pyproject.toml. Make /health report the same version as OpenAPI. Python 3.10 uses the conditional TOML parser dependency.
Fixes #199.
Type of Change
Platform/Component
Testing
The source-checkout regression initially failed: OpenAPI advertised 1.1.0 while the project declared 1.2.0. The fixed regression verifies the app, OpenAPI, and health metadata. A separate test exercises installed metadata precedence.
Local macOS, Python 3.12. The full pytest suite passed: 1,359 passed and 4 skipped. Syntax and git diff --check also passed. No live cloud service credentials were used.
Checklist
Breaking Changes
None. The health response gains a version field.
Additional Notes
AI disclosure: Codex assisted with implementation and verification.