feat: repair 重传后自动复核 (前置校验等级验证重传文件)

This commit is contained in:
AskaEth committed 2026-08-22 15:43:31 +08:00
1 parent 4defbf8b1e
commit 30419c9aae
3 files changed
+100

No files matched your search

+38
View File
@@ -593,3 +593,41 @@ def test_build_repair_cmd(tmp_path):
assert "--mkpath" in joined
assert "--bwlimit=30000" in joined
assert "src/" in joined and "dst/" in joined
# ---------- 重传后复核 ----------
def test_verify_files_list_all_ok(tmp_path):
src = tmp_path / "s"; dst = tmp_path / "d"
src.mkdir(); dst.mkdir()
for f in ("a.flac", "b.lrc"):
(src / f).write_bytes(b"data" * 100)
(dst / f).write_bytes(b"data" * 100)
ok, fail = transfer.verify_files_list(str(src), str(dst), ["a.flac", "b.lrc"])
assert set(ok) == {"a.flac", "b.lrc"} and fail == []
def test_verify_files_list_detect_fail(tmp_path):
src = tmp_path / "s"; dst = tmp_path / "d"
src.mkdir(); dst.mkdir()
(src / "a.flac").write_bytes(b"good content")
(dst / "a.flac").write_bytes(b"bad content!!")
ok, fail = transfer.verify_files_list(str(src), str(dst), ["a.flac"])
assert fail == ["a.flac"] and ok == []
def test_verify_files_list_ultrafast_size_only(tmp_path):
"""> 同大小不同内容: ultrafast 判通过, slow 判失败"""
src = tmp_path / "s"; dst = tmp_path / "d"
src.mkdir(); dst.mkdir()
data = b"x" * 1000
(src / "a.flac").write_bytes(data)
(dst / "a.flac").write_bytes(b"y" * 1000)
ok, _ = transfer.verify_files_list(str(src), str(dst), ["a.flac"], level="ultrafast")
assert ok == ["a.flac"] # 只查大小
ok2, fail2 = transfer.verify_files_list(str(src), str(dst), ["a.flac"], level="slow")
assert fail2 == ["a.flac"] # md5 查出
def test_verify_files_list_missing_target(tmp_path):
src = tmp_path / "s"; dst = tmp_path / "d"
src.mkdir(); dst.mkdir()
(src / "a.flac").write_bytes(b"x")
ok, fail = transfer.verify_files_list(str(src), str(dst), ["a.flac"])
assert fail == ["a.flac"]