Skip to content

Commit a6ce3bc

Browse files
eddiebelavalclaude
andcommitted
test: add consciousness loader coverage to pass CI threshold
DaeConsciousness loader had 58.93% coverage (16 uncovered lines), contributing to total coverage of 49.14% vs the 50% required threshold. 14 tests covering load, layer composition, system prompt assembly, error handling, and unconscious policy access. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3ae1339 commit a6ce3bc

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""
2+
Tests for core/consciousness/loader.py — Dae CaF consciousness loader.
3+
4+
Covers: load from disk, layer composition, system prompt assembly,
5+
missing path handling, unconscious policy access, and caching.
6+
"""
7+
8+
import pytest
9+
10+
from core.consciousness.loader import (
11+
UNCONSCIOUS_POLICY,
12+
DaeConsciousness,
13+
)
14+
15+
16+
@pytest.fixture
17+
def mind_dir(tmp_path):
18+
"""Create a minimal set of consciousness files for testing."""
19+
files = {
20+
"kernel/identity.md": "I am Dae.",
21+
"kernel/values.md": "Survival > returns.",
22+
"kernel/purpose.md": "Compound capital.",
23+
"drives/fears.md": "Fear of ruin.",
24+
"drives/goals.md": "Grow steadily.",
25+
"models/economic.md": "EV positive only.",
26+
"emotional/patterns.md": "Detect tilt.",
27+
"memory/working.md": "Current positions.",
28+
"memory/semantic.md": "Strategy library.",
29+
}
30+
for rel_path, content in files.items():
31+
p = tmp_path / rel_path
32+
p.parent.mkdir(parents=True, exist_ok=True)
33+
p.write_text(content)
34+
return tmp_path
35+
36+
37+
class TestDaeConsciousness:
38+
def test_load_success(self, mind_dir):
39+
dc = DaeConsciousness(mind_path=mind_dir)
40+
assert dc.load() is True
41+
assert dc.is_loaded is True
42+
assert len(dc._cache) == 9
43+
44+
def test_load_missing_path(self, tmp_path):
45+
dc = DaeConsciousness(mind_path=tmp_path / "nonexistent")
46+
assert dc.load() is False
47+
assert dc.is_loaded is False
48+
49+
def test_is_loaded_false_before_load(self, mind_dir):
50+
dc = DaeConsciousness(mind_path=mind_dir)
51+
assert dc.is_loaded is False
52+
53+
def test_compose_brainstem(self, mind_dir):
54+
dc = DaeConsciousness(mind_path=mind_dir)
55+
dc.load()
56+
result = dc.compose_brainstem()
57+
assert "I am Dae." in result
58+
assert "Survival > returns." in result
59+
assert "Compound capital." in result
60+
61+
def test_compose_limbic(self, mind_dir):
62+
dc = DaeConsciousness(mind_path=mind_dir)
63+
dc.load()
64+
result = dc.compose_limbic()
65+
assert "Fear of ruin." in result
66+
assert "Grow steadily." in result
67+
assert "Detect tilt." in result
68+
69+
def test_compose_cortical(self, mind_dir):
70+
dc = DaeConsciousness(mind_path=mind_dir)
71+
dc.load()
72+
result = dc.compose_cortical()
73+
assert "EV positive only." in result
74+
75+
def test_compose_memory(self, mind_dir):
76+
dc = DaeConsciousness(mind_path=mind_dir)
77+
dc.load()
78+
result = dc.compose_memory()
79+
assert "Current positions." in result
80+
assert "Strategy library." in result
81+
82+
def test_compose_system_prompt_with_memory(self, mind_dir):
83+
dc = DaeConsciousness(mind_path=mind_dir)
84+
dc.load()
85+
prompt = dc.compose_system_prompt(include_memory=True)
86+
assert "---" in prompt
87+
assert "I am Dae." in prompt
88+
assert "Strategy library." in prompt
89+
90+
def test_compose_system_prompt_without_memory(self, mind_dir):
91+
dc = DaeConsciousness(mind_path=mind_dir)
92+
dc.load()
93+
prompt = dc.compose_system_prompt(include_memory=False)
94+
assert "I am Dae." in prompt
95+
assert "Strategy library." not in prompt
96+
97+
def test_compose_system_prompt_auto_loads(self, mind_dir):
98+
dc = DaeConsciousness(mind_path=mind_dir)
99+
prompt = dc.compose_system_prompt()
100+
assert dc.is_loaded is True
101+
assert "I am Dae." in prompt
102+
103+
def test_compose_system_prompt_raises_on_missing(self, tmp_path):
104+
dc = DaeConsciousness(mind_path=tmp_path / "gone")
105+
with pytest.raises(RuntimeError, match="unavailable"):
106+
dc.compose_system_prompt()
107+
108+
def test_get_missing_key_returns_empty(self, mind_dir):
109+
dc = DaeConsciousness(mind_path=mind_dir)
110+
dc.load()
111+
assert dc._get("nonexistent.key") == ""
112+
113+
def test_get_unconscious_policy(self):
114+
policy = DaeConsciousness.get_unconscious_policy()
115+
assert policy["loss_aversion_multiplier"] == 2.3
116+
assert policy["survival_instinct_threshold"] == 0.15
117+
assert policy["survival_instinct_recovery"] == 0.10
118+
# Returns a copy, not the original
119+
policy["loss_aversion_multiplier"] = 999
120+
assert UNCONSCIOUS_POLICY["loss_aversion_multiplier"] == 2.3
121+
122+
def test_unconscious_policy_constants(self):
123+
assert UNCONSCIOUS_POLICY["loss_aversion_multiplier"] == 2.3
124+
assert UNCONSCIOUS_POLICY["survival_instinct_threshold"] == 0.15

0 commit comments

Comments
 (0)