Uh oh!
There was an error while loading. Please reload this page.
fix(toolshed): accept // seals so C/C++ generated files can be sealed - #2539
Open
LeSingh1 wants to merge 1 commit into
Open
fix(toolshed): accept // seals so C/C++ generated files can be sealed#2539LeSingh1 wants to merge 1 commit into
// seals so C/C++ generated files can be sealed#2539LeSingh1 wants to merge 1 commit into
Conversation
`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<prefix>#|\.\.) "
`//` 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.Contributor
This was referenced Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
toolshed/check_generated_file_seals.pydeclares three comment styles for the seal line, one per generated-file family:and
validate_generated_file_sealdeliberately compares the seal's captured prefix againstexpected_comment_prefix(filepath), so a.rstfile cannot be sealed with a#:But the marker regex only accepts two of the three declared prefixes:
//can never be captured, sofullmatchreturnsNonefor a sealed.c/.cpp/.hfile and it is rejected asMALFORMED generated-file sealbefore the prefix comparison ever runs. Theb"//"entries in_COMMENT_CHARS— and the branch that would validate them — are dead.Reproduced by writing one identical seal three ways and calling
validate_generated_file_sealdirectly:Only the prefix differs; the token, format, digest, and body are byte-identical.
The hook runs over
^cuda_bindings/withtypes: [text], which already contains C headers (cuda_bindings/cuda/bindings/_lib/param_packer.h), so the first generated.hor.cppto be sealed would be rejected with a message that points at the file rather than at the checker.Fix
Add
//to the alternation, with a comment tying it to_COMMENT_CHARSso the two do not drift apart again. One line of behavior change; no other logic touched.Tests
This script had no tests. Added
toolshed/tests/test_check_generated_file_seals.pycovering the seal round-trip for every entry in_COMMENT_CHARS(parametrized off the dict itself, so a future entry the regex cannot match fails immediately rather than silently becoming dead code), plus the wrong-prefix-for-extension rejection, the tampered-content rejection, the unsupported-extension rejection, and the never-sealed passthrough. They callvalidate_generated_file_seal(path, set())directly, so nogitsubprocess and no CUDA are involved.The new directory is wired into the existing nightly tooling job next to
ci/tools/tests:python -m pytest -v --noconftest ci/tools/tests toolshed/testsVerification
All of this was actually executed (pure Python, no GPU):
Combined
pytest --noconftest ci/tools/tests toolshed/tests: 74 passed.ruff check/ruff format --checkclean on both changed Python files (no new findings vs. anupstream/mainbaseline),toolshed/check_spdx.pyclean on the new file,python -m py_compileclean.Verified index-safely (
cpaside,git show upstream/main:<path> >, run, restore) — no staged reverts.