Answer stability round 1: 1 🔴, 1 🟡 (0 misread); stamp deploy-release's trace in UTC, end a stopped run's trace, drop redundant assertions, and the product-owner and prose fixes

This commit is contained in:
2026-11-27 14:14:28 +01:00
parent 3eb57d44c6
commit 74066a3134
13 changed files with 107 additions and 77 deletions
+45 -22
View File
@@ -1,5 +1,4 @@
import contextlib
import datetime
import io
import json
import os
@@ -485,9 +484,11 @@ class Cut(unittest.TestCase):
self.assert_cut(self.cut())
[kept] = self.traces()
lines = kept.splitlines()
self.assertRegex(lines[0], rf"^[0-9]{{4}}-[0-9]{{2}}-[0-9]{{2}}T[0-9:]{{8}}\S* deploy-release --cut {self.target} in {self.clone}$")
self.assertRegex(kept, r"(?m)^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:]{8}\S* pushed the tag v0\.2\.0$")
self.assertRegex(lines[0], rf"^[0-9]{{4}}-[0-9]{{2}}-[0-9]{{2}}T[0-9:]{{8}}Z deploy-release --cut {self.target} in {self.clone}$")
self.assertRegex(kept, r"(?m)^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:]{8}Z pushed the tag v0\.2\.0$")
self.assertIn("Done: v0.2.0 is cut and pushed", lines[-1])
[file] = (self.temp / "state" / "deploy-release").glob("*.log")
self.assertRegex(file.name, r"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}Z-[0-9]+\.log$")
def test_keeps_the_reason_a_cut_stopped_in_its_trace_and_a_rerun_writes_its_own(self):
self.assert_cut(self.cut())
@@ -496,6 +497,27 @@ class Cut(unittest.TestCase):
self.assertTrue(second.endswith(" release 0.3.0 still holds items in todo.md\n"), second)
self.assertNotIn("still holds items", first)
def test_refuses_a_release_whose_review_has_not_landed_naming_the_commit_title_that_counts(self):
self.assert_cut(self.cut())
self.git(self.clone, "pull", "-q", "--ff-only", "origin", "main")
self.commit({"CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Third.\n\n## 0.2.0\n\n- Second.\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO}, "Ship item 2")
self.git(self.clone, "push", "-q", "origin", "main")
ran = self.cut()
self.assertEqual(ran.returncode, 1)
self.assertIn("deploy-release: the release review of 0.3.0 hasn't landed: origin/main holds no commit titled `Release review of 0.3.0` after the newest tag. `chunk-preflight --help` says which commit counts.\n", ran.stderr)
def test_a_cut_stopped_by_ctrl_c_ends_its_trace_saying_so(self):
self.set_checks("pending")
process = subprocess.Popen([sys.executable, str(TOOL), "--cut", str(self.target)], cwd=self.clone, env=self.env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
self.addCleanup(process.kill)
deadline = time.monotonic() + 30
while not any("waiting for the checks" in kept for kept in self.traces()) and time.monotonic() < deadline:
time.sleep(0.05)
process.send_signal(signal.SIGINT)
self.assertNotEqual(process.wait(timeout=30), 0)
[kept] = self.traces()
self.assertRegex(kept.splitlines()[-1], r"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:]{8}Z stopped: KeyboardInterrupt\(\)$")
def test_reads_whether_the_next_releases_review_landed_beside_the_release(self):
self.assertEqual(cut.ready_release(str(self.clone), "origin/main"), cut.Ready((0, 2, 0), reviewed=True))
self.plan_patch()
@@ -782,8 +804,8 @@ class PatchCi(unittest.TestCase):
def test_a_ci_sh_that_could_not_run_or_was_stopped_tags_nothing_and_gives_the_runners_reason(self):
(self.worktree / "ci.sh").write_text("exit 0\n")
failed = patch.run_ci(self.worktree, "origin/main", lambda worktree: Failure("ci.sh still ran after 30 minutes and was stopped"))
self.assertEqual(failed, Failure("ci.sh still ran after 30 minutes and was stopped, so nothing is tagged. Rerun once that is fixed."))
failed = patch.run_ci(self.worktree, "origin/main", lambda worktree: Failure("ci.sh still ran after 30 minutes and was stopped; /state/run-ci.log holds its output"))
self.assertEqual(failed, Failure("ci.sh still ran after 30 minutes and was stopped; /state/run-ci.log holds its output. Nothing is tagged: rerun once ci.sh passes."))
def test_refuses_a_patch_without_ci_sh_before_running_anything(self):
self.assertEqual(patch.run_ci(self.worktree, "origin/main", lambda worktree: self.fail("ran")), Failure("the patch holds no ci.sh to test it with"))
@@ -925,14 +947,15 @@ class Trace(unittest.TestCase):
def setUp(self):
self.temp = pathlib.Path(tempfile.mkdtemp())
self.addCleanup(subprocess.run, ["rm", "-rf", str(self.temp)])
self.now = lambda: datetime.datetime(2026, 11, 27, 9, 30, 5)
# 2026-11-27T09:30:05Z, in seconds since the epoch.
self.now = lambda: 1795771805.0
def test_keeps_traces_under_the_state_folder_xdg_names_else_under_homes(self):
self.assertEqual(trace.trace_folder({"XDG_STATE_HOME": "/x/state"}, pathlib.Path("/home/u")), pathlib.Path("/x/state/deploy-release"))
self.assertEqual(trace.trace_folder({}, pathlib.Path("/home/u")), pathlib.Path("/home/u/.local/state/deploy-release"))
def test_names_a_run_by_its_start_and_its_process(self):
self.assertEqual(trace.run_name(self.now(), 4711), "2026-11-27T09-30-05-4711")
self.assertEqual(trace.run_name(self.now(), 4711), "2026-11-27T09-30-05Z-4711")
def test_starts_a_trace_with_the_command_then_appends_each_step_with_its_time_and_says_it(self):
file = trace.started(self.temp / "state" / "deploy-release", "run", "deploy-release --cut", self.now)
@@ -942,15 +965,15 @@ class Trace(unittest.TestCase):
say("pushed the tag v0.2.0")
say("merged pull request 3")
self.assertEqual(out.getvalue(), "deploy-release: pushed the tag v0.2.0\ndeploy-release: merged pull request 3\n")
self.assertEqual(file.read_text(), "2026-11-27T09:30:05 deploy-release --cut\n2026-11-27T09:30:05 pushed the tag v0.2.0\n2026-11-27T09:30:05 merged pull request 3\n")
self.assertEqual(file.read_text(), "2026-11-27T09:30:05Z deploy-release --cut\n2026-11-27T09:30:05Z pushed the tag v0.2.0\n2026-11-27T09:30:05Z merged pull request 3\n")
def test_starts_a_later_runs_trace_beside_the_earlier_one(self):
folder = self.temp / "state" / "deploy-release"
first = trace.started(folder, "first", "deploy-release --cut", self.now)
second = trace.started(folder, "second", "deploy-release --cut-patch a..b", self.now)
self.assertEqual((first, second), (folder / "first.log", folder / "second.log"))
self.assertEqual(second.read_text(), "2026-11-27T09:30:05 deploy-release --cut-patch a..b\n")
self.assertEqual(first.read_text(), "2026-11-27T09:30:05 deploy-release --cut\n")
self.assertEqual(second.read_text(), "2026-11-27T09:30:05Z deploy-release --cut-patch a..b\n")
self.assertEqual(first.read_text(), "2026-11-27T09:30:05Z deploy-release --cut\n")
def test_a_trace_that_cannot_be_started_is_a_failure_naming_the_file(self):
(self.temp / "state").write_text("a file where the folder goes\n")
@@ -975,9 +998,9 @@ class Rewritten(unittest.TestCase):
def test_replaces_a_files_text_and_hands_none_for_a_file_that_is_not_there(self):
file = self.temp / "CHANGELOG.md"
self.assertIsNone(cut.rewritten(file, "head CHANGELOG.md", lambda text: f"{text!r} new\n"))
self.assertIsNone(cut.rewritten(file, "head CHANGELOG.md", "Nothing is tagged.", lambda text: f"{text!r} new\n"))
self.assertEqual(file.read_text(), "None new\n")
self.assertIsNone(cut.rewritten(file, "head CHANGELOG.md", lambda text: text.upper()))
self.assertIsNone(cut.rewritten(file, "head CHANGELOG.md", "Nothing is tagged.", lambda text: text.upper()))
self.assertEqual(file.read_text(), "NONE NEW\n")
def test_a_file_that_cannot_be_read_or_written_is_a_failure_naming_the_step_and_the_file(self):
@@ -986,26 +1009,26 @@ class Rewritten(unittest.TestCase):
# A folder can't be read as a file, and a file in a folder that isn't there can't be written.
for file in (folder, self.temp / "gone" / "commit.patch"):
with self.subTest(file=file):
failed = cut.rewritten(file, "head CHANGELOG.md with ## 0.1.1, so nothing is tagged", lambda text: "new\n")
failed = cut.rewritten(file, "head CHANGELOG.md with ## 0.1.1", "Nothing is tagged.", lambda text: "new\n")
self.assertIsInstance(failed, Failure)
self.assertTrue(failed.reason.startswith("could not head CHANGELOG.md with ## 0.1.1, so nothing is tagged: "), failed.reason)
self.assertTrue(failed.reason.startswith("could not head CHANGELOG.md with ## 0.1.1: "), failed.reason)
self.assertEqual(failed.reason.count(str(file)), 1, failed.reason)
self.assertTrue(failed.reason.endswith(f"'{file}'"), failed.reason)
self.assertTrue(failed.reason.endswith(f"'{file}'. Nothing is tagged."), failed.reason)
def test_a_file_that_is_not_utf_8_is_a_failure_naming_the_step_and_the_file(self):
file = self.temp / "CHANGELOG.md"
file.write_bytes(b"caf\xe9\n")
failed = cut.rewritten(file, "head CHANGELOG.md", lambda text: "new\n")
failed = cut.rewritten(file, "head CHANGELOG.md", "Nothing is tagged.", lambda text: "new\n")
self.assertIsInstance(failed, Failure)
self.assertTrue(failed.reason.startswith("could not head CHANGELOG.md: "), failed.reason)
self.assertTrue(failed.reason.endswith(f" ({file})"), failed.reason)
self.assertTrue(failed.reason.endswith(f" ({file}). Nothing is tagged."), failed.reason)
self.assertEqual(failed.reason.count(str(file)), 1, failed.reason)
self.assertEqual(file.read_bytes(), b"caf\xe9\n")
def test_gives_the_rewrites_own_failure_and_leaves_the_file(self):
file = self.temp / "CHANGELOG.md"
file.write_text("old\n")
self.assertEqual(cut.rewritten(file, "x", lambda text: Failure("no heading")), Failure("no heading"))
self.assertEqual(cut.rewritten(file, "x", "y", lambda text: Failure("no heading")), Failure("no heading"))
self.assertEqual(file.read_text(), "old\n")
@@ -1020,17 +1043,17 @@ class PatchChangelog(unittest.TestCase):
def test_moves_the_patchs_entries_from_unreleased_to_a_section_after_it(self):
changelog = "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"
self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1", "origin/main"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
def test_leaves_an_older_section_entry_that_reads_the_same(self):
changelog = "# Changelog\n\n## Unreleased\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n"
self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n")
self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1", "origin/main"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n")
def test_puts_the_section_last_where_unreleased_is_the_last_section(self):
self.assertEqual(patch.moved_entries("# Changelog\n\n## Unreleased\n\n- Fixed.\n", ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n")
self.assertEqual(patch.moved_entries("# Changelog\n\n## Unreleased\n\n- Fixed.\n", ["- Fixed."], "0.1.1", "origin/main"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n")
def test_a_changelog_without_an_unreleased_heading_is_a_failure_that_names_it(self):
self.assertEqual(patch.moved_entries("# Changelog\n\n## 0.1.0\n\n- First.\n", ["- Fixed."], "0.1.1"), Failure("CHANGELOG.md has no ## Unreleased heading to move the entries of 0.1.1 from"))
self.assertEqual(patch.moved_entries("# Changelog\n\n## 0.1.0\n\n- First.\n", ["- Fixed."], "0.1.1", "origin/main"), Failure("CHANGELOG.md on origin/main has no ## Unreleased heading to move the entries of 0.1.1 from"))
if __name__ == "__main__":