fix: preserve image metadata in cloud get_page_content

Cloud OCR page results carry an `images` list per page, but the page
reconstruction only kept `page` and `content`, dropping images for cloud
callers of collection.get_page_content(). The local backend preserves them
and the PageContent contract / SDK prompts expect them (so the downstream
UI can render figures). Pass `images` through, omitting it when empty to
mirror the local backend's shape. Verified against the real OCR endpoint:
per-page keys are page_index/markdown/images.
This commit is contained in:
mountain 2026-07-09 19:26:57 +08:00
parent 56fc3bf7bb
commit 4456b92968
2 changed files with 24 additions and 1 deletions

View file

@ -142,6 +142,24 @@ def test_get_document_include_text_warns(monkeypatch):
backend.get_document("col", "d1", include_text=True)
def test_get_page_content_preserves_images(monkeypatch):
# Cloud OCR pages carry an `images` list; get_page_content must pass it
# through (parity with the local backend and the documented PageContent
# shape) so the SDK-prompted UI can render figures — omitting it only when
# empty. Real API uses page_index/markdown/images keys.
backend = CloudBackend(api_key="pi-test")
imgs = [{"path": "fig1.png", "width": 640, "height": 480}]
monkeypatch.setattr(backend, "_doc_request", lambda *a, **k: {"result": [
{"page_index": 1, "markdown": "page one", "images": imgs},
{"page_index": 2, "markdown": "page two", "images": []}, # empty -> omitted
]})
out = backend.get_page_content("col", "d1", "1,2")
assert out == [
{"page": 1, "content": "page one", "images": imgs},
{"page": 2, "content": "page two"},
]
# ── query_stream: terminal contract and error propagation ───────────────────
def _collect_events(backend, **kwargs):