feat(I): I-WORK-PROACTIVE — proactive workstream feed (suggestions, cooldown, dedupe, user settings, priority filtering), 34 tests passing
This commit is contained in:
@@ -297,3 +297,86 @@ class TestWorkstreamContract:
|
||||
# Verify task_type is 'handoff'
|
||||
call_args = mock_create.call_args
|
||||
assert call_args[0][3]["task_type"] == "handoff"
|
||||
|
||||
|
||||
# ─── I-WORK-PROACTIVE: Proactive Workstream Feed ─────────────────────────────
|
||||
|
||||
|
||||
class TestProactiveFeed:
|
||||
"""Test the proactive feed module (I-WORK-PROACTIVE)."""
|
||||
|
||||
def test_proactive_suggestion_dataclass(self):
|
||||
"""ProactiveSuggestion dataclass works correctly."""
|
||||
from app.ai.proactive_feed import ProactiveSuggestion
|
||||
s = ProactiveSuggestion(trigger="mail.received", title="Test", priority="medium")
|
||||
assert s.trigger == "mail.received"
|
||||
assert s.priority == "medium"
|
||||
d = s.to_dict()
|
||||
assert d["trigger"] == "mail.received"
|
||||
|
||||
def test_get_cooldown_known_trigger(self):
|
||||
"""get_cooldown returns correct cooldown for known triggers."""
|
||||
from app.ai.proactive_feed import get_cooldown
|
||||
assert get_cooldown("mail.received") == 300
|
||||
assert get_cooldown("contact.created") == 600
|
||||
assert get_cooldown("workflow.completed") == 60
|
||||
|
||||
def test_get_cooldown_unknown_trigger(self):
|
||||
"""get_cooldown returns default for unknown triggers."""
|
||||
from app.ai.proactive_feed import get_cooldown
|
||||
assert get_cooldown("unknown.trigger") == 300
|
||||
|
||||
def test_is_cooled_down_initial(self):
|
||||
"""is_cooled_down returns False for first-time trigger."""
|
||||
from app.ai.proactive_feed import is_cooled_down
|
||||
assert is_cooled_down(uuid.uuid4(), "mail.received") is False
|
||||
|
||||
def test_mark_suggested_sets_cooldown(self):
|
||||
"""mark_suggested sets cooldown for the trigger."""
|
||||
from app.ai.proactive_feed import is_cooled_down, mark_suggested
|
||||
tid = uuid.uuid4()
|
||||
mark_suggested(tid, "mail.received", "msg-123")
|
||||
assert is_cooled_down(tid, "mail.received", "msg-123") is True
|
||||
|
||||
def test_filter_by_user_settings_enabled(self):
|
||||
"""filter_by_user_settings filters by enabled flag."""
|
||||
from app.ai.proactive_feed import ProactiveSuggestion, filter_by_user_settings
|
||||
suggestions = [ProactiveSuggestion(trigger="test", priority="medium")]
|
||||
assert len(filter_by_user_settings(suggestions, {"enabled": True})) == 1
|
||||
assert len(filter_by_user_settings(suggestions, {"enabled": False})) == 0
|
||||
|
||||
def test_filter_by_user_settings_min_priority(self):
|
||||
"""filter_by_user_settings filters by min_priority."""
|
||||
from app.ai.proactive_feed import ProactiveSuggestion, filter_by_user_settings
|
||||
suggestions = [
|
||||
ProactiveSuggestion(trigger="test", priority="low"),
|
||||
ProactiveSuggestion(trigger="test", priority="medium"),
|
||||
ProactiveSuggestion(trigger="test", priority="high"),
|
||||
]
|
||||
filtered = filter_by_user_settings(suggestions, {"enabled": True, "min_priority": "medium"})
|
||||
assert len(filtered) == 2 # medium + high
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_suggestions_mail_received(self):
|
||||
"""generate_suggestions creates suggestion for mail.received trigger."""
|
||||
from app.ai.proactive_feed import generate_suggestions
|
||||
suggestions = await generate_suggestions(
|
||||
db=MagicMock(), tenant_id=uuid.uuid4(), user_id=uuid.uuid4(),
|
||||
trigger="mail.received", payload={"entity_id": str(uuid.uuid4()), "sender": "test@example.com"},
|
||||
)
|
||||
assert len(suggestions) == 1
|
||||
assert suggestions[0].trigger == "mail.received"
|
||||
assert suggestions[0].priority == "medium"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_suggestions_cooldown_blocks(self):
|
||||
"""generate_suggestions returns empty list when in cooldown."""
|
||||
from app.ai.proactive_feed import generate_suggestions, mark_suggested
|
||||
tid = uuid.uuid4()
|
||||
eid = str(uuid.uuid4())
|
||||
mark_suggested(tid, "mail.received", eid)
|
||||
suggestions = await generate_suggestions(
|
||||
db=MagicMock(), tenant_id=tid, user_id=uuid.uuid4(),
|
||||
trigger="mail.received", payload={"entity_id": eid},
|
||||
)
|
||||
assert len(suggestions) == 0
|
||||
|
||||
Reference in New Issue
Block a user