From 0d49b5d285d375477b51ad3ab9dd7d9d82ef2d83 Mon Sep 17 00:00:00 2001 From: Research Assistant Date: Sat, 9 May 2026 18:06:37 +0800 Subject: [PATCH] fix: pre-existing test issues blocking CI on non-Windows platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_ocr_preflight: mock fitz.open (not builtins.open) + set needs_sanitize=True - Code uses fitz.open(), not builtins.open() — mock was targeting wrong function - fitz.open() only called when meta.needs_sanitize is true — mock returned {} which skipped it - These tests were always broken but CI never ran before v2.1 test_e2e_cli: guard against None stdout in doctor_verdict test on Windows CI L3 runtime.test.mjs: use platform-agnostic path matching - path.join produces / on Linux but \\\\ on Windows — test used \\\\ only --- paperforge/plugin/tests/runtime.test.mjs | 2 +- tests/test_e2e_cli.py | 5 ++++- tests/test_ocr_preflight.py | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/paperforge/plugin/tests/runtime.test.mjs b/paperforge/plugin/tests/runtime.test.mjs index 0dc1da78..ae28ec92 100644 --- a/paperforge/plugin/tests/runtime.test.mjs +++ b/paperforge/plugin/tests/runtime.test.mjs @@ -36,7 +36,7 @@ describe('resolvePythonExecutable', () => { }); it('returns venv path when .venv/Scripts/python.exe exists', () => { - const d = mockDeps((p) => p.includes('.venv\\Scripts\\python.exe')); + const d = mockDeps((p) => p.includes('.venv') && p.includes('python.exe')); const r = resolvePythonExecutable('/vault', {}, d.fs, d.execFileSync); expect(r.path).toContain('.venv'); expect(r.source).toBe('auto-detected'); diff --git a/tests/test_e2e_cli.py b/tests/test_e2e_cli.py index 7fb1f4b9..20a13f5c 100644 --- a/tests/test_e2e_cli.py +++ b/tests/test_e2e_cli.py @@ -98,7 +98,10 @@ class TestCliDoctor: def test_doctor_outputs_verdict(self, test_vault: Path) -> None: """Doctor output contains [OK], [WARN], or [FAIL] verdict.""" result = _run(["doctor"], test_vault) - assert any(tag in result.stdout for tag in ["[OK]", "[WARN]", "[FAIL]"]) + stdout = result.stdout or "" + assert any(tag in stdout for tag in ["[OK]", "[WARN]", "[FAIL]"]), ( + f"No verdict in doctor output. stdout={stdout[:200]} stderr={(result.stderr or '')[:200]}" + ) class TestCliDeepReading: diff --git a/tests/test_ocr_preflight.py b/tests/test_ocr_preflight.py index 181b1f02..81d2761d 100644 --- a/tests/test_ocr_preflight.py +++ b/tests/test_ocr_preflight.py @@ -66,7 +66,7 @@ class TestOcrPreflight: ), patch( "paperforge.worker.ocr.ensure_ocr_meta", - return_value={}, + return_value={"needs_sanitize": True}, ), patch("paperforge.worker.ocr.write_json") as mock_write, patch("paperforge.worker.sync.run_selection_sync"), @@ -124,7 +124,7 @@ class TestOcrPreflight: ), patch( "paperforge.worker.ocr.ensure_ocr_meta", - return_value={}, + return_value={"needs_sanitize": True}, ), patch("paperforge.worker.ocr.write_json") as mock_write, patch("paperforge.worker.sync.run_selection_sync"), @@ -184,10 +184,10 @@ class TestOcrPreflight: ), patch( "paperforge.worker.ocr.ensure_ocr_meta", - return_value={}, + return_value={"needs_sanitize": True}, ), patch("paperforge.worker.ocr.write_json"), - patch("builtins.open") as mock_open, + patch("paperforge.worker.ocr.fitz.open") as mock_open, patch("paperforge.worker.ocr.requests.post") as mock_post, patch("paperforge.worker.ocr.requests.get") as mock_get, ): @@ -257,10 +257,10 @@ class TestOcrPreflight: ), patch( "paperforge.worker.ocr.ensure_ocr_meta", - return_value={}, + return_value={"needs_sanitize": True}, ), patch("paperforge.worker.ocr.write_json"), - patch("builtins.open") as mock_open, + patch("paperforge.worker.ocr.fitz.open") as mock_open, patch("paperforge.worker.ocr.requests.post") as mock_post, patch("paperforge.worker.ocr.requests.get") as mock_get, ):