"""End-to-end integration tests.""" from pathlib import Path import pandas as pd import pytest from core.database import clear_project_data, get_connection, insert_chainages from core.orchestrator import Orchestrator from core.submission_checker import check_submission_readiness SAMPLE_XML = Path(__file__).parent / "test_data" / "sample.xml" def test_orchestrator_full_pipeline(): assert SAMPLE_XML.exists() xml_data = SAMPLE_XML.read_bytes() orchestrator = Orchestrator() result = orchestrator.run_full_pipeline( ex_xml=xml_data, pr_xml=xml_data, project_name="IntegrationTest", ) assert result["status"] in ["complete", "partial"] assert "results" in result assert result["results"]["parse_xml"]["status"] == "success" assert result["results"]["calculate"]["status"] == "success" assert result["results"]["run_qa"]["status"] == "success" assert result["results"]["generate_report"]["status"] == "success" assert Path(result["report_path"]).exists() def test_submission_checker(): df = pd.DataFrame( { "datum_chainage": [1000, 1010, 1020], "level_m": [10.0, 10.5, 11.0], "offset_alignment": ["TestTrack"] * 3, } ) insert_chainages(df, "existing", source_file="test.xml") result = check_submission_readiness( project_name="TestProject", ex_df=df, pr_df=df, calculations={1: {"lift": {1000: 5.0}}}, drawing_issues=[], vba_script="x" * 120, ) assert "status" in result assert "issues" in result assert "recommendation" in result def test_clear_project_data(): clear_project_data() def test_db_schema(): conn = get_connection() cursor = conn.cursor() cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") tables = [row[0] for row in cursor.fetchall()] expected = ["chainages", "survey_features", "drawings", "psr", "project_metadata", "provenance"] for table in expected: assert table in tables, f"Missing table: {table}" conn.close()