DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(partners): serve partner artifacts from output downloads
ZQR11010d1696abdcf8
diff --git a/deeptutor/api/routers/outputs.py b/deeptutor/api/routers/outputs.pyindex 6d763477a..ced70bc83 100644--- a/deeptutor/api/routers/outputs.py+++ b/deeptutor/api/routers/outputs.py@@ -10,7 +10,9 @@ from fastapi.responses import FileResponsefrom deeptutor.api.routers.auth import require_authfrom deeptutor.multi_user.context import get_current_user_or_nonefrom deeptutor.multi_user.paths import get_path_service_for_scope+from deeptutor.multi_user.partner_access import visible_partnersfrom deeptutor.services.auth import TokenPayload+from deeptutor.services.partners.scope import partner_scopefrom deeptutor.services.path_service import PathServicerouter = APIRouter()@@ -37,11 +39,45 @@ def _resolve_output(path_service: PathService, relative_path: str) -> Path:return output_path+def _resolve_partner_output(relative_path: str) -> Path | None:+ """Resolve *relative_path* against partner scopes the caller may use.++ Partner web chats run inside a synthetic workspace under+ ``data/partners/<id>/workspace``, so generated files are not beneath the+ human caller's own ``data/users/<uid>`` tree. The public artifact URL shape+ is still ``/api/outputs/<relative path>``, which means the download surface+ has to search the caller's visible partner workspaces when their own+ workspace misses (#1012).++ The first-party chat flow already scopes the request to one conversation, so+ the same relative path colliding across multiple partners is vanishingly+ unlikely. Fail closed anyway: only a unique partner match is served.+ """+ matches: list[Path] = []+ for partner in visible_partners():+ partner_id = str(partner.get("partner_id") or "").strip()+ if not partner_id:+ continue+ candidate = get_path_service_for_scope(partner_scope(partner_id)).resolve_public_output_path(+ relative_path+ )+ if candidate is not None:+ matches.append(candidate)+ if len(matches) > 1:+ return None+ return matches[0] if matches else None++@router.api_route("/{output_path:path}", methods=["GET", "HEAD"])async def read_output(output_path: str,_auth: TokenPayload | None = Depends(require_auth),) -> FileResponse:- """Serve one allowlisted artifact from the authenticated user's workspace."""- path = _resolve_output(_request_path_service(), output_path)+ """Serve one allowlisted artifact from the authenticated user's reach."""+ try:+ path = _resolve_output(_request_path_service(), output_path)+ except HTTPException:+ path = _resolve_partner_output(output_path)+ if path is None:+ raisereturn FileResponse(path)diff --git a/tests/api/test_output_files.py b/tests/api/test_output_files.pyindex ac9be7c2f..2f5ff1ad0 100644--- a/tests/api/test_output_files.py+++ b/tests/api/test_output_files.py@@ -122,6 +122,30 @@ def test_auth_disabled_reads_local_admin_output(output_app) -> None:assert response.content == b"local output"+def test_authenticated_user_downloads_visible_partner_output(output_app, monkeypatch) -> None:+ relative_path = "workspace/chat/chat/session-1/code_runs/chart.png"+ alice = TokenPayload(username="alice", role="user", user_id="u_alice")+ client, admin_root, _users_root = output_app({"alice-token": alice})++ from deeptutor.api.routers import outputs++ partner_root = admin_root / "partners" / "math-bot" / "workspace"+ _write_output(partner_root, relative_path, b"\x89PNG\r\n\x1a\npartner image")+ monkeypatch.setattr(+ outputs,+ "visible_partners",+ lambda: [{"partner_id": "math-bot", "can_manage": True}],+ )++ with client:+ client.cookies.set("dt_token", "alice-token")+ response = client.get(f"/api/outputs/{relative_path}")++ assert response.status_code == 200+ assert response.content.startswith(b"\x89PNG\r\n\x1a\n")+ assert response.headers["content-type"] == "image/png"++def test_private_suffix_is_rejected(output_app) -> None:relative_path = "workspace/chat/chat/session-1/code_runs/private.json"alice = TokenPayload(username="alice", role="user", user_id="u_alice")