diff --git a/screenmind/workers/analysis_worker.py b/screenmind/workers/analysis_worker.py index 59477af..b0544da 100644 --- a/screenmind/workers/analysis_worker.py +++ b/screenmind/workers/analysis_worker.py @@ -647,7 +647,7 @@ async def _backfill_skipped(self): try: conn = self._db._get_conn() row = conn.execute( - """SELECT id, screenshot_path, window_title, app_name, ocr_text, ocr_boxes + """SELECT id, screenshot_path, window_title, COALESCE(detected_app, app_name), ocr_text, ocr_boxes FROM activities WHERE status IN ('pending', 'skipped', 'failed') AND DATE(timestamp) = DATE('now', 'localtime') diff --git a/tests/test_workers.py b/tests/test_workers.py index 8a7a396..933812e 100644 --- a/tests/test_workers.py +++ b/tests/test_workers.py @@ -174,3 +174,33 @@ def test_extract_url_strips_punctuation(self): from screenmind.workers.analysis_worker import _extract_all_urls urls = _extract_all_urls("See https://example.com/page.") assert urls[0] == "https://example.com/page" + + +class TestAnalysisWorkerBackfill: + """Backfill re-analyzes rows that were never analyzed.""" + + async def test_backfill_passes_detected_app_as_hint(self, db, tmp_path): + """Unanalyzed rows have app_name NULL; the OS-detected app must be used.""" + from PIL import Image + from screenmind.storage.models import ScreenshotEntry + from screenmind.workers.analysis_worker import AnalysisWorker + + shot = tmp_path / "shot.jpg" + Image.new("RGB", (64, 64), "white").save(shot) + db.insert_activity(ScreenshotEntry( + timestamp=datetime.now(), + screenshot_path=str(shot), + window_title="Chats", + detected_app_name="Telegram", + bookmarked=False, + analyzed=False, + )) + + worker = AnalysisWorker(queue=asyncio.Queue(maxsize=100), database=db) + worker._process = AsyncMock() + await worker._backfill_skipped() + + worker._process.assert_awaited_once() + capture = worker._process.await_args.args[0] + assert capture.app_name == "Telegram" + assert capture.window_title == "Chats"