feat: monorepo migration phase 3
App checks / changes (push) Canceled after 0s
App checks / tournament (push) Canceled after 0s
App checks / shifts (push) Canceled after 0s
App checks / changes (push) Canceled after 0s
App checks / tournament (push) Canceled after 0s
App checks / shifts (push) Canceled after 0s
This commit is contained in:
1 parent
e92ae5064c
commit
561b6a2da9
79 files changed
+4514
-1541
No files matched your search
+18
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
import json
|
||||
from html.parser import HTMLParser
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import time
|
||||
from urllib.request import urlopen
|
||||
@@ -22,13 +23,18 @@ class PageResources(HTMLParser):
|
||||
self.urls.append(attributes.get("href") or "")
|
||||
|
||||
|
||||
def check(image: str, port: int, environment: dict[str, str], routes: list[str], proxy_prefix: str = "") -> None:
|
||||
def check(image: str, port: int, environment: dict[str, str], routes: list[str], proxy_prefix: str = "",
|
||||
legacy_fixture: Path | None = None, expected_state: dict | None = None) -> None:
|
||||
name = f"crr-migration-{uuid4().hex[:12]}"
|
||||
command = ["docker", "run", "--rm", "--detach", "--name", name,
|
||||
"--tmpfs", "/data:mode=1777", "--publish", f"127.0.0.1::{port}"]
|
||||
for key, value in environment.items():
|
||||
command.extend(["--env", f"{key}={value}"])
|
||||
if legacy_fixture is not None:
|
||||
command.extend(["--mount", f"type=bind,source={legacy_fixture},target=/legacy.sqlite,readonly"])
|
||||
command.append(image)
|
||||
if legacy_fixture is not None:
|
||||
command.extend(["sh", "-c", "cp /legacy.sqlite /data/tournament.sqlite && exec uvicorn app.main:create_app --factory --host 0.0.0.0 --port 8080 --no-proxy-headers"])
|
||||
subprocess.run(command, check=True, capture_output=True, text=True)
|
||||
try:
|
||||
binding = subprocess.check_output(["docker", "port", name, str(port)], text=True).strip()
|
||||
@@ -48,7 +54,10 @@ def check(image: str, port: int, environment: dict[str, str], routes: list[str],
|
||||
assert response.status == 200, route
|
||||
body = response.read()
|
||||
if route == "/api/public/state":
|
||||
assert json.loads(body)["tournament"]["name"] == "Torneio"
|
||||
if expected_state is not None:
|
||||
assert json.loads(body) == expected_state
|
||||
else:
|
||||
assert json.loads(body)["tournament"]["name"] == "Torneio"
|
||||
elif route in {"/results", "/login"}:
|
||||
assert b"<html" in body.lower(), route
|
||||
resources = PageResources()
|
||||
@@ -73,6 +82,13 @@ if __name__ == "__main__":
|
||||
"ADMIN_PASSWORD": "migration-smoke-only-password",
|
||||
"SESSION_SECRET": "migration-smoke-only-secret",
|
||||
}, ["/api/public/state", "/results"], proxy_prefix="/jogo")
|
||||
fixtures = Path(__file__).resolve().parents[1] / "migration/fixtures"
|
||||
check("crr-tournament", 8080, {
|
||||
"ADMIN_PASSWORD": "migration-smoke-only-password",
|
||||
"SESSION_SECRET": "migration-smoke-only-secret",
|
||||
}, ["/api/public/state", "/results"], proxy_prefix="/jogo",
|
||||
legacy_fixture=fixtures / "tournament.sqlite",
|
||||
expected_state=json.loads((fixtures / "tournament-state.json").read_text()))
|
||||
check("crr-shifts", 8000, {
|
||||
"DATABASE_URL": "sqlite:////data/smoke.db",
|
||||
"SECRET_KEY": "migration-smoke-only-secret",
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"""Run legacy assertions unchanged, replacing only their backend/service transports."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CONTRACTS = ROOT / "migration/contracts"
|
||||
TEST_FILES = ["src/server/app.integration.test.ts", "src/server/services/calendar.test.ts",
|
||||
"src/server/services/classification.test.ts", "src/server/services/bracket.test.ts",
|
||||
"src/shared/finalSeeding.test.ts"]
|
||||
|
||||
|
||||
def main(freeze: bool = False):
|
||||
if freeze:
|
||||
for name in TEST_FILES:
|
||||
destination = CONTRACTS / name
|
||||
if destination.exists():
|
||||
raise FileExistsError(f"Refusing to overwrite {destination}")
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(ROOT / "apps/tournament" / name, destination)
|
||||
print("Preserved legacy assertions under migration/contracts without modifying source snapshots.")
|
||||
return
|
||||
modules = ROOT / "apps/tournament/node_modules"
|
||||
if not modules.is_dir():
|
||||
raise RuntimeError("Run make tournament-install first.")
|
||||
work = ROOT / ".migration/port-compat"
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
staging = work / "tests"
|
||||
staging.mkdir(parents=True, exist_ok=True)
|
||||
if not (staging / "node_modules").exists():
|
||||
(staging / "node_modules").symlink_to(modules, target_is_directory=True)
|
||||
(staging / "package.json").write_text('{"private":true,"type":"module"}\n')
|
||||
(staging / "vitest.config.mjs").write_text("export default {test:{include:['src/**/python.*.test.ts']}};\n")
|
||||
for name in TEST_FILES:
|
||||
destination = staging / name
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(CONTRACTS / name, destination)
|
||||
STAGING = staging
|
||||
server = STAGING / "src/server"
|
||||
shutil.copyfile(ROOT / "migration/python_fastify_adapter.mjs", server / "python_fastify_adapter.mjs")
|
||||
shutil.copyfile(ROOT / "migration/python_domain_adapter.mjs", server / "python_domain_adapter.mjs")
|
||||
files = []
|
||||
for source, module, replacement in [
|
||||
(server / "app.integration.test.ts", "./app.js", "./python_fastify_adapter.mjs"),
|
||||
(server / "services/calendar.test.ts", "./calendar.js", "../python_domain_adapter.mjs"),
|
||||
(server / "services/classification.test.ts", "./classification.js", "../python_domain_adapter.mjs"),
|
||||
(server / "services/bracket.test.ts", "./bracket.js", "../python_domain_adapter.mjs"),
|
||||
(STAGING / "src/shared/finalSeeding.test.ts", "./finalSeeding", "../server/python_domain_adapter.mjs"),
|
||||
]:
|
||||
text = source.read_text()
|
||||
original = f"from '{module}'"
|
||||
assert text.count(original) == 1, source
|
||||
destination = source.with_name("python." + source.name)
|
||||
text = text.replace(original, f"from '{replacement}'")
|
||||
if "from './auth.js'" in text:
|
||||
text = text.replace("from './auth.js'", "from './python_fastify_adapter.mjs'")
|
||||
destination.write_text(text)
|
||||
files.append(str(destination.relative_to(STAGING)))
|
||||
env = os.environ | {
|
||||
"TOURNAMENT_BACKEND": str(ROOT / "apps/tournament/backend"),
|
||||
"TOURNAMENT_PYTHON": str(ROOT / ".venv/bin/python"),
|
||||
"TOURNAMENT_WORK": str(work),
|
||||
"TOURNAMENT_BRIDGE": str(ROOT / "migration/python_domain_bridge.py"),
|
||||
"PYTHONDONTWRITEBYTECODE": "1",
|
||||
}
|
||||
result = subprocess.run(["node", str(STAGING / "node_modules/vitest/vitest.mjs"), "run", *files,
|
||||
"--reporter=default", "--reporter=json", f"--outputFile={work / 'tests.json'}"],
|
||||
cwd=STAGING, env=env)
|
||||
if result.returncode == 0:
|
||||
raw = json.loads((work / "tests.json").read_text())
|
||||
report = {
|
||||
"passed": raw["numPassedTests"],
|
||||
"tests": [{"name": test["fullName"], "status": test["status"]}
|
||||
for suite in raw["testResults"] for test in suite["assertionResults"]],
|
||||
"contract_sha256": {name: hashlib.sha256((CONTRACTS / name).read_bytes()).hexdigest()
|
||||
for name in TEST_FILES},
|
||||
}
|
||||
output = ROOT / "migration/phase3"
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
(output / "compatibility.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
raise SystemExit(result.returncode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--freeze", action="store_true", help="One-time preservation of the unchanged legacy assertions")
|
||||
main(parser.parse_args().freeze)
|
||||
Reference in new issue
Block a user