gabriel / musehub public
test_release_tag.py python
429 lines 24.0 KB
Raw
sha256:ec55e4f4980249bb2c95c8c0615a40a9ded3e1eb1c181fe3de7cefbd8298ff0d feat(release): #275 safeguard — prove a signed tag can be m… Sonnet 5.5 patch 7 days ago
1 """musehub#275 -- the production release tag: the exact verified source revision, strictly verified, signed, itself
2 verified, never moved, and a failure is a failure.
3
4 Database-free and network-free. ``FakeMuse`` stands in for the Muse CLI and reproduces the three properties of rc20 that
5 make the old ``muse tag add <tag>`` step unsafe: ``tag add`` overwrites an existing tag, ``--sign`` without a signing
6 identity only warns and writes an unsigned tag (exit 0), and HEAD is wherever the checkout happens to be.
7 """
8 from __future__ import annotations
9
10 import json
11 import subprocess
12 from pathlib import Path
13 from typing import Any
14
15 import pytest
16
17 from deploy import release_tag
18 from deploy.release_safety import RECORD_SCHEMA, DirStorage, ReleaseSafetyError, release_source_revision
19 from deploy.release_tag import ReleaseTagError, apply, capability_check, check, main, preflight, tag_for
20
21 VERSION = "0.2.1rc21"
22 SHA = "c" * 64
23 REVISION = "sha256:" + "ab" * 32
24 HEAD = "sha256:" + "ee" * 32 # where the checkout is by the time the release is activated: not the release
25 OTHER = "sha256:" + "dd" * 32
26 OPERATOR = "r" # the operator's Muse repository, as the tests name it; every other -C target is a scratch directory
27 HUB = "https://localhost:1337"
28 SIGNER = "ed25519:" + "Zg" * 21 + "Z"
29
30
31 class FakeMuse:
32 """The slice of the rc20 CLI the tag step uses, with its real JSON shapes and exit codes.
33
34 The operator repository (``-C r``) and any scratch repository the capability probe creates (``-C <tmpdir>``) are separate
35 stores. A scratch repository signs only if the operator's hub URL was copied into it and an identity exists, as in rc20,
36 where ``get_signing_identity`` is looked up by ``[hub] url`` and ``tag add --sign`` otherwise warns and writes an unsigned
37 tag with exit 0."""
38
39 def __init__(
40 self,
41 *,
42 signed_commits: tuple[str, ...] = (REVISION,),
43 can_sign: bool = True,
44 hub_url: str | None = HUB,
45 probe_signature_valid: bool = True,
46 broken_step: str | None = None,
47 ) -> None:
48 self.commits = {REVISION: True, HEAD: True, OTHER: True}
49 self.signed_commits = set(signed_commits)
50 self.can_sign = can_sign
51 self.hub_url = hub_url
52 self.probe_signature_valid = probe_signature_valid
53 self.broken_step = broken_step
54 self.tags: dict[str, dict[str, Any]] = {}
55 self.calls: list[list[str]] = []
56 self.log: list[tuple[str, list[str]]] = [] # (the -C target, the arguments)
57 self.scratch: dict[str, dict[str, Any]] = {}
58 self.scratch_existed: dict[str, bool] = {} # the directory existed while it was being used
59
60 def __call__(self, argv: list[str], **_: Any) -> "subprocess.CompletedProcess[str]":
61 assert argv[:2] == ["muse", "-C"] and argv[-1] == "--json", argv
62 where, args = argv[2], argv[3:-1]
63 self.calls.append(args)
64 self.log.append((where, args))
65 if where != OPERATOR:
66 self.scratch_existed[where] = Path(where).is_dir()
67 return self._scratch(where, args)
68 if args == ["config", "get", "hub.url"]:
69 return self._out(0, {"key": "hub.url", "value": self.hub_url or ""})
70 if args[0] == "verify-commit":
71 rev = args[-1]
72 ok = rev in self.commits and rev in self.signed_commits
73 return self._out(0 if ok else 1, {"commit_id": rev, "valid": ok})
74 if args[:2] == ["tag", "read"]:
75 tag = self.tags.get(args[2])
76 if tag is None:
77 return self._out(1, {"error": "tag_not_found", "tag": args[2]})
78 return self._out(0, {"tag": args[2], "commit_id": tag["commit_id"], "signed": tag["signed"]})
79 if args[:2] == ["tag", "verify"]:
80 tag = self.tags.get(args[2])
81 if tag is None:
82 return self._out(1, {"error": "tag_not_found"})
83 valid = tag["signed"] and tag["valid"]
84 return self._out(0 if valid else 1, {"tag": args[2], "signed": tag["signed"], "valid": valid})
85 if args[:2] == ["tag", "add"]:
86 name, ref = args[2], args[3] if not args[3].startswith("--") else HEAD # no ref -> HEAD, as the old script did
87 sign = "--sign" in args
88 status = "already_tagged" if name in self.tags else "tagged"
89 self.tags[name] = {"commit_id": ref, "signed": sign and self.can_sign, "valid": True} # overwrites; fails open
90 return self._out(0, {"status": status, "tag": name, "commit_id": ref})
91 raise AssertionError(f"unexpected muse call: {args}")
92
93 def _scratch(self, where: str, args: list[str]) -> "subprocess.CompletedProcess[str]":
94 repo = self.scratch.setdefault(where, {"hub": None, "tags": {}})
95 if self.broken_step == args[0] or self.broken_step == " ".join(args[:2]):
96 return self._out(1, {"error": "boom"})
97 if args == ["init"]:
98 return self._out(0, {"status": "initialized"})
99 if args[:3] == ["config", "set", "hub.url"]:
100 repo["hub"] = args[3]
101 return self._out(0, {"key": "hub.url", "value": args[3]})
102 if args[0] == "commit":
103 assert "--allow-empty" in args and "--sign" not in args, "the probe commit is empty and unsigned: only the tag is probed"
104 return self._out(0, {"commit_id": "sha256:" + "01" * 32})
105 if args[:2] == ["tag", "add"]:
106 signed = "--sign" in args and self.can_sign and repo["hub"] is not None # fails open: unsigned, exit 0
107 repo["tags"][args[2]] = {"signed": signed, "valid": signed and self.probe_signature_valid}
108 return self._out(0, {"status": "tagged", "tag": args[2], "signed": signed, "signer_public_key": SIGNER if signed else ""})
109 if args[:2] == ["tag", "verify"]:
110 tag = repo["tags"].get(args[2])
111 if tag is None:
112 return self._out(1, {"error": "tag_not_found"})
113 valid = tag["signed"] and tag["valid"]
114 return self._out(0 if valid else 1, {"tag": args[2], "signed": tag["signed"], "valid": valid, "signer_public_key": SIGNER if tag["signed"] else ""})
115 raise AssertionError(f"unexpected scratch call: {args}")
116
117 @staticmethod
118 def _out(code: int, data: dict[str, Any]) -> "subprocess.CompletedProcess[str]":
119 return subprocess.CompletedProcess([], code, json.dumps(data), "")
120
121 def mutations(self) -> list[list[str]]:
122 return [c for c in self.calls if c[:2] == ["tag", "add"]]
123
124 def operator_calls(self) -> list[list[str]]:
125 return [a for w, a in self.log if w == OPERATOR]
126
127 def scratch_calls(self) -> list[tuple[str, list[str]]]:
128 return [(w, a) for w, a in self.log if w != OPERATOR]
129
130
131 @pytest.fixture
132 def storage(tmp_path: Path) -> DirStorage:
133 return record(DirStorage(tmp_path / "bucket"))
134
135
136 def record(storage: DirStorage, *, version: str = VERSION, sha: str = SHA, revision: Any = REVISION) -> DirStorage:
137 body = {"schema": RECORD_SCHEMA, "version": version, "sha256": sha, "source_revision": revision}
138 storage.put_new(f"muse-{version}.release.json", json.dumps(body).encode())
139 return storage
140
141
142 class TestTagForVersion:
143 @pytest.mark.parametrize(("version", "tag"), [("0.2.1rc21", "v0.2.1-rc21"), ("0.2.1", "v0.2.1")])
144 def test_the_tag_comes_from_the_version(self, version: str, tag: str) -> None:
145 assert tag_for(version) == tag
146
147 @pytest.mark.parametrize("version", ["0.2.1.dev1", "0.2.0.dev3", "0.2.1.post1", "0.2.1+local", "1!0.2.1", "nonsense"])
148 def test_a_version_with_no_tag_form_is_refused_and_never_becomes_a_stable_tag(self, version: str) -> None:
149 with pytest.raises(ReleaseTagError):
150 tag_for(version)
151
152
153 class TestReleaseRecord:
154 def test_the_source_revision_is_what_the_record_names(self, storage: DirStorage) -> None:
155 assert release_source_revision(storage, VERSION, SHA) == REVISION
156
157 def test_no_record_means_not_a_published_release(self, tmp_path: Path) -> None:
158 with pytest.raises(ReleaseSafetyError, match="no valid release record"):
159 release_source_revision(DirStorage(tmp_path / "empty"), VERSION, SHA)
160
161 def test_a_record_for_other_bytes_is_refused(self, storage: DirStorage) -> None:
162 with pytest.raises(ReleaseSafetyError, match="not the requested"):
163 release_source_revision(storage, VERSION, "d" * 64)
164
165 @pytest.mark.parametrize("bad", [None, "", "abc123", "sha256:short", "SHA256:" + "AB" * 32, 7])
166 def test_a_malformed_source_revision_is_refused(self, tmp_path: Path, bad: Any) -> None:
167 with pytest.raises(release_tag.ProvenanceError):
168 release_source_revision(record(DirStorage(tmp_path / "b"), revision=bad), VERSION, SHA)
169
170
171 class TestCheck:
172 def test_a_verified_revision_and_an_absent_tag_is_ready(self, storage: DirStorage) -> None:
173 muse = FakeMuse()
174 out = check(storage, VERSION, SHA, Path("r"), runner=muse)
175 assert out == {"version": VERSION, "tag": "v0.2.1-rc21", "source_revision": REVISION, "tag_present": False}
176 assert ["verify-commit", "--strict", REVISION] in muse.calls and muse.mutations() == []
177
178 @pytest.mark.parametrize("why", ["unsigned", "missing"])
179 def test_the_source_revision_must_pass_strict_verification(self, storage: DirStorage, why: str) -> None:
180 muse = FakeMuse(signed_commits=())
181 if why == "missing":
182 del muse.commits[REVISION]
183 with pytest.raises(ReleaseTagError, match="strictly verified"):
184 check(storage, VERSION, SHA, Path("r"), runner=muse)
185 assert muse.mutations() == []
186
187 def test_an_existing_tag_at_the_revision_that_verifies_is_ready(self, storage: DirStorage) -> None:
188 muse = FakeMuse()
189 muse.tags["v0.2.1-rc21"] = {"commit_id": REVISION, "signed": True, "valid": True}
190 assert check(storage, VERSION, SHA, Path("r"), runner=muse)["tag_present"] is True
191
192 def test_an_existing_tag_at_another_commit_is_a_conflict_and_is_never_moved(self, storage: DirStorage) -> None:
193 muse = FakeMuse()
194 muse.tags["v0.2.1-rc21"] = {"commit_id": OTHER, "signed": True, "valid": True}
195 with pytest.raises(ReleaseTagError, match="refusing to move it"):
196 check(storage, VERSION, SHA, Path("r"), runner=muse)
197 assert muse.mutations() == [] and muse.tags["v0.2.1-rc21"]["commit_id"] == OTHER
198
199 @pytest.mark.parametrize("state", [{"signed": False, "valid": True}, {"signed": True, "valid": False}])
200 def test_an_existing_tag_at_the_revision_without_a_valid_signature_is_refused(self, storage: DirStorage, state: dict[str, bool]) -> None:
201 muse = FakeMuse()
202 muse.tags["v0.2.1-rc21"] = {"commit_id": REVISION, **state}
203 with pytest.raises(ReleaseTagError, match="valid signature"):
204 check(storage, VERSION, SHA, Path("r"), runner=muse)
205
206 def test_a_missing_record_is_refused_before_muse_is_consulted(self, tmp_path: Path) -> None:
207 muse = FakeMuse()
208 with pytest.raises(ReleaseTagError, match="release record"):
209 check(DirStorage(tmp_path / "empty"), VERSION, SHA, Path("r"), runner=muse)
210 assert muse.calls == []
211
212 def test_a_cli_that_cannot_run_is_an_error(self, storage: DirStorage) -> None:
213 def broken(argv: list[str], **_: Any) -> Any:
214 raise FileNotFoundError("muse")
215
216 with pytest.raises(ReleaseTagError, match="could not run"):
217 check(storage, VERSION, SHA, Path("r"), runner=broken)
218
219
220 class TestApply:
221 def test_the_tag_goes_on_the_recorded_revision_not_on_head_and_is_signed(self, storage: DirStorage) -> None:
222 muse = FakeMuse()
223 out = apply(storage, VERSION, SHA, Path("r"), runner=muse)
224 assert out["created"] is True and out["tag_present"] is True
225 assert muse.mutations() == [["tag", "add", "v0.2.1-rc21", REVISION, "--sign", "--message", f"release {VERSION}"]]
226 assert muse.tags["v0.2.1-rc21"] == {"commit_id": REVISION, "signed": True, "valid": True} and HEAD not in str(muse.tags)
227
228 def test_the_resulting_tag_is_verified(self, storage: DirStorage) -> None:
229 muse = FakeMuse()
230 apply(storage, VERSION, SHA, Path("r"), runner=muse)
231 assert ["tag", "verify", "v0.2.1-rc21"] in muse.calls
232
233 def test_running_it_again_creates_nothing(self, storage: DirStorage) -> None:
234 muse = FakeMuse()
235 apply(storage, VERSION, SHA, Path("r"), runner=muse)
236 out = apply(storage, VERSION, SHA, Path("r"), runner=muse)
237 assert out["created"] is False and len(muse.mutations()) == 1
238
239 def test_signing_that_fails_open_is_caught_by_verification_and_nothing_is_deleted(self, storage: DirStorage) -> None:
240 """rc20 `tag add --sign` with no signing identity warns and writes an UNSIGNED tag (exit 0)."""
241 muse = FakeMuse(can_sign=False)
242 with pytest.raises(ReleaseTagError, match="valid signature"):
243 apply(storage, VERSION, SHA, Path("r"), runner=muse)
244 assert muse.tags["v0.2.1-rc21"]["signed"] is False, "left in place for the operator; no delete or force"
245 assert not [c for c in muse.calls if c[:2] == ["tag", "delete"]]
246
247 def test_a_tag_that_appeared_after_the_check_is_not_reported_as_created(self, storage: DirStorage, monkeypatch: pytest.MonkeyPatch) -> None:
248 """If the tag raced into existence, `tag add` answers already_tagged (and overwrote): that is an error, not success."""
249 muse = FakeMuse()
250 muse.tags["v0.2.1-rc21"] = {"commit_id": REVISION, "signed": True, "valid": True}
251 stale = {"version": VERSION, "tag": "v0.2.1-rc21", "source_revision": REVISION, "tag_present": False}
252 monkeypatch.setattr(release_tag, "check", lambda *a, **k: stale)
253 with pytest.raises(ReleaseTagError, match="did not report a new tag"):
254 apply(storage, VERSION, SHA, Path("r"), runner=muse)
255
256 def test_a_conflicting_tag_stops_before_any_write(self, storage: DirStorage) -> None:
257 muse = FakeMuse()
258 muse.tags["v0.2.1-rc21"] = {"commit_id": HEAD, "signed": True, "valid": True}
259 with pytest.raises(ReleaseTagError, match="refusing to move it"):
260 apply(storage, VERSION, SHA, Path("r"), runner=muse)
261 assert muse.mutations() == [] and muse.tags["v0.2.1-rc21"]["commit_id"] == HEAD
262
263 def test_a_dev_version_is_never_tagged_at_all(self, tmp_path: Path) -> None:
264 muse = FakeMuse()
265 st = record(DirStorage(tmp_path / "b"), version="0.2.1.dev1")
266 with pytest.raises(ReleaseTagError, match="no release tag form"):
267 apply(st, "0.2.1.dev1", SHA, Path("r"), runner=muse)
268 assert muse.calls == []
269
270
271 class TestCapabilityCheck:
272 """Before production activation: can this operator actually make a signed tag? Answered with a real signed tag in a
273 throwaway repository, so the operator's repository (and every ref in it) is only read."""
274
275 def test_a_signed_probe_tag_is_made_and_verified_in_a_scratch_repo(self) -> None:
276 muse = FakeMuse()
277 out = capability_check(Path(OPERATOR), runner=muse, environ={})
278 assert out == {"signing_capable": True, "signer_public_key": SIGNER}
279 scratch = muse.scratch_calls()
280 assert any(a[:2] == ["tag", "add"] and "--sign" in a for _, a in scratch)
281 assert any(a[:2] == ["tag", "verify"] for _, a in scratch)
282
283 def test_the_operators_repository_is_only_read(self) -> None:
284 muse = FakeMuse()
285 capability_check(Path(OPERATOR), runner=muse, environ={})
286 assert muse.operator_calls() == [["config", "get", "hub.url"]], "no init, config set, commit or tag add against the real repo"
287 assert len({w for w, _ in muse.scratch_calls()}) == 1 and OPERATOR not in {w for w, _ in muse.scratch_calls()}
288
289 def test_the_probe_signs_as_the_operator_would_so_it_uses_the_operators_hub_url(self) -> None:
290 """rc20 looks the signing identity up by [hub] url; a scratch repo without it would sign nothing (or the wrong thing)."""
291 muse = FakeMuse(hub_url="https://hub.example.test")
292 capability_check(Path(OPERATOR), runner=muse, environ={})
293 (where,) = {w for w, _ in muse.scratch_calls()}
294 assert muse.scratch[where]["hub"] == "https://hub.example.test"
295
296 def test_the_scratch_repository_exists_while_used_and_is_removed_afterwards(self) -> None:
297 muse = FakeMuse()
298 capability_check(Path(OPERATOR), runner=muse, environ={})
299 (where,) = {w for w, _ in muse.scratch_calls()}
300 assert muse.scratch_existed[where] is True and not Path(where).exists()
301
302 def test_the_scratch_repository_is_removed_when_the_probe_is_refused(self) -> None:
303 muse = FakeMuse(can_sign=False)
304 with pytest.raises(ReleaseTagError):
305 capability_check(Path(OPERATOR), runner=muse, environ={})
306 (where,) = {w for w, _ in muse.scratch_calls()}
307 assert not Path(where).exists()
308
309 def test_no_signing_identity_is_refused_even_though_the_cli_exits_zero(self) -> None:
310 """rc20: `tag add --sign` with no identity warns, writes an UNSIGNED tag and exits 0. That must not pass."""
311 muse = FakeMuse(can_sign=False)
312 with pytest.raises(ReleaseTagError, match="no usable signing identity"):
313 capability_check(Path(OPERATOR), runner=muse, environ={})
314 assert muse.operator_calls() == [["config", "get", "hub.url"]]
315
316 def test_a_probe_signature_that_does_not_verify_is_refused(self) -> None:
317 with pytest.raises(ReleaseTagError, match="no usable signing identity"):
318 capability_check(Path(OPERATOR), runner=FakeMuse(probe_signature_valid=False), environ={})
319
320 @pytest.mark.parametrize("hub", [None, ""])
321 def test_an_operator_repository_without_a_hub_url_is_refused(self, hub: str | None) -> None:
322 muse = FakeMuse(hub_url=hub)
323 with pytest.raises(ReleaseTagError, match="hub url"):
324 capability_check(Path(OPERATOR), runner=muse, environ={})
325 assert muse.scratch_calls() == []
326
327 def test_a_one_shot_key_descriptor_is_refused_before_anything_runs(self) -> None:
328 """MUSE_AGENT_KEY_FD is read once and closed: a probe would spend the key the real tag needs after activation."""
329 muse = FakeMuse()
330 with pytest.raises(ReleaseTagError, match="MUSE_AGENT_KEY_FD"):
331 capability_check(Path(OPERATOR), runner=muse, environ={"MUSE_AGENT_KEY_FD": "9"})
332 assert muse.calls == []
333
334 @pytest.mark.parametrize("step", ["init", "config set", "commit", "tag add"])
335 def test_a_probe_step_that_fails_is_refused(self, step: str) -> None:
336 with pytest.raises(ReleaseTagError, match="capability probe"):
337 capability_check(Path(OPERATOR), runner=FakeMuse(broken_step=step), environ={})
338
339 def test_the_probe_tag_is_never_a_release_tag_name(self) -> None:
340 muse = FakeMuse()
341 capability_check(Path(OPERATOR), runner=muse, environ={})
342 names = {a[2] for _, a in muse.scratch_calls() if a[:2] == ["tag", "add"]}
343 assert names == {release_tag.PROBE_TAG} and not names & {"v0.2.1-rc21", "v0.2.1"}
344
345
346 class TestPreflight:
347 """Everything required before the pointer moves: the four requirements, in an order that does no work for a refusal."""
348
349 def test_all_four_requirements_hold(self, storage: DirStorage) -> None:
350 muse = FakeMuse()
351 out = preflight(storage, VERSION, SHA, Path(OPERATOR), runner=muse, environ={})
352 assert out == {
353 "version": VERSION, "tag": "v0.2.1-rc21", "source_revision": REVISION, "tag_present": False,
354 "signing_capable": True, "signer_public_key": SIGNER,
355 }
356 assert ["verify-commit", "--strict", REVISION] in muse.calls
357 assert ["tag", "add", "v0.2.1-rc21"] not in [c[:3] for c in muse.operator_calls()] and muse.operator_calls().count(["tag", "read", "v0.2.1-rc21"]) == 1
358
359 def test_the_operators_repository_gets_no_write_of_any_kind(self, storage: DirStorage) -> None:
360 muse = FakeMuse()
361 preflight(storage, VERSION, SHA, Path(OPERATOR), runner=muse, environ={})
362 writes = {"init", "commit", "add", "delete", "branch", "switch", "push"}
363 assert not [a for a in muse.operator_calls() if a[0] in writes or a[:2] in (["tag", "add"], ["config", "set"])]
364 assert muse.tags == {}
365
366 def test_a_conflicting_existing_tag_is_refused_and_nothing_is_probed(self, storage: DirStorage) -> None:
367 muse = FakeMuse()
368 muse.tags["v0.2.1-rc21"] = {"commit_id": OTHER, "signed": True, "valid": True}
369 with pytest.raises(ReleaseTagError, match="refusing to move it"):
370 preflight(storage, VERSION, SHA, Path(OPERATOR), runner=muse, environ={})
371 assert muse.scratch_calls() == [] and muse.tags["v0.2.1-rc21"]["commit_id"] == OTHER
372
373 def test_an_unverified_source_revision_is_refused_and_nothing_is_probed(self, storage: DirStorage) -> None:
374 muse = FakeMuse(signed_commits=())
375 with pytest.raises(ReleaseTagError, match="strictly verified"):
376 preflight(storage, VERSION, SHA, Path(OPERATOR), runner=muse, environ={})
377 assert muse.scratch_calls() == []
378
379 def test_a_missing_release_record_is_refused_before_muse_is_consulted(self, tmp_path: Path) -> None:
380 muse = FakeMuse()
381 with pytest.raises(ReleaseTagError, match="release record"):
382 preflight(DirStorage(tmp_path / "empty"), VERSION, SHA, Path(OPERATOR), runner=muse, environ={})
383 assert muse.calls == []
384
385 def test_no_usable_signing_identity_refuses_the_release_before_it_goes_live(self, storage: DirStorage) -> None:
386 """Without this the identity-less run would fail only AFTER the release is live (the #275 decision-4 gap)."""
387 muse = FakeMuse(can_sign=False)
388 with pytest.raises(ReleaseTagError, match="no usable signing identity"):
389 preflight(storage, VERSION, SHA, Path(OPERATOR), runner=muse, environ={})
390 assert muse.mutations() == [["tag", "add", release_tag.PROBE_TAG, "--sign", "--message", "capability probe"]]
391 assert muse.tags == {}, "and nothing was written to the operator's repository"
392
393 def test_an_existing_verified_tag_at_the_revision_still_passes_and_is_reported(self, storage: DirStorage) -> None:
394 muse = FakeMuse()
395 muse.tags["v0.2.1-rc21"] = {"commit_id": REVISION, "signed": True, "valid": True}
396 assert preflight(storage, VERSION, SHA, Path(OPERATOR), runner=muse, environ={})["tag_present"] is True
397
398
399 class TestApplyDoesNotProbe:
400 def test_apply_leaves_the_probe_to_the_preflight(self, storage: DirStorage) -> None:
401 """After activation the real tag is the capability test; a second probe would only add a way to fail late."""
402 muse = FakeMuse()
403 apply(storage, VERSION, SHA, Path(OPERATOR), runner=muse)
404 assert muse.scratch_calls() == []
405
406
407 class TestCommandLine:
408 def test_preflight_success_prints_the_result_and_exits_zero(self, storage: DirStorage, capsys: pytest.CaptureFixture[str]) -> None:
409 argv = ["--dir", str(storage.root), "preflight", "--version", VERSION, "--sha256", SHA, "--muse-repo", OPERATOR]
410 assert main(argv, runner=FakeMuse()) == 0
411 out = json.loads(capsys.readouterr().out)
412 assert out["signing_capable"] is True and out["tag"] == "v0.2.1-rc21" and out["source_revision"] == REVISION
413
414 def test_preflight_without_an_identity_exits_one_with_nothing_on_stdout(self, storage: DirStorage, capsys: pytest.CaptureFixture[str]) -> None:
415 argv = ["--dir", str(storage.root), "preflight", "--version", VERSION, "--sha256", SHA, "--muse-repo", OPERATOR]
416 assert main(argv, runner=FakeMuse(can_sign=False)) == 1
417 out = capsys.readouterr()
418 assert out.out == "" and "no usable signing identity" in out.err
419
420 def test_success_prints_the_result_and_exits_zero(self, storage: DirStorage, capsys: pytest.CaptureFixture[str]) -> None:
421 assert main(["--dir", str(storage.root), "apply", "--version", VERSION, "--sha256", SHA, "--muse-repo", "r"], runner=FakeMuse()) == 0
422 assert json.loads(capsys.readouterr().out)["tag"] == "v0.2.1-rc21"
423
424 def test_a_refusal_prints_nothing_on_stdout_and_exits_one(self, storage: DirStorage, capsys: pytest.CaptureFixture[str]) -> None:
425 muse = FakeMuse()
426 muse.tags["v0.2.1-rc21"] = {"commit_id": OTHER, "signed": True, "valid": True}
427 assert main(["--dir", str(storage.root), "check", "--version", VERSION, "--sha256", SHA, "--muse-repo", "r"], runner=muse) == 1
428 out = capsys.readouterr()
429 assert out.out == "" and "refusing to move it" in out.err
File History 2 commits
sha256:ec55e4f4980249bb2c95c8c0615a40a9ded3e1eb1c181fe3de7cefbd8298ff0d feat(release): #275 safeguard — prove a signed tag can be m… Sonnet 5.5 patch 7 days ago
sha256:0ddcb29475cfe996169320691ffb2c5705e510191a4a944487df867959d81b36 fix(release): #275 tag the verified source revision, signed… Sonnet 5.5 minor ⚠ 7 days ago