Files
smeta-web/tests/test_release_gate.py

67 lines
2.3 KiB
Python

"""The production job accepts only the exact candidate currently on release dev."""
import hashlib
import json
import subprocess
from pathlib import Path
from scripts import release_gate
def _git(cwd, *args):
return subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True,
text=True).stdout.strip()
def _candidate(tmp_path):
stage = tmp_path / "stage"
stage.mkdir()
_git(stage, "init", "-b", "release")
_git(stage, "config", "user.email", "test@example.invalid")
_git(stage, "config", "user.name", "Test")
(stage / "a.txt").write_text("candidate")
_git(stage, "add", "a.txt")
_git(stage, "commit", "-m", "candidate")
sha = _git(stage, "rev-parse", "HEAD")
index = tmp_path / "index.json"
index.write_bytes(b"index")
index_hash = hashlib.sha256(index.read_bytes()).hexdigest()
(stage / ".predeploy-stamp").write_text(f"{sha}\n2026-11-26T00:00:00Z\nfull: not-ui+ui\n")
marker = tmp_path / "ready.json"
marker.write_text(json.dumps({"sha": sha, "index_sha256": index_hash}))
return stage, index, marker, sha
def test_exact_stage_candidate_is_accepted(tmp_path):
stage, index, marker, sha = _candidate(tmp_path)
assert release_gate.verify(sha, stage, index, marker) == []
def test_unstaged_main_commit_is_refused(tmp_path):
stage, index, marker, sha = _candidate(tmp_path)
assert release_gate.verify("a" * 40, stage, index, marker)
def test_dev_moved_since_review_is_refused(tmp_path):
stage, index, marker, sha = _candidate(tmp_path)
(stage / "a.txt").write_text("next")
_git(stage, "commit", "-am", "next")
assert release_gate.verify(sha, stage, index, marker)
def test_changed_working_index_is_refused(tmp_path):
stage, index, marker, sha = _candidate(tmp_path)
index.write_bytes(b"changed")
assert release_gate.verify(sha, stage, index, marker)
def test_partial_gate_is_refused(tmp_path):
stage, index, marker, sha = _candidate(tmp_path)
(stage / ".predeploy-stamp").write_text(f"{sha}\n2026-11-26T00:00:00Z\npartial\n")
assert release_gate.verify(sha, stage, index, marker)
def test_wrong_branch_is_refused(tmp_path):
stage, index, marker, sha = _candidate(tmp_path)
_git(stage, "switch", "-c", "other")
assert release_gate.verify(sha, stage, index, marker)