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