Skip to content

fonts: derive the missing-metric code list instead of keeping a fourth copy - #288

Closed
GoKubar wants to merge 3 commits into
mainfrom
agent/ci-lane/font-diagnostics
Closed

GoKubar wants to merge 3 commits into
mainfrom
agent/ci-lane/font-diagnostics

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Closes the audit's #2 (issue #2, comment 5657695144), and fixes a related check found while doing it.

The hole

apps/mac/scripts/texmf-acceptance.sh:143 counted missing-metric diagnostics with a hand-written list:

MISSING_CODES='tfm_missing|required_metrics_unavailable|font_unavailable'

typeset.rs also emits ec_metrics_unavailable (:634), font_outline_substituted (:616) and math_font_unavailable (:757). A run emitting only those printed "0 missing-metric diagnostics = ok" — on the acceptance gate for whether the shipped app finds its bundled font metrics.

This was the third hand-maintained copy, after faces-acceptance.py (six codes) and tools/visual-oracle/fontenv.py (a different six). So rather than fixing the third copy and waiting for a fourth:

One source of truth, two questions

crates/render-pipeline/src/fontdiag.rs is now the table. Each code carries two flags, because the harnesses genuinely ask different questions — this is why the three copies disagreed rather than merely drifted:

meaning who counts it
substitution the document did not get a face or metrics it asked for font-discovery / packaging gates
geometry_void positions are no longer pdflatex's reference geometry position oracles

font_outline_substituted is exactly why one flag was not enough: the outline differs but the metrics — and so the positions — are still the reference ones.

flashtex-render --font-diagnostics json writes crates/render-pipeline/supported/font-diagnostics.json, following the existing supported-latex.json idiom. scripts/font_diagnostics.py reads it; all three consumers derive from it (shell via --format regex, Python via codes(view)). Each fails loudly if it cannot read the manifest — a gate that cannot state its own criteria must stop, not count zero.

The gate that makes it real

