import subprocess import sys import os import pytest import tempfile import sqlite3 def test_cli_help(): """Smoke test for --help flag.""" result = subprocess.run( [sys.executable, "-m", "meshchatx.meshchat", "--help"], capture_output=True, text=True, ) assert result.returncode == 0 assert "usage:" in result.stdout.lower() or "options:" in result.stdout.lower() def test_import_all_backend_modules(): """Smoke test to ensure all backend modules can be imported without error.""" import importlib backend_path = "meshchatx.src.backend" root_dir = os.path.join("meshchatx", "src", "backend") for root, dirs, files in os.walk(root_dir): for file in files: if file.endswith(".py") and not file.startswith("__"): rel_path = os.path.relpath(os.path.join(root, file), root_dir) module_name = rel_path.replace(os.sep, ".").replace(".py", "") full_module_name = f"{backend_path}.{module_name}" try: importlib.import_module(full_module_name) except Exception as e: # Skip some modules that might need special environment if "bot_process" in full_module_name: continue pytest.fail(f"Failed to import {full_module_name}: {e}") def test_database_migration_smoke(): """Smoke test for database migrations from version 0 to latest.""" from meshchatx.src.backend.database.provider import DatabaseProvider from meshchatx.src.backend.database.schema import DatabaseSchema with tempfile.TemporaryDirectory() as tmpdir: db_path = os.path.join(tmpdir, "test_migration.db") provider = DatabaseProvider(db_path) schema = DatabaseSchema(provider) # Initialize (runs all migrations) schema.initialize() # Verify it reached the latest version conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row cursor = conn.cursor() cursor.execute("SELECT value FROM config WHERE key = 'database_version'") row = cursor.fetchone() assert row is not None assert int(row["value"]) == DatabaseSchema.LATEST_VERSION conn.close() def test_markdown_renderer_smoke(): """Smoke test for MarkdownRenderer with basic markdown.""" from meshchatx.src.backend.markdown_renderer import MarkdownRenderer basic_md = "# Hello\nThis is **bold** and *italic*." result = MarkdownRenderer.render(basic_md) assert "Hello" in result assert "