python-sdk: use pinned runtime package in real coverage (2026-03-12)

2026-03-12

Switch the repo-source Python SDK real coverage over to a pinned runtime-package flow backed by GitHub release artifacts instead of PATH or explicit binary overrides.

- add sdk/python/_runtime_setup.py to download the release codex archive for a requested CODEX_PYTHON_RUNTIME_VERSION, stage a temporary codex-cli-bin package, and install it into a target Python environment with cleanup
- refactor real integration tests to run repo-source SDK code against an isolated site-packages target that contains the staged codex-cli-bin runtime
- update examples and notebook bootstrap to install and use the runtime package, and stop consulting CODEX_PYTHON_SDK_CODEX_BIN or PATH
- switch the failing turn-run and model-selection examples to runtime-compatible model selection for the pinned release binary
- keep the main SDK runtime resolution model unchanged: explicit codex_bin or installed codex-cli-bin

Validation:
- python3 -m pytest sdk/python/tests
- RUN_REAL_CODEX_TESTS=1 CODEX_PYTHON_RUNTIME_VERSION=0.115.0-alpha.11 python3 -m pytest sdk/python/tests/test_real_app_server_integration.py

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Shaqayeq
2026-03-12 09:51:07 -07:00
parent fd4beb8b37
commit 3cf1306968
9 changed files with 708 additions and 120 deletions

View File

@@ -2,10 +2,16 @@ from __future__ import annotations
import importlib.util
import os
import shutil
import sys
from pathlib import Path
_SDK_PYTHON_DIR = Path(__file__).resolve().parents[1]
_SDK_PYTHON_STR = str(_SDK_PYTHON_DIR)
if _SDK_PYTHON_STR not in sys.path:
sys.path.insert(0, _SDK_PYTHON_STR)
from _runtime_setup import ensure_runtime_package_installed
def _ensure_runtime_dependencies(sdk_python_dir: Path) -> None:
if importlib.util.find_spec("pydantic") is not None:
@@ -23,7 +29,7 @@ def _ensure_runtime_dependencies(sdk_python_dir: Path) -> None:
def ensure_local_sdk_src() -> Path:
"""Add sdk/python/src to sys.path so examples run without installing the package."""
sdk_python_dir = Path(__file__).resolve().parents[1]
sdk_python_dir = _SDK_PYTHON_DIR
src_dir = sdk_python_dir / "src"
package_dir = src_dir / "codex_app_server"
if not package_dir.exists():
@@ -38,13 +44,8 @@ def ensure_local_sdk_src() -> Path:
def runtime_config():
"""Return an example-friendly AppServerConfig for local repo usage."""
"""Return an example-friendly AppServerConfig for repo-source SDK usage."""
from codex_app_server import AppServerConfig
codex_bin = os.environ.get("CODEX_PYTHON_SDK_CODEX_BIN") or shutil.which("codex")
if codex_bin is None:
raise RuntimeError(
"Examples require a Codex CLI binary when run from this repo checkout.\n"
"Set CODEX_PYTHON_SDK_CODEX_BIN=/absolute/path/to/codex, or ensure `codex` is on PATH."
)
return AppServerConfig(codex_bin=codex_bin)
ensure_runtime_package_installed(sys.executable, _SDK_PYTHON_DIR)
return AppServerConfig()