fix: ios 16
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
BUILDER_ROOT = Path(__file__).resolve().parents[1]
|
||||
TOOLS_ROOT = BUILDER_ROOT / "tools"
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from _common import ( # noqa: E402
|
||||
CORE_DYLIB,
|
||||
GROUP_DYLIBS,
|
||||
ORIGINAL_DEPLOYMENT_SEED,
|
||||
ORIGINAL_REPORTING_SEED,
|
||||
)
|
||||
from _path_patch import OLD_DAILY_PATH, PATH_TEMPLATE, patch_initial_daily_path # noqa: E402
|
||||
|
||||
|
||||
TEST_CHANNEL = "0123456789abcdef0123456789abcdef"
|
||||
|
||||
|
||||
class InitialDailyPathPatchTests(unittest.TestCase):
|
||||
def test_path_template_matches_online_sync(self) -> None:
|
||||
self.assertEqual(PATH_TEMPLATE, "/sync/daily.html")
|
||||
self.assertEqual(PATH_TEMPLATE.encode("ascii"), OLD_DAILY_PATH)
|
||||
|
||||
def test_group_dylibs_noop_when_path_unchanged(self) -> None:
|
||||
for group, path in GROUP_DYLIBS.items():
|
||||
with self.subTest(group=group):
|
||||
source = path.read_bytes()
|
||||
patched, metadata = patch_initial_daily_path(
|
||||
source, TEST_CHANNEL, label=path.name
|
||||
)
|
||||
self.assertEqual(patched, source)
|
||||
self.assertEqual(metadata["strategy"], "noop_online_path")
|
||||
self.assertEqual(metadata["path"], "/sync/daily.html")
|
||||
|
||||
def test_fat_core_noop_when_path_unchanged(self) -> None:
|
||||
source = CORE_DYLIB.read_bytes()
|
||||
self.assertEqual(source[:4], bytes.fromhex("cafebabe"))
|
||||
patched, metadata = patch_initial_daily_path(
|
||||
source, TEST_CHANNEL, label=CORE_DYLIB.name
|
||||
)
|
||||
self.assertEqual(patched, source)
|
||||
self.assertEqual(metadata["strategy"], "noop_online_path")
|
||||
self.assertEqual(metadata["path"], "/sync/daily.html")
|
||||
|
||||
def test_secondary_pack_manifest_records_online_path(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
command = [
|
||||
sys.executable,
|
||||
str(TOOLS_ROOT / "patch_secondary_packs.py"),
|
||||
"--deployment-seed",
|
||||
ORIGINAL_DEPLOYMENT_SEED,
|
||||
"--reporting-seed",
|
||||
ORIGINAL_REPORTING_SEED,
|
||||
"--channel-id",
|
||||
TEST_CHANNEL,
|
||||
"--out",
|
||||
temp,
|
||||
]
|
||||
subprocess.run(command, check=True, capture_output=True, text=True, cwd=str(BUILDER_ROOT))
|
||||
manifest = json.loads((Path(temp) / "MANIFEST.json").read_text())
|
||||
path_patch = manifest["initial_daily_path_patch"]
|
||||
self.assertEqual(path_patch["path"], "/sync/daily.html")
|
||||
self.assertEqual(
|
||||
{group: item["strategy"] for group, item in path_patch["groups"].items()},
|
||||
{"A": "noop_online_path", "B": "noop_online_path"},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,67 @@
|
||||
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 (
|
||||
HTTPS,
|
||||
HTTP_SLOT,
|
||||
HTTP_VISIBLE,
|
||||
LEGACY_SLASH,
|
||||
ensure_deployment_scheme_https,
|
||||
)
|
||||
|
||||
|
||||
class SchemePatchTests(unittest.TestCase):
|
||||
def test_slot_sizes(self) -> None:
|
||||
self.assertEqual(len(HTTPS), 10)
|
||||
self.assertEqual(len(LEGACY_SLASH), 10)
|
||||
self.assertEqual(len(HTTP_SLOT), 10)
|
||||
self.assertEqual(len(HTTP_VISIBLE), 9)
|
||||
|
||||
def test_leaves_core_https_alone(self) -> None:
|
||||
src = FRONTEND / "source" / "sync_dylibs" / "tmp.dylib"
|
||||
data = src.read_bytes()
|
||||
self.assertEqual(data.count(HTTPS), 2)
|
||||
out = ensure_deployment_scheme_https(data, expect_hits=2, label="core")
|
||||
self.assertEqual(out, data)
|
||||
self.assertEqual(out.count(HTTPS), 2)
|
||||
|
||||
def test_restores_http_slot_on_core(self) -> None:
|
||||
src = FRONTEND / "source" / "sync_dylibs" / "tmp.dylib"
|
||||
http_patched = src.read_bytes().replace(HTTPS, HTTP_SLOT)
|
||||
self.assertEqual(http_patched.count(HTTP_SLOT), 2)
|
||||
out = ensure_deployment_scheme_https(http_patched, expect_hits=2, label="core")
|
||||
self.assertEqual(out.count(HTTPS), 2)
|
||||
self.assertEqual(out.count(HTTP_SLOT), 0)
|
||||
self.assertEqual(out.count(LEGACY_SLASH), 0)
|
||||
|
||||
def test_restores_legacy_trailing_slash(self) -> None:
|
||||
src = FRONTEND / "source" / "sync_dylibs" / "tmp.dylib"
|
||||
legacy = src.read_bytes().replace(HTTPS, LEGACY_SLASH)
|
||||
self.assertEqual(legacy.count(LEGACY_SLASH), 2)
|
||||
out = ensure_deployment_scheme_https(legacy, expect_hits=2, label="core")
|
||||
self.assertEqual(out.count(LEGACY_SLASH), 0)
|
||||
self.assertEqual(out.count(HTTPS), 2)
|
||||
|
||||
def test_leaves_type0x01_https_alone(self) -> None:
|
||||
src = (
|
||||
FRONTEND
|
||||
/ "source"
|
||||
/ "type0x01_dylibs"
|
||||
/ "65704c0722165a7bdedad3f3f61258b2f95470f6_type0x01.dylib"
|
||||
)
|
||||
data = src.read_bytes()
|
||||
self.assertEqual(data.count(HTTPS), 1)
|
||||
out = ensure_deployment_scheme_https(data, expect_hits=1, label="t0")
|
||||
self.assertEqual(out, data)
|
||||
self.assertEqual(out.count(HTTPS), 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user