1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
import json
import os
import subprocess
import tempfile
import unittest
from unittest import mock
from pathlib import Path
import scripts.conventional_commits as conventional_commits
import scripts.preview as preview
class PreviewNotesTests(unittest.TestCase):
def test_notes_contain_only_build_and_comparison_link(self):
self.assertEqual(
preview.build_notes("previous-sha", "current-sha", "2026-09-16-abcdef123456", "herdrdev/herdr"),
"Preview build 2026-09-16-abcdef123456\n\n"
"[View changes](https://github.com/herdrdev/herdr/compare/previous-sha...current-sha)\n",
)
def test_build_manifest_archives_assets_with_selected_source_generation(self):
with tempfile.TemporaryDirectory() as tmp:
output = Path(tmp) / "preview.json"
notes = "Preview notes\n"
content = preview.build_manifest(
output=output,
repo="herdrdev/herdr",
tag="preview-2026-06-02-abcdef123456",
build_id="2026-06-02-abcdef123456",
commit="abcdef1234567890",
built_at="2026-06-02T03:00:00Z",
base_version="0.6.6",
protocol=12,
notes=notes,
shas={
"linux-x86_64": "deadbeef",
"windows-x86_64": "a" * 64,
},
retain=30,
endpoint_generation=77,
)
data = json.loads(content)
self.assertEqual(data["channel"], "preview")
self.assertEqual(data["build_id"], "2026-06-02-abcdef123456")
self.assertEqual(
data["endpoint_generation"],
77,
)
self.assertEqual(
data["assets"]["linux-x86_64"]["sha256"],
"deadbeef",
)
self.assertEqual(
data["assets"]["windows-x86_64"]["url"],
"https://github.com/herdrdev/herdr/releases/download/preview-2026-06-02-abcdef123456/herdr-windows-x86_64.zip",
)
self.assertEqual(
data["assets"]["windows-x86_64"]["sha256"],
"a" * 64,
)
self.assertEqual(data["assets"]["windows-x86_64"]["format"], "zip")
self.assertIn("2026-06-02-abcdef123456", data["builds"])
self.assertEqual(
data["builds"]["2026-06-02-abcdef123456"]["endpoint_generation"],
77,
)
def test_windows_preview_asset_requires_sha256(self):
with tempfile.TemporaryDirectory() as tmp:
with self.assertRaisesRegex(ValueError, "windows-x86_64 requires"):
preview.build_manifest(
output=Path(tmp) / "preview.json",
repo="herdrdev/herdr",
tag="preview-test",
build_id="test",
commit="abcdef",
built_at="2026-06-02T03:00:00Z",
base_version="0.6.6",
protocol=12,
notes="test",
shas={},
retain=1,
)
def test_preview_range_base_advances_to_stable_tag(self):
with (
mock.patch.object(preview, "latest_stable_tag", return_value="v0.7.0"),
mock.patch.object(preview, "git_is_ancestor", return_value=True),
):
self.assertEqual(
preview.preview_range_base("previous-preview", "release"),
"v0.7.0",
)
def test_preview_range_base_keeps_previous_preview_for_unreleased_work(self):
def is_ancestor(ancestor: str, descendant: str) -> bool:
return (ancestor, descendant) in {
("v0.7.0", "new-feature"),
("previous-preview", "new-feature"),
}
with (
mock.patch.object(preview, "latest_stable_tag", return_value="v0.7.0"),
mock.patch.object(preview, "git_is_ancestor", side_effect=is_ancestor),
):
self.assertEqual(
preview.preview_range_base("previous-preview", "new-feature"),
"previous-preview",
)
def test_hotfix_preview_uses_stable_base_instead_of_newer_master_preview(self):
with (
mock.patch.object(preview, "latest_stable_tag", return_value="v0.7.0"),
mock.patch.object(preview, "git_is_ancestor", return_value=False),
):
self.assertEqual(preview.preview_range_base("newer-master", "hotfix"), "v0.7.0")
def test_post_stable_history_bases_range_on_stable_tag(self):
with tempfile.TemporaryDirectory() as tmp:
repo = Path(tmp)
def git(*args: str) -> str:
return subprocess.check_output(
["git", *args],
cwd=repo,
text=True,
stderr=subprocess.DEVNULL,
).strip()
git("init")
git("config", "user.email", "test@example.com")
git("config", "user.name", "Test User")
marker = repo / "marker.txt"
marker.write_text("preview\n", encoding="utf-8")
git("add", "marker.txt")
git("commit", "-m", "feat: previous preview")
previous_preview = git("rev-parse", "HEAD")
marker.write_text("release\n", encoding="utf-8")
git("commit", "-am", "release: v0.7.0")
release = git("rev-parse", "HEAD")
git("tag", "v0.7.0")
original_cwd = os.getcwd()
try:
os.chdir(repo)
self.assertEqual(
preview.preview_range_base(previous_preview, release),
"v0.7.0",
)
finally:
os.chdir(original_cwd)
class ConventionalCommitTests(unittest.TestCase):
def test_valid_subjects_allow_scopes_and_bang(self):
self.assertTrue(conventional_commits.valid_subject("fix(update): handle preview"))
self.assertTrue(conventional_commits.valid_subject("feat!: change config"))
self.assertFalse(conventional_commits.valid_subject("update preview channel"))
def test_commit_message_subject_skips_comments(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "COMMIT_EDITMSG"
path.write_text(
"\n# Please enter the commit message\n\nfix(update): switch channel\n",
encoding="utf-8",
)
self.assertEqual(
conventional_commits.commit_message_subject(path),
"fix(update): switch channel",
)
if __name__ == "__main__":
unittest.main()
|