diff --git a/tests/sentry/issues/ownership/test_grammar.py b/tests/sentry/issues/ownership/test_grammar.py index fbae958c005fdd..6638c50242d0f3 100644 --- a/tests/sentry/issues/ownership/test_grammar.py +++ b/tests/sentry/issues/ownership/test_grammar.py @@ -1130,3 +1130,58 @@ def test_convert_schema_to_rules_text() -> None: ) == "path:*.js #frontend m@robenolt.com\nurl:http://google.com/* #backend\npath:src/sentry/* david@sentry.io\ntags.foo:bar tagperson@sentry.io\ntags.foo:bar baz tagperson@sentry.io\nmodule:foo.bar #workflow\nmodule:foo bar meow@sentry.io\n" ) + + +@pytest.mark.parametrize( + "pattern, path_details, expected", + [ + # Pattern WITHOUT leading slash + # Path WITH leading slash + # Does not match + ( + "libs/web/views/index/**", + [ + {"filename": "/libs/web/views/index/src/widget-table.component.tsx"}, + {"abs_path": "/libs/web/views/index/src/widget-table.component.tsx"}, + ], + False, + ), + # Pattern WITH leading slash + # Path WITH leading slash + # Matches + ( + "/libs/web/views/index/**", + [ + {"filename": "/libs/web/views/index/src/widget-table.component.tsx"}, + {"abs_path": "/libs/web/views/index/src/widget-table.component.tsx"}, + ], + True, + ), + # Pattern WITHOUT leading slash + # Path WITHOUT leading slash + # Matches + ( + "libs/web/views/index/**", + [ + {"filename": "libs/web/views/index/src/widget-table.component.tsx"}, + {"abs_path": "libs/web/views/index/src/widget-table.component.tsx"}, + ], + True, + ), + # Pattern WITH leading slash + # Path WITHOUT leading slash + # Matches + ( + "/libs/web/views/index/**", + [ + {"filename": "libs/web/views/index/home.tsx"}, + {"abs_path": "libs/web/views/index/home.tsx"}, + ], + True, + ), + ], +) +def test_codeowners_leading_slash_matching( + pattern: str, path_details: Sequence[Mapping[str, str]], expected: bool +) -> None: + _assert_matcher(Matcher("codeowners", pattern), path_details, expected)