DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(quiz): resolve stored attachment URLs before judging
dajiaohuang447a5da1030c
diff --git a/deeptutor/api/routers/quiz_judge.py b/deeptutor/api/routers/quiz_judge.pyindex fded402fd..5b881fb70 100644--- a/deeptutor/api/routers/quiz_judge.py+++ b/deeptutor/api/routers/quiz_judge.py@@ -190,8 +190,12 @@ async def _build_multimodal_user_content(try:parsed = urlparse(url)parts = (parsed.path or url).strip("/").split("/")- # Expected shape: api/attachments/{sid}/{aid}/{name}- if len(parts) >= 5 and parts[0] == "api" and parts[1] == "attachments":+ # Current store URLs use files/attachments; keep older saved+ # api/attachments references readable as well.+ if len(parts) >= 5 and parts[:2] in (+ ["files", "attachments"],+ ["api", "attachments"],+ ):sid = unquote(parts[2])aid = unquote(parts[3])name = unquote("/".join(parts[4:]))diff --git a/tests/api/test_quiz_judge_attachments.py b/tests/api/test_quiz_judge_attachments.pynew file mode 100644index 000000000..ed0dfab24--- /dev/null+++ b/tests/api/test_quiz_judge_attachments.py@@ -0,0 +1,40 @@+"""Saved quiz-answer images are sent to the judge as provider-readable data."""++import base64+from pathlib import Path++import pytest++from deeptutor.api.routers.quiz_judge import _build_multimodal_user_content+from deeptutor.services.storage.attachment_store import LocalDiskAttachmentStore++[email protected]("legacy", [False, True])+async def test_saved_answer_image_is_materialized(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, legacy: bool+) -> None:+ """Use the actual store's URL, including an encoded Unicode filename."""+ store = LocalDiskAttachmentStore(tmp_path / "attachments")+ image = b"test-only-image-bytes"+ filename = "answer 中文.png"+ url = await store.put(+ session_id="quiz-session",+ attachment_id="answer-1",+ filename=filename,+ data=image,+ )+ if legacy:+ url = url.replace("/files/attachments/", "/api/attachments/")+ monkeypatch.setattr("deeptutor.services.storage.get_attachment_store", lambda: store)+ content = await _build_multimodal_user_content(+ text="Judge this answer",+ image_records=[{"url": url, "filename": filename, "mime_type": "image/png"}],+ )+ assert content == [+ {"type": "text", "text": "Judge this answer"},+ {+ "type": "image_url",+ "image_url": {"url": "data:image/png;base64," + base64.b64encode(image).decode()},+ },+ ]