The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(contributors): stop email mappings colliding on case-insensitive filesystems
james47kjv30746a94f4c6
diff --git a/scripts/add_contributor.py b/scripts/add_contributor.pyindex cb64b331cbb..c2b49758f4f 100644--- a/scripts/add_contributor.py+++ b/scripts/add_contributor.py@@ -55,6 +55,22 @@ def _legacy_login(email: str) -> str | None:return None+def _case_collision(email: str) -> str | None:+ """An existing mapping whose filename differs from `email` only in case.++ Returns the colliding filename, or None. Exact matches are not collisions --+ that is the ordinary "already mapped" path handled by the caller.+ """+ if not EMAILS_DIR.is_dir():+ return None++ folded = email.lower()+ for entry in EMAILS_DIR.iterdir():+ if entry.name != email and entry.name.lower() == folded:+ return entry.name+ return None++def add_contributor(email: str, login: str, comment: str = "") -> int:email = email.strip()login = login.strip().lstrip("@")@@ -67,6 +83,23 @@ def add_contributor(email: str, login: str, comment: str = "") -> int:return 2path = EMAILS_DIR / email++ # One file per email means the FILENAME is the key, and on a+ # case-insensitive filesystem (Windows, default macOS) two emails differing+ # only in case are the same file. Creating both makes the repo impossible to+ # check out cleanly there -- `git status` reports a phantom modification+ # forever, because whichever file git wrote second wins on disk. Refuse for+ # the same reason a conflicting login is refused: resolve it deliberately.+ collision = _case_collision(email)+ if collision is not None:+ print(+ f"error: {email} collides with existing mapping {collision} on "+ "case-insensitive filesystems (Windows/macOS) — the two are the same "+ "file there. Reuse that mapping, or resolve manually.",+ file=sys.stderr,+ )+ return 1+existing = read_mapping_file(path) if path.is_file() else Noneif existing is None:existing = _legacy_login(email)diff --git a/tests/scripts/test_contributor_map.py b/tests/scripts/test_contributor_map.pyindex 40fd3567a29..06784bd34cc 100644--- a/tests/scripts/test_contributor_map.py+++ b/tests/scripts/test_contributor_map.py@@ -116,3 +116,55 @@ def test_cli_entrypoint_end_to_end(tmp_path):assert proc.returncode == 0, proc.stderrout = (tmp_path / "contributors" / "emails" / "[email protected]").read_text(encoding="utf-8")assert out.splitlines()[0] == "cliperson"+++# ── case-insensitive filename collisions ──────────────────────────────+#+# The mapping key IS the filename, so two emails differing only in case are the+# same file on Windows and on default macOS. When both exist, git writes one and+# then reports the other as modified in a FRESH clone, permanently: the repo can+# never be checked out clean on those platforms.+#+# This pair is a real conflict in the tree today and needs a maintainer to say+# which login is correct -- they point at different logins, so deleting either+# silently reassigns commits. It is pinned here so the breakage is visible and,+# more importantly, so it cannot spread.+KNOWN_CASE_CONFLICTS = {+ frozenset(+ {+ "[email protected]",+ "[email protected]",+ }+ )+}++EMAILS_DIR = REPO_ROOT / "contributors" / "emails"+++def test_no_new_case_insensitive_mapping_collisions():+ groups: dict[str, set[str]] = {}+ for entry in EMAILS_DIR.iterdir():+ if entry.is_file():+ groups.setdefault(entry.name.lower(), set()).add(entry.name)++ collisions = {frozenset(names) for names in groups.values() if len(names) > 1}+ unexpected = collisions - KNOWN_CASE_CONFLICTS++ assert not unexpected, (+ "contributor mappings differing only in case cannot coexist on "+ "case-insensitive filesystems (Windows, default macOS) — a fresh clone "+ f"there is permanently dirty: {sorted(sorted(c) for c in unexpected)}"+ )+++def test_add_contributor_refuses_a_case_collision(tmp_path, monkeypatch):+ d = tmp_path / "emails"+ d.mkdir()+ (d / "[email protected]").write_text("someone\n")++ import add_contributor as mod++ monkeypatch.setattr(mod, "EMAILS_DIR", d)++ assert mod.add_contributor("[email protected]", "otherperson") == 1+ assert not (d / "[email protected]").exists()