fix(avocet): _write_jsonl empty-list writes empty file; add reset_last_action helper

This commit is contained in:
pyr0ball 2026-03-03 14:36:18 -08:00
parent ffd1450f62
commit c8aea3c39f
2 changed files with 20 additions and 9 deletions

View file

@ -20,6 +20,12 @@ def set_data_dir(path: Path) -> None:
_DATA_DIR = path
def reset_last_action() -> None:
"""Reset undo state — used by tests."""
global _last_action
_last_action = None
def _queue_file() -> Path:
return _DATA_DIR / "email_label_queue.jsonl"
@ -41,10 +47,8 @@ def _read_jsonl(path: Path) -> list[dict]:
def _write_jsonl(path: Path, records: list[dict]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(
"\n".join(json.dumps(r, ensure_ascii=False) for r in records) + "\n",
encoding="utf-8",
)
text = "\n".join(json.dumps(r, ensure_ascii=False) for r in records)
path.write_text(text + "\n" if records else "", encoding="utf-8")
def _append_jsonl(path: Path, record: dict) -> None:

View file

@ -1,8 +1,15 @@
# tests/test_api.py
import json, pytest
from pathlib import Path
import pytest
from app import api as api_module # noqa: F401
@pytest.fixture(autouse=True)
def reset_globals(tmp_path):
from app import api
api.set_data_dir(tmp_path)
api.reset_last_action()
yield
api.reset_last_action()
# We'll import helpers once they exist
# For now just verify the file can be imported
def test_import():
from app import api # noqa: F401