Skip to content

mac: stage JetBrains Mono into the packaged .app (fixes #742) - #744

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/gh742-app-font-packaging
Sep 17, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/gh742-app-font-packaging

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

apps/mac/scripts/make-app.sh never staged JetBrains Mono (the editor's
default face) into Contents/Resources/Fonts, so every packaged .app fell
back to SF Mono with no error. It also never staged the font's OFL licence.
This adds both, and adds a post-staging check that refuses to sign the app if
any expected resource — the new font files included — didn't land.

packaging-selftest.sh gets a matching fast check that the JetBrains source
files are still present in the repo.

Why

Filed as #742, found while verifying #720. To be precise about scope: this
is not the bug #720 fixed.
#720 fixed resource lookup for swift build/run/test (real, verified, 104 -> 1,399 executed test cases). This is
packaging: make-app.sh builds a .app through a completely different path
(explicit cp calls, not SwiftPM's resource-bundle mechanism), the font was
absent from the shipped app before #720 as well as after, and the two paths
diverging silently is exactly how a year-old-looking bug went unreported —
nobody screenshots their own editor font and notices it's slightly wrong.

Per the issue's ask, I checked whether make-app.sh's explicit resource list
was incomplete elsewhere too. It stages exactly two things by hand from
Package.swift's declared SwiftPM resources (supported-latex.json and
Resources/Fonts); the JSON file was already copied, the Fonts directory
(JetBrains Mono) was the one gap. I did not find any other missing resource
(no app icon/asset catalog is referenced anywhere in this app).

Judgement call: JetBrains Mono is SIL OFL 1.1, essentially always
redistributable, and this repo already carries OFL.txt right next to the
font files (apps/mac/Sources/FlashTeXMac/Resources/Fonts/OFL.txt) — so I
stage that file into the bundle alongside the fonts, the same way the
existing Latin Modern staging ships GUST-FONT-LICENSE.TXT.

Judgement call: the issue also asks about FlashTeXMac_FlashTeXMac.bundle
(SwiftPM's generated resource bundle). I traced EditorFontRegistration.swift
and Completion.swift: both explicitly document and implement
Contents/Resources/<name> as the first candidate for a packaged app, and
only fall back to FlashTeXMac_FlashTeXMac.bundle for swift build/run/
test, where there is no .app wrapper. make-app.sh already follows this
convention for supported-latex.json (a direct cp, never the SwiftPM
bundle), so I staged the fonts the same way rather than also copying the
.bundle into Contents/MacOS — that would be redundant with the direct copy
and inconsistent with the one already-established pattern in this script.
Confirmed by the runtime test below: the fix works with no .bundle present
in the shipped app at all.

Overlap check

  • gh pr list --repo flash-tex/flashtex --state open --search "JetBrains" /
    "make-app" / "font": no open PR touches this (only render-pipeline: font metric sweep for #710 (Latin Modern vs Computer Modern) #740, an unrelated
    font-metric sweep for Latin Modern vs Computer Modern).
  • python3 scripts/coord.py claims: GH-742-APP-FONT-PACKAGING was unclaimed;
    claimed it before starting.
  • GH-742-APP-FONT-PACKAGING closed via coord.py close with this PR's URL
    once opened.

Test results

Built from main directly (9c5b028d) — not #698 or #720. make-app.sh
only runs swift build -c release, which does not compile the test target
(PreviewV2Tests.swift, the thing #698/#720 fix), so main packages cleanly
with no test-bundle dependency.

Literal find output, before this change (apps/mac/scripts/make-app.sh --bridge /usr/bin/true built from main):

$ find build/FlashTeX.app -iname '*JetBrains*'
(0 results)

Literal find output, after this change, same build invocation:

$ find build/FlashTeX.app -iname '*JetBrains*'
build/FlashTeX.app/Contents/Resources/Fonts/JetBrainsMono-Bold.ttf
build/FlashTeX.app/Contents/Resources/Fonts/JetBrainsMono-Italic.ttf
build/FlashTeX.app/Contents/Resources/Fonts/JetBrainsMono-Regular.ttf
build/FlashTeX.app/Contents/Resources/Fonts/JetBrainsMono-BoldItalic.ttf

Runtime proof, not just presence-on-disk: launched the actual packaged
.app (open -n --env FLASHTEX_NO_ACTIVATE=1), attached lldb to the
running process, and evaluated NSFont(name: "JetBrainsMono-Regular", size: 13.0) against the live process (public AppKit API — sidesteps needing access
to the app's internal Swift types from lldb):

  • Before this change: (NSFont?) $R0 = nil
  • After this change: (NSFont?) $R0 = 0x... { baseUIFont ... isa = NSCTFont }
    (a real font instance)
  • Negative control (NotARealFontXYZ) returns nil in both cases, so the
    positive result isn't a fluke.

This proves EditorFontRegistration's CTFontManagerRegisterFontsForURLs
call actually ran and found the bundled files inside the packaged app at
runtime, from the app's own Contents/Resources/Fonts — not merely that the
files exist on disk.

New check's failure behavior, both verified directly:

  • Removed the OFL.txt source file: make-app.sh dies immediately at the
    copy step (missing .../OFL.txt (JetBrains Mono editor face)), exit 1, no
    half-built .app left ambiguous.
  • Separately, with only the new copy loop disabled (simulating some other
    future removal that skips the cp but leaves everything else): the
    independent post-staging completeness check still caught it, listing all 5
    missing files by path and refusing to sign, exit 1.

packaging-selftest.sh (fast mode, no --full, no build):

==> packaging-selftest: 33 ok, 0 failed

Not done

  • Did not run packaging-selftest.sh --full (real repro-check/launch-check
    builds) — the manual before/after find + lldb runtime checks above cover
    the same ground for this specific change, and --full needs real Rust
    helper binaries built to be fully meaningful.
  • Did not add a dedicated --full-mode negative-test to
    packaging-selftest.sh for the new completeness check (that would need a
    real build per case); I verified the failure paths manually instead (see
    above) to keep this change proportionate to the bug.
  • Rust helper binaries (flashtex-bridge, etc.) were stubbed with
    /usr/bin/true for these builds — irrelevant to font packaging, avoids
    spending a cargo build on a shared machine for an unrelated crate.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

What changed:
make-app.sh never staged the editor's JetBrains Mono faces (or their OFL
licence) into Contents/Resources/Fonts, so every packaged .app fell back to
SF Mono with no error -- confirmed on main, predates #720, and is a packaging
gap, not the swift build/run/test resource-path bug #720 fixed. It now copies
the four .ttf faces plus OFL.txt from Sources/FlashTeXMac/Resources/Fonts,
matching EditorFontRegistration.swift's own lookup order (Contents/Resources
first, the SwiftPM resource bundle only as a swift build/run/test fallback --
so FlashTeXMac_FlashTeXMac.bundle does not need to ship in the .app). A new
post-staging check (Info.plist, PkgInfo, supported-latex.json, the Latin
Modern licence/pin file, and the five new JetBrains files) now refuses to
sign an app that's missing any of them, so this can't regress silently again.
packaging-selftest.sh gained a matching fast check that the JetBrains source
files are still present.

What was run:
- swift build -c release (apps/mac): Build complete!
- apps/mac/scripts/make-app.sh --bridge /usr/bin/true, before this change:
  find build/FlashTeX.app -iname '*JetBrains*' -> 0 results; runtime
  NSFont(name: "JetBrainsMono-Regular", size: 13) -> nil (checked via lldb
  attached to the running packaged app)
- same build, after this change: find build/FlashTeX.app -iname '*JetBrains*'
  -> the 4 staged .ttf files; runtime NSFont(name: "JetBrainsMono-Regular",
  size: 13) -> a real NSFont (same lldb technique)
- negative test: renamed the JetBrains OFL.txt source away -> make-app.sh
  dies immediately with a clear message; separately, with the new copy loop
  itself disabled, the post-staging completeness check independently caught
  all 5 missing files and refused to sign
- apps/mac/scripts/packaging-selftest.sh (fast, no --full): 33 ok, 0 failed

Next step: none; scope was packaging only.

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 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent verification — VERIFIED

Fetched refs/review/pr-744 = bab6c3db, own worktree. I did not reuse the PR's build output: I packaged the .app twice myself, once from the PR head and once from its merge-base 9c5b028d (patch(readme): change to new demo image) in a separate worktree, with the same --bridge /usr/bin/true invocation.

1. The find, re-run from my own builds

Before — worktree at 9c5b028d:

$ cd /Users/dqi26/flashtex-wt/vr3-744-base/apps/mac && ./scripts/make-app.sh --bridge /usr/bin/true
...
==> Done: .../vr3-744-base/apps/mac/build/FlashTeX.app
$ find /Users/dqi26/flashtex-wt/vr3-744-base/apps/mac/build/FlashTeX.app -iname '*JetBrains*'
(0 results)

After — worktree at bab6c3db:

$ cd /Users/dqi26/flashtex-wt/vr3-744/apps/mac && ./scripts/make-app.sh --bridge /usr/bin/true
==> Copying JetBrains Mono into Contents/Resources/Fonts
==> Verifying every expected resource landed in the bundle
    all 10 expected resources present
==> Done: .../vr3-744/apps/mac/build/FlashTeX.app
$ find /Users/dqi26/flashtex-wt/vr3-744/apps/mac/build/FlashTeX.app -iname '*JetBrains*'
.../Contents/Resources/Fonts/JetBrainsMono-Bold.ttf
.../Contents/Resources/Fonts/JetBrainsMono-Italic.ttf
.../Contents/Resources/Fonts/JetBrainsMono-Regular.ttf
.../Contents/Resources/Fonts/JetBrainsMono-BoldItalic.ttf
$ find ... -iname 'OFL.txt'
.../Contents/Resources/Fonts/OFL.txt

Zero before, four faces plus the OFL licence after. The claim is exact. (Also confirms main packages cleanly for swift build -c release despite #695 — the test target is never compiled.)

2. The runtime claim, re-run

I re-ran the lldb evaluation against both packaged apps rather than taking the PR's transcript:

$ open -n --env FLASHTEX_NO_ACTIVATE=1 <app>
$ lldb -p <pid> -b -s lldb.cmds

with lldb.cmds = expr -l objc -O -- (id)[NSFont fontWithName:@"JetBrainsMono-Regular" size:13.0] then the same for @"NotARealFontXYZ".

After (pid 11596, .../vr3-744/apps/mac/build/FlashTeX.app/Contents/MacOS/FlashTeX):

(lldb) expr -l objc -O -- (id)[NSFont fontWithName:@"JetBrainsMono-Regular" size:13.0]
"JetBrainsMono-Regular 13.00 pt. P [] (0xbc6844f00) fobj=0xbc6844f00, spc=7.80"
(lldb) expr -l objc -O -- (id)[NSFont fontWithName:@"NotARealFontXYZ" size:13.0]
nil

Before (pid 11651, .../vr3-744-base/apps/mac/build/FlashTeX.app/Contents/MacOS/FlashTeX):

(lldb) expr -l objc -O -- (id)[NSFont fontWithName:@"JetBrainsMono-Regular" size:13.0]
nil
(lldb) expr -l objc -O -- (id)[NSFont fontWithName:@"NotARealFontXYZ" size:13.0]
nil

I added the control the PR did not state — that the positive result is not just a machine-wide font install leaking in:

$ ls ~/Library/Fonts /Library/Fonts | grep -i jetbrains
not installed system-wide

So the live NSFont really comes from the app's own Contents/Resources/Fonts via the per-process CTFontManagerRegisterFontsForURLs, and the nil in the before-app is the absence this PR fixes, not an lldb artefact.

3. The new check does fail when a resource is missing — both paths confirmed

The PR says it verified two ways; I ran both, without editing make-app.sh.

(a) The independent post-staging completeness check (apps/mac/scripts/make-app.sh:390-417). I made Sources/FlashTeXMac/Resources/Fonts/JetBrainsMono-Italic.ttf present but empty, so the copy loop's [[ -f ]] guard passes and only the [[ -s "$path" ]] check can catch it:

$ : > Sources/FlashTeXMac/Resources/Fonts/JetBrainsMono-Italic.ttf
$ ./scripts/make-app.sh --bridge /usr/bin/true ; echo exit=$?
==> Verifying every expected resource landed in the bundle
make-app.sh: expected resource missing or empty from .../build/FlashTeX.app:
  - .../build/FlashTeX.app/Contents/Resources/Fonts/JetBrainsMono-Italic.ttf
refusing to ship a silently-wrong bundle
exit=1

That is the stronger of the two claims: the check is genuinely independent of the copy loop, and it catches an empty staged file, not only an absent one.

(b) The copy loop's own die (make-app.sh:357), with the source removed:

$ rm Sources/FlashTeXMac/Resources/Fonts/JetBrainsMono-Italic.ttf
$ ./scripts/make-app.sh --bridge /usr/bin/true ; echo exit=$?
==> Copying JetBrains Mono into Contents/Resources/Fonts
make-app.sh: missing .../Sources/FlashTeXMac/Resources/Fonts/JetBrainsMono-Italic.ttf (JetBrains Mono editor face)
exit=1

File restored and the worktree verified clean (git diff --stat empty, shasum back to 936cdfc58bebc8b39e9aeaad3f2c92e9efc8aec4), then re-packaged successfully.

4. packaging-selftest.sh

branch: ==> packaging-selftest: 33 ok, 0 failed
base  : ==> packaging-selftest: 32 ok, 0 failed

33 vs 32 — the new JetBrains-source assertion (packaging-selftest.sh:143-155) is the one added check, so the count is accounted for rather than merely asserted.

Findings

None blocking. Every claim in the PR body reproduced exactly, including the two it called "verified directly".

Two observations for later, not for this PR:

  • REQUIRED_RESOURCES (make-app.sh:392-403) is a hand-maintained flat list. That is the right call here and the comment says why, but it means a future resource added to Package.swift is not automatically covered — the same class of gap as #742, one level up. Worth an issue if the resource set grows.
  • The negative paths are still manual. packaging-selftest.sh only checks the source files exist; nothing in CI exercises the post-staging check's failure branch. The PR's "Not done" says so honestly.

— independently verified by daniel-parent's review lane

@d-q222 d-q222 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent verification round 4 (re-check) — VERIFIED

A previous round verified this PR; this pass re-checks only what several days of
branch churn could have invalidated: that it still applies cleanly, and that the two
new checks still fire. Head bab6c3db, parent 9c5b028d, own worktree.

Still applies cleanly

$ git merge-base --is-ancestor bab6c3db^ origin/main   -> parent is ancestor of main
$ git merge-tree $(git merge-base origin/main refs/review/pr-744) origin/main refs/review/pr-744
exit=0 ; conflict markers / "changed in both": 0

$ gh pr view 744 --json mergeable,mergeStateStatus
{"headRefOid":"bab6c3db…","mergeStateStatus":"UNSTABLE","mergeable":"MERGEABLE"}

No conflict with current main. (UNSTABLE is the mac app job, which does not
compile on main today — #695 — and the macOS jobs cancelled by ci.yml's
concurrency group. Neither is this PR's doing.)

$ bash -n scripts/make-app.sh          -> make-app.sh OK
$ bash -n scripts/packaging-selftest.sh -> packaging-selftest.sh OK

packaging-selftest.sh still fires — positive and negative

$ bash scripts/packaging-selftest.sh
  ok   JetBrains Mono (4 faces + OFL.txt licence) present in Sources/FlashTeXMac/Resources/Fonts
==> packaging-selftest: 33 ok, 0 failed
exit=0

A green check is not evidence a check works, so I removed one face and re-ran:

$ mv Sources/FlashTeXMac/Resources/Fonts/JetBrainsMono-Bold.ttf /tmp/ && bash scripts/packaging-selftest.sh
  FAIL JetBrains Mono source files missing: JetBrainsMono-Bold.ttf
==> packaging-selftest: 32 ok, 1 failed
exit=1

Restored afterwards; worktree clean (git status --short apps/mac -> 0 lines).

make-app.sh's post-staging check still fires

make-app.sh cannot be run end to end here — it needs a swift build of an app that
does not compile on main (#695) — so I extracted the new block
(apps/mac/scripts/make-app.sh:390-419) verbatim and drove it against a synthetic
bundle, with a die() that reports rather than exits the outer shell:

--- positive: all 10 required paths staged ---
==> Verifying every expected resource landed in the bundle
    all 10 expected resources present
exit=0

--- negative: remove Contents/Resources/Fonts/JetBrainsMono-Bold.ttf ---
==> Verifying every expected resource landed in the bundle
DIE: expected resource missing or empty from …/App:
  - …/App/Contents/Resources/Fonts/JetBrainsMono-Bold.ttf
refusing to ship a silently-wrong bundle
exit=2

And the ordering claim — "refuses to sign the app" — holds:

$ grep -n "Post-staging completeness\|codesign\|refusing to ship" scripts/make-app.sh
390:# --- Post-staging completeness check ---
417:refusing to ship a silently-wrong bundle"
460:    codesign --force --options runtime … --sign "$SIGN_IDENTITY" "$1"
462:    codesign --force --identifier "$2" --sign - "$1"
466:if command -v codesign >/dev/null 2>&1; then

The check is at 390-419, every codesign invocation is at 460+. It genuinely gates
signing.

Source files it depends on are present

$ ls -l apps/mac/Sources/FlashTeXMac/Resources/Fonts/
277828  JetBrainsMono-Bold.ttf
279832  JetBrainsMono-BoldItalic.ttf
276840  JetBrainsMono-Italic.ttf
273900  JetBrainsMono-Regular.ttf
  4399  OFL.txt

All five names in JETBRAINS_FACES (make-app.sh:357) resolve, so the die "missing …" guard at make-app.sh:359 is unreachable on a clean checkout, as intended.

Not run

  • The full make-app.sh (and therefore the real staged .app, and any launch check):
    blocked by #695, not by this PR. The post-staging block was exercised in isolation
    as shown above, not inside a real build. Not claiming that as verified — what is
    verified is that the block's logic fires correctly on missing input, that it runs
    before signing, and that nothing about the PR has gone stale.

VERIFIED for the scope of this re-check: applies cleanly, both checks fire,
ordering correct.

— independently verified by daniel-parent's review lane

@d-q222
d-q222 merged commit 7688481 into main Sep 17, 2026
20 of 21 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.

1 participant