Stop package_helper download specs writing test_package.tar.gz to disk
What does this merge request do and why?
spec/lib/gdk/package_helper_spec.rb fails intermittently depending on RSpec's random seed. Observed on rspec: [3.4] (job 16673482262, seed 511) on !6166 (closed) while rspec: [3.2] and [3.3] passed on the identical commit; a plain retry of the job passed.
1) GDK::PackageHelper#create_package creates a package
expected: 1 time with arguments: ("test_directory", *(any args))
received: 0 times
2) GDK::PackageHelper#create_package raises an error when an unexpected error occurs
expected StandardError ... but nothing was raisedCause. create_package returns early when File.exist?(package_path). In the spec package_path is the relative string test_package.tar.gz, so that checks the working directory. The #download_package examples stub File.write, File.open and File.read for that path, but not File.binwrite, which is what download_package actually calls to persist the response. Every download example therefore writes a real test_package.tar.gz into the repository root. The success path deletes it again via FileUtils.rm_f, but when extract_package fails raises before that line on every retry and leaves the file behind. If random ordering then runs a #create_package example, it returns early and both assertions fail.
Fix. Stub File.binwrite for the package path in the #download_package before block, with and_call_original for every other path because extract_entry uses File.binwrite for real inside a tmpdir. Spec-only change; no production code is touched.
Supersedes !6171 (closed), which was identical apart from a commit message that used a short issue reference and failed Danger.
Fixes #3370 (closed)
How to set up and validate locally
Reproduce the mechanism on main without depending on the seed:
$ touch test_package.tar.gz
$ bundle exec rspec spec/lib/gdk/package_helper_spec.rb -e '#create_package'
# 2 examples, 2 failures (same messages as above)
$ rm test_package.tar.gzThen confirm the download examples were the source of that file on main:
$ bundle exec rspec spec/lib/gdk/package_helper_spec.rb -e 'when extract_package fails'
$ ls test_package.tar.gz
test_package.tar.gz # left behind on mainOn this branch the second command leaves no file, and the full spec file passes in any order:
$ bundle exec rspec spec/lib/gdk/package_helper_spec.rb --seed 511Impacted categories
The following categories relate to this merge request:
- gdk-reliability - e.g. When a GDK action fails to complete.
- gdk-usability - e.g. Improvements or suggestions around how the GDK functions.
- gdk-performance - e.g. When a GDK action is slow or times out.
Merge request checklist
- This MR references an issue describing the change.
- This change is backward compatible. If not, include steps to communicate to users.
- Tests added for new functionality. If not, raise an issue to follow-up. (Test-only change.)
- Observability added/updated (logging, metrics, tracing).
- Documentation added/updated.
- Announcement added for notable changes.
-
gdk doctortest added. - This contribution was prepared with the help of an AI assistant. I reviewed the changes and take responsibility for them.