feat(shipping-notice): 添加 MinerU 订单附件表格结构化功能,更新环境配置和数据模型以支持新布局解析和文档模板管理
This commit is contained in:
1 parent
c4095b08da
commit
c35223d49d
148 files changed
+15709
-1353
No files matched your search
@@ -108,6 +108,26 @@ class _FakeSession:
|
||||
return self.response
|
||||
|
||||
|
||||
class _AsyncSession:
|
||||
"""模拟 `/tasks` 提交、状态轮询和结果读取。"""
|
||||
|
||||
def __init__(self, result: dict):
|
||||
self.result = result
|
||||
self.calls: list[str] = []
|
||||
|
||||
def post(self, url: str, **_kwargs):
|
||||
"""返回异步任务 ID。"""
|
||||
self.calls.append(url)
|
||||
return _FakeResponse({'task_id': 'task-async'}, status_code=202)
|
||||
|
||||
def get(self, url: str, **_kwargs):
|
||||
"""第一次读取终态,结果接口返回完整 MinerU payload。"""
|
||||
self.calls.append(url)
|
||||
if url.endswith('/result'):
|
||||
return _FakeResponse(self.result)
|
||||
return _FakeResponse({'task_id': 'task-async', 'status': 'completed'})
|
||||
|
||||
|
||||
def test_mineru_candidate_preserves_table_structure_but_blocks_cell_evidence():
|
||||
"""只有整表 bbox + HTML 时必须保留行列候选并阻止确定性单元格证据。"""
|
||||
candidate = parse_mineru_candidate(_mineru_payload())
|
||||
@@ -188,6 +208,23 @@ def test_mineru_client_sends_bounded_single_file_request():
|
||||
assert response.closed is True
|
||||
|
||||
|
||||
def test_mineru_async_client_submits_polls_and_reads_result_without_long_post():
|
||||
"""生产调用应使用 `/tasks` 短提交,再通过状态和结果接口获取 completed payload。"""
|
||||
session = _AsyncSession(_mineru_payload())
|
||||
client = MinerUClient(MinerUClientConfig(
|
||||
base_url='http://mineru.internal:8100', poll_interval_seconds=0.01,
|
||||
), session=session)
|
||||
|
||||
payload = client.parse_file_async(filename='fixture.pdf', content=b'%PDF')
|
||||
|
||||
assert payload['status'] == 'completed'
|
||||
assert session.calls == [
|
||||
'http://mineru.internal:8100/tasks',
|
||||
'http://mineru.internal:8100/tasks/task-async',
|
||||
'http://mineru.internal:8100/tasks/task-async/result',
|
||||
]
|
||||
|
||||
|
||||
def test_mineru_client_rejects_unsupported_empty_and_large_files_before_network():
|
||||
"""文件类型、空内容和上传上限必须在 HTTP 请求前拒绝。"""
|
||||
session = _FakeSession(_FakeResponse(_mineru_payload()))
|
||||
|
||||
Reference in new issue
Block a user