-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_doctor.py
More file actions
299 lines (255 loc) · 10.1 KB
/
Copy pathtest_doctor.py
File metadata and controls
299 lines (255 loc) · 10.1 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
"""Tests for brigade doctor."""
from __future__ import annotations
from pathlib import Path
import json
import pytest
from brigade import doctor as doctor_mod
from brigade.install import install_selection
from brigade.selection import Selection
def test_doctor_passes_against_workspace_profile(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]),
)
rc = doctor_mod.run(target=tmp_target, harness="generic")
assert rc == 0
out = capsys.readouterr().out
assert "[ok]" in out
assert "[fail]" not in out
def test_doctor_reports_failures_on_empty_dir(tmp_target: Path, capsys):
tmp_target.mkdir()
rc = doctor_mod.run(target=tmp_target, harness="generic")
assert rc == 1
out = capsys.readouterr().out
assert "[fail]" in out
def test_doctor_fails_when_bootstrap_file_exceeds_budget(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]),
)
limit = doctor_mod.BOOTSTRAP_BUDGETS["MEMORY.md"]
(tmp_target / "MEMORY.md").write_text("x" * (limit + 1))
rc = doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
assert rc == 1
assert "[fail]" in out
assert "bootstrap-budget: MEMORY.md" in out
assert "over hard limit" in out
def test_doctor_reports_bootstrap_budget_ok(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]),
)
rc = doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
assert rc == 0
assert "bootstrap-budget: AGENTS.md" in out
assert "bootstrap-budget: MEMORY.md" in out
def test_doctor_openclaw_reports_manual_when_config_missing(tmp_target: Path, monkeypatch, capsys):
install_selection(
tmp_target,
Selection(
depth="workspace",
harnesses=["claude", "openclaw"],
owner="openclaw",
includes=[],
),
)
monkeypatch.setenv("HOME", str(tmp_target)) # so ~/.openclaw resolves into the temp dir
monkeypatch.setattr(Path, "home", lambda: tmp_target)
rc = doctor_mod.run(target=tmp_target, harness="openclaw")
out = capsys.readouterr().out
assert "openclaw: config" in out
# missing config is MANUAL, not FAIL -> exit 0
assert rc == 0
assert "[todo]" in out
def test_doctor_hermes_flags_experimental(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude", "hermes"], owner="hermes", includes=[]),
)
rc = doctor_mod.run(target=tmp_target, harness="hermes")
out = capsys.readouterr().out
assert "hermes:" in out
assert "experimental" in out or "Hermes adapter" in out
assert rc == 0
def test_doctor_reports_memory_care_files(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]),
)
decay = tmp_target / "memory" / "cards" / "decay"
decay.mkdir(exist_ok=True)
(decay / "scan-latest.json").write_text(
json.dumps({"scan_date": "2026-05-13", "counts": {"stale": 2}})
)
(decay / "refresh-queue.json").write_text(json.dumps({"cards": [{"file": "x.md"}]}))
rc = doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
assert rc == 0
assert "memory-care: scan-latest" in out
assert "stale=2" in out
assert "memory-care: refresh-queue" in out
assert "1 queued" in out
def test_doctor_verifies_memory_index_card_links(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]),
)
rc = doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
assert rc == 0
assert "memory-index: card links" in out
assert "verified" in out
def test_doctor_fails_broken_memory_index_card_link(tmp_target: Path, capsys):
install_selection(
tmp_target,
Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]),
)
memory = tmp_target / "MEMORY.md"
memory.write_text(memory.read_text() + "\n- [missing-card](memory/cards/missing-card.md)\n")
rc = doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
assert rc == 1
assert "memory-index: card links" in out
assert "broken link" in out
assert "memory/cards/missing-card.md" in out
def test_doctor_openclaw_reports_cron_memory_jobs(tmp_target: Path, monkeypatch, capsys):
install_selection(
tmp_target,
Selection(
depth="workspace",
harnesses=["claude", "openclaw"],
owner="openclaw",
includes=[],
),
)
openclaw_dir = tmp_target / ".openclaw"
cron_dir = openclaw_dir / "cron"
cron_dir.mkdir(parents=True)
(openclaw_dir / "openclaw.json").write_text(
json.dumps(
{
"plugins": {"entries": {"memory-core": {}}},
"agents": {"defaults": {"model": {"primary": "openai-codex/gpt-5.5"}}},
}
)
)
(cron_dir / "jobs.json").write_text(
json.dumps(
{
"jobs": [
{
"name": "Claude Memory Handoff Ingest",
"enabled": True,
"schedule": {"kind": "every", "everyMs": 1800000},
},
{
"name": "Card Decay Scanner (Daily)",
"enabled": True,
"schedule": {
"kind": "cron",
"expr": "30 5 * * *",
"tz": "America/New_York",
},
},
{
"name": "Card Decay Auto-Refresh (Safe)",
"enabled": True,
"schedule": {
"kind": "cron",
"expr": "40 5 * * *",
"tz": "America/New_York",
},
},
{
"name": "Card Decay Deep Report (Weekly)",
"enabled": True,
"schedule": {
"kind": "cron",
"expr": "30 5 * * 0",
"tz": "America/New_York",
},
},
]
}
)
)
monkeypatch.setenv("HOME", str(tmp_target))
monkeypatch.setattr(Path, "home", lambda: tmp_target)
rc = doctor_mod.run(target=tmp_target, harness="openclaw")
out = capsys.readouterr().out
assert rc == 0
assert "openclaw: handoff ingest cron" in out
assert "every 30 min" in out
assert "openclaw: card decay scanner" in out
assert "openclaw: card decay refresh" in out
assert "openclaw: card decay weekly" in out
def test_doctor_reports_apparent_harness_shape(tmp_target: Path, capsys):
sel = Selection(
depth="workspace",
harnesses=["claude", "codex", "openclaw"],
owner="openclaw",
includes=[],
)
install_selection(tmp_target, sel)
doctor_mod.run(tmp_target)
out = capsys.readouterr().out
assert "harnesses:" in out
assert "claude" in out
assert "codex" in out
assert "openclaw" in out
assert "owner=openclaw" in out
def test_doctor_checks_codex_inbox_when_selected(tmp_target: Path, capsys):
sel = Selection(
depth="repo",
harnesses=["claude", "codex"],
owner="claude",
includes=[],
)
install_selection(tmp_target, sel)
doctor_mod.run(tmp_target)
out = capsys.readouterr().out
assert ".codex/memory-handoffs" in out
def test_doctor_warns_for_orphan_inbox(tmp_target: Path, capsys):
"""If config says claude only, but .codex/memory-handoffs exists, warn."""
sel = Selection(
depth="repo",
harnesses=["claude"],
owner="claude",
includes=[],
)
install_selection(tmp_target, sel)
(tmp_target / ".codex" / "memory-handoffs").mkdir(parents=True)
doctor_mod.run(tmp_target)
out = capsys.readouterr().out
assert "orphan" in out.lower() or "unselected" in out.lower()
def test_doctor_falls_back_to_v0_2_behavior_when_no_config(tmp_target: Path, capsys):
"""A target without .solo-mise/config.json should still run (legacy targets)."""
tmp_target.mkdir()
(tmp_target / "AGENTS.md").write_text("# Agents")
doctor_mod.run(tmp_target)
out = capsys.readouterr().out
assert "doctor" in out
def test_doctor_includes_installed_managed_tool(monkeypatch, tmp_target, capsys):
from brigade.install import install_selection
from brigade.selection import Selection
from brigade import managed
install_selection(tmp_target, Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]))
# Pretend content-guard is installed and healthy.
monkeypatch.setattr(managed.proc, "which", lambda c: "/x/" + c if c == "content-guard" else None)
monkeypatch.setattr(managed.proc, "run", lambda args, **kw: managed.proc.Result(0, '{"ok": true}', ""))
doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
assert "content-guard" in out
def test_doctor_reports_absent_tool_as_manual(monkeypatch, tmp_target, capsys):
from brigade.install import install_selection
from brigade.selection import Selection
from brigade import managed
install_selection(tmp_target, Selection(depth="workspace", harnesses=["claude"], owner="claude", includes=[]))
monkeypatch.setattr(managed.proc, "which", lambda c: None) # nothing installed
rc = doctor_mod.run(target=tmp_target, harness="generic")
out = capsys.readouterr().out
# absent managed tools must not fail the run
assert rc == 0
assert "not installed" in out