2026-11-10 23:56:50 +08:00
|
|
|
"""Opt-in MySQL API regression, restricted to the isolated verification host."""
|
2026-11-14 14:07:26 +08:00
|
|
|
|
2026-11-10 23:56:50 +08:00
|
|
|
import asyncio
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
import uuid
|
|
|
|
|
import httpx
|
|
|
|
|
import pytest_asyncio
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
from sqlalchemy.engine import make_url
|
|
|
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
|
|
|
from alembic import command
|
|
|
|
|
from alembic.config import Config
|
2026-11-14 14:07:26 +08:00
|
|
|
from app.core.config import Settings
|
2026-11-10 23:56:50 +08:00
|
|
|
from app.main import create_app
|
|
|
|
|
from conftest import FakeProvider, PASSWORD
|
|
|
|
|
|
|
|
|
|
from test_auth import test_login_cookie_csrf_and_revocation
|
|
|
|
|
from test_jobs import test_lost_submit_response_recovers_same_id_and_known_id_never_resubmits
|
|
|
|
|
from test_core_v2 import test_submission_changed_body_conflicts_and_recovers
|
2026-11-14 14:07:26 +08:00
|
|
|
from test_fifo_json import test_prepared_fifo_uses_native_json_and_preserves_payload_and_holds
|
2026-11-10 23:56:50 +08:00
|
|
|
from test_workflows_v2 import (
|
|
|
|
|
test_snapshot_version_idempotency_owner,
|
|
|
|
|
test_engine_durable_sequential_cancel_and_no_new_job,
|
|
|
|
|
test_batch_mixed_persistent_one_active_member,
|
|
|
|
|
test_parallel_run_and_patch_versions_accept_one,
|
|
|
|
|
test_batch_does_not_advance_while_previous_cleanup_unknown,
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-14 14:07:26 +08:00
|
|
|
|
2026-11-10 23:56:50 +08:00
|
|
|
@pytest_asyncio.fixture
|
|
|
|
|
async def system(tmp_path):
|
2026-11-14 14:07:26 +08:00
|
|
|
url = make_url(os.environ["CMVR_VERIFY_MYSQL_URL"])
|
|
|
|
|
if url.host not in {"cmvr-visual-v2-test-mysql", "cmvr-visual-v4-test-mysql"}:
|
|
|
|
|
raise RuntimeError("Refusing non-isolated database")
|
|
|
|
|
name = "cmvr_visual_verify_" + uuid.uuid4().hex[:12]
|
|
|
|
|
engine = create_async_engine(url.set(database="mysql"))
|
2026-11-10 23:56:50 +08:00
|
|
|
async with engine.begin() as c:
|
2026-11-14 14:07:26 +08:00
|
|
|
await c.execute(text(f"CREATE DATABASE `{name}` CHARACTER SET utf8mb4"))
|
|
|
|
|
config = Config(str(Path(__file__).parents[1] / "alembic.ini"))
|
|
|
|
|
config.attributes["url"] = url.set(database=name)
|
2026-11-10 23:56:50 +08:00
|
|
|
try:
|
2026-11-14 14:07:26 +08:00
|
|
|
await asyncio.to_thread(command.upgrade, config, "head")
|
|
|
|
|
settings = Settings(
|
|
|
|
|
mode="production",
|
|
|
|
|
database_url=url.set(database=name),
|
|
|
|
|
workspace_root=tmp_path,
|
|
|
|
|
admin_username="admin",
|
|
|
|
|
admin_password=PASSWORD,
|
|
|
|
|
run_coordinator=False,
|
|
|
|
|
cookie_secure=False,
|
|
|
|
|
)
|
|
|
|
|
provider = FakeProvider()
|
|
|
|
|
|
|
|
|
|
async def caps():
|
|
|
|
|
return {"protocol_version": 2, "admission_policy": True}
|
|
|
|
|
|
|
|
|
|
provider.upstream_capabilities = caps
|
|
|
|
|
app = create_app(settings, provider=provider)
|
2026-11-10 23:56:50 +08:00
|
|
|
async with app.router.lifespan_context(app):
|
2026-11-14 14:07:26 +08:00
|
|
|
async with httpx.AsyncClient(
|
|
|
|
|
transport=httpx.ASGITransport(app=app), base_url="http://test"
|
|
|
|
|
) as client:
|
|
|
|
|
login = await client.post(
|
|
|
|
|
"/api/auth/login", json={"username": "admin", "password": PASSWORD}
|
|
|
|
|
)
|
|
|
|
|
assert login.status_code == 200
|
|
|
|
|
client.headers["X-CSRF-Token"] = login.json()["csrf_token"]
|
|
|
|
|
yield SimpleNamespace(app=app, client=client, settings=settings, provider=provider)
|
2026-11-10 23:56:50 +08:00
|
|
|
finally:
|
|
|
|
|
async with engine.begin() as c:
|
2026-11-14 14:07:26 +08:00
|
|
|
await c.execute(text(f"DROP DATABASE `{name}`"))
|
2026-11-10 23:56:50 +08:00
|
|
|
await engine.dispose()
|
|
|
|
|
|
2026-11-14 14:07:26 +08:00
|
|
|
|
2026-11-10 23:56:50 +08:00
|
|
|
@pytest_asyncio.fixture
|
2026-11-14 14:07:26 +08:00
|
|
|
async def wf(system):
|
|
|
|
|
return system
|