feat(tests): implement historical publication fixture preparation and validation tests

This commit is contained in:
maksyuki committed 2026-10-15 02:57:30 +08:00
1 parent 01e33b6209
commit 655c5871ea
6 files changed
+196 -4

No files matched your search

+19
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import hashlib
import os
import re
import subprocess
import tempfile
import time
@@ -28,6 +29,24 @@ def git_output(repo: Path, *args: str) -> str:
).strip()
def ensure_git_commit(url: str, destination: Path, revision: str) -> None:
"""Fetch a locked historical object without switching the active checkout."""
if re.fullmatch(r"[0-9a-f]{40}", revision) is None:
raise ValueError("historical dependency requires a full Git commit revision")
destination = destination.resolve()
if not (destination / ".git").exists():
raise RuntimeError(f"prepare the current dependency checkout first: {destination}")
try:
git_output(destination, "cat-file", "-e", f"{revision}^{{commit}}")
except subprocess.CalledProcessError:
# No checkout/refspec: preserve HEAD, index, worktree and FETCH_HEAD.
run(("git", "fetch", "--no-tags", "--no-write-fetch-head", "--depth", "1",
url, revision), cwd=destination)
if git_output(destination, "rev-parse", f"{revision}^{{commit}}") != revision:
raise RuntimeError(f"historical dependency commit mismatch: {destination}: {revision}")
print(f"[dependency] historical object available: {destination.name}: {revision}")
def ensure_git_repo(
url: str,
destination: Path,