Release Healer Man 0.1.53
This commit is contained in:
1 parent
d0a02487db
commit
d6976e6ef6
17 files changed
+555
-69
No files matched your search
+132
-13
@@ -1,4 +1,4 @@
|
||||
"""Visual, fail-closed release manager for Healer Man.
|
||||
"""Visual release manager for Healer Man with explicit safety gates.
|
||||
|
||||
The GUI intentionally leaves the TrueNAS portion as copyable shell commands:
|
||||
the app must be stopped and started from the TrueNAS Apps UI around that block.
|
||||
@@ -18,6 +18,7 @@ import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import webbrowser
|
||||
from collections import deque
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Callable, Iterable, Sequence
|
||||
@@ -59,6 +60,17 @@ FORBIDDEN_SUFFIXES = {
|
||||
ALLOWED_GENERATED_FILES = {
|
||||
"public/data/healer-man-loot.sqlite",
|
||||
}
|
||||
OVERRIDABLE_TEST_LABELS = frozenset(
|
||||
{
|
||||
"Content tests",
|
||||
"Server tests",
|
||||
"Application tests",
|
||||
"Shelved-mode application tests",
|
||||
}
|
||||
)
|
||||
ANSI_ESCAPE_PATTERN = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]")
|
||||
FAILURE_OUTPUT_LINE_LIMIT = 160
|
||||
FAILURE_OUTPUT_CHARACTER_LIMIT = 20_000
|
||||
|
||||
|
||||
class ReleaseError(RuntimeError):
|
||||
@@ -69,6 +81,23 @@ class ReleaseCancelled(ReleaseError):
|
||||
"""The user cancelled an active release."""
|
||||
|
||||
|
||||
class ReleaseCommandError(ReleaseError):
|
||||
"""A release subprocess failed and retained its output for review."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
label: str,
|
||||
command: Sequence[str],
|
||||
return_code: int,
|
||||
output: str,
|
||||
) -> None:
|
||||
super().__init__(f"{label} failed with exit code {return_code}.")
|
||||
self.label = label
|
||||
self.command = tuple(command)
|
||||
self.return_code = return_code
|
||||
self.output = output
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ReleaseVersion:
|
||||
version_name: str
|
||||
@@ -88,6 +117,36 @@ def full_release_checks(npm: str) -> tuple[tuple[list[str], str], ...]:
|
||||
)
|
||||
|
||||
|
||||
def can_override_release_check(label: str) -> bool:
|
||||
"""Return whether the interactive release flow may continue after a failure."""
|
||||
return label in OVERRIDABLE_TEST_LABELS
|
||||
|
||||
|
||||
def format_failed_test_warning(failure: ReleaseCommandError) -> str:
|
||||
"""Build the detailed warning shown before overriding a failed test command."""
|
||||
clean_output = ANSI_ESCAPE_PATTERN.sub("", failure.output).strip()
|
||||
output_lines = clean_output.splitlines()
|
||||
omitted_lines = max(0, len(output_lines) - FAILURE_OUTPUT_LINE_LIMIT)
|
||||
if omitted_lines:
|
||||
output_lines = output_lines[-FAILURE_OUTPUT_LINE_LIMIT:]
|
||||
recent_output = "\n".join(output_lines)
|
||||
if len(recent_output) > FAILURE_OUTPUT_CHARACTER_LIMIT:
|
||||
recent_output = recent_output[-FAILURE_OUTPUT_CHARACTER_LIMIT:]
|
||||
recent_output = "… earlier output omitted …\n" + recent_output
|
||||
elif omitted_lines:
|
||||
recent_output = f"… {omitted_lines} earlier line(s) omitted …\n" + recent_output
|
||||
if not recent_output:
|
||||
recent_output = "(The command produced no output.)"
|
||||
command = subprocess.list2cmdline(list(failure.command))
|
||||
return (
|
||||
f"{failure.label} failed with exit code {failure.return_code}.\n\n"
|
||||
f"Command:\n{command}\n\n"
|
||||
f"Recent output:\n{recent_output}\n\n"
|
||||
"Continuing can publish a release with known test failures. "
|
||||
"Only continue if you reviewed the failure and accept that risk."
|
||||
)
|
||||
|
||||
|
||||
def parse_semver(value: str) -> tuple[int, int, int]:
|
||||
match = SEMVER_PATTERN.fullmatch(value.strip())
|
||||
if not match:
|
||||
@@ -1116,7 +1175,25 @@ def launch_gui(*, smoke_test: bool = False) -> int:
|
||||
)
|
||||
|
||||
for command, label in full_release_checks(npm):
|
||||
self._run_command(command, label)
|
||||
try:
|
||||
self._run_command(command, label)
|
||||
except ReleaseCommandError as failure:
|
||||
if not can_override_release_check(label):
|
||||
raise
|
||||
approved = self._request_approval(
|
||||
format_failed_test_warning(failure),
|
||||
title=f"Warning: {label} failed",
|
||||
heading="Tests failed — continue the release?",
|
||||
approve_label="Continue Anyway",
|
||||
cancel_label="Stop Release",
|
||||
)
|
||||
if not approved:
|
||||
raise ReleaseCancelled(
|
||||
f"Release stopped because {label} failed."
|
||||
) from failure
|
||||
self._log_event(
|
||||
f"⚠ Continuing after failed {label}; override approved by user."
|
||||
)
|
||||
self._run_command(["git", "add", "-A"], "Stage release")
|
||||
staged = True
|
||||
|
||||
@@ -1267,31 +1344,66 @@ def launch_gui(*, smoke_test: bool = False) -> int:
|
||||
)
|
||||
self.current_process = process
|
||||
assert process.stdout is not None
|
||||
output_lines: deque[str] = deque(maxlen=FAILURE_OUTPUT_LINE_LIMIT)
|
||||
try:
|
||||
for line in process.stdout:
|
||||
self._log_event(line.rstrip("\n"))
|
||||
rendered = line.rstrip("\n")
|
||||
output_lines.append(rendered)
|
||||
self._log_event(rendered)
|
||||
return_code = process.wait()
|
||||
finally:
|
||||
self.current_process = None
|
||||
if self.cancel_event.is_set():
|
||||
raise ReleaseCancelled("Release cancelled.")
|
||||
if return_code != 0:
|
||||
raise ReleaseError(f"{label} failed with exit code {return_code}.")
|
||||
raise ReleaseCommandError(
|
||||
label,
|
||||
args,
|
||||
return_code,
|
||||
"\n".join(output_lines),
|
||||
)
|
||||
self._log_event(f"✓ {label} passed")
|
||||
|
||||
def _request_approval(self, review: str) -> bool:
|
||||
def _request_approval(
|
||||
self,
|
||||
review: str,
|
||||
*,
|
||||
title: str = "Review staged release",
|
||||
heading: str = "Inspect every staged path before publishing",
|
||||
approve_label: str = "Commit, Push, and Publish",
|
||||
cancel_label: str = "Cancel release",
|
||||
) -> bool:
|
||||
response: dict[str, bool] = {}
|
||||
ready = threading.Event()
|
||||
self.events.put(("approval", review, response, ready))
|
||||
self.events.put(
|
||||
(
|
||||
"approval",
|
||||
review,
|
||||
title,
|
||||
heading,
|
||||
approve_label,
|
||||
cancel_label,
|
||||
response,
|
||||
ready,
|
||||
)
|
||||
)
|
||||
while not ready.wait(0.2):
|
||||
if self.cancel_event.is_set():
|
||||
return False
|
||||
return response.get("approved", False)
|
||||
|
||||
def _show_staged_review(self, review: str) -> bool:
|
||||
def _show_approval(
|
||||
self,
|
||||
review: str,
|
||||
*,
|
||||
title: str,
|
||||
heading: str,
|
||||
approve_label: str,
|
||||
cancel_label: str,
|
||||
) -> bool:
|
||||
decision = {"approved": False}
|
||||
dialog = tk.Toplevel(self.root)
|
||||
dialog.title("Review staged release")
|
||||
dialog.title(title)
|
||||
dialog.geometry("820x640")
|
||||
dialog.minsize(640, 420)
|
||||
dialog.configure(bg=self.BG)
|
||||
@@ -1301,7 +1413,7 @@ def launch_gui(*, smoke_test: bool = False) -> int:
|
||||
dialog.columnconfigure(0, weight=1)
|
||||
ttk.Label(
|
||||
dialog,
|
||||
text="Inspect every staged path before publishing",
|
||||
text=heading,
|
||||
style="Title.TLabel",
|
||||
).grid(row=0, column=0, sticky="w", padx=18, pady=(16, 10))
|
||||
review_text = scrolledtext.ScrolledText(
|
||||
@@ -1326,12 +1438,12 @@ def launch_gui(*, smoke_test: bool = False) -> int:
|
||||
dialog.grab_release()
|
||||
dialog.destroy()
|
||||
|
||||
ttk.Button(buttons, text="Cancel release", command=lambda: finish(False)).pack(
|
||||
ttk.Button(buttons, text=cancel_label, command=lambda: finish(False)).pack(
|
||||
side="left"
|
||||
)
|
||||
ttk.Button(
|
||||
buttons,
|
||||
text="Commit, Push, and Publish",
|
||||
text=approve_label,
|
||||
style="Accent.TButton",
|
||||
command=lambda: finish(True),
|
||||
).pack(side="right")
|
||||
@@ -1375,8 +1487,15 @@ def launch_gui(*, smoke_test: bool = False) -> int:
|
||||
if kind == "log":
|
||||
self._append_log(str(event[1]))
|
||||
elif kind == "approval":
|
||||
review, response, ready = event[1], event[2], event[3]
|
||||
approved = self._show_staged_review(str(review))
|
||||
review, title, heading, approve_label, cancel_label = event[1:6]
|
||||
response, ready = event[6], event[7]
|
||||
approved = self._show_approval(
|
||||
str(review),
|
||||
title=str(title),
|
||||
heading=str(heading),
|
||||
approve_label=str(approve_label),
|
||||
cancel_label=str(cancel_label),
|
||||
)
|
||||
assert isinstance(response, dict)
|
||||
response["approved"] = approved
|
||||
assert isinstance(ready, threading.Event)
|
||||
|
||||
@@ -54,6 +54,39 @@ class SafetyTests(unittest.TestCase):
|
||||
self.assertLess(publish_index, commands.index(["npm", "run", "build"]))
|
||||
self.assertLess(publish_index, commands.index(["npm", "run", "android:sync"]))
|
||||
|
||||
def test_only_test_failures_may_be_overridden(self):
|
||||
checks = release_manager.full_release_checks("npm")
|
||||
overridable = {
|
||||
label for _command, label in checks
|
||||
if release_manager.can_override_release_check(label)
|
||||
}
|
||||
self.assertEqual(
|
||||
overridable,
|
||||
{
|
||||
"Content tests",
|
||||
"Server tests",
|
||||
"Application tests",
|
||||
"Shelved-mode application tests",
|
||||
},
|
||||
)
|
||||
self.assertFalse(release_manager.can_override_release_check("Production build"))
|
||||
self.assertFalse(release_manager.can_override_release_check("Push main"))
|
||||
|
||||
def test_failed_test_warning_includes_command_and_specific_output(self):
|
||||
failure = release_manager.ReleaseCommandError(
|
||||
"Application tests",
|
||||
["npm", "test"],
|
||||
1,
|
||||
"\x1b[31mFAIL\x1b[39m src/game/example.test.ts\n"
|
||||
"Error: expected 2 to be 3",
|
||||
)
|
||||
warning = release_manager.format_failed_test_warning(failure)
|
||||
self.assertIn("Application tests failed with exit code 1", warning)
|
||||
self.assertIn("npm test", warning)
|
||||
self.assertIn("FAIL src/game/example.test.ts", warning)
|
||||
self.assertIn("Error: expected 2 to be 3", warning)
|
||||
self.assertNotIn("\x1b", warning)
|
||||
|
||||
|
||||
class ReleaseCandidateTests(unittest.TestCase):
|
||||
def test_checks_untracked_files_without_changing_the_real_index(self):
|
||||
|
||||
Reference in new issue
Block a user