From 5d64b010e82e897024d919e1f0846f4cbde29adb Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:13:33 +0100 Subject: [PATCH] Preserve pathname bytes in the architecture check Architecture-Review: unchanged; the same watched paths and trailer requirements apply after pathname decoding. Co-Authored-By: Codex --- scripts/check_architecture_docs.py | 11 +++++++---- tests/test_architecture_docs.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/check_architecture_docs.py b/scripts/check_architecture_docs.py index a9a17768..c7147cb0 100644 --- a/scripts/check_architecture_docs.py +++ b/scripts/check_architecture_docs.py @@ -1,6 +1,7 @@ """Offline architecture links and public-interface review gate; see docs/ARCHITECTURE.md.""" import argparse import ast +import os import re import subprocess import sys @@ -21,9 +22,9 @@ } -def git(root, *args): +def git(root, *args, text=True): return subprocess.run(["git", *args], cwd=root, check=True, - capture_output=True, text=True).stdout + capture_output=True, text=text).stdout def interface(text, names): @@ -75,8 +76,10 @@ def link_errors(root): def check(root, base): git(root, "rev-parse", "--verify", f"{base}^{{commit}}") - changed = set(git(root, "diff", "--name-only", "-z", base).split("\0")) - changed.update(git(root, "ls-files", "--others", "--exclude-standard", "-z").split("\0")) + tracked = git(root, "diff", "--name-only", "-z", base, text=False) + untracked = git(root, "ls-files", "--others", "--exclude-standard", "-z", text=False) + changed = set(os.fsdecode(tracked).split("\0")) + changed.update(os.fsdecode(untracked).split("\0")) watched = changed.intersection(WATCHED) watched.update(p for p in changed if p.startswith(".github/workflows/")) for name, names in INTERFACES.items(): diff --git a/tests/test_architecture_docs.py b/tests/test_architecture_docs.py index 79340b8d..5be3231f 100644 --- a/tests/test_architecture_docs.py +++ b/tests/test_architecture_docs.py @@ -1,4 +1,5 @@ """Exercise the documentation check as a contributor/CI subprocess in real Git.""" +import os import subprocess import sys from pathlib import Path @@ -26,6 +27,24 @@ def run(repo, base, *args): text=True, capture_output=True, check=False) +@pytest.mark.skipif(sys.platform != "linux", reason="requires raw pathname bytes") +@pytest.mark.parametrize("staged", [False, True]) +def test_architecture_check_accepts_non_utf8_path(git_repo, staged): + base = prepare(git_repo) + path = os.fsdecode(b"caf\xe9.txt") + (git_repo / path).write_text("unrelated file\n") + if staged: + git(git_repo, "add", "--", path) + + done = run(git_repo, base) + assert done.returncode == 0, done.stderr + + (git_repo / "core/CONTRACT.md").write_text("# New authority\n") + done = run(git_repo, base) + assert done.returncode == 1 + assert "without guide update or reasoned Architecture-Review trailer" in done.stderr + + @pytest.mark.parametrize("sync", ["missing", "guide", "trailer", "empty", "squash"]) def test_architecture_change_requires_update_or_reasoned_review(git_repo, sync): base = prepare(git_repo)