from pathlib import Path ROOT = Path(__file__).resolve().parents[1] APP_JS = (ROOT / "ui_builder/static/app.js").read_text(encoding="utf-8") APP = (ROOT / "app.py").read_text(encoding="utf-8") def _block(start: str, end: str) -> str: return APP_JS.split(start, 1)[1].split(end, 1)[0] def test_prepared_penalty_does_not_force_vmix_rebalance(): block = _block("function emitHockeyEventUpdated", "function createHockeyPenaltyDraft") assert "rebalanceVmixPenaltyTargets" not in block draft = _block("function createHockeyPenaltyDraft", "function findHockeyPenalty") assert "startedOnce: false" in draft control = _block("function controlHockeyPenalty", "function formatHockeyPenaltyTime") start_branch = control.split('if (command === "start")', 1)[1].split('} else if (command === "pause")', 1)[0] assert "event.startedOnce = true" in start_branch def test_penalty_vmix_display_uses_only_started_or_paused_active_penalties(): assert "function activeHockeyPenaltyEntries()" in APP_JS sorted_block = _block("function sortedPenaltyEntries", "function penaltyLocalAdvantageSide") assert "activeHockeyPenaltyEntries()" in sorted_block def test_main_countdown_start_pause_stop_all_hard_sync_web_value(): block = _block("async function syncActiveVmixGameCountdown", "function penaltyMirrorKey") start = block.split('if (["timer_start", "timer_restart", "timer_resume"].includes(eventName))', 1)[1].split('} else if (eventName === "timer_pause")', 1)[0] assert start.index('Function: "SetCountdown"') < start.index('Function: "StartCountdown"') pause = block.split('eventName === "timer_pause"', 1)[1].split('} else if (["timer_stop", "timer_finished"]', 1)[0] assert pause.index('Function: "PauseCountdown"') < pause.index('Function: "SetCountdown"') stop = block.split('["timer_stop", "timer_finished"].includes(eventName)', 1)[1].split('} else if (["timer_reset"', 1)[0] assert stop.index('Function: "StopCountdown"') < stop.index('Function: "SetCountdown"') def test_penalty_pause_freezes_before_reseed_and_start_reseeds_before_run(): block = _block("async function rebalanceVmixPenaltyTargets", "function finishActionMatchesSource") assert 'stopCommands.push({ Function: "PauseCountdown"' in block assert 'setCommands.push({ Function: "SetCountdown"' in block assert 'runCommands.push({ Function: "StartCountdown"' in block assert "Never StartCountdown for a prepared item" in block def test_combined_shortcut_changes_web_first_then_synchronizes_vmix(): block = APP_JS.split('case "hockey_vmix_timers_start":', 1)[1].split('case "delay":', 1)[0] web_game = block.index("if (step.start_web_game)") vmix_game = block.index("if (step.sync_vmix_game && step.game_vmix_input)") assert web_game < vmix_game assert block.index('Function: "PauseCountdown"') < block.index('Function: "SetCountdown"', block.index('Function: "PauseCountdown"')) assert 'Function: "StartCountdown"' in block def test_build95_runtime_version(): assert 'BUILD_VERSION = "2026.08.20.16"' in APP