Improve isolation and robustness in Project::TreeSaver spec
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do and why?
This MR introduces several improvements to ee/spec/services/ee/import/gitlab/import_export/project/tree_saver_spec.rb to enhance test isolation, robustness, and reliability:
- Unique Temporary Directories for Exports:
- Previously, all examples in the spec used a fixed temporary path (
#{Dir.tmpdir}/project_tree_saver_spec_ee) for project export operations. This could lead to flakiness due to:- Stale files from previously failed or interrupted examples polluting subsequent test runs.
- Potential race conditions if examples were ever run in parallel.
- This change modifies the spec setup to use
Dir.mktmpdirto generate a fresh, unique temporary directory for each test example. Theproject.import_export_shared.export_pathis dynamically updated to point to this unique directory for the duration of each example, ensuring true file system isolation.
- More Robust Assertions for Array Contents:
-
Vulnerabilities Export: Assertions for exported vulnerabilities now fetch all exported vulnerability objects into an array and then use
findto locate the specific vulnerability created by the test setup (e.g., by matching ontitleandreport_type). This avoids failures due to changes in export order or if other vulnerabilities exist on the project. Previously, it assumed the test's vulnerability would be the.firstin the array. -
Notes in Restricted Associations: Similarly, when testing the filtering of notes based on permissions, the assertion now maps the exported notes to their text content and uses
contain_exactlyto verify against the expected note contents. This is more robust than relying on a fixed order or count if the exact notes change.
These changes make the spec less brittle, more resilient to unrelated data or ordering changes, and improve overall test hygiene. More details in the commit messages.
Closes: #537925 (closed) and #436936 (closed)
How to set up and validate locally
- Check out this branch.
bundle install && yarn install- Run the spec file:
bundle exec rspec ee/spec/services/ee/import/gitlab/import_export/project/tree_saver_spec.rb
- All tests should pass. The changes primarily affect test setup and assertion logic to improve stability, so the functional behavior of the
TreeSaveritself is not intended to change.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Zakaria Fatahi