From 1f4080e75dea8bcbb1cc45c048091570a34ffd95 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 30 Aug 2026 22:37:22 +0200 Subject: [PATCH] fix: the release preview can be run, and can preview a group's real delta Two things it could not do, both found trying to preview this release. It read SELFTEST_GROUPS off os.environ before anything had loaded .env, so its own documented invocation refused every group unless the variable had been exported by hand. Fail-closed, so it never posted anywhere wrong -- it simply never posted at all. And it always rendered the delta from the *running* build, which is empty once the bump is committed. Three releases landing together are still one announcement to a group recorded three versions back, so --seen renders what that group will actually be shown rather than what the current build would add. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_017w1HZ3cZ7neL3rFdQ6VMBA --- tool/preview_release.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/tool/preview_release.py b/tool/preview_release.py index e6f41fa..3e6bccc 100755 --- a/tool/preview_release.py +++ b/tool/preview_release.py @@ -16,6 +16,7 @@ look at Signal, then bump for real. tool/preview_release.py testbot tool/preview_release.py testbot --ordinal 20 --print-only + tool/preview_release.py testbot --seen 0.1.5 # what a group behind will get Fail-closed the same way scripts/selftest.sh is: the group must be named in SELFTEST_GROUPS, so this cannot post a release that does not exist into the @@ -31,6 +32,7 @@ import sys from typing import Final import httpx +from dotenv import load_dotenv from signal_bot.announce import render from signal_bot.app import HTTP_TIMEOUT_SECONDS, USER_AGENT @@ -75,26 +77,35 @@ async def group_id_for(client: httpx.AsyncClient, groups_url: str, name: str) -> raise PreviewError(message) -def announcement_for(ordinal: int) -> str: - """Return the message a release at ``ordinal`` would post, for a group here. +def announcement_for(ordinal: int, seen: str | None = None) -> str: + """Return the message a release at ``ordinal`` would post to a group. - Keyed off the running version, because that is what every group is - recorded at, so this is the delta they would actually be shown. + Keyed off the running version by default, because that is what every + group is recorded at, so this is the delta they would actually be shown. + + ``seen`` overrides it with the version a group is actually recorded at, + which is what makes this usable *after* a bump: three releases land in + one commit series, every group is still at the version before them, and + the message they will get is the three-block one this renders -- not the + one-block delta from the build that is now running. """ if not 1 <= ordinal <= len(POPES): message = f"no pope with ordinal {ordinal}; the list has {len(POPES)}" raise PreviewError(message) - pending = since(load(), __version__) + floor = __version__ if seen is None else seen + pending = since(load(), floor) if not pending: message = ( - f"DOCS-changelog.md has nothing newer than {__version__}; " + f"DOCS-changelog.md has nothing newer than {floor}; " f"add the ## {version_for(ordinal)} section first" ) raise PreviewError(message) return render(pope_for(ordinal), pending) -async def send_preview(group: str, ordinal: int, *, print_only: bool) -> None: +async def send_preview( + group: str, ordinal: int, *, print_only: bool, seen: str | None = None +) -> None: """Render the announcement and, unless asked not to, post it.""" permitted = allowed_groups(os.environ) if group not in permitted: @@ -103,7 +114,7 @@ async def send_preview(group: str, ordinal: int, *, print_only: bool) -> None: raise PreviewError(message) pope = pope_for(ordinal) - text = announcement_for(ordinal) + text = announcement_for(ordinal, seen) sys.stdout.write(f"== {version_for(ordinal)} «{latin_name(pope)}» -> {group}\n") sys.stdout.write(f"== caption: {len(text)} chars, {len(text.encode())} bytes\n") sys.stdout.write(f"{text}\n") @@ -140,11 +151,22 @@ def main() -> int: default=None, help="papal ordinal to preview (default: the next one after this build)", ) + parser.add_argument( + "--seen", + default=None, + help="the version the group is recorded at (default: this build's), which is " + "how to preview a run of releases after they have already been bumped", + ) parser.add_argument("--print-only", action="store_true", help="render it, send nothing") args = parser.parse_args() + # Before the SELFTEST_GROUPS check, not after: load_config() would load + # the .env eventually, but the fail-closed gate reads os.environ first, + # so without this the documented invocation refused every group unless + # the variable had been exported into the shell by hand. + load_dotenv() ordinal = RELEASE_ORDINAL + 1 if args.ordinal is None else args.ordinal try: - asyncio.run(send_preview(args.group, ordinal, print_only=args.print_only)) + asyncio.run(send_preview(args.group, ordinal, print_only=args.print_only, seen=args.seen)) except (PreviewError, httpx.HTTPError) as error: sys.stderr.write(f"preview_release: {error}\n") return EXIT_REFUSED