"""Keep the documents' release status in step with the published tags. Add a release to PUBLISHED when its tag is pushed; a published tag is never moved or rebuilt. The list is written out because CI checks out a shallow clone without tags. Documents may describe a release as proposed or not yet tagged only while it is absent from PUBLISHED.""" import re import unittest from tests.test_overriding import CONTRACT, ROOT, codes, section, table_rows PUBLISHED = ("v0.15.0", "v0.16.0", "v0.17.0", "v0.18.0") DOCUMENTS = ("README.md", "OVERRIDING.md", "RELEASE-NOTES.md", "docs/authoritative/instruction-package-contract.md") # An unpublished marker within this many characters of a published tag, in # either order, describes that tag as unpublished. NEARBY = 40 UNPUBLISHED = r"not[- ]yet[- ](?:tagged|published)|proposed" def flat(text): return " ".join(text.split()) def read(path): return flat((ROOT / path).read_text()) class ReleaseStatusTests(unittest.TestCase): def test_documents_never_call_a_published_release_unpublished(self): for document in DOCUMENTS: text = read(document) for tag in PUBLISHED: escaped = re.escape(tag) pattern = (rf"(?:{UNPUBLISHED})[^.;|]{{0,{NEARBY}}}{escaped}" rf"|{escaped}[^.;|]{{0,{NEARBY}}}(?:{UNPUBLISHED})") with self.subTest(document=document, tag=tag): self.assertIsNone(re.search(pattern, text, re.I)) def test_package_matrix_names_published_releases_plainly(self): rows = table_rows(section((ROOT / "OVERRIDING.md").read_text(), "Package matrix")) for row in rows: release = codes(row[6])[0] if release in PUBLISHED: with self.subTest(package=codes(row[0])[0]): self.assertEqual(row[6], f"`{release}`") def test_contract_adoption_table_marks_releases_published(self): adoption = section(CONTRACT.read_text(), "RelayView adoption of the Tester and Coordinator pairs") for row in table_rows(adoption): release = codes(row[0])[0] if release in PUBLISHED: with self.subTest(release=release): self.assertEqual(row[0], f"`{release}`, published") def test_contract_explains_the_shared_v0_16_0_and_v0_17_0_commit(self): releases = flat(section(CONTRACT.read_text(), "Releases are immutable")) self.assertIn("`v0.16.0` and `v0.17.0` tag the same commit", releases) self.assertIn("A bundle for either tag takes only the packages that declare it.", releases) def test_release_notes_cover_each_published_release_without_a_pending_marker(self): headings = re.findall(r"^## (.+)$", (ROOT / "RELEASE-NOTES.md").read_text(), re.M) for tag in PUBLISHED: with self.subTest(tag=tag): self.assertIn(tag, headings) self.assertEqual(headings, sorted(headings, key=lambda tag: tuple(map(int, tag[1:].split("."))), reverse=True)) class DesignerAdoptionTests(unittest.TestCase): """RelayView pins v0.15.0 and assigns specification-designer-default.""" def test_package_matrix_names_the_pinned_specification_designer_default(self): rows = {codes(row[0])[0]: row[7] for row in table_rows(section((ROOT / "OVERRIDING.md").read_text(), "Package matrix"))} self.assertTrue(rows["specification-designer-default"].startswith("Pinned Designer default")) self.assertFalse(rows["issue-designer-default"].startswith("Pinned Designer default")) def test_documents_drop_the_pending_designer_adoption(self): for document in ("README.md", "OVERRIDING.md"): with self.subTest(document=document): self.assertIsNone(re.search(r"until it pins `?v0\.15\.0|not yet pinned", read(document))) adoption = flat(section(CONTRACT.read_text(), "RelayView adoption of the Specification Designer default")) self.assertNotIn("Before RelayView pins", adoption) self.assertIn("first-party-skills/v0.15.0/", adoption) def test_designer_methods_are_captured_only_when_assigned(self): adoption = flat(section(CONTRACT.read_text(), "RelayView adoption of the Specification Designer default")) self.assertIn("New Designer Chats receive `specification-designer-default`.", adoption) self.assertIn("captures one only when an Operator assigns it", adoption) def test_pair_adoption_names_the_bundled_subset(self): adoption = flat(section(CONTRACT.read_text(), "RelayView adoption of the Tester and Coordinator pairs")) self.assertIn("Before RelayView bundles a package declaring either pair", adoption) self.assertNotIn("Before RelayView pins a release containing either pair", adoption) if __name__ == "__main__": unittest.main()