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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 |
import pytest
from prami import cli
from prami import repository as repo
from prami.config import config
from prami.db import session_scope
@pytest.fixture
def cli_db(tmp_path, monkeypatch):
monkeypatch.setattr(config, "database_url", f"sqlite:///{tmp_path / 'cli.db'}")
cli.main(["reset", "--yes"])
def current_pet():
with session_scope() as session:
pet = repo.get_pet(session)
session.expunge(pet)
return pet
def test_feed_changes_state_through_cli(cli_db, capsys):
cli.main(["feed", "--user", "@alice@example.com"])
out = capsys.readouterr().out.strip()
assert out
assert current_pet().hunger == 5
def test_status_is_narrative_not_raw_numbers(cli_db, capsys):
cli.main(["status", "--user", "@alice@example.com"])
out = capsys.readouterr().out
assert "Prami" in out
assert "hunger :" not in out
def test_debug_state_exposes_raw_numbers(cli_db, capsys):
cli.main(["debug-state"])
out = capsys.readouterr().out
for field in ("hunger", "happiness", "energy", "health", "cleanliness", "social", "trust", "chaos", "asleep", "mood", "updated_at"):
assert field in out
def test_feed_cooldown_blocks_second_call(cli_db, capsys):
cli.main(["feed", "--user", "@alice@example.com"])
cli.main(["feed", "--user", "@alice@example.com"])
assert current_pet().hunger == 5
def test_different_users_are_independent(cli_db):
cli.main(["feed", "--user", "@alice@example.com"])
cli.main(["feed", "--user", "@bob@example.com"])
assert current_pet().hunger == 0
def test_tick_applies_decay(cli_db):
before = current_pet().hunger
cli.main(["tick"])
assert current_pet().hunger > before
def test_tick_hours_scales_with_decay_interval(cli_db):
cli.main(["tick", "--hours", "3"])
assert current_pet().hunger == 100
def test_sleep_and_wake_toggle_state(cli_db):
cli.main(["sleep", "--user", "@alice@example.com"])
assert current_pet().asleep is True
cli.main(["wake", "--user", "@alice@example.com"])
assert current_pet().asleep is False
def test_reset_restores_defaults(cli_db):
cli.main(["feed", "--user", "@alice@example.com"])
cli.main(["reset", "--yes"])
assert current_pet().hunger == 40
def test_cli_nickname_sets_and_appears_in_relationship(cli_db, capsys):
cli.main(["nickname", "Soup", "Wizard", "--user", "@alice@example.com"])
capsys.readouterr()
cli.main(["relationship", "--user", "@alice@example.com"])
out = capsys.readouterr().out
assert "Soup Wizard" in out
assert "bond_level" in out
def test_cli_relationship_tracks_interaction_counts(cli_db, capsys):
cli.main(["feed", "--user", "@alice@example.com"])
cli.main(["pet", "--user", "@alice@example.com"])
capsys.readouterr()
cli.main(["relationship", "--user", "@alice@example.com"])
out = capsys.readouterr().out
assert "total_interactions" in out
assert "trust_score" in out
def test_blocked_user_gets_no_response(cli_db, capsys):
monkey_block(["alice@example.com"])
cli.main(["feed", "--user", "@alice@example.com"])
out = capsys.readouterr().out
assert "blocked" in out.lower()
def monkey_block(accts):
with session_scope() as session:
for acct in accts:
repo.block_user(session, acct)
|