diff --git a/app.py b/app.py index 376be87..14e36c2 100644 --- a/app.py +++ b/app.py @@ -1144,10 +1144,12 @@ PROXY_ALERT_GB = 100 def _job_source_url(job) -> Optional[str]: """The ``-u`` argument of the job's main.py command, if it was a URL job.""" cmd = list((job or {}).get('cmd') or []) - for flag in ('-u', '--url'): - if flag in cmd: - i = cmd.index(flag) - return cmd[i + 1] if i + 1 < len(cmd) else None + # The command is ``python -u main.py -u ``: skip past the script + # name first or the interpreter's own ``-u`` flag is what gets matched. + start = next((i + 1 for i, a in enumerate(cmd) if str(a).endswith('main.py')), 0) + for i in range(start, len(cmd) - 1): + if cmd[i] in ('-u', '--url'): + return cmd[i + 1] return None diff --git a/tests/test_proxy_ledger.py b/tests/test_proxy_ledger.py index 3ddf896..9260e7f 100644 --- a/tests/test_proxy_ledger.py +++ b/tests/test_proxy_ledger.py @@ -176,3 +176,10 @@ def test_alert_folds_a_burst_into_one_message(monkeypatch): def test_host_of_strips_credentials_and_paths(): assert proxy_ledger.host_of("https://user:pw@www.youtube.com/watch?v=1") == "www.youtube.com" assert proxy_ledger.host_of(None) is None + + +def test_job_source_url_skips_the_interpreter_flag(): + app = pytest.importorskip("app") + job = {"cmd": ["/usr/bin/python3", "-u", "main.py", "-u", "https://www.youtube.com/watch?v=x", "-o", "out"]} + assert app._job_source_url(job) == "https://www.youtube.com/watch?v=x" + assert app._job_source_url({"cmd": ["/usr/bin/python3", "-u", "main.py", "-i", "file.mp4"]}) is None