Repository navigation
Commit cae1c78
fix(refresh-reviewers): byte-faithful rewrite — bytes read, CRLF-aware block inserts, refuse multi-line flow sequences (#309)
* fix(refresh-reviewers): byte-faithful rewrite — bytes read, CRLF-aware block inserts, refuse multi-line flow sequences
The generator documents a byte-faithful surgical rewrite: only the
`reviewers:` / `default_pool:` lists change, everything else is preserved.
Three paths broke that promise.
1. The committed config was read with `subprocess.run(..., text=True)`, whose
universal-newline translation rewrites a CRLF config's `\r\n` to `\n`
before the rewrite ever sees the file — so every line of the proposal
differed from the committed bytes. It is now read as bytes and decoded
explicitly, via a testable `read_committed_config()` helper, and a config
that is not valid UTF-8 takes the documented clean no-op instead of a lossy
rewrite. The proposal is written with `newline=""` so the runner OS cannot
translate it a second time on the way out.
2. `text.split("\n")` leaves the `\r` on every line, so the flow/scalar edits
were already faithful — but an INSERTED block item had no line to inherit
from and came out bare-LF. Each inserted item now copies the ending of the
item line it replaces, per line, so a mixed-ending file stays mixed.
3. A multi-line flow sequence (`reviewers: [alice,` closing on a later line)
was tagged `("flow", i)` and rewritten in place, leaving the continuation
lines behind as orphaned YAML a real parser refuses to load. Such lists are
now tagged `("unterminated", i)`, skipped by the rewrite, surfaced by
`unterminated_locations()` as a `::warning::` naming file and line, and
listed in the drift PR's body with the one-line fix. `_parse_flow` itself
is untouched, so the `config` half of `parse_reviewer_config` is identical
to before — verified across 24 fixtures against the pre-change parser.
Tests: CRLF versions of every rewrite shape; both unterminated shapes; a
round-trip regression corpus (re-parse, orphan-line, line-ending and — where
PyYAML is present — `yaml.safe_load` legs) that reds on defects 2 and 3; and a
`tempfile` git repo exercising the read helper on CRLF, LF and non-UTF-8 blobs.
* fix(refresh-reviewers): make the skip decision reach the report, and the endings reach every inserted line
Review follow-ups on the byte-faithful rewrite. `rewrite_config` correctly
refused to edit a multi-line flow sequence, but nothing else knew:
- A skipped list still got `replacements[i]`, so `report.json` and the PR
body advertised `changed: true` for bytes that never moved, and
`select_default_pool` anchored the pool on rule owners the file never
received. The rewritability predicate is now module-level
(`rule_is_rewritable`) and the per-rule loop is extracted to
`build_rule_reports`, so the report, the table and the anti-pile-on count
are all computed from the same answer the rewrite uses.
- The `before` column came from `_parse_flow`'s truncated `s[1:]` fallback
(`[carol]` for a committed `[carol, dave]`). `_parse_flow_continued` reads
the full committed list for reporting only; the parity parse is unchanged.
- A torn `paths:` was not tracked at all. That is the dangerous half: the
rule's `reviewers:` IS a single editable line, so it was rewritten from
scores computed against globs truncated at the line break — a silently
wrong write. Its rule is now skipped and warned about like any other.
- Line endings for inserted block items were sampled once from the first
item line, so a mixed block came back uniform and a CRLF block whose first
item line is an unterminated final line took bare LFs. Endings are now
assigned per output position, falling back to the block's (then the
document's) dominant ending, and the final line keeps its absence of one.
- `"]" not in s` was not quote-aware, so `reviewers: ["a]b", carol,` looked
closed and the span rewrite tore it at the quoted bracket. `_find_unquoted`
backs both the guard and `_rewrite_flow_line`.
- A CR-only config is one giant line to a reader that deliberately does no
newline translation, which scored zero rule buckets while still proposing
a default pool. It now takes the documented clean no-op. The runtime
assigner splits on /\r?\n/ too, so this matches what it can consume.
Also fixes a fixture whose `\\n` escapes made it one physical line, so the
two-line shape its name described was never parsed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent a404fd4 commit cae1c78
4 files changed
Lines changed: 1077 additions & 87 deletions
File tree
- .github/refresh-reviewers
- tests
- docs/callers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
60 | 92 | | |
61 | 93 | | |
62 | 94 | | |
| |||
0 commit comments