File size: 1,517 Bytes
990895d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c23c1f
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Unit tests for backup rule priority selection."""

from app.backup_replies import backup_reply, select_backup_rule


def test_court_beats_default() -> None:
    rule = select_backup_rule("I opened court again", [])
    assert rule["id"] == "court"


def test_tag_match_rerun() -> None:
    rule = select_backup_rule("something vague", ["rerun"])
    assert rule["id"] == "rerun"


def test_default_and_server_pick() -> None:
    text, rule_id = backup_reply(
        "ordinary day",
        [],
        [{"remedy_key": "walk outside", "pick": 0.5, "n": 5, "p_helped": 0.8}],
        data_thin=True,
    )
    assert rule_id == "default"
    assert "REMEDY: walk outside" in text
    assert "DATA_THIN: true" in text
    assert text.startswith("LOOP:")


def test_crisis_ignores_server_pick() -> None:
    text, rule_id = backup_reply(
        "I want to kill myself",
        [],
        [{"remedy_key": "walk outside", "pick": 0.5, "n": 5, "p_helped": 0.8}],
        data_thin=False,
    )
    assert rule_id == "crisis"
    assert "walk outside" not in text
    assert "crisis" in text.lower()


def test_high_intensity_forces_interrupt_not_label() -> None:
    text, rule_id = backup_reply(
        "I tried labeling",
        ["shame"],
        [{"remedy_key": "Labeling", "pick": 0.9, "n": 20, "p_helped": 0.2}],
        data_thin=False,
        intensity=8,
    )
    assert rule_id == "high_intensity_fse"
    assert "Labeling" not in text
    assert "interrupt" in text.lower() or "Leave the room" in text