Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion screenmind/workers/analysis_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
30 changes: 30 additions & 0 deletions tests/test_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"