From 320a833b2cebb5f5beed0e5b242e72e6c5c03892 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 26 Nov 2026 00:16:01 +0800 Subject: [PATCH] =?UTF-8?q?test(smb,docs):=20=E8=A1=A5=E9=BD=90=20SMB=20?= =?UTF-8?q?=E6=B5=81=E5=BC=8F=E5=8D=95=E6=B5=8B=E8=A6=86=E7=9B=96=E5=B9=B6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=9E=B6=E6=9E=84=E6=80=BB=E8=A7=88=E8=BE=B9?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/architecture-overview.md | 2 +- tests/test_mediaserver_streaming.py | 39 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/docs/architecture-overview.md b/docs/architecture-overview.md index 3708cf5e3..f34a10d38 100644 --- a/docs/architecture-overview.md +++ b/docs/architecture-overview.md @@ -851,7 +851,7 @@ flowchart LR | 指标 | 当前值 | |---|---:| | Python 模块 | 1200 | -| 内部导入边 | 10,675 | +| 内部导入边 | 10,678 | | 非平凡 SCC | 1(29 个模块的 TMDB vendor 精确 containment) | | Application / Chain 具体 Adapter 直连 | 0 / 0 | | Direct egress | 52(精确 policy 准入,Application / Chain 均为 0;本知识 Adapter 仍复用宿主 HTTP 层) | diff --git a/tests/test_mediaserver_streaming.py b/tests/test_mediaserver_streaming.py index 2e9fb8807..f0289be23 100644 --- a/tests/test_mediaserver_streaming.py +++ b/tests/test_mediaserver_streaming.py @@ -904,3 +904,42 @@ def test_remote_storage_smb_and_http_progressive_stream_tickets( }, ) assert unsupported.status_code == 400 + + +def test_smb_open_file_stream_branches(monkeypatch: pytest.MonkeyPatch) -> None: + """ + 验证 SMB.open_file_stream 的空路径、正常打开与异常回退分支。 + """ + import io + import sys + import types + + from app.modules.filemanager.storages.smb import SMB + from app.schemas.file import FileItem + + storage = SMB.__new__(SMB) + storage._connected = False # noqa: SLF001 + monkeypatch.setattr(storage, "_check_connection", lambda: None) + monkeypatch.setattr(storage, "_normalize_path", lambda p: f"\\\\nas\\share\\{p.lstrip('/')}") + + fake_stream = io.BytesIO(b"hello-smb") + fake_smbclient = types.SimpleNamespace( + stat=lambda _p: SimpleNamespace(st_size=9), + open_file=lambda _p, mode="rb": fake_stream if mode == "rb" else None, + ) + monkeypatch.setitem(sys.modules, "smbclient", fake_smbclient) + + assert storage.open_file_stream(FileItem(storage="smb", type="file", path="", name="empty.mp4")) is None + + result = storage.open_file_stream(FileItem(storage="smb", type="file", path="/movies/a.mp4", name="a.mp4")) + assert result == (fake_stream, 9) + + def _boom(_p: str): + raise OSError("smb broken") + + monkeypatch.setitem( + sys.modules, + "smbclient", + types.SimpleNamespace(stat=_boom, open_file=lambda _p, mode="rb": None), + ) + assert storage.open_file_stream(FileItem(storage="smb", type="file", path="/movies/a.mp4", name="a.mp4")) is None