fix(附件): 配置转换超时并重试临时文件清理

将项目文档提取超时配置为 30 秒,适应 Windows 下独立 LibreOffice 配置目录的启动耗时,并记录本地安装与 PATH 配置方法。

附件清理改为异步,遇到转换子进程退出后的短暂文件占用时进行最多 2 秒的重试,保持事件循环可响应并确保上传计数仅释放一次。

本机已安装 LibreOffice 26.8.1.1 并加入用户 PATH。真实 DOC 正文和中文表格提取、正常及强制超时后的目录清理验证通过;全量测试 134 项通过,无跳过。Ruff 静态检查、改动代码格式检查、pip check 和差异检查通过。
This commit is contained in:
starrrLight committed 2026-10-15 18:29:31 +08:00
1 parent 1b48d0146c
commit bc9afe2d47
6 files changed
+44 -10

No files matched your search

+24
View File
@@ -517,6 +517,30 @@ async def test_extraction_timeout_and_cancellation_reap_process(tmp_path, monkey
assert children[1].returncode is not None
async def test_cleanup_retries_transient_file_locks_without_blocking(monkeypatch):
released = asyncio.Event()
notifications = []
store = AttachmentStore(Limits(), on_close=lambda: notifications.append("closed"))
store.raw_path.write_bytes(b"original upload")
cleanup = store.directory.cleanup
def locked_cleanup():
if not released.is_set():
raise PermissionError("converter is still closing its handles")
cleanup()
monkeypatch.setattr(store.directory, "cleanup", locked_cleanup)
async def release_lock():
await asyncio.sleep(0)
released.set()
await asyncio.gather(store.aclose(), release_lock())
await store.aclose()
assert notifications == ["closed"]
assert_clean([store])
@pytest.mark.parametrize("stage", ["receive", "extract", "stream"])
async def test_disconnect_cleans_upload_at_each_stage(tmp_path, stores, monkeypatch, stage):
from middleware import attachments