fix(conventions): read the PR body file with utf-8-sig

A pull request body saved with a UTF-8 byte order mark starts with
U+FEFF before "### What", so the first heading is not recognised and the
checker reports the What section as missing. Decode the body file with
utf-8-sig so the mark is dropped and the sections are found.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V9UU71SP1UKGR51Sowbgmq
This commit is contained in:
GalaxyGamingFR 2026-10-11 11:57:50 -07:00 committed by Adrià Franch
parent bb9a4d8a24
commit d15cc41299
3 changed files with 54 additions and 1 deletions

View File

@ -102,6 +102,8 @@ if(BUILD_TESTING)
set_tests_properties(pad_input PROPERTIES TIMEOUT 20)
add_test(NAME trace_digest COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_trace_digest.py)
add_test(NAME conventions_body_bom COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_check_conventions_body_bom.py)
endif()
endif()

View File

@ -397,5 +397,5 @@ if __name__ == "__main__":
if pr:
check.pull_request(pr["title"], pr["body"])
elif args.title is not None or args.body:
check.pull_request(args.title or "", open(args.body, encoding="utf-8").read() if args.body else "")
check.pull_request(args.title or "", open(args.body, encoding="utf-8-sig").read() if args.body else "")
raise SystemExit(output(check, os.environ.get("GITHUB_REPOSITORY", "boykopovar/AnyPS5")))

View File

@ -0,0 +1,51 @@
import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
BODY = (
"### What\nFix x.\n\n### Tested\nNot tested.\n\n### Checklist\n"
"- [x] Depends on: none\n- [x] AI-assisted: no\n"
)
class BodyBomTests(unittest.TestCase):
def run_checker(self, body):
checker = Path(__file__).resolve().parents[1] / "check_conventions.py"
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
def git(*args):
return subprocess.run(
["git", "-c", "user.name=Conventions Test", "-c", "user.email=test@example.com",
"-c", "commit.gpgsign=false", *args],
cwd=root, capture_output=True, text=True, check=True,
)
git("init", "-q")
(root / "README.md").write_text("# Example\n", encoding="utf-8")
git("add", ".")
git("commit", "-qm", "docs: add readme")
(root / "body.md").write_bytes(body)
return subprocess.run(
[sys.executable, "-I", str(checker), "--base", "HEAD", "--head", "HEAD",
"--title", "fix: x", "--body", "body.md"],
cwd=root, capture_output=True, text=True, encoding="utf-8",
env={key: value for key, value in os.environ.items()
if key not in ("GITHUB_EVENT_PATH", "GITHUB_STEP_SUMMARY", "GITHUB_ACTIONS")},
)
def test_body_with_utf8_bom_keeps_its_first_section(self):
result = self.run_checker(b"\xef\xbb\xbf" + BODY.encode("utf-8"))
self.assertNotIn("section 'What' is missing", result.stdout)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_body_without_bom_passes(self):
result = self.run_checker(BODY.encode("utf-8"))
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
if __name__ == "__main__":
unittest.main()