Skip to content

render-pipeline: the \columnseprule oracles compare rules in both directions - #290

Merged
d-q222 merged 3 commits into
mainfrom
agent/ci-lane/rule-oracle-symmetry
Sep 16, 2026
Merged

d-q222 merged 3 commits into
mainfrom
agent/ci-lane/rule-oracle-symmetry

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Closes the audit's #5 (issue #2, comment 5657695144): the \columnseprule oracles compared rules in one direction only.

The hole

page_frame.rs:264-272 and footnotes_oracle.rs:163-172 both totalled and verified only the reference rules — for each pdflatex rule, ours.iter().any(|r| within_tol(r)). A rule our renderer paints with no pdflatex counterpart was counted in neither direction, and the scoring denominator was the reference count, so a spurious rule could not even move the score.

The fix

Both files shared that sweep and the per-page Item::Rule extraction verbatim. Both now live in tests/common/mod.rs:

rules_of(&Rendered) -> Vec<Vec<Rule>>
match_rules(want, got, tol_bp) -> RuleMatch { matched, missing, extra }

match_rules is a bijection by greedy match-and-consume, not two independent exists-sweeps: each reference rule takes the nearest still-unused rule of ours and consumes it (nearest = smallest max-of-four-coordinate deviation, so the pairing does not depend on emission order when several candidates sit inside the tolerance). Leftovers on our side are extra. This also catches many-to-one: two of our rules collapsing onto one reference rule leaves one unpaired.

Tolerances and the match predicate are unchanged — page_frame keeps TOL_BP = 0.1 * 72.0 / 72.27, footnotes_oracle keeps RULE_TOL_BP = 0.1, and a match is still all four of (x, top, width, height) within tolerance. Only the bookkeeping changed.

Denominator is matched + max(missing, extra): identical to the old reference count whenever extra == 0, so passing summary lines print the same numbers, while any extra forces total > matched so a spurious rule can never score clean. footnotes_oracle now also walks max(want_pages, got_pages), so rules on a page we invent cannot escape the pairing.

Result: PASS — no over-painting defect

Verified non-vacuous: 09-article-twocolumn-rule scores rules 3/3 (the only page-frame fixture with rules) and 21 gated footnote fixtures score 1–3 rules each. Since rules_ok == rules_total implies extra == 0, every gated fixture is confirmed free of spurious rules.

One new signal, in fixtures that were already ungated. The extra direction shows two REPORTED footnote fixtures paint the rule at the wrong top, previously scored only as "missing":

  • 14-multipar-note p1 — top off by ~18.93 bp
  • 15-math-note p1 — top off by ~1.44 bp

Both are downstream of the note-layout gaps those fixtures already document (\long \@footnotetext, math at body size). They remain ungated and the gate's verdict is unchanged. Nothing was weakened and the renderer was not changed.

Demonstrated failing — both directions

New direction (duplicate our first rule on page 1 — simultaneously the over-paint and many-to-one case). The old code passes with the spurious rule; that is the bug:

# OLD code + duplicated rule
test footnotes_against_pdflatex ... ok
test page_frame_against_pdflatex ... ok

# FIXED code + the same injection
panicked at tests/page_frame.rs:357:
  09-article-twocolumn-rule: pages 3/3 chrome 3/3 rules 3/4 edges 5/5
    p1: ours paints rule (305.4246578216553, 124.80199241638184, 0.39850521087646484, 547.9452056884766)
        with no pdflatex counterpart; pdflatex [(305.425, 124.802, 0.398, 547.945)]

panicked at tests/footnotes_oracle.rs:213:
  01-single: pages 1/1 words 388/388 (worst 0.005bp) rules 1/2
    p1 ours paints rule (133.768, 663.111, 137.484, 0.398) with no pdflatex counterpart
  02-multiple: ... rules 2/3   (and 6 further fixtures)

Original direction (drop one of our rules) still fails, with a message byte-identical to the pre-existing one:

09-article-twocolumn-rule: ... rules 2/3 ...
  p1: pdflatex rule (305.425, 124.802, 0.398, 547.945) ours []
01-single: ... rules 0/1
  p1 rule (133.768, 663.11, 137.482, 0.398): ours []

All injections reverted; restored files diffed identical to the pre-injection copies and re-run green.

Side finding, left untouched

crates/render-pipeline/tests/multicol_oracle.rs (~:198) has the same asymmetric sweep. Measured non-invasively with a temporary greedy-pairing probe: currently clean (09-columnseprule pairs 1-for-1; every other fixture paints no rules), but the check is equally incapable of failing on over-painting. match_rules is reusable there once its tuple carries the page number. Out of scope for this PR — happy to follow up.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…ections

page_frame.rs and footnotes_oracle.rs both totalled and verified only the
REFERENCE rules: for each pdflatex rule, `ours.iter().any(|r| within_tol(r))`.
A rule our renderer paints with no pdflatex counterpart was counted in neither
direction, so over-painting could not fail the oracle, and the scoring
denominator was the reference count -- a spurious rule could not even move the
score.

Both files shared that sweep and the per-page Item::Rule extraction verbatim.
Both now live in tests/common/mod.rs:

  rules_of(&Rendered) -> Vec<Vec<Rule>>
  match_rules(want, got, tol_bp) -> RuleMatch { matched, missing, extra }

match_rules is a bijection by greedy match-and-consume, not two independent
exists-sweeps: each reference rule takes the NEAREST still-unused rule of ours
and consumes it (nearest = smallest max-of-four-coordinate deviation, so the
pairing does not depend on emission order when several candidates sit inside
the tolerance). Leftovers on our side are `extra`. This also catches many-to-one:
two of our rules collapsing onto one reference rule leaves one unpaired.

