fix: restore ensure_ascii=False in utils jsonl helpers; remove dead _last_action from api.py

This commit is contained in:
pyr0ball 2026-05-01 20:59:44 -07:00
parent 167d7351e3
commit cbec776ef1
3 changed files with 2 additions and 12 deletions

View file

@ -80,11 +80,6 @@ def _config_file() -> Path:
return _ROOT / "config" / "label_tool.yaml" return _ROOT / "config" / "label_tool.yaml"
def reset_last_action() -> None:
"""Reset undo state — used by tests."""
global _last_action
_last_action = None
def _queue_file() -> Path: def _queue_file() -> Path:
return _DATA_DIR / "email_label_queue.jsonl" return _DATA_DIR / "email_label_queue.jsonl"
@ -161,9 +156,6 @@ app.include_router(imitate_router, prefix="/api/imitate")
from app.style import router as style_router from app.style import router as style_router
app.include_router(style_router, prefix="/api/style") app.include_router(style_router, prefix="/api/style")
# In-memory last-action store (single user, local tool — in-memory is fine)
_last_action: dict | None = None
class AccountTestRequest(BaseModel): class AccountTestRequest(BaseModel):
account: dict account: dict

View file

@ -106,7 +106,7 @@ def read_jsonl(path: Path) -> list[dict]:
def write_jsonl(path: Path, records: list[dict]) -> None: def write_jsonl(path: Path, records: list[dict]) -> None:
"""Write records to a JSONL file, overwriting any existing content.""" """Write records to a JSONL file, overwriting any existing content."""
path.parent.mkdir(parents=True, exist_ok=True) path.parent.mkdir(parents=True, exist_ok=True)
content = "\n".join(json.dumps(r) for r in records) content = "\n".join(json.dumps(r, ensure_ascii=False) for r in records)
path.write_text(content + ("\n" if records else ""), encoding="utf-8") path.write_text(content + ("\n" if records else ""), encoding="utf-8")
@ -114,4 +114,4 @@ def append_jsonl(path: Path, record: dict) -> None:
"""Append a single record to a JSONL file.""" """Append a single record to a JSONL file."""
path.parent.mkdir(parents=True, exist_ok=True) path.parent.mkdir(parents=True, exist_ok=True)
with open(path, "a", encoding="utf-8") as fh: with open(path, "a", encoding="utf-8") as fh:
fh.write(json.dumps(record) + "\n") fh.write(json.dumps(record, ensure_ascii=False) + "\n")

View file

@ -9,12 +9,10 @@ def reset_globals(tmp_path):
from app import api from app import api
from app.data import label as label_module from app.data import label as label_module
api.set_data_dir(tmp_path) api.set_data_dir(tmp_path)
api.reset_last_action()
label_module.set_data_dir(tmp_path) label_module.set_data_dir(tmp_path)
label_module.set_config_dir(tmp_path) label_module.set_config_dir(tmp_path)
label_module.reset_last_action() label_module.reset_last_action()
yield yield
api.reset_last_action()
label_module.reset_last_action() label_module.reset_last_action()