from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
JS = (ROOT / "ui_builder" / "static" / "app.js").read_text(encoding="utf-8")
APP = (ROOT / "app.py").read_text(encoding="utf-8")


def test_build_version_bumped():
    assert 'BUILD_VERSION = "2026.08.19.22"' in APP


def test_sequence_targets_match_active_overlay_input():
    assert "function shortcutSequenceOverlayTargets" in JS
    assert "function sequenceMatchesRuntimeOverlay" in JS
    assert "normalizeRuntimeVmixInputRef(current.input) === normalizeRuntimeVmixInputRef(target.input)" in JS


def test_normal_and_scoreboard_alternate_inputs_are_tracked():
    assert "addTarget(parsed.layer, templateSequenceValue(step.input, context))" in JS
    assert "step.scoreboard_alternate_input" in JS


def test_onair_prefers_runtime_target_match():
    start = JS.index("function shortcutSequenceIsOnAir")
    snippet = JS[start:start + 1800]
    assert "if (sequenceStillOwnsRuntimeOverlay(id)) return true;" in snippet
    assert "sequenceMatchesRuntimeOverlay(sequence)" in snippet
    assert "state.quickPanelOnAirSequences.has(id)" in snippet


def test_target_detection_respects_step_conditions():
    assert "sequenceConditionMatches(step.condition, context, step.condition_value)" in JS
