File size: 2,133 Bytes
abe09ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# pages/98_Test_Dashboard.py
from __future__ import annotations
"""Streamlit Test Dashboard for AI E-Consult V2.

Runs the internal smoke and integration tests (tests/smoke_v2.py, tests/integration_v2.py)
and displays their console output live within the UI.
"""

import io
import sys
import contextlib
import runpy
from pathlib import Path

import streamlit as st

st.title("πŸ§ͺ Test Dashboard β€” AI E-Consult V2")
st.caption("Run smoke and integration tests directly within the Hugging Face Space.")

tests_dir = Path(__file__).resolve().parents[1] / "tests"
smoke_path = tests_dir / "smoke_v2.py"
integ_path = tests_dir / "integration_v2.py"

if not smoke_path.exists() or not integ_path.exists():
    st.error("❌ Test files not found. Please ensure tests/smoke_v2.py and tests/integration_v2.py exist.")
    st.stop()

st.markdown("**Available tests:**")
st.markdown("- `smoke_v2.py` β€” basic schema and module checks")
st.markdown("- `integration_v2.py` β€” module wiring and export determinism")

run_btn = st.button("▢️ Run All Tests", use_container_width=True)

output_buf = io.StringIO()

def _run_script(path: Path):
    print(f"\n=== Running {path.name} ===")
    try:
        runpy.run_path(str(path), run_name="__main__")
    except SystemExit as e:
        print(f"Exited with code {getattr(e, 'code', '?')}")
    except Exception as e:
        print(f"⚠️ Error running {path.name}: {e}")

if run_btn:
    with contextlib.redirect_stdout(output_buf), contextlib.redirect_stderr(output_buf):
        print("πŸ” Starting internal test suite...\n")
        _run_script(smoke_path)
        _run_script(integ_path)
        print("\nβœ… Test run completed.")

    st.success("Test run completed.")
    st.markdown("**Console Output:**")
    st.code(output_buf.getvalue(), language="bash")

    # Offer download
    st.download_button(
        "πŸ’Ύ Download Results",
        data=output_buf.getvalue(),
        file_name="test_results_v2.txt",
        mime="text/plain",
        use_container_width=True,
    )
else:
    st.info("Click 'Run All Tests' to execute internal test scripts and view results here.")