from pathlib import Path

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


def test_browser_worker_is_bound_to_launching_run_id():
    app = (ROOT / "web/static/app.js").read_text(encoding="utf-8")
    assert "let executionRunId = '';" in app
    assert "runWorker(data.item,data.run.settings,runId);" in app
    assert "executeNext(runId)" in app
    assert "encodeURIComponent(runId)}/profiles" in app
    assert "setTimeout(()=>executeNext(runId),25);" in app
    assert "$('runSelect').disabled=locked;" in app


def test_worker_and_backend_carry_run_link():
    worker = (ROOT / "web/static/struc_i_worker.js").read_text(encoding="utf-8")
    web = (ROOT / "gal_fingerprint_i/web.py").read_text(encoding="utf-8")
    assert "const { item, settings, run_id } = event.data;" in worker
    assert "run_id," in worker
    assert 'run_id: str = ""' in web
    assert "Run link mismatch" in web
