Evaluate globs in expectations of scripts/verify-tff-mapping
Problem
In !167621 (merged) we started to disable (by commenting the code) verifying test mappings which use globs:
# See https://gitlab.com/gitlab-org/gitlab/-/issues/466068#note_1988359861
- source: '(?<prefix>ee/)?lib/sidebars/(?<rest>.+)\.rb'
test: '%{prefix}spec/features/**/{navbar,sidebar}_spec.rb'
Proposed solution
- Use glob patterns to dynamically match test files
- Expand these patterns at runtime using Ruby's Dir.glob
- Re-enable previously disabled test verifications
diff --git a/scripts/verify-tff-mapping b/scripts/verify-tff-mapping
index d0d4877b9efa..22537705d8d2 100755
--- a/scripts/verify-tff-mapping
+++ b/scripts/verify-tff-mapping
@@ -754,18 +754,14 @@ tests = [
# We cannot uncomment this, as this "spec" would fail as soon as we add/remove a file in
# the "spec/features" folder hierarchy that would contain the word navbar/sidebar.
#
- # {
- # explanation: 'https://gitlab.com/gitlab-org/gitlab/-/issues/466068#note_1988359861',
- # changed_file: 'lib/sidebars/projects/menus/issues_menu.rb',
- # expected: %w[
- # spec/features/boards/sidebar_spec.rb
- # spec/features/dashboard/navbar_spec.rb
- # spec/features/explore/navbar_spec.rb
- # spec/features/groups/navbar_spec.rb
- # spec/features/projects/navbar_spec.rb
- # spec/lib/sidebars/projects/menus/issues_menu_spec.rb
- # ]
- # },
+ {
+ explanation: 'https://gitlab.com/gitlab-org/gitlab/-/issues/466068#note_1988359861',
+ changed_file: 'lib/sidebars/projects/menus/issues_menu.rb',
+ expected: %w[
+ spec/features/**/{navbar,sidebar}_spec.rb
+ spec/lib/sidebars/projects/menus/issues_menu_spec.rb
+ ]
+ },
# Why is it commented out?
#
@@ -846,7 +842,7 @@ class MappingTest
@explanation = explanation
@changed_file = changed_file
@strategy = strategy
- @expected_set = Set.new(expected)
+ @expected_set = Set.new(expected.flat_map { |glob| Dir.glob(glob) })
@actual_set = Set.new(actual)
end
The diff above
Business Impact
- Reduced Maintenance Burden: Eliminates manual updates to test lists when adding/removing matching test files
- Improved CI Reliability: Prevents flaky tests caused by hardcoded test path references
- Enhanced Developer Experience: Simplifies test mapping definitions with powerful pattern matching
- Better Code Quality: Re-enables critical test verification that was previously disabled
- Future-Proofing: Creates a more flexible system that accommodates ongoing test file additions
- Time Savings: Reduces time spent updating hardcoded test paths during code organization changes
Discussions
The following discussion from !188543 (merged) should be addressed:
-
@splattael started a discussion: Suggestion (non-blocking) Since we are using globs (
'spec/tooling/lib/tooling/glci/**/*_spec.rb') to match tests the expected list of tests will change if the tests are added or removed. This might caused flaky specs similar to https://gitlab.com/gitlab-org/gitlab/-/blob/master/scripts/verify-tff-mapping#L752-818 (#466068 (comment 1939569462)).I wonder if we should use globs in
expectedlist as well and useDir.glob:diff --git a/scripts/verify-tff-mapping b/scripts/verify-tff-mapping index d0d4877b9efa..22537705d8d2 100755 --- a/scripts/verify-tff-mapping +++ b/scripts/verify-tff-mapping @@ -754,18 +754,14 @@ tests = [ # We cannot uncomment this, as this "spec" would fail as soon as we add/remove a file in # the "spec/features" folder hierarchy that would contain the word navbar/sidebar. # - # { - # explanation: 'https://gitlab.com/gitlab-org/gitlab/-/issues/466068#note_1988359861', - # changed_file: 'lib/sidebars/projects/menus/issues_menu.rb', - # expected: %w[ - # spec/features/boards/sidebar_spec.rb - # spec/features/dashboard/navbar_spec.rb - # spec/features/explore/navbar_spec.rb - # spec/features/groups/navbar_spec.rb - # spec/features/projects/navbar_spec.rb - # spec/lib/sidebars/projects/menus/issues_menu_spec.rb - # ] - # }, + { + explanation: 'https://gitlab.com/gitlab-org/gitlab/-/issues/466068#note_1988359861', + changed_file: 'lib/sidebars/projects/menus/issues_menu.rb', + expected: %w[ + spec/features/**/{navbar,sidebar}_spec.rb + spec/lib/sidebars/projects/menus/issues_menu_spec.rb + ] + }, # Why is it commented out? # @@ -846,7 +842,7 @@ class MappingTest @explanation = explanation @changed_file = changed_file @strategy = strategy - @expected_set = Set.new(expected) + @expected_set = Set.new(expected.flat_map { |glob| Dir.glob(glob) }) @actual_set = Set.new(actual) endLet's follow-up on this
💪