feat: support delta update packages

This commit is contained in:
Your Name committed 2026-06-28 00:32:01 +08:00
1 parent 7234bf0cac
commit e315aaf80b
8 files changed
+625 -6

No files matched your search

+63
View File
@@ -104,6 +104,69 @@ def test_forced_update_downloads_verifies_and_launches_installer(tmp_path):
assert any(arg.startswith("/LOG=") for arg in launched[0])
def test_forced_update_prefers_matching_delta_package(tmp_path):
from douyin.updater.force_update import UpdateSettings, perform_forced_update
import zipfile
file_payload = b"new exe 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.3",
"to_version": "3.3.4",
"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] = []
launched: list[Path] = []
def fetch_manifest(url: str, timeout: float) -> dict:
return {
"version": "3.3.4",
"url": "https://example.test/full.exe",
"sha256": "0" * 64,
"delta": {
"from_version": "3.3.3",
"to_version": "3.3.4",
"url": "https://example.test/DouyinGuaji-3.3.3_to_3.3.4_delta.zip",
"filename": "DouyinGuaji-3.3.3_to_3.3.4_delta.zip",
"sha256": delta_sha,
},
}
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.3",
fetch_manifest=fetch_manifest,
download_file=download,
launch_installer=lambda cmd: pytest.fail("should not launch full installer"),
launch_delta_update=lambda path, version: launched.append(path),
)
assert result.status == "delta_update_started"
assert result.exit_required is True
assert downloaded == ["https://example.test/DouyinGuaji-3.3.3_to_3.3.4_delta.zip"]
assert launched == [tmp_path / "DouyinGuaji-3.3.3_to_3.3.4_delta.zip"]
assert result.delta_path == launched[0]
def test_forced_update_accepts_signed_manifest(tmp_path, monkeypatch):
from douyin.updater import force_update
from douyin.updater.force_update import UpdateSettings, perform_forced_update