|
|
@@ -60,6 +60,63 @@ def test_event_log_store_ignores_duplicate_event_id(tmp_path):
|
|
|
assert count == 1
|
|
|
|
|
|
|
|
|
+def test_event_log_store_recent_and_health_use_sqlite_mirror(tmp_path):
|
|
|
+ store = EventLogStore(tmp_path)
|
|
|
+ store.write_events(
|
|
|
+ 3,
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "event_id": "evt-003",
|
|
|
+ "chapter": 3,
|
|
|
+ "event_type": "promise_created",
|
|
|
+ "subject": "救人承诺",
|
|
|
+ "payload": {"target": "小医仙"},
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ store.write_events(
|
|
|
+ 4,
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "event_id": "evt-004",
|
|
|
+ "chapter": 4,
|
|
|
+ "event_type": "promise_paid_off",
|
|
|
+ "subject": "救人承诺",
|
|
|
+ "payload": {"target": "小医仙"},
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ )
|
|
|
+
|
|
|
+ recent = store.list_recent(limit=10)
|
|
|
+ assert [item["event_id"] for item in recent] == ["evt-004", "evt-003"]
|
|
|
+ chapter_only = store.list_recent(chapter=3, limit=10)
|
|
|
+ assert chapter_only == [
|
|
|
+ {
|
|
|
+ "event_id": "evt-003",
|
|
|
+ "chapter": 3,
|
|
|
+ "event_type": "promise_created",
|
|
|
+ "subject": "救人承诺",
|
|
|
+ "payload": {"target": "小医仙"},
|
|
|
+ }
|
|
|
+ ]
|
|
|
+
|
|
|
+ health = store.health()
|
|
|
+ assert health["ok"] is True
|
|
|
+ assert health["sqlite_rows"] == 2
|
|
|
+ assert health["event_files"] == 2
|
|
|
+
|
|
|
+
|
|
|
+def test_event_log_store_recent_and_health_without_table(tmp_path):
|
|
|
+ store = EventLogStore(tmp_path)
|
|
|
+ (tmp_path / ".webnovel").mkdir(parents=True, exist_ok=True)
|
|
|
+ sqlite3.connect(tmp_path / ".webnovel" / "index.db").close()
|
|
|
+
|
|
|
+ assert store.list_recent() == []
|
|
|
+ health = store.health()
|
|
|
+ assert health["sqlite_rows"] == 0
|
|
|
+ assert health["event_files"] == 0
|
|
|
+
|
|
|
+
|
|
|
def test_story_events_cli_reads_chapter_file(tmp_path, monkeypatch, capsys):
|
|
|
_ensure_scripts_on_path()
|
|
|
events_dir = tmp_path / ".story-system" / "events"
|