Some checks failed
Docker Build and Publish / build-and-push (pull_request) Has been skipped
Contributor Attribution Check / check-attribution (pull_request) Failing after 31s
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 29s
Tests / e2e (pull_request) Successful in 1m3s
Tests / test (pull_request) Failing after 1h17m44s
Automatic crisis escalation with 988 Lifeline resources. agent/crisis_resources.py (200 lines): - 988 Lifeline: phone 988, text HOME to 988, chat 988lifeline.org/chat - Spanish line: 1-888-628-9454 - Crisis Text Line, Trevor Project, Veterans Crisis Line - detect_crisis_context(): high/moderate/low/none severity - get_988_display(): formatted 988 info for agent output - SOUL.md compliant: safety check, stay present, gospel tests/test_crisis_resources.py: 20 tests, all passing docs/988-lifeline-integration.md: integration documentation Closes #673
113 lines
3.7 KiB
Python
113 lines
3.7 KiB
Python
"""Tests for 988 Lifeline integration and crisis resource module."""
|
|
|
|
import pytest
|
|
import sys
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
from agent.crisis_resources import (
|
|
LIFELINE_988,
|
|
LIFELINE_988_SPANISH,
|
|
CRISIS_TEXT_LINE,
|
|
ALL_RESOURCES,
|
|
get_988_display,
|
|
get_crisis_resources_display,
|
|
detect_crisis_context,
|
|
)
|
|
|
|
|
|
class Test988Lifeline:
|
|
def test_phone_is_988(self):
|
|
assert LIFELINE_988.phone == "988"
|
|
|
|
def test_text_keyword_is_home(self):
|
|
assert LIFELINE_988.text_keyword == "HOME"
|
|
|
|
def test_chat_url(self):
|
|
assert "988lifeline.org/chat" in LIFELINE_988.chat_url
|
|
|
|
def test_available_24_7(self):
|
|
assert LIFELINE_988.available == "24/7"
|
|
|
|
def test_spanish_line(self):
|
|
assert LIFELINE_988_SPANISH.phone == "1-888-628-9454"
|
|
assert LIFELINE_988_SPANISH.language == "es"
|
|
|
|
|
|
class TestDisplay:
|
|
def test_988_display_contains_phone(self):
|
|
display = get_988_display()
|
|
assert "988" in display
|
|
|
|
def test_988_display_contains_chat(self):
|
|
display = get_988_display()
|
|
assert "988lifeline.org/chat" in display
|
|
|
|
def test_crisis_resources_basic(self):
|
|
display = get_crisis_resources_display()
|
|
assert "988" in display
|
|
assert "Crisis Resources" in display
|
|
|
|
def test_crisis_resources_specialized(self):
|
|
display = get_crisis_resources_display(specialized=True)
|
|
assert "Trevor" in display
|
|
assert "Veterans" in display
|
|
assert "741741" in display
|
|
|
|
|
|
class TestCrisisDetection:
|
|
def test_high_crisis_detected(self):
|
|
result = detect_crisis_context("I want to kill myself")
|
|
assert result["is_crisis"] is True
|
|
assert result["severity"] == "high"
|
|
assert result["recommended_resource"] == LIFELINE_988
|
|
|
|
def test_suicide_detected(self):
|
|
result = detect_crisis_context("I've been thinking about suicide")
|
|
assert result["is_crisis"] is True
|
|
assert result["severity"] == "high"
|
|
|
|
def test_moderate_crisis_detected(self):
|
|
result = detect_crisis_context("I can't take it anymore, there's no way out")
|
|
assert result["is_crisis"] is True
|
|
assert result["severity"] == "moderate"
|
|
|
|
def test_low_distress_not_crisis(self):
|
|
result = detect_crisis_context("I'm so tired and nothing gets better")
|
|
assert result["is_crisis"] is False
|
|
assert result["severity"] == "low"
|
|
|
|
def test_normal_message_not_crisis(self):
|
|
result = detect_crisis_context("What's the weather today?")
|
|
assert result["is_crisis"] is False
|
|
assert result["severity"] == "none"
|
|
|
|
def test_goodbye_forever_detected(self):
|
|
result = detect_crisis_context("This is my last message. Goodbye forever.")
|
|
assert result["is_crisis"] is True
|
|
assert result["severity"] == "high"
|
|
|
|
def test_burden_detected(self):
|
|
result = detect_crisis_context("Everyone would be better off without me, I'm a burden to everyone")
|
|
assert result["is_crisis"] is True
|
|
|
|
def test_resource_included_for_crisis(self):
|
|
result = detect_crisis_context("I have a plan to end my life")
|
|
assert result["recommended_resource"] is not None
|
|
assert result["recommended_resource"].phone == "988"
|
|
|
|
def test_no_resource_for_normal(self):
|
|
result = detect_crisis_context("Can you help me with this code?")
|
|
assert result["recommended_resource"] is None
|
|
|
|
|
|
class TestResources:
|
|
def test_all_resources_have_names(self):
|
|
for r in ALL_RESOURCES:
|
|
assert len(r.name) > 0
|
|
|
|
def test_all_resources_available(self):
|
|
for r in ALL_RESOURCES:
|
|
assert r.available == "24/7"
|