fix(proxy): read the job's source URL after the script name, not python's -u flag

Claude-Session: https://claude.ai/code/session_014i9z6mLTy978uRCfSsMfBq
This commit is contained in:
juancarlos.cavero 2026-09-01 18:18:47 +02:00
parent 4748e1bfa6
commit c20ecc69c5
2 changed files with 13 additions and 4 deletions

10
app.py
View file

@ -1144,10 +1144,12 @@ PROXY_ALERT_GB = 100
def _job_source_url(job) -> Optional[str]: def _job_source_url(job) -> Optional[str]:
"""The ``-u`` argument of the job's main.py command, if it was a URL job.""" """The ``-u`` argument of the job's main.py command, if it was a URL job."""
cmd = list((job or {}).get('cmd') or []) cmd = list((job or {}).get('cmd') or [])
for flag in ('-u', '--url'): # The command is ``python -u main.py -u <url>``: skip past the script
if flag in cmd: # name first or the interpreter's own ``-u`` flag is what gets matched.
i = cmd.index(flag) start = next((i + 1 for i, a in enumerate(cmd) if str(a).endswith('main.py')), 0)
return cmd[i + 1] if i + 1 < len(cmd) else None for i in range(start, len(cmd) - 1):
if cmd[i] in ('-u', '--url'):
return cmd[i + 1]
return None return None

View file

@ -176,3 +176,10 @@ def test_alert_folds_a_burst_into_one_message(monkeypatch):
def test_host_of_strips_credentials_and_paths(): 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("https://user:pw@www.youtube.com/watch?v=1") == "www.youtube.com"
assert proxy_ledger.host_of(None) is None 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