refactor(meta): read role names, titles and authors from one source

i18n/names kept a private _sources() that walked the role directories, read
the README heading and added galaxy_info.name. The brand rule needs the same
knowledge, and a second copy is the drift that has already bitten this branch
twice.

The three readers live under utils/meta now. titles also pins the precedence
that was implicit: the README heading wins over galaxy_info.name, because the
documentation is built from the heading. authors stays thin on purpose - the
derivation from the Credits sections belongs to utils/roles/credits, and this
is only the entry point for a reader that wants the names without the URLs.

The titles arrive sorted and deduplicated rather than in read order, which the
alternation built from them does not notice: it sorts by length itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-25 20:54:03 +02:00
1 parent c9510d4d9e
commit 353c4b87fb
8 files changed
+199 -34

No files matched your search

Whitespace-only changes.
@@ -0,0 +1,70 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from utils.meta.role.names import role_names
from utils.meta.role.titles import role_title, role_titles
class TestRoleTitle(unittest.TestCase):
def setUp(self) -> None:
self._tmp = tempfile.TemporaryDirectory(prefix="infinito-titles-")
self.role = Path(self._tmp.name) / "web-app-demo"
(self.role / "meta").mkdir(parents=True)
self.addCleanup(self._tmp.cleanup)
def test_the_readme_heading_is_the_title(self) -> None:
(self.role / "README.md").write_text("# Demo App\n\nText.\n", encoding="utf-8")
self.assertEqual(role_title(self.role), "Demo App")
def test_the_metadata_name_stands_in_without_a_heading(self) -> None:
(self.role / "meta" / "main.yml").write_text(
"galaxy_info:\n name: Declared Name\n", encoding="utf-8"
)
self.assertEqual(role_title(self.role), "Declared Name")
def test_the_heading_wins_over_the_metadata(self) -> None:
(self.role / "README.md").write_text("# Demo App\n", encoding="utf-8")
(self.role / "meta" / "main.yml").write_text(
"galaxy_info:\n name: Declared Name\n", encoding="utf-8"
)
self.assertEqual(
role_title(self.role),
"Demo App",
"the documentation is built from the heading, so that is what a "
"reader sees the role called",
)
def test_only_the_first_heading_counts(self) -> None:
(self.role / "README.md").write_text(
"# Demo App\n\n# Later Heading\n", encoding="utf-8"
)
self.assertEqual(role_title(self.role), "Demo App")
def test_a_role_declaring_nothing_has_no_title(self) -> None:
self.assertEqual(role_title(self.role), "")
class TestRepositorySources(unittest.TestCase):
def test_every_role_directory_is_listed(self) -> None:
names = role_names()
self.assertIn("web-app-nextcloud", names)
self.assertEqual(list(names), sorted(names))
def test_the_titles_are_unique_and_sorted(self) -> None:
titles = role_titles()
self.assertIn("Nextcloud", titles)
self.assertEqual(len(titles), len(set(titles)))
self.assertEqual(list(titles), sorted(titles))
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,30 @@
from __future__ import annotations
import unittest
from utils.meta.authors import author_names
from utils.roles.credits import author_urls
from utils.software import SOFTWARE_AUTHOR
class TestAuthorNames(unittest.TestCase):
def test_the_credited_people_are_listed(self) -> None:
self.assertIn(SOFTWARE_AUTHOR, author_names())
def test_the_names_are_sorted_and_unique(self) -> None:
names = author_names()
self.assertEqual(list(names), sorted(names))
self.assertEqual(len(names), len(set(names)))
def test_it_carries_exactly_the_keys_of_the_url_map(self) -> None:
self.assertEqual(
set(author_names()),
set(author_urls()),
"the names are the map's keys, not a second list that could drift "
"from the Credits sections they are derived from",
)
if __name__ == "__main__":
unittest.main()