Smarter download_artifacts tool#653
Conversation
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the DownloadArtifactsTool to automatically download artifacts to a dynamically created temporary directory instead of requiring a user-specified target_path. It also updates the tool output to return the temporary directory path as a JSON response and ensures cleanup of the directory in case of download failures. Feedback is provided to clean up the temporary directory created during successful test runs to prevent resource leaks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| target_path = Path(result.target_path) | ||
| path = target_path / url.rsplit("/", 1)[-1].removesuffix(".gz") | ||
| assert path.read_bytes() == content |
There was a problem hiding this comment.
The unit test currently leaks the dynamically created temporary directory on successful runs. Since DownloadArtifactsTool now creates a temporary directory using tempfile.mkdtemp() and returns it, the test should ensure that this directory is cleaned up after assertions are complete.
| target_path = Path(result.target_path) | |
| path = target_path / url.rsplit("/", 1)[-1].removesuffix(".gz") | |
| assert path.read_bytes() == content | |
| import shutil | |
| target_path = Path(result.target_path) | |
| try: | |
| path = target_path / url.rsplit("/", 1)[-1].removesuffix(".gz") | |
| assert path.read_bytes() == content | |
| finally: | |
| shutil.rmtree(target_path, ignore_errors=True) |
References
- Ensure temporary resources created during test execution are cleaned up to prevent resource leaks on the host system.
The tool has been rewritten to allow less space for errors. Instead of letting agent choose where to download files to, which is also a security hazard, the agent can only choose what to download. Upon invocation, the tool creates a temporary directory, and all artifacts are downloaded there.
Path to the temporary directory is returned upon successful tool run. If the tool fails, the temporary directory and all contents are removed.
The cleanup step is, arguably, an overkill. Name of the temporary dir is generated randomly, and unless the agent were to get into a particularly vicious loop, it is unlikely to run out possible names.
The tool output has been written with custom
get_text_contentmethod, to cut down number of tokens used. It is very much a question of taste, as we are saving handful of tokens per call at best.Fixes
PACKIT-5157: Download artifacts failing due to nonexistent directory
RELEASE NOTES BEGIN
The
download_artifactstool now uses temporary directories to store downloaded artifacts, and does not allow agent to choose where artifacts are downloaded.RELEASE NOTES END