From 38f1013af48cd2251d18b4f6b87cdc74aa1c1f18 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Thu, 3 Dec 2026 10:51:56 +0100 Subject: [PATCH] Compare with main: duplicate share-image tags still fail Co-Authored-By: Claude Opus 5.5 --- scripts/rebrand/compare_builds.py | 15 +++++++++------ scripts/tests/test_rebrand_checks.py | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/rebrand/compare_builds.py b/scripts/rebrand/compare_builds.py index bd0cd24d9c9..5b4b7f33344 100644 --- a/scripts/rebrand/compare_builds.py +++ b/scripts/rebrand/compare_builds.py @@ -155,12 +155,15 @@ def _equivalent_descriptions(before, after): def _without_default_images(before, after): """Drop the default share images and their alt texts where main's default became a tray, and nothing else.""" def drop(tags, pattern, alt): - keys = ("og:image", "twitter:image") - images = {tag for tag in tags for key in keys if tag.startswith(key + "=") and pattern.fullmatch(tag[len(key) + 1:])} - alts = {f"{key}:alt={alt}" for key in keys} - if len(images) != len(keys) or not alts <= set(tags): - return None - return [tag for tag in tags if tag not in images | alts] + dropped = [] + for key in ("og:image", "twitter:image"): + images = [tag for tag in tags if tag.startswith(key + "=")] + alts = [tag for tag in tags if tag.startswith(key + ":alt=")] + # Duplicate tags are left for the ordinary comparison. + if len(images) != 1 or not pattern.fullmatch(images[0][len(key) + 1:]) or alts != [f"{key}:alt={alt}"]: + return None + dropped += images + alts + return [tag for tag in tags if tag not in dropped] old, new = drop(before, _OLD_DEFAULT_IMAGE, _OLD_DEFAULT_ALT), drop(after, _TRAY_IMAGE, _TRAY_ALT) return (before, after) if old is None or new is None else (old, new) diff --git a/scripts/tests/test_rebrand_checks.py b/scripts/tests/test_rebrand_checks.py index ef7a314a2cd..f38a0e4c4ce 100644 --- a/scripts/tests/test_rebrand_checks.py +++ b/scripts/tests/test_rebrand_checks.py @@ -337,6 +337,9 @@ def test_the_default_share_image_may_become_a_brick_tray(self): (tray.replace("_hu_0123456789abcdef", ""), new_alt)): with self.subTest(image=image, alt=alt): self.assertIn("a", compare_heads({"a": before}, {"a": self.default_tags(image, alt)})) + for extra in ("og:image=" + tray, "twitter:image=https://forrt.org/other.png", "og:image:alt=" + new_alt): + with self.subTest(extra=extra): + self.assertIn("a", compare_heads({"a": before}, {"a": sorted(after + [extra])})) # A page that had an image of its own must keep it, and nothing else may change along with the default. own = self.default_tags("https://forrt.org/rebrand-doors/img/own.png", old_alt) self.assertIn("a", compare_heads({"a": own}, {"a": after}))