Skip to content

test: compare template_data_keys finding offsets with the text as Python reads it - #437

Merged
JuroOravec merged 1 commit into
mainfrom
fix/template-data-keys-crlf-test
Oct 27, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/template-data-keys-crlf-test

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

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_warning fails with assert 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 slices module_file.read_bytes() by the finding's start_index and end_index. Those offsets do not count in the raw bytes on disk.

Documented contract

start_index and end_index are UTF-8 byte offsets "with each line break counted as one \n byte, as Python reads a text file" (docs_site/content/advanced/cli.md, the comment in _lsp_range_coordinates in packages/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 with newline="\r\n" on every platform, so macOS and Linux runs catch the same mistake. The slice uses read_text(...).encode("utf-8"). The test also asserts line, column, end_line, and end_column point 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. ComponentGraphLocation documents offsets in the "normalized root template", and _component_graph.py reads the file with read_text, so this matches the code.

Sweep

  • git grep 'read_bytes()\[' over packages, docs_site, and crates found only these two tests.
  • Every other test that compares start_index / end_index with 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)

  • With the old raw-bytes slice restored, the new CR LF test fails with the same message as CI: assert b'gs)\r\n ' == b'"badge"'.
  • With the fix: 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 check and ruff format --check pass on both files.

No changelog entry (test-only).

🤖 Generated with Claude Code

…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]>
@JuroOravec
JuroOravec merged commit 3c4b364 into main Oct 27, 2026
16 of 28 checks passed
@JuroOravec
JuroOravec deleted the fix/template-data-keys-crlf-test branch October 27, 2026 13:35
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant