v31.1-roots.1 · Commit 8: [PATCH 08/17] chore(roots): integrate v31 identity and maintenance tooling
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..6f9fe3ecb1d5742cffb477370d4f91a4af7cd3be
Download original patch · Release notes
Diff rows 1–94 of 94. 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,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
(repository / "crlf.svg").write_bytes(b"<svg>\r\ncore\r\n</svg>\r\n")
|
| 31 |
+
workflow = repository / ".github/workflows/ci.yml"
|
| 32 |
+
workflow.parent.mkdir(parents=True)
|
| 33 |
+
workflow.write_text("name: Core CI\n", encoding="utf-8")
|
| 34 |
+
self.git(repository, "add", "source", "crlf.svg", ".github")
|
| 35 |
+
self.git(repository, "commit", "-m", "core", capture_output=True)
|
| 36 |
+
core_commit = self.git(repository, "rev-parse", "HEAD", capture_output=True, text=True).stdout.strip()
|
| 37 |
+
self.git(repository, "tag", "-a", "v29.4", "-m", "Core v29.4")
|
| 38 |
+
self.git(repository, "switch", "-c", "roots/29.4", capture_output=True)
|
| 39 |
+
(repository / "source").write_text("roots\n", encoding="utf-8")
|
| 40 |
+
(repository / "crlf.svg").write_bytes(b"<svg>\r\nroots\r\n</svg>\r\n")
|
| 41 |
+
self.git(repository, "commit", "-am", "roots text", capture_output=True)
|
| 42 |
+
(repository / "binary.dat").write_bytes(bytes(range(256)))
|
| 43 |
+
self.git(repository, "add", "binary.dat")
|
| 44 |
+
self.git(repository, "commit", "-m", "roots binary", capture_output=True)
|
| 45 |
+
workflow.write_text("name: Roots CI\n", encoding="utf-8")
|
| 46 |
+
self.git(repository, "commit", "-am", "ci: use Roots tests", capture_output=True)
|
| 47 |
+
self.git(repository, "tag", "-a", RELEASE_TAG, "-m", RELEASE_TAG)
|
| 48 |
+
self.git(repository, "checkout", "--detach", RELEASE_TAG, capture_output=True)
|
| 49 |
+
return repository, core_commit
|
| 50 |
+
|
| 51 |
+
def test_generates_product_series_and_omits_github_automation(self):
|
| 52 |
+
repository, core_commit = self.make_release_repository()
|
| 53 |
+
output = repository / "artifacts/bitcoin-roots-29.4-roots.1.patch"
|
| 54 |
+
environment = {**os.environ, "RELEASE_CANONICAL_REF": "refs/heads/roots/29.4"}
|
| 55 |
+
subprocess.run([SCRIPT, RELEASE_TAG, output], cwd=repository, env=environment, check=True)
|
| 56 |
+
|
| 57 |
+
patch = output.read_text(encoding="utf-8")
|
| 58 |
+
self.assertIn("GIT binary patch", patch)
|
| 59 |
+
self.assertIn(f"base-commit: {core_commit}", patch)
|
| 60 |
+
self.assertGreaterEqual(patch.count("Subject: [PATCH"), 2)
|
| 61 |
+
self.assertNotIn("diff --git a/.github/", patch)
|
| 62 |
+
self.assertNotIn("ci: use Roots tests", patch)
|
| 63 |
+
|
| 64 |
+
with tempfile.TemporaryDirectory() as replay_dir:
|
| 65 |
+
replay = Path(replay_dir) / "repository"
|
| 66 |
+
subprocess.run(["git", "clone", "--quiet", repository, replay], check=True)
|
| 67 |
+
self.git(replay, "checkout", "--detach", core_commit, capture_output=True)
|
| 68 |
+
self.git(
|
| 69 |
+
replay, "-c", "user.name=Patch replay", "-c", "user.email=replay@example.invalid",
|
| 70 |
+
"am", "-3", "--keep-cr", output, capture_output=True,
|
| 71 |
+
)
|
| 72 |
+
self.git(
|
| 73 |
+
replay, "diff", "--quiet", RELEASE_TAG, "HEAD", "--",
|
| 74 |
+
".", ":(exclude).github/**",
|
| 75 |
+
)
|
| 76 |
+
self.git(replay, "diff", "--quiet", core_commit, "HEAD", "--", ".github")
|
| 77 |
+
self.assertEqual((replay / ".github/workflows/ci.yml").read_text(encoding="utf-8"), "name: Core CI\n")
|
| 78 |
+
self.assertEqual((replay / "crlf.svg").read_bytes(), b"<svg>\r\nroots\r\n</svg>\r\n")
|
| 79 |
+
|
| 80 |
+
def test_rejects_noncanonical_release(self):
|
| 81 |
+
repository, _ = self.make_release_repository()
|
| 82 |
+
self.git(repository, "branch", "--force", "roots/29.4", "v29.4")
|
| 83 |
+
output = repository / "release.patch"
|
| 84 |
+
result = subprocess.run(
|
| 85 |
+
[SCRIPT, RELEASE_TAG, output], cwd=repository,
|
| 86 |
+
env={**os.environ, "RELEASE_CANONICAL_REF": "refs/heads/roots/29.4"},
|
| 87 |
+
capture_output=True, text=True,
|
| 88 |
+
)
|
| 89 |
+
self.assertNotEqual(result.returncode, 0)
|
| 90 |
+
self.assertFalse(output.exists())
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
if __name__ == "__main__":
|
| 94 |
+
unittest.main()
|