| | @@ -0,0 +1,252 @@ |
| 1 | +"""Tests for enhanced action item detection."""
|
| 2 | +
|
| 3 | +import json
|
| 4 | +from unittest.mock import MagicMock
|
| 5 | +
|
| 6 | +import pytest
|
| 7 | +
|
| 8 | +from video_processor.analyzers.action_detector import ActionDetector
|
| 9 | +from video_processor.models import ActionItem, TranscriptSegment
|
| 10 | +
|
| 11 | +
|
| 12 | +class TestPatternExtract:
|
| 13 | + def test_detects_need_to(self):
|
| 14 | + detector = ActionDetector()
|
| 15 | + items = detector.detect_from_transcript(""Tests for enhanced action m detection."""
|
| 16 | +
|
| 17 | +""Tests for enhanced action itehanced action item detection."""
|
| 18 | +
|
| 19 | +import json
|
| 20 | +from unittest.mock import MagicMock
|
| 21 | +
|
| 22 | +from video_processor.analyzers.action_detector import ActionDetector
|
| 23 | +from video_processor.models import ActionItem, TranscriptSegment
|
| 24 | +
|
| 25 | +
|
| 26 | +class TestPatternExtract:
|
| 27 | + def test_detects_need_to(self):
|
| 28 | + detector = ActionDetector()
|
| 29 | + items = detector.detect_from_transcript(
|
| 30 | + "We need"Action item: set up monitterns(self):
|
| 31 | + roadmap.")
|
| 32 | + assert len(items) >= 1
|
| 33 | +
|
| 34 | + def test_detects_follow_up(self):
|
| 35 | + detector = ActionDetector()
|
| 36 | + items = detector.detect_from_transcript("Follow up with the client about requirements.")
|
| 37 | + assert len(items) >= 1
|
| 38 | +
|
| 39 | + def test_detects_lets(self):
|
| 40 | + detector = ActionDetector()
|
| 41 | + items = detector.detect_from_transcript("Let's schedule a meeting to discuss the roadmap.")
|
| 42 | + assert len(items) >= 1
|
| 43 | +
|
| 44 | + def test_ignores_short_sentences(self):
|
| 45 | + detector = ActionDetector()
|
| 46 | + items = detector.detect_from_transcript("Do it.")
|
| 47 | + assert len(items) == 0
|
| 48 | +
|
| 49 | + def test_no_action_patterns(self):
|
| 50 | + detector = ActionDetec
|
| 51 | + "con"The weather was nice to
|
| 52 | + )
|
| 53 | + assert len(items) == 0
|
| 54 | +
|
| 55 | + def test_multiple_sentences(self):
|
| 56 | + detector = Actio""Tests for enhanced actioced action item detection."""
|
| 57 | +
|
| 58 | +We need to deploy the fix. A"
|
| 59 | + tences("The sky is blue."
|
| 60 | + detector = ActionDetectextterns(self):
|
| 61 | + len(items) == 2
|
| 62 | +
|
| 63 | + def test_source_is_transcript(self):
|
| 64 | + detector = ActionDetector()
|
| 65 | + items = detector.detect_from_transcript("We need to fix the authentication module.")
|
| 66 | + for item in items:
|
| 67 | + assert item.source == "transcript"
|
| 68 | +
|
| 69 | +
|
| 70 | +class TestLLMExtract:
|
| 71 | + def test_llm_extraction(self):
|
| 72 | + pm = MagicMock()
|
| 73 | + pm.chat.return_value = json.dumps([ext": Non { assert len(items) >= 1
|
| 74 | + "assignee": "Bob","priority": "high", "Action item: set up monito}
|
| 75 | + ])_no_match_no_context(self):
|
| 76 | + em detection."""
|
| 77 | +
|
| 78 | +import json
|
| 79 | +from unittest.mock import MagicMock
|
| 80 | +
|
| 81 | +fro"""Tests for enhanced action item detection."""
|
| 82 | +
|
| 83 | +import json
|
| 84 | +from unittest.mock import MagicMock
|
| 85 | +
|
| 86 | +from video_processor.analyzers.action_detector import ActionDetector
|
| 87 | +from video_processor.models import ActionItem, TranscriptSegment
|
| 88 | +
|
| 89 | +
|
| 90 | +class TestPatternExtract:
|
| 91 | + def test_detects_need_to(self):
|
| 92 | + detector = ActionDetector()
|
| 93 | + items = detector.detect_from_transcript(
|
| 94 | + "We need to update the database schema before release."
|
| 95 | + )
|
| 96 | + assert len(items) >= 1
|
| 97 | + assert any("database" in i.action.lower() for i in items)
|
| 98 | +
|
| 99 | + def test_detects_should(self):
|
| 100 | + detector = ActionDetector()
|
| 101 | + items = detector.detect_from_transcript("Alice should review the pull request by Friday.")
|
| 102 | + assert len(items) >= 1
|
| 103 | +
|
| 104 | + def test_detects_action_item_keyword(self):
|
| 105 | + detector = ActionDetector()
|
| 106 | + items = detector.detect_from_transcript(
|
| 107 | + "Action item: set up monitoring for the new service."
|
| 108 | + )
|
| 109 | + assert len(items) >= 1
|
| 110 | +
|
| 111 | + def test_detects_follow_up(self):
|
| 112 | + detector = ActionDetector()
|
| 113 | + items = detector.detect_from_transcript("Follow up with the client about requirements.")
|
| 114 | + [ext": Non"""Tests for enhanced action item dsts for enhanced action ite{"action": "", "assignee": "Bob"])_no_match_no_context(self):
|
| 115 | + em detection."""
|
| 116 | +
|
| 117 | +import json
|
| 118 | +from unittest.mock import MagicMock
|
| 119 | +
|
| 120 | +fro"""Tests .")
|
| 121 | + assert len(items) >= 1
|
| 122 | +
|
| 123 | + def test_detects_lets(self):
|
| 124 | + detector = ActionDetector()
|
| 125 | + items = detector.detect_from_transcript("Let's schedule a meeting to discuss the roadmap.")
|
| 126 | + assert len(items) >= 1
|
| 127 | +
|
| 128 | + def test_ignores_short_sentences(self):
|
| 129 | + detector = ActionDetector()
|
| 130 | + items = detector.detect_from_transcript("Do it.")
|
| 131 | + assert len(items) == 0
|
| 132 | +
|
| 133 | + def test_no_action_patterns(self):
|
| 134 | + detector = ActionDetector()
|
| 135 | + items = detector.detect_from_transcript("The weather was nice today. We had lunch at noon.")
|
| 136 | + assert len(items) == 0
|
| 137 | +
|
| 138 | + def test_multiple_sentences(self):
|
| 139 | + detector = ActionDetector()
|
| 140 | + text = "We need to deploy the fix. Alice should test it first. The sky is blue."
|
| 141 | + items = detector.detect_from_transcript(text)
|
| 142 | + assert len(items) == 2
|
| 143 | +
|
| 144 | + def test_source_is_transcript(self):
|
| 145 | + detector = ActionDetector()
|
| 146 | + items = detector.detect_from_transcript("We need to fix the authentication module.")
|
| 147 | + for item in items:
|
| 148 | + assert item.source == "transcript"
|
| 149 | +
|
| 150 | +
|
| 151 | +class TestLLMExtract:
|
| 152 | + def test_llm_extraction(self):
|
| 153 | + pm = MagicMock()
|
| 154 | + pm.chat.return_value = json.dumps(
|
| 155 | + [
|
| 156 | + {
|
| 157 | + "action": "Deploy new version",
|
| 158 | + "assignee": "Bob",
|
| 159 | + "deadline": "Friday",
|
| 160 | + "priority": "high",
|
| 161 | + "context": "Production release",
|
| 162 | + }
|
| 163 | + ]
|
| 164 | + )
|
| 165 | + detector = ActionDetector(provider_manager=pm)
|
| 166 | + items = detector.detect_from_transcript("Deploy new version by Friday.")
|
| 167 | + assert len(items) == 1
|
| 168 | + assert items[0].action == "Deploy new version"
|
| 169 | + assert items[0].assignee == "Bob"
|
| 170 | + assert items[0].deadline == "Friday"
|
| 171 | + assert items[0].priority == "high"
|
| 172 | + assert items[0].source == "transcript"
|
| 173 | +
|
| 174 | + def test_llm_returns_empty(self):
|
| 175 | + pm = MagicMock()
|
| 176 | + pm.chat.return_value = "[]"
|
| 177 | + detector = ActionDetector(provider_manager=pm)
|
| 178 | + items = detector.detect_from_transcript("No action items here.")
|
| 179 | + assert items == []
|
| 180 | +
|
| 181 | + def test_llm_error_returns_empty(self):
|
| 182 | + pm = MagicMock()
|
| 183 | + pm.chat.side_effect = Exception("API error")
|
| 184 | + detector = ActionDetector(provider_manager=pm)
|
| 185 | + items = detector.detect_from_transcript("We need to fix this.")
|
| 186 | + assert items == []
|
| 187 | +
|
| 188 | + def test_llm_bad_json(self):
|
| 189 | + pm = MagicMock()
|
| 190 | + pm.chat.return_value = "not valid json"
|
| 191 | + detector = ActionDetector(provider_manager=pm)
|
| 192 | + items = detector.detect_from_transcript("Update the docs.")
|
| 193 | + assert items == []
|
| 194 | +
|
| 195 | + def test_llm_skips_items_without_action(self):
|
| 196 | + pm = MagicMock()
|
| 197 | + pm.chat.return_value = json.dumps(
|
| 198 | + [
|
| 199 | + {"action": "Valid action", "assignee": None},
|
| 200 | + {"assignee": "Alice"}, # No action field
|
| 201 | + {"action": "", "assignee": "Bob"}, # Empty action
|
| 202 | + ]
|
| 203 | + )
|
| 204 | + detector = ActionDetector(provider_manager=pm)
|
| 205 | + items = detector.detect_from_transcript("Some text.")
|
| 206 | + assert len(items) == 1
|
| 207 | + assert items[0].action == "Valid action"
|
| 208 | +
|
| 209 | +
|
| 210 | +class TestDetectFromDiagrams:
|
| 211 | + def test_dict_diagrams(self):
|
| 212 | + pm = MagicMock()
|
| 213 | + pm.chat.return_value = json.dumps(
|
| 214 | + [
|
| 215 | + {
|
| 216 | + "action": "Migrate database",
|
| 217 | + "assignee": None,
|
| 218 | + "deadline": None,
|
| 219 | + "priority": None,
|
| 220 | + "context": None,
|
| 221 | + },
|
| 222 | + ]
|
| 223 | + )
|
| 224 | + detector = ActionDetector(provider_manager=pm)
|
| 225 | + diagrams = [
|
| 226 | + {"text_content": "Step 1: Migrate database", "elements": ["DB", "Migration"]},
|
| 227 | + ]
|
| 228 | + items = detector.detect_from_diagrams(diagrams)
|
| 229 | + assert len(items) == 1
|
| 230 | + assert items[0].source == "diagram"
|
| 231 | +
|
| 232 | + def test_object_diagrams(self):
|
| 233 | + pm = MagicMock()
|
| 234 | + pm.chat.return_value = json.dumps(
|
| 235 | + [
|
| 236 | + {
|
| 237 | + "action": "Update API",
|
| 238 | + "assignee": None,
|
| 239 | + "deadline": None,
|
| 240 | + "priority": None,
|
| 241 | + "context": None,
|
| 242 | + },
|
| 243 | + ]
|
| 244 | + )
|
| 245 | + detector = ActionDetector(provider_manager=pm)
|
| 246 | +
|
| 247 | + class FakeDiagram:
|
| 248 | + text_content = "Update API endpoints"
|
| 249 | + elements = ["API", "Gateway"]
|
| 250 | +
|
| 251 | + items = detector.detect_from_diagrams([FakeDiagram()])
|
| 252 | + assert len(ite |