#!/usr/bin/env python3 """Статические ограничения стенда lab4; не заменяет docker compose config/nginx -t.""" import ast import json import os from pathlib import Path import shutil import subprocess import yaml ROOT = Path(__file__).resolve().parents[1] def main(): config = yaml.safe_load((ROOT / "compose.yaml").read_text(encoding="utf-8")) services = config["services"] assert {"api-a", "api-b", "migrate", "nginx", "db", "redis", "minio", "minio-init", "cleanup"} <= services.keys() assert config["networks"]["data"]["internal"] is True for name, service in services.items(): assert "container_name" not in service, name assert float(service["cpus"]) > 0 and service["mem_limit"], name if name != "nginx": assert "ports" not in service, name for name in ("api-a", "api-b"): assert services[name]["depends_on"]["migrate"]["condition"] == "service_completed_successfully" assert services[name]["stop_grace_period"] == "10s" assert services["migrate"]["command"] == ["python", "-m", "app.migrate"] assert services["nginx"]["image"] == "nginx:1.28.0-alpine" assert services["nginx"]["networks"] == ["edge"] assert {"pgdata", "miniodata"} <= config["volumes"].keys() assert services["minio"]["environment"]["MINIO_BROWSER"] == "off" assert "latest" not in services["minio"]["image"] assert "MINIO_ROOT_PASSWORD" not in services["api-a"]["environment"] assert "S3_SECRET_KEY" in services["api-a"]["environment"] assert services["cleanup"]["command"] == ["python", "-m", "app.cleanup", "--loop"] assert not any("docker.sock" in str(s) for s in services.values()) spec = json.loads((ROOT / "contracts/openapi.json").read_text(encoding="utf-8")) operation = spec["paths"]["/api/v1/chats/{chat_id}/messages"]["post"] assert any(p["name"] == "Idempotency-Key" and p["required"] for p in operation["parameters"]) for directory in ("app", "scripts", "student-tests", "unit-tests", "tests"): for path in (ROOT / directory).rglob("*.py"): ast.parse(path.read_text(encoding="utf-8"), filename=str(path)) shell = shutil.which("sh") if shell: for path in list((ROOT / "scripts").glob("*.sh")) + list((ROOT / "infra").rglob("*.sh")): subprocess.run([shell, "-n", str(path)], check=True) else: print("SKIP: shell syntax (sh unavailable); container entrypoint requires runtime verification.") for filename in ("scripts/stop_one.py", "scripts/restart.py"): path = ROOT / filename assert path.is_file() if os.name != "nt": assert path.stat().st_mode & 0o111 print("PASS: lab4 static structure, resource/port isolation, contract, Python syntax; runtime NOT tested.") if __name__ == "__main__": main()