Skip to content

Commit cae1c78

Browse files
mattmilleraiclaude
andauthored
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/README.md‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,40 @@ rationale from ComfyUI_frontend#5448) minus `map_exclude`.
5555

5656
The rewrite is **surgical**: only the `reviewers: [...]` / `default_pool:
5757
[...]` sequences (flow or block) are replaced; every comment and all other
58-
bytes are preserved. The config's comments are its documentation — a
59-
YAML-dump rewrite would be a regression.
58+
bytes — the document's own line endings included — are preserved. The config's
59+
comments are its documentation — a YAML-dump rewrite would be a regression.
60+
The committed blob is read as bytes and decoded explicitly (never with
61+
`text=True`, whose universal-newline translation would silently rewrite a
62+
CRLF config to LF), inserted block items copy — per position — the line
63+
ending of the item they displace, and the proposal is written with
64+
`newline=""` so the runner OS cannot translate anything on the way out. A
65+
config that is not valid UTF-8, or one written with CR-only line breaks
66+
(which the byte-faithful reader does not split on, so it would arrive as a
67+
single line), takes the documented clean no-op rather than a lossy or
68+
half-read rewrite.
69+
70+
Two shapes the rewrite deliberately **cannot** manage, both left exactly as
71+
committed rather than edited:
72+
73+
- an inline trailing comment on a *block-form list item* (`- alice # why`) is
74+
not carried over when that list's membership changes — keep per-reviewer
75+
rationales on their own comment lines;
76+
- a **multi-line flow sequence** (`reviewers: [alice,` closing on a later
77+
line). Every edit the rewrite makes is confined to the one line a location
78+
names, so rewriting the opening line would leave the continuation lines
79+
behind as orphaned YAML. Those lists are parsed but never rewritten; each
80+
one emits a `::warning::` naming its file and line and is listed in the
81+
drift PR's body. Put the list on one line to let the refresher manage it.
82+
A torn **`paths:`** holds back its rule's `reviewers:` for a different
83+
reason: that list *is* editable, but the rule's globs were truncated at
84+
the line break, so anything selected from them would be scored against the
85+
wrong bucket — a wrong write rather than a skipped one.
86+
87+
A list the rewrite skips is reported as skipped everywhere, not just in the
88+
bytes: `report.json` marks it `skipped` and never `changed`, its before/after
89+
row shows the committed list (read across the continuation lines, so the
90+
`before` column is the real one and not the parser's truncated view), and it
91+
still counts toward the default pool's anti-pile-on tally.
6092

6193
The PR body carries the per-rule before/after table with scores/touches, the
6294
unresolved-email count, the knob values, and a report-only **taxonomy gap**

0 commit comments

Comments
 (0)