返回 last30days-skill
test_doctor_postmortem_after_run.py
根目录 / tests / test_doctor_postmortem_after_run.py
1 """`doctor --postmortem` reads the run the engine just saved.
2
3 On 2026-11-10 a Disney run saved its raw file and the next `doctor
4 --postmortem` printed "No saved run found - run `/last30days <topic>` first".
5 The engine stamped last-report.json "last30days-report-cache/v2"; doctor still
6 compared it with "/v1" and treated every saved run as unreadable.
7 """
8
9 import last30days as cli
10 from lib import doctor, health, schema
11 from tests.test_last_run_state import _report
12
13
14 def _run_with_outcomes():
15 report = _report("Disney")
16 report.source_status = {
17 "youtube": schema.SourceOutcome(source="youtube", state=health.OK, items_returned=13),
18 "reddit": schema.SourceOutcome(
19 source="reddit", state=health.TIMEOUT, items_returned=0,
20 detail="reddit timed out after 180s", fix_hint="doctor",
21 ),
22 "digg": schema.SourceOutcome(
23 source="digg", state=health.PARTIAL, items_returned=12,
24 detail="12 items returned: no recent local sync",
25 ),
26 }
27 return report
28
29
30 def test_doctor_reads_the_stamp_the_engine_writes():
31 assert doctor.REPORT_CACHE_SCHEMA_VERSION == cli.REPORT_CACHE_VERSION
32 assert doctor.REPORT_CACHE_FILENAME == cli._last_report_cache_path().name
33
34
35 def test_postmortem_after_a_run_reports_that_runs_outcomes():
36 assert cli._write_last_run("Disney", _run_with_outcomes())
37
38 postmortem = doctor.build_postmortem({})
39 text = doctor.render_postmortem_text(postmortem)
40
41 assert postmortem["present"] is True
42 assert "No saved run found" not in text
43 assert "last run: Disney" in text
44 assert postmortem["outcomes"]["youtube"]["items_returned"] == 13
45 # A source timeout is named with its detail.
46 assert "✕ reddit — timeout: reddit timed out after 180s" in text
47 assert "⚠ digg (12 items) — 12 items returned: no recent local sync" in text
48
49
50 def test_postmortem_with_no_run_still_says_so():
51 text = doctor.render_postmortem_text(doctor.build_postmortem({}))
52
53 assert "No saved run found" in text
54
54 lines PYTHON