fix(выкладка): единая main и запрет серверного расхождения

This commit is contained in:
Hermes
2026-11-26 17:15:50 +10:00
parent 0f0ce038d2
commit ce3c018beb
5 changed files with 241 additions and 14 deletions
+87
View File
@@ -1,6 +1,7 @@
"""predeploy/deploy: прод только с копией, --no-pull, rollback floor не сбрасывает базу."""
import os
import subprocess
from datetime import datetime, timezone
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
@@ -75,3 +76,89 @@ def test_prod_db_must_not_be_the_same_file(tmp_path):
env={"APP_DIR": str(app)})
assert r.returncode == 2
assert "боевую базу" in r.stderr or "inode" in r.stderr
def _git(*args, cwd=None):
result = subprocess.run(["git", *args], cwd=cwd, text=True, capture_output=True,
check=True)
return result.stdout.strip()
def _deployment_repo(tmp_path):
origin = tmp_path / "origin.git"
app = tmp_path / "app"
_git("init", "--bare", "-b", "main", str(origin))
_git("clone", str(origin), str(app))
_git("config", "user.email", "test@example.invalid", cwd=app)
_git("config", "user.name", "Test", cwd=app)
(app / "tracked.txt").write_text("initial\n")
_git("add", "tracked.txt", cwd=app)
_git("commit", "-m", "initial", cwd=app)
_git("push", "-u", "origin", "main", cwd=app)
return app, origin
def _stamp(app, head):
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
(app / ".predeploy-stamp").write_text(f"{head}\n{now}\nfull: not-ui+ui\n")
def test_deploy_branch_preflight_accepts_published_main_without_moving_head(tmp_path):
app, _ = _deployment_repo(tmp_path)
head = _git("rev-parse", "HEAD", cwd=app)
_stamp(app, head)
result = _run(DEPLOY, "--preflight", env={"APP_DIR": str(app)})
assert result.returncode == 0, result.stderr
assert "branch preflight ok" in result.stdout
assert _git("rev-parse", "HEAD", cwd=app) == head
def test_deploy_branch_preflight_accepts_fast_forward_target(tmp_path):
app, origin = _deployment_repo(tmp_path)
old = _git("rev-parse", "HEAD", cwd=app)
author = tmp_path / "author"
_git("clone", str(origin), str(author))
_git("config", "user.email", "test@example.invalid", cwd=author)
_git("config", "user.name", "Test", cwd=author)
(author / "tracked.txt").write_text("next\n")
_git("commit", "-am", "next", cwd=author)
_git("push", cwd=author)
_stamp(app, _git("rev-parse", "HEAD", cwd=author))
result = _run(DEPLOY, "--preflight", env={"APP_DIR": str(app)})
assert result.returncode == 0, result.stderr
assert _git("rev-parse", "HEAD", cwd=app) == old
def test_deploy_branch_preflight_refuses_unpublished_commit(tmp_path):
app, _ = _deployment_repo(tmp_path)
remote_head = _git("rev-parse", "HEAD", cwd=app)
(app / "tracked.txt").write_text("server only\n")
_git("commit", "-am", "server only", cwd=app)
_stamp(app, remote_head)
result = _run(DEPLOY, "--preflight", env={"APP_DIR": str(app)})
assert result.returncode != 0
assert "origin/main" in result.stderr
def test_deploy_branch_preflight_refuses_other_branch(tmp_path):
app, _ = _deployment_repo(tmp_path)
_stamp(app, _git("rev-parse", "HEAD", cwd=app))
_git("switch", "-c", "feature", cwd=app)
result = _run(DEPLOY, "--preflight", env={"APP_DIR": str(app)})
assert result.returncode != 0
assert "main" in result.stderr
def test_deploy_branch_preflight_requires_matching_full_gate(tmp_path):
app, _ = _deployment_repo(tmp_path)
result = _run(DEPLOY, "--preflight", env={"APP_DIR": str(app)})
assert result.returncode != 0
assert "predeploy" in result.stderr
def test_deploy_no_pull_cannot_bypass_branch_guard(tmp_path):
app, _ = _deployment_repo(tmp_path)
_stamp(app, _git("rev-parse", "HEAD", cwd=app))
result = _run(DEPLOY, "--no-pull", "--preflight", env={"APP_DIR": str(app)})
assert result.returncode != 0
assert "--no-pull" in result.stderr