From fb7a97fa8df9a194d4cf79b4ff31af2631345a0d Mon Sep 17 00:00:00 2001 From: Research Assistant Date: Mon, 1 Jun 2026 12:47:57 +0800 Subject: [PATCH] fix: always write ocr_redo field in frontmatter_note (defaults to false) --- paperforge/worker/sync.py | 4 +-- tests/test_sync.py | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 tests/test_sync.py diff --git a/paperforge/worker/sync.py b/paperforge/worker/sync.py index 47c67c2c..2c7c038a 100644 --- a/paperforge/worker/sync.py +++ b/paperforge/worker/sync.py @@ -1037,8 +1037,8 @@ def frontmatter_note(entry: dict, existing_text: str = "", preserved_tags: list[ f"fulltext_md_path: {yaml_quote('[[{}]]'.format(entry['fulltext_path']) if entry.get('ocr_status') == 'done' and entry.get('fulltext_path') else '')}", ] ) - if preserved_ocr_redo: - lines.append("ocr_redo: true") + ocr_redo_value = bool(preserved_ocr_redo) + lines.append(f"ocr_redo: {str(ocr_redo_value).lower()}") if preserved_tags is not None: lines.append("tags:") for tag in preserved_tags: diff --git a/tests/test_sync.py b/tests/test_sync.py new file mode 100644 index 00000000..f9d47187 --- /dev/null +++ b/tests/test_sync.py @@ -0,0 +1,59 @@ +def test_frontmatter_note_writes_ocr_redo_false_by_default(): + from paperforge.worker.sync import frontmatter_note + + entry = { + "title": "Test Paper", + "zotero_key": "ABCD1234", + "citation_key": "test2024", + "year": "2024", + "journal": "Test Journal", + "first_author": "Smith", + "domain": "test", + "doi": "", + "pmid": "", + "collections": [], + "collection_tags": [], + "impact_factor": "", + "abstract": "", + "has_pdf": False, + "do_ocr": False, + "analyze": False, + "ocr_status": "pending", + "deep_reading_status": "pending", + "pdf_path": "", + "fulltext_path": "", + } + + result = frontmatter_note(entry) + assert "ocr_redo: false" in result + + +def test_frontmatter_note_preserves_ocr_redo_true(): + from paperforge.worker.sync import frontmatter_note + + entry = { + "title": "Test Paper", + "zotero_key": "ABCD1234", + "citation_key": "test2024", + "year": "2024", + "journal": "Test Journal", + "first_author": "Smith", + "domain": "test", + "doi": "", + "pmid": "", + "collections": [], + "collection_tags": [], + "impact_factor": "", + "abstract": "", + "has_pdf": False, + "do_ocr": False, + "analyze": False, + "ocr_status": "pending", + "deep_reading_status": "pending", + "pdf_path": "", + "fulltext_path": "", + } + + result = frontmatter_note(entry, preserved_ocr_redo=True) + assert "ocr_redo: true" in result + assert "ocr_redo: false" not in result