Repository navigation
test: compare template_data_keys finding offsets with the text as Python reads it - #437
Merged
Merged
Conversation
…hon reads it The documented contract for a finding's start_index and end_index is that they are UTF-8 byte offsets with each line break counted as one "\n" byte, as Python reads a text file. The template_data_keys test sliced the raw bytes on disk instead. On Windows, Path.write_text turns every "\n" into "\r\n", so the raw bytes are longer than the text the offsets count in, and the slice landed a few bytes early. The finding was right and the test was wrong. The test now writes the module with CR LF line endings on every platform, so macOS and Linux runs catch the same mistake, and slices the text as Python reads it. It also checks that line and column point at the key. The component graph test had the same raw-bytes slice (it only passed because the reference was on the first line), so it now puts the reference after a CR LF line break and slices the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 27, 2026
JuroOravec
added a commit
that referenced
this pull request
Oct 28, 2026
A PR merged while its checks were still queued kept those runs, and they ran in full after the merge: about 300 to 400 job-minutes each for #430, #435, #436 and #437, while the merge's own run on main tested the same change again. Every check workflow that runs on pull requests now also starts on the PR's `closed` event. That run joins the PR's concurrency group, whose cancel-in-progress cancels the PR's queued and running checks, and every job skips on that event, so the cancelling run itself needs no runner. The notification and relock workflows are left out because they run no checks. A test checks each check workflow's trigger types and that every job that can start a run skips on `closed`. This is step 1 of the #405 proposal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 free
to 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.
Failing CI
main is red on every Windows cell (run 40502014569, commit 9f8ee0d).
packages/py/citry/tests/test_lint_template_data_keys.py::test_a_literal_key_the_list_leaves_out_is_a_warningfails withassert b'gs)\r\n ' == b'"badge"'.Cause
The test writes a module with
Path.write_text, which writes CR LF line breaks on Windows, then slicesmodule_file.read_bytes()by the finding'sstart_indexandend_index. Those offsets do not count in the raw bytes on disk.Documented contract
start_indexandend_indexare UTF-8 byte offsets "with each line break counted as one\nbyte, as Python reads a text file" (docs_site/content/advanced/cli.md, the comment in_lsp_range_coordinatesinpackages/py/citry/citry/_checker.py). The finding is right; the test was wrong. No product code changes.What changed (tests only)
test_lint_template_data_keys.py: the module is written withnewline="\r\n"on every platform, so macOS and Linux runs catch the same mistake. The slice usesread_text(...).encode("utf-8"). The test also assertsline,column,end_line, andend_columnpoint at the key, computed from the text.test_component_graph.py: the inherited-file-template test used the same raw-bytes slice. It passed only because the reference sat on the first line. The template now has the reference after a CR LF line break and the slice uses the text as Python reads it.ComponentGraphLocationdocuments offsets in the "normalized root template", and_component_graph.pyreads the file withread_text, so this matches the code.Sweep
git grep 'read_bytes()\['overpackages,docs_site, andcratesfound only these two tests.start_index/end_indexwith source text (test_analysis.py,test_browser_analysis.py, and others) slices an in-memory string's.encode(), never file bytes, so CR LF cannot differ. No API documenting raw-file offsets turned up.Test evidence (macOS, local)
assert b'gs)\r\n ' == b'"badge"'.test_lint_template_data_keys.py,test_component_graph.py,test_check.py,test_check_app_rules.py,test_check_inject_keys.py,test_check_libraries.py,test_check_depth_frames.py: 519 passed.ruff checkandruff format --checkpass on both files.No changelog entry (test-only).
🤖 Generated with Claude Code