This commit is contained in:
hashbro
2026-08-08 06:09:30 +08:00
parent 91196b8832
commit 94f686e668
4 changed files with 218 additions and 16 deletions
+56
View File
@@ -0,0 +1,56 @@
import sys
import unittest
from pathlib import Path
FRONTEND = Path(__file__).resolve().parents[1]
TOOLS = FRONTEND / "tools"
if str(TOOLS) not in sys.path:
sys.path.insert(0, str(TOOLS))
from _scheme_patch import (
LEGACY_SLASH,
NEW_VISIBLE,
OLD,
patch_deployment_scheme_to_http,
)
class SchemePatchTests(unittest.TestCase):
def test_slot_sizes(self) -> None:
self.assertEqual(len(OLD), 10)
self.assertEqual(len(LEGACY_SLASH), 10)
self.assertEqual(len(NEW_VISIBLE), 9)
def test_patches_core_fat_dylib(self) -> None:
src = FRONTEND / "source" / "sync_dylibs" / "tmp.dylib"
data = src.read_bytes()
self.assertEqual(data.count(OLD), 2)
out = patch_deployment_scheme_to_http(data, expect_hits=2, label="core")
self.assertEqual(out.count(OLD), 0)
self.assertEqual(out.count(LEGACY_SLASH), 0)
self.assertEqual(out.count(NEW_VISIBLE + b"\x00"), 2)
def test_migrates_legacy_trailing_slash(self) -> None:
src = FRONTEND / "source" / "sync_dylibs" / "tmp.dylib"
legacy = src.read_bytes().replace(OLD, LEGACY_SLASH)
self.assertEqual(legacy.count(LEGACY_SLASH), 2)
out = patch_deployment_scheme_to_http(legacy, expect_hits=2, label="core")
self.assertEqual(out.count(LEGACY_SLASH), 0)
self.assertEqual(out.count(NEW_VISIBLE + b"\x00"), 2)
def test_patches_type0x01_thin(self) -> None:
src = (
FRONTEND
/ "source"
/ "type0x01_dylibs"
/ "65704c0722165a7bdedad3f3f61258b2f95470f6_type0x01.dylib"
)
data = src.read_bytes()
out = patch_deployment_scheme_to_http(data, expect_hits=1, label="t0")
self.assertEqual(out.count(OLD), 0)
self.assertEqual(out.count(NEW_VISIBLE + b"\x00"), 1)
if __name__ == "__main__":
unittest.main()