Files
metin-release-cli/tests/test_diff_remote.py
Jan Nedbal d2dd2c88b6 tests: cover phase 1 commands end to end
Pytest suite with a tiny_client fixture, an ephemeral Ed25519 keypair
fixture, and a threaded HTTPServer helper. Exercises cli dispatch,
inspect (including excluded-path handling), build-manifest and sign
against the real m2dev-client scripts, diff-remote via a local server,
and the full release publish composite against a local rsync target.
2026-04-14 18:59:50 +02:00

72 lines
2.1 KiB
Python

from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
import pytest
# Make fixtures importable.
sys.path.insert(0, str(Path(__file__).parent / "fixtures"))
from http_server import serve_dir # noqa: E402
from metin_release.commands import diff_remote # noqa: E402
from metin_release.workspace import Context # noqa: E402
def _write_manifest(path: Path, hashes: list[str]) -> None:
manifest = {
"version": "v1",
"created_at": "2026-04-14T00:00:00Z",
"launcher": {"path": "Metin2Launcher.exe", "sha256": hashes[0], "size": 1},
"files": [
{"path": f"file{i}", "sha256": h, "size": 1}
for i, h in enumerate(hashes[1:])
],
}
path.write_text(json.dumps(manifest, indent=2))
def test_diff_remote_reports_missing(tmp_path: Path):
hashes = [
"a" * 64,
"b" * 64,
"c" * 64,
]
manifest = tmp_path / "manifest.json"
_write_manifest(manifest, hashes)
# Remote serves only two of the three blobs.
remote = tmp_path / "remote"
remote.mkdir()
for h in hashes[:2]:
d = remote / "files" / h[:2]
d.mkdir(parents=True)
(d / h).write_bytes(b"x")
with serve_dir(remote) as base_url:
args = argparse.Namespace(manifest=manifest, base_url=base_url, timeout=5.0)
result = diff_remote.run(Context(), args)
stats = result.data["stats"]
assert stats["manifest_blob_count"] == 3
assert stats["missing_blob_count"] == 1
assert stats["missing_blobs"] == [hashes[2]]
def test_diff_remote_all_present(tmp_path: Path):
hashes = ["d" * 64]
manifest = tmp_path / "manifest.json"
_write_manifest(manifest, hashes)
remote = tmp_path / "remote"
(remote / "files" / "dd").mkdir(parents=True)
(remote / "files" / "dd" / hashes[0]).write_bytes(b"x")
with serve_dir(remote) as base_url:
args = argparse.Namespace(manifest=manifest, base_url=base_url, timeout=5.0)
result = diff_remote.run(Context(), args)
assert result.data["stats"]["missing_blob_count"] == 0