11import ntpath
2+ import posixpath
23from dataclasses import dataclass , field
34from pathlib import Path
45from types import SimpleNamespace
@@ -126,6 +127,10 @@ def extractall(self, target_dir: str) -> None: # noqa: ARG002
126127 return None
127128
128129
130+ def _build_fake_archive_entries (archive_root : str ) -> list [str ]:
131+ return [archive_root , posixpath .join (archive_root , ".dockerignore" )]
132+
133+
129134def _build_fake_httpx_module (state : _FakeAsyncClientState ) -> SimpleNamespace :
130135 class _FakeAsyncClient :
131136 def __init__ (self , ** kwargs ):
@@ -420,13 +425,22 @@ async def test_download_file_logs_url_and_target_path_on_failure(
420425 assert any (str (target_path ) in message for message in log_messages )
421426
422427
428+ @pytest .mark .parametrize (
429+ "archive_root" ,
430+ [
431+ "AstrBotDevs-AstrBot-39386ee/" ,
432+ "AstrBotDevs-AstrBot-39386ee" ,
433+ "owner-repo-branch/subdir/" ,
434+ "." ,
435+ ],
436+ )
423437def test_repo_unzip_file_normalizes_windows_extended_length_paths (
424438 monkeypatch : pytest .MonkeyPatch ,
439+ archive_root : str ,
425440) -> None :
426441 import astrbot .core .zip_updator as zip_updator_module
427442
428443 target_dir = r"\\?\\C:\\Users\\admin\\AppData\\Local\\AstrBot\\backend\\app"
429- archive_root = "AstrBotDevs-AstrBot-39386ee/"
430444 expected_root = ntpath .normpath (ntpath .join (target_dir , archive_root ))
431445 expected_file = ntpath .normpath (
432446 ntpath .join (target_dir , archive_root , ".dockerignore" )
@@ -447,9 +461,7 @@ def fake_listdir(path: str) -> list[str]:
447461 monkeypatch .setattr (
448462 zip_updator_module .zipfile ,
449463 "ZipFile" ,
450- lambda path , mode : _FakeZipArchive (
451- [archive_root , f"{ archive_root } .dockerignore" ]
452- ),
464+ lambda path , mode : _FakeZipArchive (_build_fake_archive_entries (archive_root )),
453465 )
454466 monkeypatch .setattr (zip_updator_module .logger , "debug" , lambda message : None )
455467 monkeypatch .setattr (zip_updator_module .logger , "warning" , lambda message : None )
@@ -504,9 +516,7 @@ def fake_listdir(path: str) -> list[str]:
504516 monkeypatch .setattr (
505517 plugin_updator_module .zipfile ,
506518 "ZipFile" ,
507- lambda path , mode : _FakeZipArchive (
508- [archive_root , f"{ archive_root } .dockerignore" ]
509- ),
519+ lambda path , mode : _FakeZipArchive (_build_fake_archive_entries (archive_root )),
510520 )
511521 monkeypatch .setattr (plugin_updator_module .logger , "info" , lambda message : None )
512522 monkeypatch .setattr (plugin_updator_module .logger , "warning" , lambda message : None )
0 commit comments