mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
Work-in-progress commit on the collective code-scanning sidetree, so main can be merged in; the single quality-high gate runs on the integration branch before the pull request. Fixes the CodeQL notes py/import-and-import-from, py/unused-import, py/unused-global-variable, py/empty-except, py/mixed-tuple-returns and py/unused-local-variable across 194 files, and adds one lint per rule under tests/lint/repository/python/ so none of them can come back: test_import_and_import_from, test_unused_imports_hidden_from_ruff, test_unused_global_variables, test_empty_except, test_mixed_tuple_returns, test_unused_local_variables, plus test_modules_import. Accepted security finding: MEDUSA-MP-SCAN-2056 (low) on utils/i18n/client.py:21, an import line matched by a keyword heuristic; operator-confirmed false positive. 🎯 Fix: 85 % 💥 Break: 8 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 78 🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
4.1 KiB
Python
119 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
import unittest.mock
|
|
from pathlib import Path
|
|
|
|
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 unittest.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 (
|
|
unittest.mock.patch.dict("os.environ", {"INFINITO_GIT_AUTHOR_EMAIL": " "}),
|
|
unittest.mock.patch("subprocess.run") as run,
|
|
):
|
|
run.return_value = unittest.mock.Mock(stdout="from-git\n")
|
|
self.assertEqual(committing_as(), ("from-git", "from-git"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|