crates/render-pipeline/tests/fontdiag.rs does more than check the generated file is current. It scans src/ for every Diagnostic::warning|error|note("code" literal (truncating each file at its trailing #[cfg(test)], so unit-test fixtures are not mistaken for emissions) and fails if any emitted code is classified in neither table. A new code now forces a decision instead of silently landing outside every gate. It caught one of my own mistakes while I was writing it.

Bonus: the removed: sub-test could not fail either

The audit asked whether removed: (delete ec-lmr10.tfm, expect n>0) was passing incidentally. Measured on an intact tree, the answer is more interesting than the guess:

  • The intact run already emits ec_metrics_unavailable whose message reads "… ec-lmr10.tfm used" — so the grep -q 'ec-lmr10.tfm' half never discriminated.
  • The deletion's actual evidence is a tfm_missing naming ec-lmr10.tfm, which the intact run does not produce. Under the old list that made n go 0→1, so the sub-test was sound — the audit's guess that it "fails for the wrong reason" was wrong.
  • But once ec_metrics_unavailable correctly counts, n > 0 holds without the deletion. My widening would have turned this into another check that cannot fail.

So it is now differential: the deletion must produce a tfm_missing naming ec-lmr10.tfm that the intact env-direct run does not.

⚠️ Needs a Mac run

texmf-acceptance.sh and faces-acceptance.py are macOS-only (sandbox-exec/ditto/shasum) and were not executed here. Widening the counted set can make a bundle that previously passed now fail. That is the gate working, not a regression — but someone needs to run it on a Mac to see what the real bundle emits. My Linux probe suggests ec_metrics_unavailable may fire on the env-direct route; if it does, that is a real packaging gap this gate was previously scoring as clean.

faces-acceptance.py also gains math_metrics_opentype (its copy omitted it). fontenv.py's two sets are unchanged in content, only in provenance.

Demonstrated failing

injected defect result
Diagnostic::warning("lm_math_subset_missing", …) added to typeset.rs every_emitted_code_is_classified FAILS, naming the code and its file
checked-in JSON edited by hand generated_json_is_current FAILS
ec_metrics_unavailable flipped back out of the substitution set (the original bug) the_two_views_are_what_the_gates_need FAILS

Against a compile_result carrying ec_metrics_unavailable + font_outline_substituted + math_font_unavailable:

OLD hard-coded list  -> count 0  -> VERDICT: ok    <-- three real substitutions, reported clean
NEW derived list     -> count 3  -> VERDICT: FAIL

And the new differential removed: check, where the old shape said ok for all three rows:

case                                  new check                                     old shape
deletion noticed (the real case)      ok                                            ok
deletion NOT noticed                  bad (no tfm_missing naming it)                ok
intact bundle already reports it      bad (proves nothing about the deletion)       ok

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…h copy

`apps/mac/scripts/texmf-acceptance.sh` counted missing-metric diagnostics with
a hand-written `MISSING_CODES='tfm_missing|required_metrics_unavailable|
font_unavailable'`. typeset.rs also emits `ec_metrics_unavailable` (:634),
`font_outline_substituted` (:616) and `math_font_unavailable` (:757), none of
them in that list -- so a run emitting only those printed "0 missing-metric
diagnostics = ok". That is the acceptance gate for whether the *shipped* app
finds its bundled font metrics, and it could not fail for three of the seven
ways it can go wrong.

This was the third hand-maintained copy of the list, after faces-acceptance.py
(six codes) and tools/visual-oracle/fontenv.py (a different six, because it
asks a different question). So rather than fixing the third copy:

crates/render-pipeline/src/fontdiag.rs is now the single source of truth. Each
code carries two flags, because the harnesses genuinely ask two questions:

  substitution   the document did not get a face or metrics it asked for --
                 what the font-discovery and packaging gates count.
  geometry_void  positions are no longer pdflatex's reference geometry -- what
                 the position oracles must refuse to score.

`font_outline_substituted` is exactly why one flag was not enough: the outline
differs but the metrics, and so the positions, are still the reference ones.

`flashtex-render --font-diagnostics json` writes
crates/render-pipeline/supported/font-diagnostics.json, following the
supported-latex.json idiom. scripts/font_diagnostics.py reads it, and all three
consumers now derive their list from it -- shell via `--format regex`, Python
via `codes(view)`. Each fails loudly if it cannot read the manifest: a gate that
cannot state its own criteria must stop, not count zero.

crates/render-pipeline/tests/fontdiag.rs is the gate that makes it a real source
of truth. Beyond checking the generated file is current, it scans src/ for every
`Diagnostic::warning|error|note("code"` literal (truncating each file at its
trailing `#[cfg(test)]`, so unit-test fixtures are not mistaken for emissions)
and fails if any emitted code is classified in neither table. A new code now
forces a decision instead of silently landing outside every gate.

The `removed:` sub-test is also fixed, and this one is new. It deleted
ec-lmr10.tfm and asserted `n > 0` plus `grep ec-lmr10.tfm`. Measured on an
intact tree: the intact run ALREADY emits `ec_metrics_unavailable` whose message
reads "... ec-lmr10.tfm used", so the grep half never discriminated; and once
that code correctly counts as missing, `n > 0` holds without the deletion too --
the widened list would have turned this into another check that cannot fail. It
is now differential: the deletion must produce a `tfm_missing` naming
ec-lmr10.tfm that the intact env-direct run does not. Measured on Linux, that is
exactly what the deletion produces and the intact run does not.

faces-acceptance.py gains `math_metrics_opentype` (its copy omitted it);
fontenv.py's two sets are unchanged in content, only in provenance.

NOTE FOR REVIEW: texmf-acceptance.sh and faces-acceptance.py are macOS-only
(sandbox-exec/ditto/shasum) and were not executed here. Widening the counted set
can make a bundle that previously passed now fail. That is the gate working, but
it needs a Mac run to confirm what the real bundle emits.

Demonstrated failing:
* injecting `Diagnostic::warning("lm_math_subset_missing", ...)` into typeset.rs
  fails every_emitted_code_is_classified, naming the code and its file.
* editing the checked-in JSON fails generated_json_is_current.
* flipping ec_metrics_unavailable back out of the substitution set -- the
  original bug -- fails the_two_views_are_what_the_gates_need.
* against a compile_result carrying ec_metrics_unavailable +
  font_outline_substituted + math_font_unavailable, the old three-code list
  counts 0 ("ok"); the derived list counts 3 (FAIL).
* the new differential removed: check rejects both "deletion produced no new
  evidence" and "the intact bundle already reports it", where the old shape
  said ok for all three cases.

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

# Conflicts:
#	crates/render-pipeline/src/bin/flashtex-render.rs
float_footnote_unplaced and table_limitation are new on main since this
PR was written; classified both as non-font (layout/color limitations,
not font-discovery failures) and regenerated font-diagnostics.json.

Implementation-Agent: daniel-muse-lead
@GoKubar

GoKubar commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30

@GoKubar GoKubar closed this Sep 30, 2026
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