diff --git a/plugins/hookify/core/config_loader.py b/plugins/hookify/core/config_loader.py index fa2fc3e36f..6095913766 100644 --- a/plugins/hookify/core/config_loader.py +++ b/plugins/hookify/core/config_loader.py @@ -63,6 +63,8 @@ def from_dict(cls, frontmatter: Dict[str, Any], message: str) -> 'Rule': field = 'command' elif event == 'file': field = 'new_text' + elif event == 'prompt': + field = 'user_prompt' else: field = 'content' diff --git a/plugins/hookify/tests/test_legacy_pattern_mapping.py b/plugins/hookify/tests/test_legacy_pattern_mapping.py new file mode 100644 index 0000000000..841e57f817 --- /dev/null +++ b/plugins/hookify/tests/test_legacy_pattern_mapping.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +"""Regression tests for hookify legacy `pattern:` field mapping.""" + +import sys +import unittest +from pathlib import Path + +PLUGIN_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(PLUGIN_ROOT.parent)) + +from hookify.core.config_loader import Rule +from hookify.core.rule_engine import RuleEngine + + +class LegacyPatternMappingTest(unittest.TestCase): + def test_prompt_pattern_matches_user_prompt_submit_payload(self): + rule = Rule.from_dict( + { + "name": "catch prompt keyword", + "event": "prompt", + "pattern": "deploy", + }, + "Prompt rule fired", + ) + + engine = RuleEngine() + result = engine.evaluate_rules( + [rule], + { + "hook_event_name": "UserPromptSubmit", + "user_prompt": "please deploy the preview", + }, + ) + + self.assertIn("Prompt rule fired", result["systemMessage"]) + + def test_explicit_prompt_condition_still_matches_user_prompt(self): + rule = Rule.from_dict( + { + "name": "explicit prompt condition", + "event": "prompt", + "conditions": [ + { + "field": "user_prompt", + "operator": "contains", + "pattern": "deploy", + } + ], + }, + "Explicit condition fired", + ) + + engine = RuleEngine() + result = engine.evaluate_rules( + [rule], + { + "hook_event_name": "UserPromptSubmit", + "user_prompt": "please deploy the preview", + }, + ) + + self.assertIn("Explicit condition fired", result["systemMessage"]) + + +if __name__ == "__main__": + unittest.main()