Improve isolation and robustness in Project::TreeSaver spec

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:

  1. 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.mktmpdir to generate a fresh, unique temporary directory for each test example. The project.import_export_shared.export_path is dynamically updated to point to this unique directory for the duration of each example, ensuring true file system isolation.
  1. More Robust Assertions for Array Contents:
  • Vulnerabilities Export: Assertions for exported vulnerabilities now fetch all exported vulnerability objects into an array and then use find to locate the specific vulnerability created by the test setup (e.g., by matching on title and report_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 .first in 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_exactly to 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

  1. Check out this branch.
  2. bundle install && yarn install
  3. Run the spec file:
bundle exec rspec ee/spec/services/ee/import/gitlab/import_export/project/tree_saver_spec.rb
  1. All tests should pass. The changes primarily affect test setup and assertion logic to improve stability, so the functional behavior of the TreeSaver itself 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

Merge request reports

Loading