import os import shutil import subprocess import sys import zipfile from pathlib import Path def test_built_wheel_omits_vector_sql_migrations_and_discovers_cli(tmp_path): harness = Path(__file__).parents[1] wheelhouse = tmp_path / "wheelhouse" target = tmp_path / "site" wheelhouse.mkdir() uv = shutil.which("uv") assert uv is not None, "uv is required to verify the production wheel" build_env = {**os.environ, "UV_CACHE_DIR": str(tmp_path / "uv-cache")} subprocess.run( [ uv, "build", "--wheel", "--out-dir", str(wheelhouse), str(harness), ], check=True, capture_output=True, text=True, env=build_env, ) wheel = next(wheelhouse.glob("tht-*.whl")) with zipfile.ZipFile(wheel) as archive: names = set(archive.namelist()) assert not any(name.startswith("tht/migrations/vector/") for name in names) assert "tht/migrations/sessions/001_schema.sql" in names assert "tht/migrations/sessions/002_security.sql" in names assert "tht/migrations/memory/001_memory.sql" in names assert "tht/migrations/memory/002_hybrid_projection.sql" in names assert "tht/migrations/memory/003_review_receipts.sql" in names subprocess.run( [sys.executable, "-m", "pip", "install", "--no-deps", "--target", str(target), wheel], check=True, capture_output=True, text=True, ) env = {**os.environ, "PYTHONPATH": str(target)} probe = subprocess.run( [ sys.executable, "-c", ( "from typer.testing import CliRunner; from tht.cli import app; " "r=CliRunner().invoke(app, ['session','migrate','--help']); " "print(r.output); raise SystemExit(r.exit_code)" ), ], env=env, check=False, capture_output=True, text=True, cwd=tmp_path, ) assert probe.returncode == 0, probe.stderr + probe.stdout assert "--status" in probe.stdout