v29.4-roots.2 · Commit 7: [PATCH 07/21] release: establish Roots maintenance and assurance
ci/test/test_create_patch_series.py
Before: /dev/null · After: ci/test/test_create_patch_series.py
File metadata
new file mode 100755 index 0000000000000000000000000000000000000000..3c9bac53b7094e56532fa69720c4cee83192afcc
Download original patch · Release notes
Diff rows 1–81 of 81. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
ci/test/test_create_patch_series.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# Copyright (c) 2026-present The Bitcoin Roots developers
|
| 3 |
+
# Distributed under the MIT software license, see the accompanying
|
| 4 |
+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import subprocess
|
| 9 |
+
import tempfile
|
| 10 |
+
import unittest
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[2]
|
| 14 |
+
SCRIPT = ROOT / "ci/release/create-patch-series.sh"
|
| 15 |
+
RELEASE_TAG = "v29.4-roots.1"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class CreatePatchSeriesTest(unittest.TestCase):
|
| 19 |
+
def git(self, repository, *args, **kwargs):
|
| 20 |
+
return subprocess.run(["git", "-C", repository, *args], check=True, **kwargs)
|
| 21 |
+
|
| 22 |
+
def make_release_repository(self):
|
| 23 |
+
temporary_dir = tempfile.TemporaryDirectory()
|
| 24 |
+
repository = Path(temporary_dir.name)
|
| 25 |
+
self.addCleanup(temporary_dir.cleanup)
|
| 26 |
+
subprocess.run(["git", "init", "--initial-branch=main", repository], check=True, capture_output=True)
|
| 27 |
+
self.git(repository, "config", "user.name", "Patch test")
|
| 28 |
+
self.git(repository, "config", "user.email", "patch@example.invalid")
|
| 29 |
+
(repository / "source").write_text("core\n", encoding="utf-8")
|
| 30 |
+
self.git(repository, "add", "source")
|
| 31 |
+
self.git(repository, "commit", "-m", "core", capture_output=True)
|
| 32 |
+
core_commit = self.git(repository, "rev-parse", "HEAD", capture_output=True, text=True).stdout.strip()
|
| 33 |
+
self.git(repository, "tag", "-a", "v29.4", "-m", "Core v29.4")
|
| 34 |
+
self.git(repository, "switch", "-c", "roots/29.4", capture_output=True)
|
| 35 |
+
(repository / "source").write_text("roots\n", encoding="utf-8")
|
| 36 |
+
self.git(repository, "commit", "-am", "roots text", capture_output=True)
|
| 37 |
+
(repository / "binary.dat").write_bytes(bytes(range(256)))
|
| 38 |
+
self.git(repository, "add", "binary.dat")
|
| 39 |
+
self.git(repository, "commit", "-m", "roots binary", capture_output=True)
|
| 40 |
+
self.git(repository, "tag", "-a", RELEASE_TAG, "-m", RELEASE_TAG)
|
| 41 |
+
release_tree = self.git(repository, "rev-parse", "HEAD^{tree}", capture_output=True, text=True).stdout.strip()
|
| 42 |
+
self.git(repository, "checkout", "--detach", RELEASE_TAG, capture_output=True)
|
| 43 |
+
return repository, core_commit, release_tree
|
| 44 |
+
|
| 45 |
+
def test_generates_binary_full_index_series_that_replays_identically(self):
|
| 46 |
+
repository, core_commit, release_tree = self.make_release_repository()
|
| 47 |
+
output = repository / "artifacts/bitcoin-roots-29.4-roots.1.patch"
|
| 48 |
+
environment = {**os.environ, "RELEASE_CANONICAL_REF": "refs/heads/roots/29.4"}
|
| 49 |
+
subprocess.run([SCRIPT, RELEASE_TAG, output], cwd=repository, env=environment, check=True)
|
| 50 |
+
|
| 51 |
+
patch = output.read_text(encoding="utf-8")
|
| 52 |
+
self.assertIn("GIT binary patch", patch)
|
| 53 |
+
self.assertIn(f"base-commit: {core_commit}", patch)
|
| 54 |
+
self.assertGreaterEqual(patch.count("Subject: [PATCH"), 2)
|
| 55 |
+
|
| 56 |
+
with tempfile.TemporaryDirectory() as replay_dir:
|
| 57 |
+
replay = Path(replay_dir) / "repository"
|
| 58 |
+
subprocess.run(["git", "clone", "--quiet", repository, replay], check=True)
|
| 59 |
+
self.git(replay, "checkout", "--detach", core_commit, capture_output=True)
|
| 60 |
+
self.git(
|
| 61 |
+
replay, "-c", "user.name=Patch replay", "-c", "user.email=replay@example.invalid",
|
| 62 |
+
"am", "-3", output, capture_output=True,
|
| 63 |
+
)
|
| 64 |
+
replayed_tree = self.git(replay, "rev-parse", "HEAD^{tree}", capture_output=True, text=True).stdout.strip()
|
| 65 |
+
self.assertEqual(replayed_tree, release_tree)
|
| 66 |
+
|
| 67 |
+
def test_rejects_noncanonical_release(self):
|
| 68 |
+
repository, _, _ = self.make_release_repository()
|
| 69 |
+
self.git(repository, "branch", "--force", "roots/29.4", "v29.4")
|
| 70 |
+
output = repository / "release.patch"
|
| 71 |
+
result = subprocess.run(
|
| 72 |
+
[SCRIPT, RELEASE_TAG, output], cwd=repository,
|
| 73 |
+
env={**os.environ, "RELEASE_CANONICAL_REF": "refs/heads/roots/29.4"},
|
| 74 |
+
capture_output=True, text=True,
|
| 75 |
+
)
|
| 76 |
+
self.assertNotEqual(result.returncode, 0)
|
| 77 |
+
self.assertFalse(output.exists())
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
unittest.main()
|