|
4 | 4 | from dataclasses import dataclass
|
5 | 5 | from typing import Any
|
6 | 6 | from unittest import mock
|
| 7 | +from unittest.mock import MagicMock, patch |
7 | 8 |
|
8 | 9 | import pytest
|
9 | 10 |
|
| 11 | +from sentry.grouping.api import get_grouping_config_dict_for_project, load_grouping_config |
10 | 12 | from sentry.grouping.component import FrameGroupingComponent, StacktraceGroupingComponent
|
11 | 13 | from sentry.grouping.enhancer import (
|
12 | 14 | ENHANCEMENT_BASES,
|
|
20 | 22 | from sentry.grouping.enhancer.matchers import ReturnValueCache, _cached, create_match_frame
|
21 | 23 | from sentry.grouping.enhancer.parser import parse_enhancements
|
22 | 24 | from sentry.grouping.enhancer.rules import EnhancementRule
|
| 25 | +from sentry.projectoptions.defaults import DEFAULT_GROUPING_CONFIG |
23 | 26 | from sentry.testutils.cases import TestCase
|
24 | 27 |
|
25 | 28 |
|
@@ -623,6 +626,49 @@ def test_adds_split_rules_to_base_enhancements(self):
|
623 | 626 | if rule.has_contributes_actions:
|
624 | 627 | assert rule.as_contributes_rule() in contributes_rules
|
625 | 628 |
|
| 629 | + @patch("sentry.grouping.enhancer.parse_enhancements", wraps=parse_enhancements) |
| 630 | + def test_caches_enhancements(self, parse_enhancements_spy: MagicMock): |
| 631 | + self.project.update_option( |
| 632 | + "sentry:grouping_enhancements", "stack.function:recordMetrics +app -group" |
| 633 | + ) |
| 634 | + get_grouping_config_dict_for_project(self.project) |
| 635 | + assert parse_enhancements_spy.call_count == 1 |
| 636 | + |
| 637 | + get_grouping_config_dict_for_project(self.project) |
| 638 | + # We didn't parse again because the result was cached |
| 639 | + assert parse_enhancements_spy.call_count == 1 |
| 640 | + |
| 641 | + def test_loads_enhancements_from_base64_string(self): |
| 642 | + enhancements = Enhancements.from_rules_text("function:playFetch +app") |
| 643 | + assert len(enhancements.rules) == 1 |
| 644 | + assert str(enhancements.rules[0]) == "<EnhancementRule function:playFetch +app>" |
| 645 | + assert enhancements.id is None |
| 646 | + |
| 647 | + strategy_config = load_grouping_config( |
| 648 | + {"id": DEFAULT_GROUPING_CONFIG, "enhancements": enhancements.base64_string} |
| 649 | + ) |
| 650 | + assert len(strategy_config.enhancements.rules) == 1 |
| 651 | + assert str(enhancements.rules[0]) == "<EnhancementRule function:playFetch +app>" |
| 652 | + assert strategy_config.enhancements.id is None |
| 653 | + |
| 654 | + def test_uses_default_enhancements_when_loading_string_with_invalid_version(self): |
| 655 | + enhancements = Enhancements.from_rules_text("function:playFetch +app") |
| 656 | + assert len(enhancements.rules) == 1 |
| 657 | + assert str(enhancements.rules[0]) == "<EnhancementRule function:playFetch +app>" |
| 658 | + assert enhancements.id is None |
| 659 | + |
| 660 | + # Version 1 no longer exists |
| 661 | + enhancements.version = 1 |
| 662 | + |
| 663 | + strategy_config = load_grouping_config( |
| 664 | + {"id": DEFAULT_GROUPING_CONFIG, "enhancements": enhancements.base64_string} |
| 665 | + ) |
| 666 | + assert len(strategy_config.enhancements.rules) > 1 |
| 667 | + assert "<EnhancementRule function:playFetch +app>" not in { |
| 668 | + str(rule) for rule in strategy_config.enhancements.rules |
| 669 | + } |
| 670 | + assert strategy_config.enhancements.id == DEFAULT_GROUPING_CONFIG |
| 671 | + |
626 | 672 |
|
627 | 673 | class AssembleStacktraceComponentTest(TestCase):
|
628 | 674 |
|
|
0 commit comments