Skip to content

fix(api): report the installed or source package version - #203

Open
cloudgpuapp wants to merge 1 commit into
open-devops-agent:mainfrom
cloudgpuapp:fix/199-api-version
Open

cloudgpuapp wants to merge 1 commit into
open-devops-agent:mainfrom
cloudgpuapp:fix/199-api-version

Conversation

@cloudgpuapp

Copy link
Copy Markdown

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

  • Bug fix (non-breaking change which fixes an issue)

Platform/Component

  • API Server
  • Tests

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.

  • Unit tests added/updated
  • Tested with dummy data

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

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Breaking Changes

None. The health response gains a version field.

Additional Notes

AI disclosure: Codex assisted with implementation and verification.

@OkiriGabriel OkiriGabriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cloudgpuapp, this is a clean fix for #199, and the regression test is the right one. Two changes before merging:

  1. Don't let a missing file stop the server from starting. _app_version() runs at import time. If the package isn't installed and pyproject.toml isn't next to the source (a slimmed image, or a vendored copy), the FileNotFoundError or KeyError stops api.server from importing at all. Please catch OSError, KeyError and ValueError in the fallback and return "0.0.0+unknown" (or "unknown").

  2. Prefer the source checkout's pyproject.toml, then installed metadata. At the moment, an older devops-ai-agent installed in the same environment wins over the source you're actually running. For example, pip install devops-ai-agent==1.1.0 in a venv followed by running from a checkout at 1.2.0 reports 1.1.0, and test_api_version_matches_project_metadata fails in that environment. Installed wheels don't ship pyproject.toml beside api/, 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_distribution so it covers the no-pyproject.toml case, 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.

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Heads-up @cloudgpuapp: #235 (fix for #225) makes the unauthenticated /health return only {"status": "ok"} and moves the runtime fields to an authenticated GET /status. When you update this PR, please put "version" in /status instead of /health (the OpenAPI info.version change is fine as is). Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API reports version 1.1.0 while the package is 1.2.0: read it from package metadata

2 participants