diff --git a/app/api.py b/app/api.py index 7148d9c..bebbe68 100644 --- a/app/api.py +++ b/app/api.py @@ -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: diff --git a/tests/test_api.py b/tests/test_api.py index 311e8f7..50d316e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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