Use resolve_dir for direct URL destination (follow-up to #19)#21
Open
bradleesand wants to merge 1 commit into
Open
Use resolve_dir for direct URL destination (follow-up to #19)#21bradleesand wants to merge 1 commit into
bradleesand wants to merge 1 commit into
Conversation
_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.
36240c5 to
feac780
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #19 addressing @loganbuilt's review comment:
_run_direct_url_with_clinow callsresolve_dir((destination or "").strip(), paths.single_downloads_dir)instead of doing its ownos.path.isabs/os.path.joindance — matches the queue path inengine/job_queue.py:_resolve_job_output_dir.../etc) now raiseValueErrorinstead of silently resolving outsideDOWNLOADS_DIR.tests/test_direct_url_contracts.py:"Singles"lands undersingle_downloads_dir/Singles/"../../etc"is rejected anddownload_with_ytdlpis never invokedKnown 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:This comes from
platform._sys_version_parserchoking on the bare"3.11.9"string installed by the existingmonkeypatch.setattr(sys, "version", "3.11.9", ...)line in theapi_modulefixture, afterwsgiref.simple_serveris imported transitively viagoogle_auth_oauthlibduringapi.mainimport. Whether it triggers depends on whetherwsgiref.simple_serverwas already cached insys.modulesbefore the fixture runs. The samemonkeypatchpattern is used in ~19 fixtures acrosstests/, 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 onmainwith afinal_formatassertion 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'ssys.versionpatch doesn't breakwsgirefimportpytest tests/test_direct_url_contracts.py::test_server_direct_url_escape_destination_is_rejected— same caveatsingle_download_folder="Singles"→ file in$DOWNLOADS_DIR/Singles/destination="../outside"→ rejected with a clear error