|
| 1 | +"""Tests for rules_check hook module.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from deepwork.hooks.rules_check import extract_promise_tags |
| 6 | + |
| 7 | + |
| 8 | +class TestExtractPromiseTags: |
| 9 | + """Tests for extract_promise_tags function.""" |
| 10 | + |
| 11 | + def test_extracts_simple_promise(self) -> None: |
| 12 | + """Test extracting a simple promise tag.""" |
| 13 | + text = "I've reviewed this. <promise>Rule Name</promise>" |
| 14 | + result = extract_promise_tags(text) |
| 15 | + assert result == {"Rule Name"} |
| 16 | + |
| 17 | + def test_extracts_promise_with_checkmark(self) -> None: |
| 18 | + """Test extracting promise tag with checkmark prefix.""" |
| 19 | + text = "Done. <promise>✓ Rule Name</promise>" |
| 20 | + result = extract_promise_tags(text) |
| 21 | + assert result == {"Rule Name"} |
| 22 | + |
| 23 | + def test_extracts_promise_with_checkmark_no_space(self) -> None: |
| 24 | + """Test extracting promise tag with checkmark but no space.""" |
| 25 | + text = "<promise>✓Rule Name</promise>" |
| 26 | + result = extract_promise_tags(text) |
| 27 | + assert result == {"Rule Name"} |
| 28 | + |
| 29 | + def test_extracts_multiple_promises(self) -> None: |
| 30 | + """Test extracting multiple promise tags.""" |
| 31 | + text = """ |
| 32 | + <promise>Rule One</promise> |
| 33 | + <promise>✓ Rule Two</promise> |
| 34 | + <promise>Rule Three</promise> |
| 35 | + """ |
| 36 | + result = extract_promise_tags(text) |
| 37 | + assert result == {"Rule One", "Rule Two", "Rule Three"} |
| 38 | + |
| 39 | + def test_case_insensitive_tag(self) -> None: |
| 40 | + """Test that promise tags are case-insensitive.""" |
| 41 | + text = "<PROMISE>Rule Name</PROMISE>" |
| 42 | + result = extract_promise_tags(text) |
| 43 | + assert result == {"Rule Name"} |
| 44 | + |
| 45 | + def test_preserves_rule_name_case(self) -> None: |
| 46 | + """Test that rule name case is preserved.""" |
| 47 | + text = "<promise>Architecture Documentation Accuracy</promise>" |
| 48 | + result = extract_promise_tags(text) |
| 49 | + assert result == {"Architecture Documentation Accuracy"} |
| 50 | + |
| 51 | + def test_handles_whitespace_in_tag(self) -> None: |
| 52 | + """Test handling of whitespace around rule name.""" |
| 53 | + text = "<promise> Rule Name </promise>" |
| 54 | + result = extract_promise_tags(text) |
| 55 | + assert result == {"Rule Name"} |
| 56 | + |
| 57 | + def test_handles_newlines_in_tag(self) -> None: |
| 58 | + """Test handling of newlines in promise tag.""" |
| 59 | + text = "<promise>\n Rule Name\n</promise>" |
| 60 | + result = extract_promise_tags(text) |
| 61 | + assert result == {"Rule Name"} |
| 62 | + |
| 63 | + def test_returns_empty_set_for_no_promises(self) -> None: |
| 64 | + """Test that empty set is returned when no promises exist.""" |
| 65 | + text = "No promises here." |
| 66 | + result = extract_promise_tags(text) |
| 67 | + assert result == set() |
| 68 | + |
| 69 | + def test_handles_empty_string(self) -> None: |
| 70 | + """Test handling of empty string.""" |
| 71 | + result = extract_promise_tags("") |
| 72 | + assert result == set() |
| 73 | + |
| 74 | + def test_real_world_command_error_promise(self) -> None: |
| 75 | + """Test promise format shown in command error output.""" |
| 76 | + # This is the exact format shown to agents when a command rule fails |
| 77 | + text = "<promise>✓ Manual Test: Infinite Block Command</promise>" |
| 78 | + result = extract_promise_tags(text) |
| 79 | + assert result == {"Manual Test: Infinite Block Command"} |
| 80 | + |
| 81 | + def test_mixed_formats_in_same_text(self) -> None: |
| 82 | + """Test extracting both checkmark and non-checkmark promises.""" |
| 83 | + text = """ |
| 84 | + <promise>Rule Without Checkmark</promise> |
| 85 | + <promise>✓ Rule With Checkmark</promise> |
| 86 | + """ |
| 87 | + result = extract_promise_tags(text) |
| 88 | + assert result == {"Rule Without Checkmark", "Rule With Checkmark"} |
| 89 | + |
| 90 | + def test_promise_with_special_characters_in_name(self) -> None: |
| 91 | + """Test promise with special characters in rule name.""" |
| 92 | + text = "<promise>Source/Test Pairing</promise>" |
| 93 | + result = extract_promise_tags(text) |
| 94 | + assert result == {"Source/Test Pairing"} |
| 95 | + |
| 96 | + def test_promise_embedded_in_markdown(self) -> None: |
| 97 | + """Test promise tag embedded in markdown text.""" |
| 98 | + text = """ |
| 99 | + I've reviewed the documentation and it's accurate. |
| 100 | +
|
| 101 | + <promise>Architecture Documentation Accuracy</promise> |
| 102 | + <promise>README Accuracy</promise> |
| 103 | +
|
| 104 | + The changes were purely cosmetic. |
| 105 | + """ |
| 106 | + result = extract_promise_tags(text) |
| 107 | + assert result == {"Architecture Documentation Accuracy", "README Accuracy"} |
0 commit comments