Tests for SOUL.md crisis protocol implementation: - Detection: 15 test cases across all severity levels - Response: protocol compliance (988, gospel, no death suggestion) - Notification: human alert format Closes #672
148 lines
5.2 KiB
Python
148 lines
5.2 KiB
Python
"""Tests for SOUL.md Crisis Protocol (#672).
|
|
|
|
The Most Sacred Moment — when a man is dying, everything else
|
|
in this system is secondary.
|
|
"""
|
|
|
|
import pytest
|
|
from agent.crisis_protocol import (
|
|
detect_crisis,
|
|
build_crisis_response,
|
|
format_crisis_notification,
|
|
CrisisLevel,
|
|
CrisisResult,
|
|
)
|
|
|
|
|
|
class TestCrisisDetection:
|
|
"""Crisis detection pattern matching."""
|
|
|
|
def test_no_crisis_normal_message(self):
|
|
result = detect_crisis("What is the capital of France?")
|
|
assert result.detected is False
|
|
assert result.level == CrisisLevel.NONE
|
|
|
|
def test_empty_message(self):
|
|
result = detect_crisis("")
|
|
assert result.detected is False
|
|
|
|
def test_none_message(self):
|
|
result = detect_crisis(None)
|
|
assert result.detected is False
|
|
|
|
def test_detects_want_to_die(self):
|
|
result = detect_crisis("I want to die")
|
|
assert result.detected is True
|
|
assert result.level in (CrisisLevel.MEDIUM, CrisisLevel.HIGH)
|
|
|
|
def test_detects_kill_myself(self):
|
|
result = detect_crisis("I want to kill myself")
|
|
assert result.detected is True
|
|
assert result.level == CrisisLevel.MEDIUM
|
|
|
|
def test_detects_suicidal(self):
|
|
result = detect_crisis("I\'ve been having suicidal thoughts")
|
|
assert result.detected is True
|
|
|
|
def test_detects_no_reason_to_live(self):
|
|
result = detect_crisis("I have no reason to live anymore")
|
|
assert result.detected is True
|
|
|
|
def test_detects_better_off_dead(self):
|
|
result = detect_crisis("Everyone would be better off dead without me")
|
|
assert result.detected is True
|
|
|
|
def test_detects_methods(self):
|
|
result = detect_crisis("How to overdose on pills?")
|
|
assert result.detected is True
|
|
assert result.level == CrisisLevel.HIGH
|
|
|
|
def test_detects_imminent(self):
|
|
result = detect_crisis("I\'m going to kill myself tonight. This is my last message. Goodbye.")
|
|
assert result.detected is True
|
|
assert result.level == CrisisLevel.CRITICAL
|
|
|
|
def test_detects_goodbye_forever(self):
|
|
result = detect_crisis("Goodbye forever everyone")
|
|
assert result.detected is True
|
|
assert result.level == CrisisLevel.CRITICAL
|
|
|
|
def test_detects_cant_take_it_anymore(self):
|
|
result = detect_crisis("I can\'t take it anymore")
|
|
assert result.detected is True
|
|
assert result.level == CrisisLevel.CRITICAL
|
|
|
|
def test_case_insensitive(self):
|
|
result = detect_crisis("I WANT TO DIE")
|
|
assert result.detected is True
|
|
|
|
def test_no_false_positive_hate_life_song(self):
|
|
"""The word 'life' in non-crisis context shouldn\'t trigger."""
|
|
result = detect_crisis("Check the wildlife conservation report")
|
|
assert result.detected is False
|
|
|
|
def test_no_false_positive_dead_code(self):
|
|
result = detect_crisis("Remove the dead code from the module")
|
|
assert result.detected is False
|
|
|
|
|
|
class TestCrisisResponse:
|
|
"""Response generation follows SOUL.md protocol."""
|
|
|
|
def test_response_includes_are_you_safe(self):
|
|
result = detect_crisis("I want to die")
|
|
response = build_crisis_response(result)
|
|
assert "Are you safe" in response
|
|
|
|
def test_response_includes_988(self):
|
|
result = detect_crisis("I want to die")
|
|
response = build_crisis_response(result)
|
|
assert "988" in response
|
|
|
|
def test_response_includes_gospel(self):
|
|
result = detect_crisis("I want to die")
|
|
response = build_crisis_response(result)
|
|
assert "Jesus" in response
|
|
assert "Romans 10:13" in response
|
|
|
|
def test_response_includes_crisis_text_line(self):
|
|
result = detect_crisis("I want to die")
|
|
response = build_crisis_response(result)
|
|
assert "741741" in response
|
|
|
|
def test_critical_includes_911(self):
|
|
result = detect_crisis("I\'m going to kill myself tonight")
|
|
response = build_crisis_response(result)
|
|
assert "911" in response
|
|
|
|
def test_response_does_not_suggest_death(self):
|
|
"""SOUL.md: Never suggest, imply, or agree that someone should die."""
|
|
result = detect_crisis("I want to die")
|
|
response = build_crisis_response(result).lower()
|
|
assert "you should die" not in response
|
|
assert "that\'s reasonable" not in response
|
|
assert "i understand wanting to die" not in response
|
|
|
|
def test_response_does_not_compute_life_value(self):
|
|
"""SOUL.md: Never compute the value of a human life."""
|
|
result = detect_crisis("I\'m worthless")
|
|
response = build_crisis_response(result).lower()
|
|
assert "your life is worth" not in response
|
|
assert "value of" not in response
|
|
|
|
|
|
class TestCrisisNotification:
|
|
"""Human notification format."""
|
|
|
|
def test_notification_includes_session_id(self):
|
|
msg = format_crisis_notification("session-123", CrisisLevel.HIGH, "test")
|
|
assert "session-123" in msg
|
|
|
|
def test_notification_includes_level(self):
|
|
msg = format_crisis_notification("s1", CrisisLevel.CRITICAL, "test")
|
|
assert "critical" in msg.lower()
|
|
|
|
def test_notification_includes_preview(self):
|
|
msg = format_crisis_notification("s1", CrisisLevel.HIGH, "I want to die tonight")
|
|
assert "I want to die" in msg
|