mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
feat(meta): derive author identity and profile from .mailmap
The README generator read its author URL out of the ## Credits sections it
writes itself. .mailmap now folds every address a person commits under into
their @infinito.nexus one, whose local part names their social profile, and
that profile becomes the single point of truth for an author.
utils/meta/identity.py parses .mailmap rather than shelling out to
git check-mailmap, which refuses the worktree the test container mounts.
Cross-checked against git over all 14 identities in the history: no
disagreement.
A new env handler carries the committing identity into the container, which
mounts the checkout but not the contributor's git configuration. Without it
both new tests would skip exactly where they are meant to fire:
* tests/integration/meta/test_commit_identity.py fails when the configured
address does not fold, and prints the .mailmap line to add.
* tests/external/repository/test_author_profile.py probes that profile
live, behind a canary so an unreachable instance is not reported as a
missing profile.
Both look at the current address only. Probing every declared author would be
red for people who have not created a profile yet, and a suite that is red for
someone else's omission stops being read.
Marko Pjevac is declared as a role author but has no address here, so his
Credits line stays unlinked.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
caee86e168
commit
fa015ab432
14 files changed
+481
-46
No files matched your search
@@ -2,8 +2,8 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from utils.meta.authors import author_names
|
||||
from utils.roles.credits import author_urls
|
||||
from utils.cache.files import PROJECT_ROOT
|
||||
from utils.meta.authors import author_names, role_authors
|
||||
from utils.software import SOFTWARE_AUTHOR
|
||||
|
||||
|
||||
@@ -17,14 +17,30 @@ class TestAuthorNames(unittest.TestCase):
|
||||
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:
|
||||
def test_every_name_is_declared_by_at_least_one_role(self) -> None:
|
||||
declared = set()
|
||||
for role_dir in sorted((PROJECT_ROOT / "roles").iterdir()):
|
||||
if role_dir.is_dir():
|
||||
declared.update(role_authors(role_dir))
|
||||
|
||||
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",
|
||||
declared,
|
||||
"the names come from galaxy_info.author, not from prose that could "
|
||||
"drift from the role metadata",
|
||||
)
|
||||
|
||||
def test_a_role_crediting_several_people_yields_each_of_them(self) -> None:
|
||||
multi = [
|
||||
names
|
||||
for role_dir in sorted((PROJECT_ROOT / "roles").iterdir())
|
||||
if role_dir.is_dir() and len(names := role_authors(role_dir)) > 1
|
||||
]
|
||||
|
||||
self.assertTrue(multi, "no role credits more than one author any more")
|
||||
for names in multi:
|
||||
self.assertTrue(all(name and not name.startswith(" ") for name in names))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,116 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from utils.meta.identity import (
|
||||
DOMAIN,
|
||||
MAILMAP,
|
||||
PROFILE_BASE,
|
||||
by_name,
|
||||
canonical,
|
||||
committing_as,
|
||||
profile_url,
|
||||
)
|
||||
|
||||
MAILMAP_BODY = """\
|
||||
# a comment line
|
||||
Alejandro Roman Ibanez <alexromanibanez@infinito.nexus> <romanibanez.alex@gmail.com>
|
||||
Kevin Veen-Birkenbach <kevinveenbirkenbach@infinito.nexus> <kevin@veen.world>
|
||||
Kevin Veen-Birkenbach <kevinveenbirkenbach@infinito.nexus> Old Name <old@example.com>
|
||||
<prageethpanicker@infinito.nexus> <prage.pani@gmail.com>
|
||||
"""
|
||||
|
||||
|
||||
class TestProfileUrl(unittest.TestCase):
|
||||
def test_the_local_part_names_the_profile(self) -> None:
|
||||
self.assertEqual(
|
||||
profile_url(f"kevinveenbirkenbach@{DOMAIN}"),
|
||||
f"{PROFILE_BASE}/kevinveenbirkenbach/profile",
|
||||
)
|
||||
|
||||
def test_a_foreign_domain_names_no_profile(self) -> None:
|
||||
self.assertEqual(profile_url("someone@example.com"), "")
|
||||
|
||||
def test_the_domain_is_matched_case_insensitively(self) -> None:
|
||||
self.assertTrue(profile_url(f"someone@{DOMAIN.upper()}"))
|
||||
|
||||
def test_an_empty_local_part_names_no_profile(self) -> None:
|
||||
self.assertEqual(profile_url(f"@{DOMAIN}"), "")
|
||||
|
||||
|
||||
class TestMailmap(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self._tmp = tempfile.TemporaryDirectory(prefix="infinito-identity-")
|
||||
self.root = Path(self._tmp.name)
|
||||
(self.root / MAILMAP).write_text(MAILMAP_BODY, encoding="utf-8")
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
by_name.cache_clear()
|
||||
self.addCleanup(by_name.cache_clear)
|
||||
|
||||
def test_an_alias_folds_into_the_canonical_address(self) -> None:
|
||||
self.assertEqual(
|
||||
canonical("Alejandro Roman", "romanibanez.alex@gmail.com", self.root),
|
||||
("Alejandro Roman Ibanez", "alexromanibanez@infinito.nexus"),
|
||||
)
|
||||
|
||||
def test_an_alias_written_with_a_name_folds_too(self) -> None:
|
||||
self.assertEqual(
|
||||
canonical("Old Name", "old@example.com", self.root)[1],
|
||||
"kevinveenbirkenbach@infinito.nexus",
|
||||
)
|
||||
|
||||
def test_an_entry_without_a_canonical_name_keeps_the_commit_name(self) -> None:
|
||||
self.assertEqual(
|
||||
canonical("Prageeth Panicker", "prage.pani@gmail.com", self.root),
|
||||
("Prageeth Panicker", "prageethpanicker@infinito.nexus"),
|
||||
)
|
||||
|
||||
def test_an_unknown_address_is_returned_unchanged(self) -> None:
|
||||
self.assertEqual(
|
||||
canonical("Nobody", "nobody@example.com", self.root),
|
||||
("Nobody", "nobody@example.com"),
|
||||
)
|
||||
|
||||
def test_the_address_is_matched_case_insensitively(self) -> None:
|
||||
self.assertEqual(
|
||||
canonical("Kevin Veen-Birkenbach", "Kevin@Veen.World", self.root)[1],
|
||||
"kevinveenbirkenbach@infinito.nexus",
|
||||
)
|
||||
|
||||
def test_by_name_reads_the_canonical_column(self) -> None:
|
||||
self.assertEqual(
|
||||
by_name(str(self.root))["Kevin Veen-Birkenbach"],
|
||||
"kevinveenbirkenbach@infinito.nexus",
|
||||
)
|
||||
|
||||
def test_a_missing_mailmap_folds_nothing(self) -> None:
|
||||
empty = Path(self._tmp.name) / "empty"
|
||||
empty.mkdir()
|
||||
|
||||
self.assertEqual(
|
||||
canonical("Nobody", "nobody@example.com", empty),
|
||||
("Nobody", "nobody@example.com"),
|
||||
)
|
||||
|
||||
|
||||
class TestCommittingAs(unittest.TestCase):
|
||||
def test_the_carried_environment_wins_over_git(self) -> None:
|
||||
carried = {
|
||||
"INFINITO_GIT_AUTHOR_NAME": "Carried Name",
|
||||
"INFINITO_GIT_AUTHOR_EMAIL": "carried@example.com",
|
||||
}
|
||||
with mock.patch.dict("os.environ", carried):
|
||||
self.assertEqual(committing_as(), ("Carried Name", "carried@example.com"))
|
||||
|
||||
def test_an_empty_carried_address_falls_through_to_git(self) -> None:
|
||||
with mock.patch.dict("os.environ", {"INFINITO_GIT_AUTHOR_EMAIL": " "}):
|
||||
with mock.patch("subprocess.run") as run:
|
||||
run.return_value = mock.Mock(stdout="from-git\n")
|
||||
self.assertEqual(committing_as(), ("from-git", "from-git"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user