This commit is contained in:
1 parent
16019ee649
commit
329b7756f4
17 files changed
+754
-85
No files matched your search
@@ -205,6 +205,71 @@ def test_forced_update_prefers_matching_delta_package(tmp_path):
|
||||
assert result.delta_path == launched[0]
|
||||
|
||||
|
||||
def test_forced_update_picks_matching_delta_from_list(tmp_path):
|
||||
from douyin.updater.force_update import UpdateSettings, perform_forced_update
|
||||
|
||||
import zipfile
|
||||
|
||||
file_payload = b"latest bytes"
|
||||
file_sha = hashlib.sha256(file_payload).hexdigest()
|
||||
delta_zip = tmp_path / "delta-source.zip"
|
||||
with zipfile.ZipFile(delta_zip, "w") as zf:
|
||||
zf.writestr(
|
||||
"manifest.json",
|
||||
json.dumps(
|
||||
{
|
||||
"schema": 1,
|
||||
"from_version": "3.3.7",
|
||||
"to_version": "3.3.9",
|
||||
"files": [{"path": "DouyinGuajiGUI.exe", "sha256": file_sha, "size": len(file_payload)}],
|
||||
"delete": [],
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
zf.writestr("files/DouyinGuajiGUI.exe", file_payload)
|
||||
delta_payload = delta_zip.read_bytes()
|
||||
delta_sha = hashlib.sha256(delta_payload).hexdigest()
|
||||
settings = UpdateSettings(enabled=True, manifest_url="https://example.test/update.json", download_dir=tmp_path)
|
||||
downloaded: list[str] = []
|
||||
|
||||
def download(url: str, dest: Path, timeout: float) -> None:
|
||||
downloaded.append(url)
|
||||
dest.write_bytes(delta_payload)
|
||||
|
||||
result = perform_forced_update(
|
||||
settings,
|
||||
current_version="3.3.7",
|
||||
fetch_manifest=lambda url, timeout: {
|
||||
"version": "3.3.9",
|
||||
"url": "https://example.test/full.exe",
|
||||
"sha256": "0" * 64,
|
||||
"delta": [
|
||||
{
|
||||
"from_version": "3.3.8",
|
||||
"to_version": "3.3.9",
|
||||
"url": "https://example.test/DouyinGuaji-3.3.8_to_3.3.9_delta.zip",
|
||||
"filename": "DouyinGuaji-3.3.8_to_3.3.9_delta.zip",
|
||||
"sha256": "1" * 64,
|
||||
},
|
||||
{
|
||||
"from_version": "3.3.7",
|
||||
"to_version": "3.3.9",
|
||||
"url": "https://example.test/DouyinGuaji-3.3.7_to_3.3.9_delta.zip",
|
||||
"filename": "DouyinGuaji-3.3.7_to_3.3.9_delta.zip",
|
||||
"sha256": delta_sha,
|
||||
},
|
||||
],
|
||||
},
|
||||
download_file=download,
|
||||
launch_installer=lambda cmd: pytest.fail("should not launch full installer"),
|
||||
launch_delta_update=lambda path, version: None,
|
||||
)
|
||||
|
||||
assert result.status == "delta_update_started"
|
||||
assert downloaded == ["https://example.test/DouyinGuaji-3.3.7_to_3.3.9_delta.zip"]
|
||||
|
||||
|
||||
def test_forced_update_falls_back_to_full_installer_when_delta_download_fails(tmp_path):
|
||||
from douyin.updater.force_update import UpdateSettings, perform_forced_update
|
||||
|
||||
|
||||
@@ -276,6 +276,38 @@ class TestAdbFunctions:
|
||||
result = list_adb_devices("/nonexistent/path/to/adb")
|
||||
assert isinstance(result, list)
|
||||
|
||||
def test_list_adb_devices_normalizes_mdns_serial_to_ip_port(self, monkeypatch):
|
||||
from gui.gui_core_pkg import adb as adb_mod
|
||||
|
||||
calls = []
|
||||
|
||||
class _Proc:
|
||||
returncode = 0
|
||||
|
||||
def __init__(self, stdout: str):
|
||||
self.stdout = stdout
|
||||
self.stderr = ""
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
calls.append(cmd)
|
||||
if cmd[1:3] == ["devices", "-l"]:
|
||||
return _Proc(
|
||||
"List of devices attached\n"
|
||||
"adb-ABC._adb-tls-connect._tcp device product:x model:x\n"
|
||||
)
|
||||
if cmd[1:3] == ["mdns", "services"]:
|
||||
return _Proc(
|
||||
"List of discovered mdns services\n"
|
||||
"adb-ABC _adb-tls-connect._tcp 192.168.10.105:46107\n"
|
||||
)
|
||||
return _Proc("")
|
||||
|
||||
monkeypatch.setattr(adb_mod.subprocess, "run", fake_run)
|
||||
|
||||
assert adb_mod.list_adb_devices("/adb") == ["192.168.10.105:46107"]
|
||||
assert calls[0][1:3] == ["devices", "-l"]
|
||||
assert calls[1][1:3] == ["mdns", "services"]
|
||||
|
||||
def test_resolve_adb_device_with_invalid_id_raises(self):
|
||||
# 指定了不存在的 device_id 应抛 RuntimeError
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
@@ -260,6 +260,43 @@ def test_admin_can_publish_delta_update_and_download_zip(tmp_path):
|
||||
assert download.content == delta_payload
|
||||
|
||||
|
||||
def test_admin_can_publish_multiple_cumulative_delta_updates(tmp_path):
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from license_server import api
|
||||
from license_server.core import LicenseService
|
||||
from tests.license_test_keys import TEST_PRIVATE_KEY_PEM
|
||||
|
||||
service = LicenseService(db_path=tmp_path / "license.db", private_key_pem=TEST_PRIVATE_KEY_PEM)
|
||||
client = TestClient(api.create_app(service=service, admin_token="secret"))
|
||||
client.post("/admin/login", data={"admin_token": "secret"}, follow_redirects=False)
|
||||
|
||||
client.post(
|
||||
"/admin/update/publish",
|
||||
cookies={api.ADMIN_CSRF_COOKIE: "csrf-token"},
|
||||
data={"csrf_token": "csrf-token", "version": "3.3.9", "notes": "", "force": "1"},
|
||||
files={"installer": ("DouyinGuaji-3.3.9-Setup.exe", b"installer", "application/octet-stream")},
|
||||
)
|
||||
for from_version, payload in [("3.3.7", b"delta37"), ("3.3.8", b"delta38")]:
|
||||
resp = client.post(
|
||||
"/admin/update/publish-delta",
|
||||
cookies={api.ADMIN_CSRF_COOKIE: "csrf-token"},
|
||||
data={"csrf_token": "csrf-token", "from_version": from_version, "to_version": "3.3.9"},
|
||||
files={"delta_file": (f"DouyinGuaji-{from_version}_to_3.3.9_delta.zip", payload, "application/zip")},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
manifest = client.get("/api/v1/update/manifest").json()
|
||||
deltas = manifest["delta"]
|
||||
|
||||
assert isinstance(deltas, list)
|
||||
assert [item["from_version"] for item in deltas] == ["3.3.7", "3.3.8"]
|
||||
assert deltas[0]["url"].endswith("/api/v1/update/download/DouyinGuaji-3.3.7_to_3.3.9_delta.zip")
|
||||
download = client.get("/api/v1/update/download/DouyinGuaji-3.3.7_to_3.3.9_delta.zip")
|
||||
assert download.status_code == 200
|
||||
assert download.content == b"delta37"
|
||||
|
||||
|
||||
def test_license_server_rejects_untrusted_host(tmp_path):
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@@ -8,8 +8,12 @@ from pathlib import Path
|
||||
|
||||
def _assert_bootstrap_before(path: str, *late_markers: str) -> None:
|
||||
text = Path(path).read_text(encoding="utf-8")
|
||||
import_marker = "from douyin.updater.bootstrap import run_startup_update_check_early"
|
||||
call_marker = "run_startup_update_check_early("
|
||||
import_marker = (
|
||||
"from douyin.updater.bootstrap import run_startup_update_check_early"
|
||||
if "run_startup_update_check_early(" in text
|
||||
else "from gui.components.update_progress import run_gui_startup_update_check_early"
|
||||
)
|
||||
call_marker = "run_startup_update_check_early(" if "run_startup_update_check_early(" in text else "run_gui_startup_update_check_early("
|
||||
assert import_marker in text
|
||||
assert call_marker in text
|
||||
call_index = text.index(call_marker)
|
||||
@@ -26,9 +30,10 @@ def _assert_packaging_uses_wrapper(wrapper_path: str, target_script: str) -> Non
|
||||
|
||||
def _assert_wrapper_imports_target_after_bootstrap(path: str, target_import: str) -> None:
|
||||
text = Path(path).read_text(encoding="utf-8")
|
||||
assert "run_startup_update_check_early(" in text
|
||||
call_marker = "run_startup_update_check_early(" if "run_startup_update_check_early(" in text else "run_gui_startup_update_check_early("
|
||||
assert call_marker in text
|
||||
assert target_import in text
|
||||
assert text.index("run_startup_update_check_early(") < text.index(target_import)
|
||||
assert text.index(call_marker) < text.index(target_import)
|
||||
|
||||
|
||||
def _assert_source_entry_bootstraps_under_main_guard(path: str, late_marker: str) -> None:
|
||||
|
||||
@@ -47,3 +47,21 @@ def test_update_delta_build_and_apply_round_trip(tmp_path):
|
||||
with zipfile.ZipFile(delta) as zf:
|
||||
package_manifest = json.loads(zf.read("manifest.json").decode("utf-8"))
|
||||
assert package_manifest["files"] == manifest["files"]
|
||||
|
||||
|
||||
def test_update_delta_build_many_creates_cumulative_delta_packages(tmp_path):
|
||||
from tools.update_delta import create_delta_zips
|
||||
|
||||
old37 = tmp_path / "DouyinGuaji-3.3.7"
|
||||
old38 = tmp_path / "DouyinGuaji-3.3.8"
|
||||
new = tmp_path / "DouyinGuaji-3.3.9"
|
||||
out = tmp_path / "delta"
|
||||
for root, text in [(old37, "37"), (old38, "38"), (new, "39")]:
|
||||
root.mkdir()
|
||||
(root / "app.txt").write_text(text, encoding="utf-8")
|
||||
|
||||
manifests = create_delta_zips([old37, old38], new, out, to_version="3.3.9")
|
||||
|
||||
assert [item["from_version"] for item in manifests] == ["3.3.7", "3.3.8"]
|
||||
assert (out / "DouyinGuaji-3.3.7_to_3.3.9_delta.zip").exists()
|
||||
assert (out / "DouyinGuaji-3.3.8_to_3.3.9_delta.zip").exists()
|
||||
@@ -441,6 +441,18 @@ class TestDiscoverAdbDevices:
|
||||
assert len(devs) == 1
|
||||
assert devs[0].target == "192.168.10.66:40075"
|
||||
|
||||
def test_connected_wifi_devices_are_scan_fallback(self):
|
||||
with patch.object(scan, "discover_mdns_targets", return_value=[]), \
|
||||
patch.object(scan, "discover_connected_wifi_targets", return_value=[("192.168.10.105", 46107)]), \
|
||||
patch.object(scan, "get_local_subnets", return_value=["192.168.10.0/30"]), \
|
||||
patch.object(scan, "scan_open_ports", return_value=[]), \
|
||||
patch.object(scan, "verify_adb_target", return_value=("connected", "already connected")), \
|
||||
patch.object(scan, "query_device_model", return_value="PEPM00"):
|
||||
devs = scan.discover_adb_devices("/adb")
|
||||
|
||||
assert len(devs) == 1
|
||||
assert devs[0].target == "192.168.10.105:46107"
|
||||
|
||||
def test_returns_devs_with_correct_ports(self):
|
||||
"""两个 (ip, port) 分别返回各自端口的 DiscoveredDevice。"""
|
||||
with patch.object(
|
||||
|
||||
Reference in new issue
Block a user