73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def write_manifest(path: Path, package_url: str, version: str = "1.1.0") -> None:
|
|
path.write_text(
|
|
json.dumps(
|
|
{
|
|
"product": "yiyezhqiu-refactored",
|
|
"version": version,
|
|
"channel": "stable",
|
|
"min_supported_version": "1.0.0",
|
|
"package_url": package_url,
|
|
"sha256": "a" * 64,
|
|
"release_notes": "模块迁移",
|
|
"published_at": "2026-09-11",
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
def test_check_returns_available_for_file_manifest(tmp_path: Path) -> None:
|
|
from dx_productivity.update.service import UpdateService
|
|
|
|
manifest_path = tmp_path / "manifest.json"
|
|
write_manifest(manifest_path, "file:///release.zip")
|
|
|
|
result = UpdateService().check(manifest_path.as_uri(), "1.0.0")
|
|
|
|
assert result.status == "available"
|
|
assert result.manifest is not None
|
|
assert str(result.manifest.version) == "1.1.0"
|
|
|
|
|
|
def test_check_returns_up_to_date_for_equal_version(tmp_path: Path) -> None:
|
|
from dx_productivity.update.service import UpdateService
|
|
|
|
manifest_path = tmp_path / "manifest.json"
|
|
write_manifest(manifest_path, "file:///release.zip", version="1.0.0")
|
|
|
|
result = UpdateService().check(manifest_path.as_uri(), "1.0.0")
|
|
|
|
assert result.status == "up-to-date"
|
|
|
|
|
|
def test_check_returns_error_for_offline_or_malformed_source(tmp_path: Path) -> None:
|
|
from dx_productivity.update.service import UpdateService
|
|
|
|
malformed = tmp_path / "bad.json"
|
|
malformed.write_text("not-json", encoding="utf-8")
|
|
result = UpdateService().check(malformed.as_uri(), "1.0.0")
|
|
|
|
assert result.status == "error"
|
|
assert result.manifest is None
|
|
assert result.message
|
|
|
|
|
|
def test_check_filters_development_manifest_from_stable_channel(tmp_path: Path) -> None:
|
|
from dx_productivity.update.service import UpdateService
|
|
|
|
manifest_path = tmp_path / "dev.json"
|
|
write_manifest(manifest_path, "file:///release.zip")
|
|
data = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
data["channel"] = "development"
|
|
manifest_path.write_text(json.dumps(data), encoding="utf-8")
|
|
|
|
result = UpdateService().check(manifest_path.as_uri(), "1.0.0", channel="stable")
|
|
|
|
assert result.status == "incompatible"
|
|
assert "channel" in result.message
|