From 6780ee5bf96d648174930cc42be6aae40656248c Mon Sep 17 00:00:00 2001 From: Shashank Jarmale Date: Thu, 6 Nov 2025 11:58:10 -0800 Subject: [PATCH 1/2] Repro test for CODEOWNERS leading slashes in pattern & path --- tests/sentry/issues/ownership/test_grammar.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/sentry/issues/ownership/test_grammar.py b/tests/sentry/issues/ownership/test_grammar.py index fbae958c005fdd..a2dda7aba3b67f 100644 --- a/tests/sentry/issues/ownership/test_grammar.py +++ b/tests/sentry/issues/ownership/test_grammar.py @@ -1130,3 +1130,71 @@ 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", + [ + # THIS IS THE ONE THAT FAILS + # Pattern WITHOUT leading slash + # Path WITH leading slash + # Should match + ( + "libs/mobile/screens/home/**", + [ + { + "filename": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" + }, + { + "abs_path": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" + }, + ], + True, + ), + # Pattern WITH leading slash + # Path WITH leading slash + # Should match + ( + "/libs/mobile/screens/home/**", + [ + { + "filename": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" + }, + { + "abs_path": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" + }, + ], + True, + ), + # Pattern WITHOUT leading slash + # Path WITHOUT leading slash + # Should match + ( + "libs/mobile/screens/home/**", + [ + { + "filename": "libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" + }, + { + "abs_path": "libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" + }, + ], + True, + ), + # Pattern WITH leading slash + # Path WITHOUT leading slash + # Should match + ( + "/libs/mobile/screens/home/**", + [ + {"filename": "libs/mobile/screens/home/index.tsx"}, + {"abs_path": "libs/mobile/screens/home/index.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) From ae3df1a173c912fb421bbb8ece250222842fa159 Mon Sep 17 00:00:00 2001 From: Shashank Jarmale Date: Tue, 11 Nov 2025 09:48:05 -0800 Subject: [PATCH 2/2] Codifies behavior around CODEOWNER rules matching involving leading slashes with a test --- tests/sentry/issues/ownership/test_grammar.py | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/tests/sentry/issues/ownership/test_grammar.py b/tests/sentry/issues/ownership/test_grammar.py index a2dda7aba3b67f..6638c50242d0f3 100644 --- a/tests/sentry/issues/ownership/test_grammar.py +++ b/tests/sentry/issues/ownership/test_grammar.py @@ -1135,60 +1135,47 @@ def test_convert_schema_to_rules_text() -> None: @pytest.mark.parametrize( "pattern, path_details, expected", [ - # THIS IS THE ONE THAT FAILS # Pattern WITHOUT leading slash # Path WITH leading slash - # Should match + # Does not match ( - "libs/mobile/screens/home/**", + "libs/web/views/index/**", [ - { - "filename": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" - }, - { - "abs_path": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" - }, + {"filename": "/libs/web/views/index/src/widget-table.component.tsx"}, + {"abs_path": "/libs/web/views/index/src/widget-table.component.tsx"}, ], - True, + False, ), # Pattern WITH leading slash # Path WITH leading slash - # Should match + # Matches ( - "/libs/mobile/screens/home/**", + "/libs/web/views/index/**", [ - { - "filename": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" - }, - { - "abs_path": "/libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" - }, + {"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 - # Should match + # Matches ( - "libs/mobile/screens/home/**", + "libs/web/views/index/**", [ - { - "filename": "libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" - }, - { - "abs_path": "libs/mobile/screens/home/src/views/home/components/tiles/invest-tile.component.tsx" - }, + {"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 - # Should match + # Matches ( - "/libs/mobile/screens/home/**", + "/libs/web/views/index/**", [ - {"filename": "libs/mobile/screens/home/index.tsx"}, - {"abs_path": "libs/mobile/screens/home/index.tsx"}, + {"filename": "libs/web/views/index/home.tsx"}, + {"abs_path": "libs/web/views/index/home.tsx"}, ], True, ),