Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions scripts/check_architecture_docs.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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():
Expand Down
19 changes: 19 additions & 0 deletions tests/test_architecture_docs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Linux-only skip does not cover filesystems that reject non-UTF-8 names

The skip only checks sys.platform. On a Linux filesystem that requires UTF-8 names (for example ZFS with utf8only=on, or some casefolded or encrypted mounts), write_text on caf\xe9.txt raises OSError and the test fails instead of being skipped. Smallest fix: try creating the file first and call pytest.skip on OSError/UnicodeEncodeError. This is non-blocking. The fix itself is correct: git ... -z emits raw, unquoted path bytes, and os.fsdecode with surrogateescape keeps them round-trippable. WATCHED and INTERFACES contain only ASCII names, so set membership is unaffected. The test fails before the fix because the strict decode raised UnicodeDecodeError, which main turns into a FAIL, and it also checks that a watched change still fails.

@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)
Expand Down
Loading