Tolerances and the match predicate are unchanged -- page_frame keeps
TOL_BP = 0.1 * 72.0 / 72.27, footnotes_oracle keeps RULE_TOL_BP = 0.1, and a
match is still all four of (x, top, width, height) within tolerance. Only the
bookkeeping changed.

The denominator is matched + max(missing, extra): identical to the old
reference-rule count whenever extra == 0, so passing summary lines print the
same numbers, while any extra forces total > matched so a spurious rule can
never score clean. footnotes_oracle now also walks max(want_pages, got_pages)
rather than only reference pages, so rules on a page we invent cannot escape
the pairing.

Result: PASS, no over-painting defect. Verified non-vacuous -- page_frame's
09-article-twocolumn-rule scores rules 3/3 (the only page-frame fixture with
rules) and 21 gated footnote fixtures score 1-3 rules each; rules_ok ==
rules_total implies extra == 0, so every gated fixture is confirmed free of
spurious rules.

One new signal in fixtures that were already ungated: the extra direction shows
two REPORTED footnote fixtures paint the rule at the wrong `top`, previously
scored only as "missing" -- 14-multipar-note p1 off by ~18.93bp, 15-math-note p1
off by ~1.44bp. Both are downstream of the note-layout gaps those fixtures
already document; they remain ungated and the gate's verdict is unchanged.
Nothing was weakened and the renderer was not changed.

Demonstrated failing, both directions:
* Over-paint (duplicate our first rule on page 1, which is also the many-to-one
  case): the OLD code passes -- that is the bug. The new code fails both tests:
  "09-article-twocolumn-rule: ... rules 3/4 ... p1: ours paints rule
  (305.42, 124.80, 0.398, 547.95) with no pdflatex counterpart".
* Under-paint (drop one of our rules): still fails, with a message byte-identical
  to the pre-existing one -- "rules 2/3 ... p1: pdflatex rule (...) ours []".

Side finding, untouched: crates/render-pipeline/tests/multicol_oracle.rs (~:198)
has the same asymmetric sweep. Measured non-invasively: currently clean
(09-columnseprule pairs 1-for-1, every other fixture paints no rules), but the
check is equally incapable of failing on over-painting. match_rules is reusable
there once its tuple carries the page number.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…acle-symmetry

# Conflicts:
#	crates/render-pipeline/tests/footnotes_oracle.rs
#	crates/render-pipeline/tests/page_frame.rs
What changed:
Rebasing PR #290 onto main pulled in fixture 35-article-maketitle-thanks
(added by 7185035 after this PR was authored). Its \thanks-triggered
\footins material is already documented here as unimplemented and its
body baselines were already reported-not-gated via MAKETITLE_Y_UNGATED.
The same unimplemented \footins material also paints a spurious
footnote-separator rule pdflatex doesn't. The old one-directional rule
check couldn't see it (want_rules was empty, so 0/0 passed either way),
but this PR's new symmetric match_rules counts it as `extra`, newly
failing page_frame_against_pdflatex on a fixture this PR's diff never
touched. Extended the same ungating to rules for that one fixture, with
a comment explaining why, rather than leave it gated on a pre-existing,
already-documented, unrelated gap.

What was run:
CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-pr290 CARGO_BUILD_JOBS=4 cargo test --no-run (crates/render-pipeline) -> all targets built, 0 compile errors
cargo test --test page_frame --test footnotes_oracle --test multicol_oracle:
  test footnotes_against_pdflatex ... ok
  test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.42s
  test multicol_fixtures_against_pdflatex ... ok
  test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.63s
  test page_frame_against_pdflatex ... ok
  test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.84s

Next step: none; rebase complete, PR ready for review/merge.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Rebased onto main (was CONFLICTING, now MERGEABLE, head cf56c7c2).

Conflicts resolved

Both real conflicts (page_frame.rs, footnotes_oracle.rs) were the same shape: this PR's HEAD already delegates rule extraction to the new shared rules_of() in common/mod.rs, while main had independently inlined the identical extraction using p.resident_items() (from an unrelated page-windowing/elision refactor to Page — it no longer exposes a public items field, only .items()/.resident_items()). Kept HEAD's delegation to rules_of() in both files.

Silent breakage caught by the mandatory post-merge build (no conflict markers here): the PR's own new rules_of() in common/mod.rs still read p.items directly (written before main's Page refactor landed). That doesn't compile against current main. Fixed to p.resident_items(), matching the pre-existing words_of() in the same file.

New signal from the rebase itself

Rebasing pulled in fixture 35-article-maketitle-thanks (added by main's 7185035e, after this PR was authored). Its \thanks-triggered \footins material is already documented in page_frame.rs as unimplemented, with body baselines already reported-not-gated via MAKETITLE_Y_UNGATED. The same unimplemented material also paints a spurious footnote-separator rule pdflatex doesn't emit — invisible to the old one-directional check (an empty want_rules made it 0/0 either way), but caught by this PR's own new symmetric match_rules as extra, which newly failed page_frame_against_pdflatex on a fixture this PR's diff never touches. Extended the same ungating to rules for that one fixture (comment explains why) rather than leave a pre-existing, already-documented, unrelated rendering gap gated by an unrelated PR.

No silent duplicates: git grep for match_rules/RuleMatch on origin/main found nothing, so none of this PR's content had landed independently.

Test results

CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-pr290 CARGO_BUILD_JOBS=4 cargo test --no-run   (all targets built, 0 errors)

test footnotes_against_pdflatex ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.42s

test multicol_fixtures_against_pdflatex ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.63s

test page_frame_against_pdflatex ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.84s

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

d-q222 added a commit that referenced this pull request Sep 16, 2026
@d-q222
d-q222 merged commit e36aca5 into main Sep 16, 2026
21 of 22 checks passed
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.

2 participants