Skip to content

Use resolve_dir for direct URL destination (follow-up to #19)#21

Open
bradleesand wants to merge 1 commit into
sudoStacks:mainfrom
bradleesand:followup/direct-url-resolve-dir
Open

Use resolve_dir for direct URL destination (follow-up to #19)#21
bradleesand wants to merge 1 commit into
sudoStacks:mainfrom
bradleesand:followup/direct-url-resolve-dir

Conversation

@bradleesand
Copy link
Copy Markdown
Contributor

@bradleesand bradleesand commented Apr 24, 2026

Summary

Follow-up to #19 addressing @loganbuilt's review comment:

  • _run_direct_url_with_cli now calls resolve_dir((destination or "").strip(), paths.single_downloads_dir) instead of doing its own os.path.isabs / os.path.join dance — matches the queue path in engine/job_queue.py:_resolve_job_output_dir.
  • Destinations that escape the base (e.g. ../etc) now raise ValueError instead of silently resolving outside DOWNLOADS_DIR.
  • Adds two regression tests in tests/test_direct_url_contracts.py:
    • relative destination "Singles" lands under single_downloads_dir/Singles/
    • escape destination "../../etc" is rejected and download_with_ytdlp is never invoked

Known test-environment issue

On a fresh process under Python 3.11.15 the new tests (and the rest of test_direct_url_contracts.py) fail at fixture setup with:

ValueError: failed to parse CPython sys.version: '3.11.9'

This comes from platform._sys_version_parser choking on the bare "3.11.9" string installed by the existing monkeypatch.setattr(sys, "version", "3.11.9", ...) line in the api_module fixture, after wsgiref.simple_server is imported transitively via google_auth_oauthlib during api.main import. Whether it triggers depends on whether wsgiref.simple_server was already cached in sys.modules before the fixture runs. The same monkeypatch pattern is used in ~19 fixtures across tests/, so this isn't unique to this file.

Not touching the fixture in this PR to keep the diff focused on the review comment. Planning a follow-up PR to bring the full test suite under GitHub Actions; once CI is running the whole test_* family we can fix the fixture pattern once for everyone.

Separately, two pre-existing tests in this file (test_*_video_mode_*) fail on main with a final_format assertion mismatch ('mp3' != 'mkv'), unrelated to this change — left untouched.

Test plan

  • pytest tests/test_direct_url_contracts.py::test_server_direct_url_relative_destination_resolves_under_downloads_dir — passes in environments where the fixture's sys.version patch doesn't break wsgiref import
  • pytest tests/test_direct_url_contracts.py::test_server_direct_url_escape_destination_is_rejected — same caveat
  • Manual: submit a direct URL with single_download_folder="Singles" → file in $DOWNLOADS_DIR/Singles/
  • Manual: submit a direct URL with destination="../outside" → rejected with a clear error

_run_direct_url_with_cli now calls resolve_dir on the destination,
matching the queue path in engine/job_queue.py:_resolve_job_output_dir.
This handles empty/relative/absolute destinations consistently and
rejects paths that escape DOWNLOADS_DIR (e.g. "../etc") with a
ValueError, instead of silently resolving outside the base.

Adds two regression tests in tests/test_direct_url_contracts.py:
- relative destination "Singles" lands under
  single_downloads_dir/Singles/
- escape destination "../../etc" raises ValueError and
  download_with_ytdlp is never invoked

Addresses the review comment on sudoStacks#19.
@bradleesand bradleesand force-pushed the followup/direct-url-resolve-dir branch from 36240c5 to feac780 Compare April 28, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant