Repository navigation
[CTX-1706] fix(render): close the #2875 kitty-graphics review follow-ups F2-F6 - #2895
Conversation
…ups F2-F6 F2: decode_png and precheck_png_payload now share one admission body (png_admission) that returns (w,h,pixels); the duplicated signature/IHDR/ceiling checks are gone. F3: scope the probe guarantee to declared geometry (dimension/area/byte ceilings), and pin the header-gate vs codec asymmetry with an executable test. F4: document that image-cell footprints are grid rows, not paint-frame rows ((scrollback_len - scroll_offset) + cursor_follow_window_start), and pin it with a cropped+scrolled test that places the image before the scrollback pressure. F5: fold the f=100 PNG arm into the single probe=>paint contract test; drop the duplicate PNG-only test. F6: sort and merge each row's covered ranges once, then answer the covered test with one forward cursor per row (column_covered removed). bitty#2875
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Xuepoo
left a comment
There was a problem hiding this comment.
Independent review — I did not write this code. Head f43c87a7b36b05d382ab3654e74712e75c519cc0, base origin/main @ 2f1be92ade92644cbf345129c79d716e502082ac (branch ctx-1706/fix-2875-followups).
All commands ran in the lane worktree (.worktrees/ctx-1706-fix-2875-followups) with CARGO_TARGET_DIR=/mnt/data/Workspace/Projects/bitty-terminal/.targets/ctx-1706 and --offline. just ci-local/act not run. Every injection was reverted immediately; the tree is clean at this head (see each section's revert proof).
1. Scope — PASS
$ git diff --name-status origin/main...HEAD
M crates/bitty-rich/src/kitty_decode.rs
M crates/bitty-runtime/src/inspect.rs
M crates/bitty-runtime/src/runtime/kitty_images.rs
M crates/bitty-runtime/tests/kitty_image_text_fallback.rs
M crates/bitty-runtime/tests/kitty_queries.rs
5 files changed, 355 insertions(+), 56 deletions(-)
Exactly the five files the PR claims, one commit ([CTX-1706] fix(render): close the #2875 kitty-graphics review follow-ups F2-F6). Cargo.lock is absent from the diff, and no manifest changed, so no dependency edge moved — consistent with "no lockfile churn". No unrelated crate, no formatting noise.
2. F2 — one admission implementation — PASS
Both PNG entry points run the same body; the checks exist once.
- Wrapper the
a=qprobe calls —crates/bitty-rich/src/kitty_decode.rs:408:pub fn precheck_png_payload(payload: &[u8]) -> Result<(), KittyDecodeError> { png_admission(payload).map(|_| ()) // :409 }
- Transmit path —
crates/bitty-rich/src/kitty_decode.rs:454:let (width, height, pixels) = png_admission(payload)?;
- The only body —
crates/bitty-rich/src/kitty_decode.rs:417:fn png_admission(...)runssniff_png_ihdr→checked_dimensions→ the RGBA8 byte cap (:418-427). - Probe call site —
crates/bitty-runtime/src/runtime/kitty_images.rs:2257:
if channels.is_none() && bitty_rich::precheck_png_payload(payload).is_err() {
grep -n sniff_png_ihdr now shows two hits only: the definition (:348) and the single call inside png_admission (:418). The other checked_dimensions/byte-cap occurrences (:251, :303) are the raw RGB/RGBA path (decode_raw/decode_raw_owned), not a PNG copy. What remains inside decode_png after admission is output-side only: codec Limits (:462-464) and the decoded-length/byte re-check (:473), which is the documented defense-in-depth, not a second admission. No duplicated signature/IHDR/ceiling/byte-cap check survives.
3. F3 — overclaim scoped, asymmetry pinned by a named test — PASS
crates/bitty-rich/src/kitty_decode.rs:388-401replaces the blanket claim with a# Scopesection: "the gate is header-only … a payload with a validIHDRand a corrupt or truncated stream past it passes here and is refused by the codec (MalformedPng) …decode_pngstays the authority on stream validity."crates/bitty-runtime/src/runtime/kitty_images.rs:2094-2106scopes thea=qverdict doc the same way: "a probe never answersOKfor anIHDRthe transmit path refuses (side/area/byte ceilings, zero dimensions, malformed header) … What the gate cannot prove is stream validity."- No surviving blanket statement:
grep -rn "never answers" crates/finds no other kitty claim (only unrelated harness docs). - Test:
precheck_admits_a_header_only_png_that_the_decoder_refuses(crates/bitty-rich/src/kitty_decode.rs:711) asserts gateOk+decode_png=MalformedPng. It ran green in the full suite (gates.log:172).
Sensitivity (injected a stream check into the gate, i.e. precheck_png_payload → decode_png(payload).map(|_| ())):
test kitty_decode::tests::precheck_admits_a_header_only_png_that_the_decoder_refuses ... FAILED
panicked at crates/bitty-rich/src/kitty_decode.rs:720:38:
the gate reads only the header: MalformedPng("CRC error: expected 0x0 have 0x1f15c489 while decoding ChunkType { type: IHDR, … } chunk.")
test result: FAILED. 0 passed; 1 failed (exit 101)
Reverted: git checkout -- crates/bitty-rich/src/kitty_decode.rs → git status --short empty.
4. F4 — both paint-base terms documented, test is not vacuous — PASS
Doc names both terms at crates/bitty-runtime/src/runtime/kitty_images.rs:1943-1958:
/// the same placements against a different base —
/// `(scrollback_len - scroll_offset) + cursor_follow_window_start(
/// cursor_row, grid_rows, frame_rows)` (`present.rs` leaf pass) —
…plus the reason units stay in grid space (decoration inset, default 80x24 grid in a 76x22 frame, window start 2). The seam call site carries an inline note (:1979-1982).
Sensitivity proven twice, by injecting each term into the seam body (kitty_image_cell_spans_for_origin):
- scroll_offset term → let scrollback_now = scrollback_now.saturating_sub(2);
test footprint_rows_stay_in_grid_space_under_a_cropped_and_scrolled_view ... FAILED
panicked at crates/bitty-runtime/tests/kitty_image_text_fallback.rs:240:5:
assertion `left == right` failed: the footprint marks the grid row the image is anchored on, not the frame row the paint pass draws it at
left: [ImageCellSpan { row: 21, col: 2, rows: 1, cols: 2 }]
right: [ImageCellSpan { row: 19, col: 2, rows: 1, cols: 2 }]
(exit 101)
+ window_start term → scrollback_now.saturating_add(2)
same test ... FAILED, crates/bitty-runtime/tests/kitty_image_text_fallback.rs:240:5
left: [ImageCellSpan { row: 17, col: 2, rows: 1, cols: 2 }]
right: [ImageCellSpan { row: 19, col: 2, rows: 1, cols: 2 }]
(exit 101)
Revert proof:
$ git checkout -- crates/bitty-runtime/src/runtime/kitty_images.rs
$ git status --short
(empty)
$ git rev-parse HEAD
f43c87a7b36b05d382ab3654e74712e75c519cc0
Observation (non-blocking, not a FAIL): my first injection put the -2 in the pane-session branch of kitty_image_cell_spans_for_view (:1977-1984) and the test stayed green, because the headless runtime in this test has no pane_sessions entry for the focused view — it drives the primary branch. The shared body (kitty_image_cell_spans_for_origin) is covered; the pane-session arm of the wrapper is not exercised by any test today.
5. F5 — one contract test carries both arms — PASS
query_probe_ok_implies_the_same_payload_paints (crates/bitty-runtime/tests/kitty_queries.rs:364) holds both wire shapes: raw arm f=32 at :375-389, PNG arm f=100 at :391-412 (probe OK, then a=T,c=1,r=1 and kitty_last_frame_images() == 2). The standalone query_probe_png_still_answers_ok_when_the_decoder_accepts is deleted (grep → absent), so the PNG side is asserted in exactly one place, as the PR body states.
Sensitivity (PNG-only production regression: the a=q PNG gate over-refuses every payload, kitty_images.rs:2257):
test query_probe_ok_implies_the_same_payload_paints ... FAILED
panicked at crates/bitty-runtime/tests/kitty_queries.rs:394:5:
assertion `left == right` failed: a decodable PNG must probe OK, never over-refuse
left: [[27,95,71,105,61,51,50,59,69,73,78,86,65,76,58,98,97,100,32,100,97,116,97,27,92]] = ESC_Gi=32;EINVAL:bad data ESC\
right: [[27,95,71,105,61,51,50,59,79,75,27,92]] = ESC_Gi=32;OK ESC\
(exit 101)
The raw arm's assertions passed before the PNG arm failed, so the failure is PNG-specific and the PNG arm is genuinely load-bearing (removing the assertion, as with any assertion, could only hide it). Reverted: git status --short empty.
6. F6 — merged ranges + forward cursor, both tests bite — PASS
crates/bitty-runtime/src/inspect.rs:575-597sorts each row's ranges withsort_unstable()and merges in place (ranges[write].1 = max(...),truncate(write + 1)), so overlap/touching collapse.crates/bitty-runtime/src/inspect.rs:483-497walks them with one advancing cursor (while current.is_some_and(|(_, end)| c >= end) { current = ranges.next() }), replacing the removedcolumn_covered(grep -rn column_covered crates/→ only a comment mention at:486).
Un-merge injection (sort/merge block deleted, ranges left in insertion order):
test inspect::tests::image_row_coverage_sorts_and_merges_overlapping_spans ... FAILED
panicked at crates/bitty-runtime/src/inspect.rs:847:9:
assertion `left == right` failed: overlapping spans collapse into one sorted range
left: [[(6, 8), (2, 5), (3, 7)]]
right: [[(2, 8)]]
(exit 101)
Cursor freeze injection (while false && …, cursor never advances):
test inspect::tests::grid_text_projects_disjoint_footprints_across_gaps ... FAILED
panicked at crates/bitty-runtime/src/inspect.rs:888:9:
assertion `left == right` failed: cells 2-3 stay blank between two disjoint footprints
left: ""
right: " "
(exit 101)
Both reverted → git status --short empty. (The disjoint-gaps test is insensitive to un-merging alone because its spans are already inserted in order; the cursor injection above is what proves it non-vacuous.)
7. Gates — PASS (all run here, --offline, lane target dir)
cargo fmt --all -- --check exit 0
cargo clippy -p bitty-rich -p bitty-runtime --all-targets -- -D warnings exit 0
cargo +1.85 check -p bitty-rich -p bitty-runtime --tests --offline exit 0 (cargo/rustc 1.85.1)
RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-rich -p bitty-runtime --no-deps --offline exit 0
cargo test -p bitty-rich --offline exit 0 397 passed, 0 failed, 10 suites
cargo test -p bitty-runtime --offline exit 0 3439 passed, 0 failed, 215 suites
grep -E '^test .* FAILED|^error(\[|:)|panicked at' over the whole gate log → no hits. The doc gate was re-run after touching both lib.rs files so rustdoc actually rebuilt (the first attempt in my wrapper had a shell quoting bug, env RUSTDOCFLAGS=-D warnings → exit 127; the corrected run documented both crates with zero warnings). Host toolchain cargo/rustc 1.98.1; MSRV leg 1.85.1.
Named tests observed passing in the suite run: kitty_decode::tests::precheck_admits_a_header_only_png_that_the_decoder_refuses (log:172), inspect::tests::grid_text_projects_disjoint_footprints_across_gaps (643), inspect::tests::image_row_coverage_sorts_and_merges_overlapping_spans (645), footprint_rows_stay_in_grid_space_under_a_cropped_and_scrolled_view (3002), query_probe_ok_implies_the_same_payload_paints (3108).
8. Test-count honesty — PASS
The body claims no test count it cannot back; every test it names exists by that exact name at this head:
| Named in body | Found |
|---|---|
precheck_admits_a_header_only_png_that_the_decoder_refuses |
crates/bitty-rich/src/kitty_decode.rs:711 |
footprint_rows_stay_in_grid_space_under_a_cropped_and_scrolled_view |
crates/bitty-runtime/tests/kitty_image_text_fallback.rs:177 |
query_probe_ok_implies_the_same_payload_paints |
crates/bitty-runtime/tests/kitty_queries.rs:364 |
image_row_coverage_sorts_and_merges_overlapping_spans |
crates/bitty-runtime/src/inspect.rs:832 |
grid_text_projects_disjoint_footprints_across_gaps |
crates/bitty-runtime/src/inspect.rs:867 |
query_probe_png_still_answers_ok_when_the_decoder_accepts (claimed deleted) |
absent — correct |
git diff | grep '^+.*fn …' shows 3 new #[test] fns plus the F4 integration test and two helpers, matching the six-item sensitivity table; the body's suite totals (397 / 3439, 10 / 215 suites) reproduce exactly in my run.
9. Claim honesty — PASS
- Line 1 of the body is
Related #2875; the only mention of "Closes" is the negation at line 76 ("That is also why this isRelated #2875, notCloses"). NoCloses/Fixes/Resolves #2875. - No parity claim: image.nvim/Ghostty appears only in "Not verified — needs a real GPU compositor".
- No overclaim about the devtools path: "Live
bitty devtoolsgrid-text snapshot through the IPC store: covered structurally only". No pixel-replay claim anywhere; the animation/pixel work stays out of this diff (tests only).
Non-blocking observations
- The F4 test drives only the primary branch of
kitty_image_cell_spans_for_view; injecting the paint-base offset into the pane-session branch alone (kitty_images.rs:1977-1984) left it green. The shared body is pinned; the wrapper's session arm is not. grid_text_projects_disjoint_footprints_across_gapsis insensitive to un-merging on its own (already-ordered spans); it is pinned against cursor smearing instead, which I confirmed bites.- The
a=qdoc atkitty_images.rs:2088-2106is correctly scoped, but the code comment at the gate call site (:2251-2256) still says "a probe must never answerOKfor bytes the decoder then refuses". The comment is internal and reads as intent rather than a guarantee, so I am not treating it as a defect — but it is the one place the old phrasing survives.
VERDICT: APPROVE
Related #2875
Follow-up to #2894. That PR merged after an independent review that approved it with five non-blocking findings; this PR closes all five (F2–F6) and nothing else.
F2 — one shared PNG admission gate
decode_pngduplicated the signature /IHDR/ ceiling checks instead of calling the probe's gate. Both now call one body:crates/bitty-rich/src/kitty_decode.rs:417—png_admissionreturns(width, height, pixels); it is the only place that runssniff_png_ihdr→checked_dimensions→ the RGBA8 byte cap.crates/bitty-rich/src/kitty_decode.rs:408—precheck_png_payloadis now a thin wrapper (.map(|_| ())), the function thea=qprobe calls.crates/bitty-rich/src/kitty_decode.rs:454—decode_pngconsumes the same tuple. The only checks left indecode_pngare the output-side ones (decoded-vs-header dimensions at:482, codecLimitsat:462), not a second copy of admission.F3 — doc overclaim scoped, asymmetry pinned
"A probe never answers
OKfor bytes a transmit would refuse" is false for a header-valid PNG with a corrupt stream. The wording is now scoped to what the gate proves:crates/bitty-rich/src/kitty_decode.rs:388-397— new# Scopesection: the gate is header-only, bounds refusals not acceptances;OKmeans "declared geometry is admissible", anddecode_pngremains the authority on stream validity.crates/bitty-runtime/src/runtime/kitty_images.rs:2092-2106— thea=qverdict doc says the same, naming the side/area/byte ceilings and the deliberate asymmetry.precheck_admits_a_header_only_png_that_the_decoder_refuses(crates/bitty-rich/src/kitty_decode.rs:711): a header-only PNG passes the gate anddecode_pngreturnsMalformedPng.F4 — footprint seam documented as grid space, with a test that bites
Paint resolves placements against
(scrollback_len - scroll_offset) + cursor_follow_window_start(..); the text projection consumes the grid snapshot, so footprints must stay in grid rows.crates/bitty-runtime/src/runtime/kitty_images.rs:1940-1958—# Coordinate spacesection onkitty_image_cell_spans_for_view, including why mixing the paint base in would move every stand-in by the decoration inset (default headless: 80x24 grid in a 76x22 content frame, window start 2).crates/bitty-runtime/src/runtime/kitty_images.rs:1982-1985— in-line note at the seam call site.footprint_rows_stay_in_grid_space_under_a_cropped_and_scrolled_view(crates/bitty-runtime/tests/kitty_image_text_fallback.rs:177).The image is deliberately placed before the scrollback pressure, so
placement.scrollback_base == 0against a non-zero live scrollback length: the grid base (anchor - len) and a paint-style base (anchor - (len - scroll_offset)) resolve to different rows. The test then scrolls the leaf (set_scroll_offset(2, ..)) and re-asserts. Both paint-base terms were injected as production reverts and each turned the test red (see the sensitivity table).F5 — one probe⇒paint contract test
The
f=100PNG arm is folded intoquery_probe_ok_implies_the_same_payload_paints(crates/bitty-runtime/tests/kitty_queries.rs:364; PNG arm:391-412): the same fixture must probeOK, then transmit-and-paint, with the frame image count going 1 → 2. The standalonequery_probe_png_still_answers_ok_when_the_decoder_acceptsis deleted, so the PNG side of the contract is asserted in exactly one place.F6 — sorted/merged ranges, one forward cursor per row
crates/bitty-runtime/src/inspect.rs:551image_row_coveragesorts and merges each row's[start, end)ranges in place (:579-597).crates/bitty-runtime/src/inspect.rs:486-499the cell loop walks them with one forward cursor, so the covered test is one amortised step per cell instead of anO(cells × ranges)rescan;column_coveredis removed.image_row_coverage_sorts_and_merges_overlapping_spans(:832) andgrid_text_projects_disjoint_footprints_across_gaps(:867).Failure sensitivity (production reverts, each restored)
cargo test -p bitty-runtime --lib image_row_coverage_sorts_and_mergesleft: [[(6, 8), (2, 5), (3, 7)]]vs[[(2, 8)]], exit 101current.is_some())cargo test -p bitty-runtime --lib grid_text_projects_disjoint_footprints_across_gapsvs , exit 101+ window_startin the seam (+ 2)cargo test -p bitty-runtime --test kitty_image_text_fallback footprint_rows_stay_in_grid_space- scroll_offsetin the seam (- 2)cargo test -p bitty-runtime --test kitty_queries query_probe_ok_implies_the_same_payload_paintscargo test -p bitty-rich --lib precheck_admits_a_header_only_pngMalformedPng("no IDAT"), exit 101All six injections were reverted before the commit;
git statusis clean at the claims below.Verification (this head,
--offline,CARGO_TARGET_DIR=.targets/ctx-1706)just ci-local/actwas not run: another lane may hold the act slot, so this tick used targeted cargo only.MSRV 1.85: no let-chains and no const-read-only-in-const-eval introduced;
cargo +1.85 check --testsis the evidence.Note:
RUSTDOCFLAGS="-D warnings" cargo doccaught a private intra-doc link ([decode_png]from publicprecheck_png_payloaddocs) introduced by the F2 doc rewrite; this branch fixes it, and the public docs keep the name in plain code font.Not verified
bitty devtoolsgrid-text snapshot through the IPC store: covered structurally only (kitty_image_cell_spans_for_primaryvs..for_view), plusctltext tests.Related #2875, notCloses— the umbrella's acceptance criteria are broader than F2–F6.Summary by CodeRabbit
Bug Fixes
Documentation