feat: add OCR document types and ports
OcrDocumentElement extends the layout element with text; OcrDocumentResult stays independent because the parent's defaulted call_stats forbids a required markdown field. OcrDocumentTransport is a separate Protocol so existing OcrTransport implementers keep passing isinstance.
This commit is contained in:
@@ -12,6 +12,7 @@ from polygateway.ports import (
|
||||
GateState,
|
||||
GateUpdate,
|
||||
Middleware,
|
||||
OcrDocumentTransport,
|
||||
OcrTransport,
|
||||
Permit,
|
||||
ProviderGate,
|
||||
@@ -193,6 +194,7 @@ class TestReasoningTierIsOnlyOnTheChatPort:
|
||||
(EmbeddingTransport, "embed"),
|
||||
(OcrTransport, "recognize_text"),
|
||||
(OcrTransport, "parse_layout"),
|
||||
(OcrDocumentTransport, "parse_document"),
|
||||
],
|
||||
)
|
||||
def test_other_transports_have_no_reasoning_tier(self, protocol, method):
|
||||
@@ -372,6 +374,34 @@ class TestOcrPorts:
|
||||
assert isinstance(GoodClient(), OcrLayoutPort)
|
||||
assert isinstance(GoodTransport(), OcrTransport)
|
||||
|
||||
def test_document_ports_are_runtime_checkable(self):
|
||||
from polygateway.ports import OcrDocumentPort, OcrDocumentTransport
|
||||
|
||||
class GoodClient:
|
||||
async def parse_document(self, document): ...
|
||||
|
||||
class GoodTransport:
|
||||
async def parse_document(self, *, document, source, call_id): ...
|
||||
|
||||
class Empty: ...
|
||||
|
||||
assert isinstance(GoodClient(), OcrDocumentPort)
|
||||
assert isinstance(GoodTransport(), OcrDocumentTransport)
|
||||
assert not isinstance(Empty(), OcrDocumentPort)
|
||||
assert not isinstance(Empty(), OcrDocumentTransport)
|
||||
|
||||
def test_ocr_transport_members_are_unchanged(self):
|
||||
"""新能力走独立 Protocol: 往旧 runtime_checkable Protocol 加成员,会让所有
|
||||
现有实现(测试替身、下游自带 fake)在 isinstance 上一夜之间不合格。"""
|
||||
from polygateway.ports import OcrTransport
|
||||
|
||||
members = {
|
||||
name
|
||||
for name in vars(OcrTransport)
|
||||
if not name.startswith("_") and callable(getattr(OcrTransport, name))
|
||||
}
|
||||
assert members == {"recognize_text", "parse_layout", "check_health"}
|
||||
|
||||
def test_missing_method_rejected(self):
|
||||
from polygateway.ports import OcrTransport
|
||||
|
||||
|
||||
Reference in New Issue
Block a user