from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def read(rel):
    return (ROOT / rel).read_text(encoding="utf-8")


def test_export_cleaner_strips_ai_markdown_placeholders_and_candidate_notes():
    doc = read("includes/class-ssc-ch-doc-builder.php")
    assert "function clean_export_text" in doc
    assert "NOTES\\s+FOR\\s+CANDIDATE" in doc
    assert "phone(?:\\s+number)?|email(?:\\s+address)?" in doc
    assert "preg_replace('/^\\*\\*(.+?)\\*\\*:?$/', '$1', $line)" in doc
    assert "preg_replace('/^[-*]\\s+/', '• ', $line)" in doc


def test_docx_and_pdf_paths_clean_before_rendering():
    doc = read("includes/class-ssc-ch-doc-builder.php")
    build_docx = doc.split("public static function build_docx", 1)[1].split("public static function suggest_filename", 1)[0]
    build_print = doc.split("public static function build_print_html", 1)[1].split("/* ------------------------------------------------------------------", 1)[0]
    assert "self::clean_export_text" in build_docx
    assert "self::clean_export_text" in build_print


def test_version_bumped_for_export_cleanup_release():
    main = read("ssc-career-hub.php")
    assert "Version: 1.12.37" in main
    assert "SSC_CH_VERSION', '1.12.37'" in main
