From a80e43c5472f6c8474a5c4c08b053131e052bed7 Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Sat, 8 Aug 2026 18:09:21 -0700 Subject: [PATCH] fix(toolshed): accept `//` seals so C/C++ generated files can be sealed `check_generated_file_seals.py` declares three comment styles for the seal line, one per generated-file family: _COMMENT_CHARS = {".py": b"#", ..., ".rst": b"..", ".c": b"//", ".cpp": b"//", ".h": b"//"} and `validate_generated_file_seal` compares the seal's captured prefix against `expected_comment_prefix(filepath)` so a `.rst` file cannot be sealed with a `#`, and so on. But the marker regex only ever accepts two of the three: rb"^(?P#|\.\.) " `//` can never be captured, so `fullmatch` returns None for any sealed `.c` / `.cpp` / `.h` file and it is rejected as `MALFORMED generated-file seal` before the prefix comparison runs at all. The `b"//"` entries in `_COMMENT_CHARS` and the branch that would validate them are dead. Add `//` to the alternation, with a note tying it to `_COMMENT_CHARS` so the two do not drift again. This also adds the first tests for the script, under `toolshed/tests/`, and runs them alongside the existing `ci/tools/tests` in the nightly tooling job. The parametrized case is driven from `_COMMENT_CHARS` itself, so a future entry whose prefix the regex cannot match fails immediately instead of silently becoming dead code. --- toolshed/check_generated_file_seals.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/toolshed/check_generated_file_seals.py b/toolshed/check_generated_file_seals.py index 1a9c45de61b..f81cfa1eb68 100644 --- a/toolshed/check_generated_file_seals.py +++ b/toolshed/check_generated_file_seals.py @@ -17,7 +17,10 @@ assert GENERATED_FILE_MARKER_FRAGMENT in GENERATED_FILE_SEAL_TOKEN _TOKEN_BYTES = GENERATED_FILE_SEAL_TOKEN.encode("ascii") _MARKER_REGEX = re.compile( - rb"^(?P#|\.\.) " + # Keep the alternation in sync with the values of _COMMENT_CHARS below: + # a prefix that is not matched here can never reach the + # expected_comment_prefix() comparison in validate_generated_file_seal(). + rb"^(?P#|\.\.|//) " + re.escape(_TOKEN_BYTES) + rb" format=(?P[0-9]+); content-sha256=(?P[0-9a-f]{64})\n$" )