4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
81 lines
3.3 KiB
Python
81 lines
3.3 KiB
Python
"""Regression tests for the frozen-binary stdlib ``platform`` loader.
|
|
|
|
The first-party ``platform`` package shadows the stdlib ``platform`` module and
|
|
re-exports its API. In a PyInstaller frozen build the stdlib is not laid out as
|
|
loose ``.py`` files, so the release workflow bundles a copy of ``platform.py``
|
|
that ``platform/__init__.py`` loads from ``sys._MEIPASS``. These tests guard that
|
|
contract so the binary smoke test cannot silently regress again.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from config.platform_bootstrap import ensure_project_platform_package
|
|
|
|
ensure_project_platform_package()
|
|
|
|
import platform as _platform_pkg # noqa: E402 (first-party package after bootstrap)
|
|
|
|
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
_RELEASE_WORKFLOW = _REPO_ROOT / ".github" / "workflows" / "release.yml"
|
|
|
|
_FROZEN_STDLIB_DIR = _platform_pkg._FROZEN_STDLIB_DIR
|
|
_candidate_stdlib_platform_paths = _platform_pkg._candidate_stdlib_platform_paths
|
|
_load_stdlib_platform = _platform_pkg._load_stdlib_platform
|
|
|
|
_BUNDLED_PLATFORM_SOURCE = "OPENSRE_BUNDLED_MARKER = 'bundled'\n"
|
|
|
|
|
|
def test_first_party_platform_is_a_package_proxying_stdlib() -> None:
|
|
"""The shadowing package must still expose the stdlib platform API."""
|
|
assert hasattr(_platform_pkg, "__path__") # it is a package
|
|
assert _platform_pkg.system() # stdlib API copied in
|
|
assert _platform_pkg.python_version()
|
|
|
|
|
|
def test_candidate_paths_prioritize_meipass(monkeypatch, tmp_path) -> None:
|
|
"""Frozen builds must probe the bundled copy under ``sys._MEIPASS`` first."""
|
|
monkeypatch.setattr(sys, "_MEIPASS", str(tmp_path), raising=False)
|
|
|
|
candidates = _candidate_stdlib_platform_paths()
|
|
|
|
assert candidates[0] == tmp_path / _FROZEN_STDLIB_DIR / "platform.py"
|
|
|
|
|
|
def test_candidate_paths_without_meipass_resolve_real_stdlib(monkeypatch) -> None:
|
|
"""Source checkouts must still resolve the genuine stdlib ``platform.py``."""
|
|
monkeypatch.delattr(sys, "_MEIPASS", raising=False)
|
|
|
|
candidates = _candidate_stdlib_platform_paths()
|
|
|
|
assert candidates # at least the sysconfig location
|
|
assert any(path.is_file() for path in candidates)
|
|
|
|
|
|
def test_load_stdlib_platform_uses_bundled_copy_when_frozen(monkeypatch, tmp_path) -> None:
|
|
"""When frozen, the loader must read the bundled copy, not a system path."""
|
|
bundled_dir = tmp_path / _FROZEN_STDLIB_DIR
|
|
bundled_dir.mkdir()
|
|
(bundled_dir / "platform.py").write_text(_BUNDLED_PLATFORM_SOURCE, encoding="utf-8")
|
|
monkeypatch.setattr(sys, "_MEIPASS", str(tmp_path), raising=False)
|
|
|
|
module = _load_stdlib_platform()
|
|
|
|
assert getattr(module, "OPENSRE_BUNDLED_MARKER", None) == "bundled"
|
|
|
|
|
|
def test_release_workflow_bundles_stdlib_platform() -> None:
|
|
"""The release build must stage and bundle ``platform.py`` for the binary.
|
|
|
|
This ties the workflow's ``--add-data`` destination to ``_FROZEN_STDLIB_DIR``
|
|
so renaming the constant without updating the workflow fails fast instead of
|
|
only surfacing as a release-time binary crash.
|
|
"""
|
|
workflow = _RELEASE_WORKFLOW.read_text(encoding="utf-8")
|
|
|
|
assert "platform.py" in workflow # staging step copies the stdlib module
|
|
assert ".stdlib_vendor" in workflow # staged into a relative dir
|
|
assert _FROZEN_STDLIB_DIR in workflow # bundled under the loader's dest dir
|