From ba71cc1a41aab897aa491e8b366fbaef1f50aeed Mon Sep 17 00:00:00 2001 From: AxelNoun <150222552+AxelNoun@users.noreply.github.com> Date: Tue, 6 Oct 2026 16:08:20 +0200 Subject: [PATCH] Fetch full history in CI and skip frozen-commit tests without it. actions/checkout fetched depth 1, so test_osf_deposit could not read 0a5e794 and CI has failed since 85ff1e9. A shallow clone or release archive now reports the three tests as skipped instead of failed. No frozen prereg-v1 file or threshold is touched. --- .github/workflows/tests.yml | 4 ++++ tests/test_osf_deposit.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e69ec7f..e68e98b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,10 @@ jobs: python-version: ["3.11", "3.12"] steps: - uses: actions/checkout@v4 + with: + # tests/test_osf_deposit.py reads the frozen prereg-v1 commit + # (0a5e794) from git; the default depth-1 checkout lacks it. + fetch-depth: 0 - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} diff --git a/tests/test_osf_deposit.py b/tests/test_osf_deposit.py index b3adc8c..9504019 100644 --- a/tests/test_osf_deposit.py +++ b/tests/test_osf_deposit.py @@ -1,5 +1,7 @@ """Frozen prereg hashes must match git at 0a5e794. No network.""" +import subprocess + from tpl.io.osf_deposit import ( FROZEN_COMMIT, FROZEN_SHA256, @@ -10,6 +12,38 @@ import pytest +def _frozen_commit_available(): + """True if FROZEN_COMMIT is in the git repository of the current directory. + + osf_deposit reads the frozen files with `git show` from the current + directory, so the check runs there too. It is false in a shallow clone + (CI checkout at depth 1), in a release zip/tarball (no .git), or when git + is not installed. + """ + try: + subprocess.run( + ["git", "cat-file", "-e", f"{FROZEN_COMMIT}^{{commit}}"], + check=True, + capture_output=True, + ) + except (OSError, subprocess.CalledProcessError): + return False + return True + + +# Skip rather than fail: the hashes cannot be checked without the commit, and a +# missing commit says nothing about whether they match. Run from a full clone +# (`git fetch --unshallow` in a shallow one) to exercise these tests. +requires_frozen_commit = pytest.mark.skipif( + not _frozen_commit_available(), + reason=( + f"frozen commit {FROZEN_COMMIT[:7]} (prereg-v1) is not in this checkout " + "(shallow clone or release archive); clone the full history to run" + ), +) + + +@requires_frozen_commit def test_snapshot_matches_pinned_hashes(): snap = snapshot() assert set(snap) == set(FROZEN_SHA256) @@ -18,6 +52,7 @@ def test_snapshot_matches_pinned_hashes(): assert rec["nbytes"] == len(rec["bytes"]) +@requires_frozen_commit def test_manifest_points_at_the_freeze_not_head(): man = manifest() assert man["commit"] == FROZEN_COMMIT @@ -30,6 +65,7 @@ def test_upload_refuses_an_empty_token(): upload("") +@requires_frozen_commit def test_write_bundle_matches_git(tmp_path): from tpl.io.osf_deposit import write_bundle