Files
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

83 lines
2.9 KiB
Python

"""Tests for the decoupled image-build path (build_image, _resolve_image_uri)."""
from __future__ import annotations
import pytest
import platform.deployment.ecr_deploy.stack as stack_module
from platform.deployment.ecr_deploy import lifecycle as deploy_module
from platform.deployment.ecr_deploy.lifecycle import _IMAGE_URI_ENV
_FAKE_URI = "123456789012.dkr.ecr.us-east-1.amazonaws.com/opensre:latest"
# ── _resolve_image_uri ────────────────────────────────────────────────────────
def test_resolve_image_uri_uses_env_var(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv(_IMAGE_URI_ENV, _FAKE_URI)
assert deploy_module._resolve_image_uri() == _FAKE_URI
def test_resolve_image_uri_falls_back_to_saved_file(
monkeypatch: pytest.MonkeyPatch,
tmp_path: pytest.TempPathFactory,
) -> None:
uri_file = tmp_path / "image-uri.txt"
uri_file.write_text(_FAKE_URI + "\n")
monkeypatch.delenv(_IMAGE_URI_ENV, raising=False)
monkeypatch.setattr(stack_module, "_IMAGE_URI_FILE", uri_file)
assert deploy_module._resolve_image_uri() == _FAKE_URI
def test_resolve_image_uri_env_takes_precedence_over_file(
monkeypatch: pytest.MonkeyPatch,
tmp_path: pytest.TempPathFactory,
) -> None:
uri_file = tmp_path / "image-uri.txt"
uri_file.write_text("stale-uri-from-file:old\n")
monkeypatch.setattr(stack_module, "_IMAGE_URI_FILE", uri_file)
monkeypatch.setenv(_IMAGE_URI_ENV, _FAKE_URI)
assert deploy_module._resolve_image_uri() == _FAKE_URI
def test_resolve_image_uri_fails_fast_when_nothing_available(
monkeypatch: pytest.MonkeyPatch,
tmp_path: pytest.TempPathFactory,
) -> None:
monkeypatch.delenv(_IMAGE_URI_ENV, raising=False)
monkeypatch.setattr(stack_module, "_IMAGE_URI_FILE", tmp_path / "nonexistent.txt")
with pytest.raises(RuntimeError, match="make build-image"):
deploy_module._resolve_image_uri()
# ── build_image ───────────────────────────────────────────────────────────────
def test_build_image_saves_uri_and_returns_it(
monkeypatch: pytest.MonkeyPatch,
tmp_path: pytest.TempPathFactory,
) -> None:
uri_file = tmp_path / "image-uri.txt"
monkeypatch.setattr(stack_module, "_IMAGE_URI_FILE", uri_file)
monkeypatch.setattr(
deploy_module.ecr,
"create_repository",
lambda *_a, **_kw: {"uri": "123456789012.dkr.ecr.us-east-1.amazonaws.com/opensre"},
)
monkeypatch.setattr(
deploy_module.ecr,
"build_and_push",
lambda *_a, **_kw: _FAKE_URI,
)
result = deploy_module.build_image()
assert result == _FAKE_URI
assert uri_file.exists()
assert uri_file.read_text().strip() == _FAKE_URI