Files
mtusi2026lab2/student-tests/track1_baseline.py
T
OlegRood 834876c938 ЛР 2: закрыть уровень 4
Завершить PostgreSQL, Redis-сессии, миграции, таймауты и диагностику. Зафиксировать собственные тесты и доказательства финального прогона: 43 PASS, 0 FAIL, 0 SKIP; 768 HTTP-запросов без ошибок. Добавить официальный отчёт с запуском, архитектурой, SQL-планами и ограничениями. PR отложен до завершения уровня 5.
2026-10-28 13:30:26 +03:00

69 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Repeat the sorting baseline with the current Go/JSON code and test harness.
Creates a temporary local clone, overlays the current tracked files and the
validation tests, and replaces only the message repository with the saved
pre-optimization version. The original checkout is not modified.
"""
import argparse
import hashlib
import json
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
ROOT = Path(__file__).resolve().parents[1]
REPOSITORY = "internal/database/repository/message.go"
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--ref", default="9de1152204e649c733d442255467dd81e1f16c59")
parser.add_argument("--image", required=True)
parser.add_argument("--output", required=True)
args = parser.parse_args()
output = Path(args.output)
if output.is_absolute() or output.parent != Path("evidence") or output.suffix != ".json":
parser.error("--output must be evidence/<name>.json")
if (ROOT / output).exists():
parser.error("output already exists; choose a new filename")
baseline = subprocess.check_output(["git", "show", args.ref + ":" + REPOSITORY], cwd=ROOT)
paths = subprocess.check_output(["git", "ls-files", "-z"], cwd=ROOT).decode().split("\0")
# Include the new HTTP tests before the author commits them.
paths.append("student-tests/validation_edges.py")
with tempfile.TemporaryDirectory(prefix="highload-track1-baseline-") as directory:
checkout = Path(directory) / "source"
subprocess.run(["git", "clone", "--quiet", "--local", "--no-hardlinks", str(ROOT), str(checkout)], check=True)
for relative in filter(None, paths):
source = ROOT / relative
if source.is_file():
target = checkout / relative
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)
(checkout / REPOSITORY).write_bytes(baseline)
invocation = [sys.executable, "student-tests/track1.py", "run", "--build",
"--image", args.image, "--label", "before-go127",
"--histories", "100,1000,10000", "--concurrency", "1,5,10",
"--duration", "10", "--warmup", "2", "--repeats", "1", "--output", str(output)]
result = subprocess.run(invocation, cwd=checkout)
for generated in (checkout / "evidence").glob(output.stem + "*"):
if generated.is_file():
shutil.copy2(generated, ROOT / "evidence" / generated.name)
if (ROOT / output).exists():
data = json.loads((ROOT / output).read_text())
data["baseline_preparation"] = {
"command": [sys.executable, *sys.argv], "repository_ref": args.ref,
"replaced_file": REPOSITORY,
"method": "Current working files, Go 1.27.1 and JSON v2; only the message repository restored from ref in a temporary clone",
"source_file_sha256": hashlib.sha256(baseline).hexdigest(),
}
(ROOT / output).write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n")
return result.returncode
if __name__ == "__main__":
raise SystemExit(main())