Advance native LaTeX execution and preview

This commit is contained in:
gloamxun committed 2026-11-18 22:17:21 +08:00
1 parent 91f9d76b16
commit 2741546ca8
414 files changed
+99872 -933

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
{
"entry": "tex/latex/base/latex.ltx",
"version": "LaTeX2e 2025-11-01 patch 0",
"sha256": "95c2ef02c2d92aa29e4a77a5e5a7d9f25b5589143d1e879fb80ffa0b20be1e6d",
"scope": "Unmodified entry source. This does not pin the full transitive format/package/font distribution."
}
+662
View File
@@ -0,0 +1,662 @@
{
"schema": 1,
"profile": "pdfTeX/pdfLaTeX",
"reference": {
"version": "pdfTeX 3.141592653-2.6-1.40.29 (TeX Live 2026)",
"binary_sha256": "63e3a0c1ee5998a544fee9b52a4d9f99cc43f20ac9dba25fe7ba2428f4426527",
"entry_namespace": [
"TEXMFDIST",
"tex/latex/tex-ini-files/pdflatex.ini"
]
},
"corpus_sha256": {
"a0-minimal/main.tex": "c3070b29b89db7c42dbadabca460f7762958437278d96e77db2bf95c11bfce62",
"a1-fonts-10/main.tex": "fc1dd150184b423d766f26d38075d848054f9d8d0da682248b03bdeb70f87ac4",
"a1-fonts-11/main.tex": "7bdf2ec66f584e767668e7a7b8fbc262a6a1ff5c5dcd45ed35f5ac6e3c8b46e0",
"a1-fonts-12/main.tex": "af402a739155300f1a54483805ebed404ebe841d240254fde5870785c9b1ba3a",
"a2-math/main.tex": "f3cc2a98cec3a0910b57cc28d69883ca21d734aea2fb218eb01b7e26ed065c34",
"a3-pages/main.tex": "608be73ddc1f3200a4b63993da2acc7eed8f84b8d0d42c19044e5ae28a582e01",
"a4-project/chapter.tex": "600cd36d55571103fc9f79ca694c723d23d1ac1f27ddaed2b448602d0e4a46be",
"a4-project/main.tex": "e9928c6e5136a5f037789d8febe60b344004942bdbea7cf8d7b6d049b2214080"
},
"resources": [
{
"namespace": "EXTERNAL",
"path": "/etc/texlive/web2c/texmf.cnf",
"bytes": 43785,
"sha256": "f9ff709ae5592107d213aa88803405f77e28a00a944a7830deb4daeb18b0e1bb"
},
{
"namespace": "PROJECT",
"path": "a0-minimal/main.tex",
"bytes": 76,
"sha256": "c3070b29b89db7c42dbadabca460f7762958437278d96e77db2bf95c11bfce62"
},
{
"namespace": "PROJECT",
"path": "a1-fonts-10/main.tex",
"bytes": 575,
"sha256": "fc1dd150184b423d766f26d38075d848054f9d8d0da682248b03bdeb70f87ac4"
},
{
"namespace": "PROJECT",
"path": "a1-fonts-11/main.tex",
"bytes": 571,
"sha256": "7bdf2ec66f584e767668e7a7b8fbc262a6a1ff5c5dcd45ed35f5ac6e3c8b46e0"
},
{
"namespace": "PROJECT",
"path": "a1-fonts-12/main.tex",
"bytes": 575,
"sha256": "af402a739155300f1a54483805ebed404ebe841d240254fde5870785c9b1ba3a"
},
{
"namespace": "PROJECT",
"path": "a2-math/main.tex",
"bytes": 312,
"sha256": "f3cc2a98cec3a0910b57cc28d69883ca21d734aea2fb218eb01b7e26ed065c34"
},
{
"namespace": "PROJECT",
"path": "a3-pages/main.tex",
"bytes": 566,
"sha256": "608be73ddc1f3200a4b63993da2acc7eed8f84b8d0d42c19044e5ae28a582e01"
},
{
"namespace": "PROJECT",
"path": "a4-project/chapter.tex",
"bytes": 174,
"sha256": "600cd36d55571103fc9f79ca694c723d23d1ac1f27ddaed2b448602d0e4a46be"
},
{
"namespace": "PROJECT",
"path": "a4-project/main.tex",
"bytes": 381,
"sha256": "e9928c6e5136a5f037789d8febe60b344004942bdbea7cf8d7b6d049b2214080"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmbx10.tfm",
"bytes": 1328,
"sha256": "ae296e8e41b2b0f73e9a17fdc42c743b9ddcc58d23c30acaa3411206f7824780"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmbx12.tfm",
"bytes": 1324,
"sha256": "0eb2f13840155007c2d3c59b074322a3aa7358b9643aa314f3146468ae7f0806"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmex10.tfm",
"bytes": 992,
"sha256": "0890bccea1dd4d27f001ac30e86c63af35bc803e0557c35aafb1903c8d208e92"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmmi10.tfm",
"bytes": 1528,
"sha256": "e442c5487f84df70218ff37f775c87060856f5b6e04c011b6cadbbadfcf46645"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmmi5.tfm",
"bytes": 1508,
"sha256": "8839e40838381a0a3c976bdd5becf72afd60bde5a965c3d9b985c3479c6cf75e"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmmi7.tfm",
"bytes": 1528,
"sha256": "ce55681703aae565f17286d800ea9780223132589bdbaeda1751b869aba26a38"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmr10.tfm",
"bytes": 1296,
"sha256": "87f2d8981927644cbecaf3d639e96e348ea4e7be49d8804468bd8ba9ff3f5244"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmr12.tfm",
"bytes": 1288,
"sha256": "1ce8af37ed38e93940829d3540e494eaaddc5201758d036b9074467e70a738dc"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmr17.tfm",
"bytes": 1292,
"sha256": "86b6e8a52aae6ad1655e32099e12bd2904b158aba4c8afb74143266d2d9cd18f"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmr5.tfm",
"bytes": 1220,
"sha256": "581be818f67bd11a1792d05e129abe3ea30c5cbdfce3bed8da7c5fb50f5ba95b"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmr7.tfm",
"bytes": 1300,
"sha256": "28f9f4d237bdae4babef4a59d90f17686a09d6f9df0b2c3c23b2ba15f20eee82"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmsy10.tfm",
"bytes": 1124,
"sha256": "0ca13d421ac7133271aed7c935099ecf3d1d08ac9e15f81acb34a16564ab8a46"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmsy5.tfm",
"bytes": 1112,
"sha256": "6b7dc18cba9ca8996d7b146f1ed78d9227577b26248083310fec227692198ca5"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmsy7.tfm",
"bytes": 1120,
"sha256": "4f59bbf683e947c807158641621982dc83f55fec042fea7963d8ce9f9da98256"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmti10.tfm",
"bytes": 1480,
"sha256": "46a66e937f809c4fbe317947b583a14b408aca41ecb835eca3be46391190432a"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmti12.tfm",
"bytes": 1484,
"sha256": "92d92985d932893a426546c1e59b69107423785857f6f29aa866be0aa8970883"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmtt10.tfm",
"bytes": 768,
"sha256": "11f3331c958b696fd484fe45c28285622617a2593d7a34511a1d6b279e1578a2"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/cm/cmtt12.tfm",
"bytes": 772,
"sha256": "156417e26b9a51c7e052d5fdb3db7b25f10d4fa0d094180ae7834894189a0a0b"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/latex-fonts/lcircle10.tfm",
"bytes": 820,
"sha256": "f5aaff47e226ff644ae94765b8d6012e0ffb6d62956993acac2f2dd4ad589929"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/latex-fonts/lcirclew10.tfm",
"bytes": 820,
"sha256": "7906e4c5d770db4002740cba4d8194281b06d6fe7edd9d9949b60a291b753646"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/latex-fonts/line10.tfm",
"bytes": 748,
"sha256": "250200d9efa885fecff118d72e5239adacd0783ccb00c4fb96fa677708ce5217"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/tfm/public/latex-fonts/linew10.tfm",
"bytes": 748,
"sha256": "925de632e8afb641692c58bf6c464fb1aa79782212523532590dd6b91b78c40f"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmbx10.pfb",
"bytes": 34811,
"sha256": "ca41102968b817bf6e8b22fd6de205ca23bf5088218511cce0c8129e1577cb70"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmbx12.pfb",
"bytes": 32080,
"sha256": "c838238f31d86a9f198873dfaf501601a4fc966845b9c59e7dc251c4e85d1f1f"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmex10.pfb",
"bytes": 30251,
"sha256": "791b31aa1db8608d0144b3a40fc0fe53383a60f6b00d0e8fd9f06ac4a11df8cb"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmmi10.pfb",
"bytes": 36299,
"sha256": "e3661061e8aa474d6de5ffa916edceb0e3d8b998862018c147f0357fce00bcd7"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmr10.pfb",
"bytes": 35752,
"sha256": "fdcede8794018df5f2b58f0905fb20a2b418ed8f67b73ee12445855dfbe5b1be"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmr12.pfb",
"bytes": 32722,
"sha256": "9b58bfa828b9553b7c8331cf26c45443b836f8aab62e820b40a5b65c8531dd42"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmr7.pfb",
"bytes": 32762,
"sha256": "b37e8671820b0753c6e233eaa3230c6ab9cff04e6c4baee312d60ae261e5aba1"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmti10.pfb",
"bytes": 37944,
"sha256": "b6f162e1549a649c7e9b2edfb77306f60e1b0da74547f33cba39ff6ba0bdd473"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmti12.pfb",
"bytes": 36118,
"sha256": "4f343bda5844ca1782bbad5e6d4052519c2f4e6f1e3bfb1a3a514a280e2608c9"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmtt10.pfb",
"bytes": 31099,
"sha256": "d6bdecc0378f3cd16683d1ac348bdbc4ccde9a552e87b53fe9e2de5cfc7aa61d"
},
{
"namespace": "TEXMFDIST",
"path": "fonts/type1/public/amsfonts/cm/cmtt12.pfb",
"bytes": 24252,
"sha256": "cc6ac592f4045f6726b0cd5cbb1f623a44fe5af2559b967d5ad32470e49cb1c6"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/atbegshi/atbegshi.sty",
"bytes": 24708,
"sha256": "a73003b4bb2dc8a814533ddbd31600e6626827799c2a465d03ef42e7a33fa71b"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/babel/hyphen.cfg",
"bytes": 6443,
"sha256": "75c6b7c2bf639d58f441b611a094cc43dedbd64cf884ff1dc724f3d1f8cb8463"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/config/language.dat",
"bytes": 2855,
"sha256": "ff1aba9505ca78e3cf2b1fd54e32d7f370a23e9a16d8f8f7aedf7836d75329e3"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyph-utf8/loadhyph/loadhyph-en-gb.tex",
"bytes": 632,
"sha256": "fa15619f1b05c09aae62efa6d5cf8d2309ddf6b2e991a728350a0370558b4261"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyph-utf8/loadhyph/loadhyph-en-us.tex",
"bytes": 636,
"sha256": "0930a68b3c94b2ee48637b09ffd9fdee9f7a36399a1811a181cf015e06850de8"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyph-utf8/patterns/tex/hyph-en-gb.tex",
"bytes": 58474,
"sha256": "e95bb4ab350f620c41c231c4785d7bdb4f91949d3e631b30e08b3ead3c340a52"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyph-utf8/patterns/tex/hyph-en-us.tex",
"bytes": 34128,
"sha256": "f4ffcd96c5cbc886bdad23f95dcae8edc3cd3620eae62f7946eceda97c4e68f8"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyphen/dumyhyph.tex",
"bytes": 419,
"sha256": "99d210320228a242478c36c0dfde48c7513e4495d4feea7fe3997aab27582dfc"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyphen/hyphen.tex",
"bytes": 27860,
"sha256": "2c18acdc04c1a066aeb1759905e7ca449f0616c314b5ed6aebe55b9d4a89b8d4"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/hyphen/zerohyph.tex",
"bytes": 402,
"sha256": "80b6e5b7ff3bcd2ff1d32599f9fcd7d3aa40a4c67aa06f72527dd6eb741b551c"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/knuth-lib/null.tex",
"bytes": 212,
"sha256": "f97bbac8e7e0f3ff0cd1b9ac9cb42894ffe58464c6e05d0f566455a94d15d6f0"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/pdftex/glyphtounicode.tex",
"bytes": 216747,
"sha256": "395e568c1f4db5e89013e6aa4aac22a668b543256a20b4349436070356870851"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/tex-ini-files/pdftexconfig.tex",
"bytes": 549,
"sha256": "4d3b409dd8899980dc75f91cceb5f018f941a8bcbc5ef14b79ff8560b373aa37"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/unicode-data/CaseFolding.txt",
"bytes": 87539,
"sha256": "ff8d8fefbf123574205085d6714c36149eb946d717a0c585c27f0f4ef58c4183"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/unicode-data/GraphemeBreakProperty.txt",
"bytes": 99377,
"sha256": "d6b51d1d2ae5c33b451b7ed994b48f1f4dc62b2272a5831e7fd418514a6bae89"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/unicode-data/SpecialCasing.txt",
"bytes": 17049,
"sha256": "efc25faf19de21b92c1194c111c932e03d2a5eaf18194e33f1156e96de4c9588"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/unicode-data/UnicodeData.txt",
"bytes": 2198209,
"sha256": "2e1efc1dcb59c575eedf5ccae60f95229f706ee6d031835247d843c11d96470c"
},
{
"namespace": "TEXMFDIST",
"path": "tex/generic/unicode-data/WordBreakProperty.txt",
"bytes": 114445,
"sha256": "72274cac1e6b919507db35655c3e175aa27274668a1ece95c28d2069f2ad9852"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/atveryend/atveryend.sty",
"bytes": 1695,
"sha256": "2e84f857c2b0aa670d1d11588b14740bfed4a9f3dd816997e5da3372874e9eaa"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/article.cls",
"bytes": 20144,
"sha256": "f9c8770a909e5b6526eb72284e457cd379b9bedbf3b508a96bd7f922d4cb24ec"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/atbegshi-ltx.sty",
"bytes": 2963,
"sha256": "27c4c97014158dbab3e6c5ddbdae9953ead40da7158e83a6d9aff571a6391577"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/atveryend-ltx.sty",
"bytes": 2378,
"sha256": "848443ae8cd053c59629e5869d39edad1957ffa6ebc7901b4d3cccb3b7f7de6a"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/fontmath.cfg",
"bytes": 1978,
"sha256": "453562f623cd0bbf738f0811e3432f02aff2d39ef1fb3d2d979bdf356fe1ba25"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/fontmath.ltx",
"bytes": 24944,
"sha256": "9fd31d60ad1ecf79be9a44693eaba6c20bf1a780e41efbe9ace8bc0417c3737a"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/fonttext.cfg",
"bytes": 1978,
"sha256": "06a5278ca8b02a4b1660011a2745060ef53045f2224c8e006ab7ef5b291d9c39"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/fonttext.ltx",
"bytes": 3317,
"sha256": "d0eae62e8fb5164f93c14cfe61b09545d59e56317bf37d23ac7952c07b802d91"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/latex.ltx",
"bytes": 765547,
"sha256": "95c2ef02c2d92aa29e4a77a5e5a7d9f25b5589143d1e879fb80ffa0b20be1e6d"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/omlcmm.fd",
"bytes": 2332,
"sha256": "e0681a94d7d050054e80fb9f2d488e8c8cd05bcddda8a24abd85e48f6462ac11"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/omlenc.def",
"bytes": 1947,
"sha256": "9fbe93cc1bd098b73a2b9baeb18fcda1daeb05629b86150e29974a6b02b3253b"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/omscmsy.fd",
"bytes": 2262,
"sha256": "29486e41444fffb963d8454a220aa80b507d2e798867aea7a4e50c7d40810293"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/omsenc.def",
"bytes": 2739,
"sha256": "bc16b36cf9589d086d67d8dfe68779e4ee2e3e38cc198e6e9f8855d4356850e7"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/omsenc.dfu",
"bytes": 1990,
"sha256": "c2e604b1808969aa2d2ec2217105e8c4d55f5563541583798e858eca6cea7c71"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/omxcmex.fd",
"bytes": 2040,
"sha256": "4794f162c9f328ae01a85d632da18bf5149f915958f677bbc5ff8c6a298d8331"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ot1cmr.fd",
"bytes": 3705,
"sha256": "c0519dd4765bbd696713d4825cb13bc7e96a96fdc9ee2079501cba00e232b0ec"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ot1cmss.fd",
"bytes": 3152,
"sha256": "496718763c3728117d19be4ea5a28f60cbe3e36bf59c101411774923c6655fa9"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ot1cmtt.fd",
"bytes": 2909,
"sha256": "614deabbbd3914169a17c9b0ad8d0885fef679db0d7ffe0ebb0ff2d30798cca4"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ot1enc.def",
"bytes": 4781,
"sha256": "aae56e6438e717dfea948a3d92210fa1feac4c4e8e54ff8dcbf4bd863977879e"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ot1enc.dfu",
"bytes": 3534,
"sha256": "49546a5c2b9dac9b6fd1b88f77a17bf047268143774e59f26728068c6c0062bc"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/preload.cfg",
"bytes": 1977,
"sha256": "6d041ac05f2357153f291a90b725ab674fa9d721408ec10e6113261bbbdbe121"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/preload.ltx",
"bytes": 2024,
"sha256": "1f54b83e5ce511e375ac04399e8e4a5a79c897813ad47f25d317060de62cb96d"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/size10.clo",
"bytes": 8448,
"sha256": "2896162dd5ed894689ca1f336fe2e084007114dc07f8ab17203281911479548f"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/size11.clo",
"bytes": 8464,
"sha256": "f2a208d3ff388ce24290aac6a36c9edb20e10bc7ea5b5a6222e965b91fc4132d"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/size12.clo",
"bytes": 8449,
"sha256": "1fa2b9b8a83a342cbf5fcd90bda383099b130c9e347891cb20d9e7e6924bde89"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/t1cmr.fd",
"bytes": 2569,
"sha256": "7e50fbc42f64da3194e17dafefa2f7f7166fd4fed1c44eedfc2e1a5357e7e612"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/t1cmss.fd",
"bytes": 2641,
"sha256": "7baf2a0df1f3e7ff3f286c117a0f2b5519494f681b25dc536adf5f7336196fd6"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/t1cmtt.fd",
"bytes": 2443,
"sha256": "e673449acc838b508ec83ad8ac213c70beaeeb0374daa4226ec28cebd79f7516"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/t1enc.def",
"bytes": 11012,
"sha256": "423d5dfaa6283806e22229e6885fa39d3c77d264671ad4f51083004f6c4c4d0a"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/t1enc.dfu",
"bytes": 12786,
"sha256": "2b9d78a9402f0915485484a9a778073d18515a5299c054eb7c26d2e10b767c7d"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/texsys.cfg",
"bytes": 8067,
"sha256": "a0986d94c81fd7ce2251695a1affc58060055ccc9430483e64a73f4aa5e53306"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ts1cmr.fd",
"bytes": 2466,
"sha256": "7e7a1d251a9bcbeadce179e7731710d8ebe308f5dd24dff7d16fcd6a6c67da42"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ts1cmss.fd",
"bytes": 2411,
"sha256": "ff0bf4aa034205784dafc6cec30a7a26e67f40d6035786f918f6b14cfccb63b8"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ts1cmtt.fd",
"bytes": 2324,
"sha256": "217325a82a349031f36d75342e8e02431dc94a770cee1b347a7e2324019cbd55"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ts1enc.def",
"bytes": 8090,
"sha256": "4f69a99eeffa5ac70ec245672756e47870b88b7be9cd1a48bc575bdbc2acef16"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ts1enc.dfu",
"bytes": 5133,
"sha256": "cd9aec2ee54900b244c8ee5c4faa1ea4e97f1668e49452e8a3bc173fb7351e03"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/ucmr.fd",
"bytes": 3680,
"sha256": "db0bcaa76c20a89d8a47df51532cad944b48d57137c4676d1ebfbfc234957cb0"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/base/utf8.def",
"bytes": 11506,
"sha256": "391ea8a922cedd4aab7f7843b0156e56192c9030ba93359679ea0d6de53b43c2"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/l3backend/l3backend-pdftex.def",
"bytes": 30909,
"sha256": "3bf193bc2caafa410a92881b34e997dddced870a7bfe73902118d62695c3c920"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/l3kernel/expl3-code.tex",
"bytes": 1379042,
"sha256": "12dbfa350f7e1b8d056f883726327e653c5c778aa95ea12112a06ebde8d97a74"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/l3kernel/expl3.ltx",
"bytes": 5632,
"sha256": "05826ac6fe3bc16f74704be6bb29bd8a7c05b28f9403c80f0eeca9912f8b7656"
},
{
"namespace": "TEXMFDIST",
"path": "tex/latex/tex-ini-files/pdflatex.ini",
"bytes": 130,
"sha256": "ee7cfc155f6121a97fef60881d972d7a900c9267909d476da0698e1954d49d03"
},
{
"namespace": "TEXMFSYSVAR",
"path": "fonts/map/pdftex/updmap/pdftex.map",
"bytes": 280328,
"sha256": "90a4b16f0289640fb7711d615adeb3dbb0d8decc71ea781b606b34fa95b8e736"
}
],
"required_cases": [
"a0-minimal",
"a1-fonts-10",
"a1-fonts-11",
"a1-fonts-12",
"a2-math",
"a3-pages",
"a4-project"
],
"raster_gate": {
"dpi": 144,
"coverage_radius_pixels": 1,
"bbox_pixels": 1,
"max_xor_ratio": 0.01
},
"geometry_gate": {
"native_list_sp": 1,
"pdf_word_box_bp": 0.02
},
"scope": "Reference inputs only; generated fmt/aux/PDF are artifacts, not native implementation evidence."
}
+238
View File
@@ -0,0 +1,238 @@
//! Live terminal/log/status and output protection around native show diagnostics.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::{Path, PathBuf},
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-context-cli-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
fn native(dir: &Path) -> std::process::Output {
native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "native.pdf"])
.current_dir(dir)
.output()
.unwrap()
}
fn reference(dir: &Path, fatal: bool) -> String {
let mut c = Command::new("pdftex");
c.args(["-ini", "-etex", "-interaction=nonstopmode"]);
if fatal {
c.arg("-halt-on-error");
}
let o = c
.arg("probe.tex")
.current_dir(dir)
.output()
.expect("real INITEX required");
assert_eq!(o.status.code(), Some(1));
String::from_utf8(o.stdout).unwrap()
}
#[test]
fn real_show_diagnostics_match_both_channels_and_continue_file_io_and_pdf_with_status_one() {
let dir = directory();
let source = "\\catcode123=1\\catcode125=2\\catcode35=6\\errorcontextlines=100\n\\font\\rm=cmr10\\rm\\hsize=200pt\n\\long\\def\\A#1{hello #1}\\show\\A\n\\count0=13\\showthe\\count0\\relax\n\\message{AFTER_DIAGNOSTICS}\\immediate\\openout1=real.aux \\immediate\\write1{ACTUAL=\\the\\count0}\\immediate\\closeout1\n\\noindent Still renders after diagnostics.\\par\\end\n";
fs::write(dir.join("probe.tex"), source).unwrap();
let r = reference(&dir, false);
let n = native(&dir);
assert_eq!(n.status.code(), Some(1));
let terminal = String::from_utf8(n.stderr).unwrap();
assert!(!terminal.contains("error:"), "{terminal}");
let exact = &r[r.find("> ").unwrap()..r.find("AFTER_DIAGNOSTICS").unwrap()];
let log = fs::read_to_string(dir.join("native.log")).unwrap();
assert!(
terminal.contains(exact),
"native:\n{terminal}\nreference:\n{r}"
);
let reference_log = fs::read_to_string(dir.join("probe.log")).unwrap();
let exact_log = &reference_log
[reference_log.find("> ").unwrap()..reference_log.find("AFTER_DIAGNOSTICS").unwrap()];
assert!(log.contains(exact_log), "{log}\n{reference_log}");
assert_eq!(
fs::read_to_string(dir.join("real.aux")).unwrap(),
"ACTUAL=13\n"
);
assert!(
fs::read(dir.join("native.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
let text = Command::new("pdftotext")
.args(["native.pdf", "-"])
.current_dir(&dir)
.output()
.unwrap();
assert!(text.status.success());
assert_eq!(
String::from_utf8(text.stdout)
.unwrap()
.split_whitespace()
.collect::<Vec<_>>(),
["Still", "renders", "after", "diagnostics."]
);
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn fatal_after_show_keeps_existing_pdf_and_logs_actual_context_without_becoming_legal_show_status()
{
let dir = directory();
let source = "\\catcode123=1\\catcode125=2\\catcode35=6\\errorcontextlines=100\n\\show\\relax\n\\def\\A#1{#1\\relax}\\A{\\bad\\relax}\\end\n";
fs::write(dir.join("probe.tex"), source).unwrap();
fs::write(dir.join("native.pdf"), b"KEEP").unwrap();
let r = reference(&dir, false);
let n = native(&dir);
assert_eq!(n.status.code(), Some(1));
let terminal = String::from_utf8(n.stderr).unwrap();
assert!(terminal.contains("error:"));
assert!(terminal.contains("undefined native control sequence"));
assert!(!terminal.contains("\nUNREACHABLE\n"));
let exact = r
.split_once("! Undefined control sequence.\n")
.unwrap()
.1
.split_once(" )\n")
.unwrap()
.0;
assert!(terminal.contains(exact), "{terminal}\n{r}");
let log = fs::read_to_string(dir.join("native.log")).unwrap();
assert!(log.contains(exact));
assert!(log.contains("! undefined native control sequence"));
assert_eq!(fs::read(dir.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(dir.join("probe.tex")).unwrap(), source);
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn real_read_rejects_outer_tokens_and_readline_keeps_the_same_file_bytes_literal() {
let dir = directory();
let data = b"\\A\n";
fs::write(dir.join("data.tex"), data).unwrap();
for (primitive, success) in [("read", false), ("readline", true)] {
let source = format!(
"\\catcode123=1\\catcode125=2\\endlinechar=-1\n\\outer\\def\\A{{YES}}\\openin0=data.tex \\{primitive}0 to\\B \\message{{READLINE=\\meaning\\B}}\\end\n"
);
fs::write(dir.join("probe.tex"), &source).unwrap();
fs::write(dir.join("native.pdf"), b"KEEP").unwrap();
let r = Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"probe.tex",
])
.current_dir(&dir)
.output()
.expect("real INITEX required");
let n = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"trace.json",
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert_eq!(
r.status.success(),
success,
"{}",
String::from_utf8_lossy(&r.stdout)
);
assert_eq!(
n.status.success(),
success,
"{}",
String::from_utf8_lossy(&n.stderr)
);
let terminal = String::from_utf8(n.stderr).unwrap();
if success {
assert!(terminal.contains(r"READLINE=macro:->\A"), "{terminal}");
assert!(
String::from_utf8(r.stdout)
.unwrap()
.contains(r"READLINE=macro:->\A")
);
} else {
assert!(terminal.contains("forbidden outer"), "{terminal}");
assert!(terminal.contains("data.tex:1:1"), "{terminal}");
}
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("trace.json")).unwrap()).unwrap();
assert_eq!(trace["stream_reads"][0]["bytes"], data.len());
assert_eq!(fs::read(dir.join("data.tex")).unwrap(), data);
assert_eq!(fs::read(dir.join("native.pdf")).unwrap(), b"KEEP");
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn interaction_modes_route_actual_messages_like_initex() {
let dir = directory();
let source = r"\catcode123=1\catcode125=2
\message{START=\the\interactionmode}
{\interactionmode=0\message{HIDDEN=\the\interactionmode}}
\ifnum\interactionmode=0 \message{AFTERGROUP=0}\fi
\nonstopmode\message{VISIBLE=\the\interactionmode}
\def\modereport{\message{ASSIGNED=\the\interactionmode}}
\afterassignment\modereport\scrollmode\message{SCROLL=\the\interactionmode}
\errorstopmode\message{ERRORSTOP=\the\interactionmode}
\global\batchmode\message{BATCH=\the\interactionmode}
\end";
fs::write(dir.join("probe.tex"), source).unwrap();
let oracle = Command::new("pdftex")
.args(["-ini", "-etex", "-interaction=nonstopmode", "probe.tex"])
.current_dir(&dir)
.output()
.expect("real INITEX required");
assert!(
oracle.status.success(),
"{}",
String::from_utf8_lossy(&oracle.stdout)
);
let actual = native(&dir);
assert!(
actual.status.success(),
"{}",
String::from_utf8_lossy(&actual.stderr)
);
let oracle_terminal = String::from_utf8(oracle.stdout).unwrap();
let native_terminal = String::from_utf8(actual.stderr).unwrap();
let oracle_log = fs::read_to_string(dir.join("probe.log")).unwrap();
let native_log = fs::read_to_string(dir.join("native.log")).unwrap();
for message in [
"START=1",
"HIDDEN=0",
"AFTERGROUP=0",
"VISIBLE=1",
"ASSIGNED=2",
"SCROLL=2",
"ERRORSTOP=3",
"BATCH=0",
] {
assert!(
oracle_log.contains(message) && native_log.contains(message),
"{message}:\n{native_log}"
);
assert_eq!(
oracle_terminal.contains(message),
native_terminal.contains(message),
"{message}:\n{native_terminal}"
);
}
fs::remove_dir_all(dir).unwrap();
}
+138
View File
@@ -0,0 +1,138 @@
//! Actual native PDF device state, without changing original TeX geometry.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-device-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn real_device_fixture_keeps_each_physical_page_and_actual_late_aux_writes() {
let p = directory();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let source = root.join("examples/native-bootstrap/device.tex");
let before = fs::read(&source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
])
.arg(&source)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let r = Command::new("pdfinfo")
.args(["-f", "1", "-l", "3", "native.pdf"])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success());
let text = String::from_utf8(r.stdout).unwrap();
let sizes: Vec<Vec<f64>> = text
.lines()
.filter(|s| s.starts_with("Page"))
.filter_map(|s| {
s.split_once("size:").map(|(_, s)| {
s.split_whitespace()
.take(3)
.filter_map(|s| s.parse().ok())
.collect()
})
})
.collect();
assert_eq!(sizes.len(), 3, "{text}");
assert_eq!(sizes[0], [320.0, 240.0]);
assert_eq!(sizes[1], [280.0, 210.0]);
assert!((sizes[2][0] - 255.104).abs() < 0.002, "{text}");
assert_eq!(
fs::read(p.join("device.aux")).unwrap(),
b"SHIP=1;MAG=1200\nSHIP=2;MAG=1200\nSHIP=3;MAG=1200\n"
);
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
for suffix in [
"device.tex",
"math-fonts.tex",
"cmr10.tfm",
"cmmi7.tfm",
"cmr10.pfb",
"cmmi7.pfb",
] {
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|v| v["path"].as_str().unwrap().ends_with(suffix)),
"missing {suffix}"
);
}
assert_eq!(fs::read(source).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn illegal_or_incompatible_magnification_and_huge_pages_protect_existing_pdf() {
let p = directory();
for (body, expected) in [
(r"\mag=0\shipout\hbox{}\end", "magnification"),
(r"\mag=-1\dimen0=1truept\end", "magnification"),
(r"\mag=32769\shipout\hbox{}\end", "magnification"),
(
r"\mag=1200\dimen0=1truept\mag=1000\shipout\hbox{}\end",
"magnification",
),
(
r"\shipout\hbox{}\mag=1200\shipout\hbox{}\end",
"magnification",
),
(
r"\hoffset=16383pt\shipout\hbox{\vrule width100pt}\end",
"huge native page",
),
(r"\pdfgamma=1000\end", "undefined native control sequence"),
] {
let source = format!("\\catcode123=1\\catcode125=2\n{body}\n");
fs::write(p.join("probe.tex"), &source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert_eq!(r.status.code(), Some(1), "{body}");
assert!(
String::from_utf8_lossy(&r.stderr).contains(expected),
"{body}: {}",
String::from_utf8_lossy(&r.stderr)
);
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
}
fs::remove_dir_all(p).unwrap();
}
+526
View File
@@ -0,0 +1,526 @@
//! Actual dynamic fonts, PDF embedding and late resource I/O through the CLI.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-dynamic-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn mathematical_font_descriptors_widths_and_word_positions_match_real_pdftex() {
let p = directory();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let fixture = root.join("examples/native-bootstrap/math-operators.tex");
let before = fs::read(&fixture).unwrap();
let output = native_fonts::command()
.args(["native", "--initex", "--etex"])
.arg(&fixture)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
fs::write(p.join("reference.tex"),format!(r"\pdfoutput=1\pdfobjcompresslevel=0\pdfpagewidth=612bp\pdfpageheight=792bp\vsize=648bp\topskip=10bp\input {}",fixture.display())).unwrap();
let output = Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"reference.tex",
])
.env(
"TEXINPUTS",
format!("{}:", fixture.parent().unwrap().display()),
)
.current_dir(&p)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stdout)
);
let script = r#"
import re,subprocess,xml.etree.ElementTree as ET
from pathlib import Path
def inspect(name):
data=Path(name).read_bytes()
objects={int(m[1]):m[2]for m in re.finditer(rb'(?ms)(\d+) 0 obj\s*(.*?)\s*endobj',data)}
metrics={};widths={}
for body in objects.values():
if re.search(rb'/Type\s*/FontDescriptor\b',body):
font=re.search(rb'/FontName\s*/([^\s/]+)',body)[1].decode().split('+')[-1]
metrics[font]=[int(re.search(rb'/'+key+rb'\s+(-?\d+)',body)[1])for key in [b'Ascent',b'Descent',b'CapHeight',b'XHeight']]
if re.search(rb'/Subtype\s*/Type1\b',body):
font=re.search(rb'/BaseFont\s*/([^\s/]+)',body)[1].decode().split('+')[-1]
first=int(re.search(rb'/FirstChar\s+(\d+)',body)[1])
inline=re.search(rb'/Widths\s*\[([^]]*)\]',body)
if inline: values=inline[1]
else: values=objects[int(re.search(rb'/Widths\s+(\d+) 0 R',body)[1])].strip()[1:-1]
widths[font]=(first,[float(n)for n in values.split()])
words=[(w.text,{k:float(v)for k,v in w.attrib.items()})for w in ET.fromstring(subprocess.check_output(['pdftotext','-bbox',name,'-'])).iter()if w.tag.endswith('}word')]
return metrics,widths,words
a,b=inspect('native.pdf'),inspect('reference.pdf')
assert 'CMEX10' in a[0]
assert a[0]==b[0],(a[0],b[0])
assert a[1]==b[1],(a[1],b[1])
assert [w[0]for w in a[2]]==[w[0]for w in b[2]]
error=max(abs(x[1][k]-y[1][k])for x,y in zip(a[2],b[2])for k in x[1])
assert error<=0.02,error
print(len(a[2]),'actual words, exact font descriptors/widths, maximum bbox error:',error)
"#;
let output = Command::new("python3")
.args(["-c", script])
.current_dir(&p)
.output()
.unwrap();
assert!(
output.status.success(),
"{}\n{}\n{p:?}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(fs::read(fixture).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn requested_resources_sizes_and_font_programs_reach_the_actual_pdf() {
let p = directory();
let source = include_bytes!("../examples/native-bootstrap/dynamic-fonts.tex");
fs::write(p.join("probe.tex"), source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
"probe.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
assert_eq!(fs::read(p.join("probe.tex")).unwrap(), source);
let fonts = Command::new("pdffonts")
.arg(p.join("native.pdf"))
.output()
.unwrap();
assert!(fonts.status.success());
let fonts = String::from_utf8(fonts.stdout).unwrap();
for name in ["CMR10", "CMR7", "CMBX10", "CMTI10", "CMTT10", "CMSS10"] {
assert!(
fonts
.lines()
.any(|l| l.starts_with(name) && l.contains("Type 1") && l.contains("yes")),
"{fonts}"
);
}
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
for stem in ["cmr10", "cmr7", "cmbx10", "cmti10", "cmtt10", "cmss10"] {
for ext in ["tfm", "pfb"] {
assert!(
trace["reads"].as_array().unwrap().iter().any(|r| r["path"]
.as_str()
.unwrap()
.ends_with(&format!("/{stem}.{ext}"))),
"missing actual {stem}.{ext}: {trace}"
);
}
}
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with("/pdftex.map"))
);
let text = Command::new("pdftotext")
.args([p.join("native.pdf").to_str().unwrap(), "-"])
.output()
.unwrap();
assert!(text.status.success());
let text = String::from_utf8(text.stdout).unwrap();
for s in [
"Real native fonts",
"bold text",
"italic text",
"mono text",
"sans text",
"without replacement",
] {
assert!(text.contains(s), "{text}");
}
fs::remove_dir_all(p).unwrap();
}
#[test]
fn tfm_only_measurement_needs_no_outline_and_missing_output_resources_protect_pdf() {
let p = directory();
let empty = p.join("empty");
fs::create_dir(&empty).unwrap();
fs::write(p.join("measure.tex"),br"\catcode123=1\catcode125=2\font\F=cmr10 at12pt\setbox0=\hbox{\F AV}\message{WIDTH=\number\wd0}\end").unwrap();
let r = native_fonts::command()
.env("T1FONTS", &empty)
.env("TEXFONTMAPS", &empty)
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"measure.json",
"measure.tex",
"measure.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
assert!(!p.join("measure.pdf").exists());
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("measure.json")).unwrap()).unwrap();
assert!(
trace["reads"].as_array().unwrap().iter().all(|r| !r["path"]
.as_str()
.unwrap()
.ends_with(".pfb")
&& !r["path"].as_str().unwrap().ends_with(".map"))
);
fs::write(p.join("draw.tex"),br"\catcode123=1\catcode125=2\font\F=cmr10 at12pt\F\hsize=100pt\baselineskip=12pt\parfillskip=0pt plus1fil AV\par\end").unwrap();
fs::write(p.join("keep.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.env("T1FONTS", &empty)
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"missing.json",
"draw.tex",
"keep.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert!(!r.status.success());
assert!(
String::from_utf8_lossy(&r.stderr).contains("cmr10.pfb"),
"{}",
String::from_utf8_lossy(&r.stderr)
);
assert_eq!(fs::read(p.join("keep.pdf")).unwrap(), b"KEEP");
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("missing.json")).unwrap()).unwrap();
assert!(trace["lookups"].as_array().unwrap().iter().any(|r| {
r["kind"] == "Type1"
&& r["name"] == "cmr10.pfb"
&& r["resolved"].is_null()
&& r["candidates"]
.as_array()
.is_some_and(|c| c.contains(&serde_json::json!(empty.join("cmr10.pfb"))))
}));
assert!(
!trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["path"].as_str().is_some_and(|p| p.ends_with("cmr10.pfb")))
);
fs::remove_dir_all(p).unwrap();
}
fn raster(path: &std::path::Path, base: &std::path::Path) -> (usize, usize, Vec<u8>) {
let r = Command::new("pdftoppm")
.args(["-singlefile", "-gray", "-r", "144"])
.arg(path)
.arg(base)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let bytes = fs::read(base.with_extension("pgm")).unwrap();
let (mut at, mut fields) = (0, Vec::new());
for _ in 0..4 {
while bytes[at].is_ascii_whitespace() {
at += 1;
}
let start = at;
while !bytes[at].is_ascii_whitespace() {
at += 1;
}
fields.push(std::str::from_utf8(&bytes[start..at]).unwrap());
}
assert_eq!(fields[0], "P5");
assert_eq!(fields[3], "255");
let w = fields[1].parse::<usize>().unwrap();
let h = fields[2].parse::<usize>().unwrap();
at += 1;
let pixels = bytes[at..].to_vec();
assert_eq!(pixels.len(), w * h);
(w, h, pixels)
}
#[test]
fn external_encoding_and_map_syntax_use_actual_program_glyphs_like_pdftex() {
let p = directory();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
fs::copy(
root.join("crates/texrra-tex-core/assets/cmr10.tfm"),
p.join("fancy.tfm"),
)
.unwrap();
fs::copy(root.join("assets/fonts/cmr10.pfb"), p.join("cmr10.pfb")).unwrap();
let mut encoding = vec![".notdef"; 256];
encoding[65] = "W";
encoding[86] = "V";
fs::write(
p.join("custom.enc"),
format!(
"/NativeEncoding [\n{}\n] def\n",
encoding
.iter()
.map(|n| format!("/{n}"))
.collect::<Vec<_>>()
.join(" ")
),
)
.unwrap();
let source = format!(
r"\catcode123=1\catcode125=2\font\F={}/fancy at12pt\F\hsize=100pt\parindent=0pt\baselineskip=12pt\parfillskip=0pt plus1fil AV AV\par\end",
p.display()
);
fs::write(p.join("native.tex"), &source).unwrap();
fs::write(
p.join("reference.tex"),
format!(
r"\pdfoutput=1\pdfpagewidth=612bp\pdfpageheight=792bp\vsize=648bp\topskip=10bp {source}"
),
)
.unwrap();
for (spec, reencoded) in [
(
r#"" NativeEncoding ReEncodeFont " <custom.enc <cmr10.pfb"#,
true,
),
(
r#"" DifferentName ReEncodeFont " <custom.enc <cmr10.pfb"#,
true,
),
("<[custom.enc <cmr10.pfb", true),
(r#"" ReEncodeFont " <custom.enc <cmr10.pfb"#, true),
(r#"" ignoredword " <custom.enc <cmr10.pfb"#, true),
(r#"" DifferentName ReEncodeFont " <cmr10.pfb"#, false),
] {
fs::write(p.join("pdftex.map"), format!("fancy CMR10 {spec}\n")).unwrap();
let r = native_fonts::command()
.env("TEXFONTMAPS", &p)
.env("T1FONTS", &p)
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"trace.json",
"native.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert!(
r.status.success(),
"{spec}\n{}",
String::from_utf8_lossy(&r.stderr)
);
let r = Command::new("pdftex")
.env("TEXFONTMAPS", &p)
.env("T1FONTS", &p)
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"reference.tex",
])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stdout));
let a = raster(&p.join("native.pdf"), &p.join("native-ink"));
let b = raster(&p.join("reference.pdf"), &p.join("reference-ink"));
assert_eq!((a.0, a.1), (b.0, b.1));
let w = a.0 as isize;
for (x, y) in [(&a.2, &b.2), (&b.2, &a.2)] {
let unmatched = x
.iter()
.enumerate()
.filter(|(i, v)| {
**v < 200
&& !(-1..=1).any(|dy| {
(-1..=1).any(|dx| {
y.get((*i as isize + dy * w + dx) as usize)
.is_some_and(|p| *p < 200)
})
})
})
.count();
assert_eq!(unmatched, 0, "{spec}");
}
let texts: [String; 2] = ["native.pdf", "reference.pdf"].map(|name| {
let r = Command::new("pdftotext")
.arg(p.join(name))
.arg("-")
.output()
.unwrap();
assert!(r.status.success());
String::from_utf8(r.stdout).unwrap()
});
assert_eq!(texts[0], texts[1], "{spec}");
assert!(texts[0].contains(if reencoded { "WV WV" } else { "AV AV" }));
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("trace.json")).unwrap()).unwrap();
assert_eq!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with("/custom.enc")),
reencoded
);
}
// A mapped name which has no actual CharString must fail, not paint blank.
encoding[65] = "MissingGlyphProgram";
fs::write(
p.join("custom.enc"),
format!(
"/NativeEncoding [{}] def",
encoding
.iter()
.map(|n| format!("/{n}"))
.collect::<Vec<_>>()
.join(" ")
),
)
.unwrap();
fs::write(p.join("pdftex.map"), "fancy CMR10 <custom.enc <cmr10.pfb\n").unwrap();
fs::write(p.join("native.pdf"), b"PRESERVE").unwrap();
let r = native_fonts::command()
.env("TEXFONTMAPS", &p)
.env("T1FONTS", &p)
.args(["native", "--initex", "native.tex", "native.pdf"])
.current_dir(&p)
.output()
.unwrap();
assert!(!r.status.success());
assert!(String::from_utf8_lossy(&r.stderr).contains("MissingGlyphProgram"));
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"PRESERVE");
fs::remove_dir_all(p).unwrap();
}
#[test]
fn only_selected_discretionary_material_requests_its_actual_font_program() {
let p = directory();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let fonts = p.join("fonts");
fs::create_dir(&fonts).unwrap();
fs::copy(root.join("assets/fonts/cmr10.pfb"), fonts.join("cmr10.pfb")).unwrap();
let source = |penalty: i32| {
format!(
r"\catcode123=1\catcode125=2\font\body=cmr10\font\alt=cmss10 at12pt\body\hsize=100pt\baselineskip=15pt\rightskip=0pt plus1fil\parfillskip=0pt plus1fil\pretolerance=10000\hyphenpenalty={penalty} A\discretionary{{\alt P}}{{\alt Q}}{{R}}B\par\end"
)
};
let run = |stem: &str| {
native_fonts::command()
.env("T1FONTS", &fonts)
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
&format!("{stem}.json"),
&format!("{stem}.tex"),
&format!("{stem}.pdf"),
])
.current_dir(&p)
.output()
.unwrap()
};
let text = |stem: &str| {
let r = Command::new("pdftotext")
.args(["-layout"])
.arg(p.join(format!("{stem}.pdf")))
.arg("-")
.output()
.unwrap();
assert!(r.status.success());
String::from_utf8(r.stdout).unwrap()
};
fs::write(p.join("unbroken.tex"), source(10000)).unwrap();
let r = run("unbroken");
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
assert!(text("unbroken").contains("ARB"));
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("unbroken.json")).unwrap()).unwrap();
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with("cmss10.tfm"))
);
assert!(
!trace["lookups"]
.as_array()
.unwrap()
.iter()
.any(|r| r["name"] == "cmss10.pfb"),
"unselected alternatives must not read outlines"
);
fs::write(p.join("broken.tex"), source(-10000)).unwrap();
fs::write(p.join("broken.pdf"), b"KEEP").unwrap();
let r = run("broken");
assert!(!r.status.success());
assert!(String::from_utf8_lossy(&r.stderr).contains("cmss10.pfb"));
assert_eq!(fs::read(p.join("broken.pdf")).unwrap(), b"KEEP");
fs::copy(
root.join("assets/fonts/cmss10.pfb"),
fonts.join("cmss10.pfb"),
)
.unwrap();
let r = run("broken");
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let printed = text("broken");
assert!(
printed.contains("AP") && printed.contains("QB") && !printed.contains('R'),
"{printed}"
);
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("broken.json")).unwrap()).unwrap();
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with("cmss10.pfb"))
);
assert_eq!(
fs::read_to_string(p.join("broken.tex")).unwrap(),
source(-10000)
);
fs::remove_dir_all(p).unwrap();
}
+524
View File
@@ -0,0 +1,524 @@
//! The native CLI enters the Route-D executor before the server/v1 compiler.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let path = std::env::temp_dir().join(format!(
"texrra-native-cli-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&path).unwrap();
path
}
#[test]
fn native_cli_executes_input_macros_registers_and_exports_a_real_pdf() {
let directory = directory();
fs::write(
directory.join("bootstrap.tex"),
r"\countdef\counter=0 \counter=4 \def\greet#1{Hello, #1.}\endinput",
)
.unwrap();
fs::write(directory.join("main.tex"), "\\input bootstrap\n\\message{NATIVE-READY=\\the\\counter}\n\\greet{Route-D}\\par\n{\\counter=9 \\greet{local}}\\par\n\\ifnum\\counter=4 Bootstrap restored.\\else BAD\\fi\\end\n").unwrap();
let output = native_fonts::command()
.args(["native", "main.tex", "native.pdf"])
.current_dir(&directory)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stdout).contains("native Route-D"));
assert!(String::from_utf8_lossy(&output.stderr).contains("NATIVE-READY=4"));
let pdf = fs::read(directory.join("native.pdf")).unwrap();
assert!(pdf.starts_with(b"%PDF-"));
match Command::new("pdftotext")
.args(["native.pdf", "native.txt"])
.current_dir(&directory)
.output()
{
Ok(output) => {
assert!(output.status.success());
let text = fs::read_to_string(directory.join("native.txt")).unwrap();
assert!(text.contains("Hello, Route-D."), "{text}");
assert!(text.contains("Hello, local."), "{text}");
assert!(text.contains("Bootstrap restored."), "{text}");
assert!(!text.contains("BAD"), "{text}");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: native PDF text check skipped")
}
Err(e) => panic!("{e}"),
}
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn unsupported_native_latex_is_an_error_and_cannot_overwrite_an_existing_pdf() {
let directory = directory();
fs::write(
directory.join("unsupported.tex"),
"\\documentclass{article}\n\\begin{document}Text\\end{document}",
)
.unwrap();
fs::write(directory.join("existing.pdf"), b"preserve").unwrap();
let output = native_fonts::command()
.args(["native", "unsupported.tex", "existing.pdf"])
.current_dir(&directory)
.output()
.unwrap();
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr).contains("undefined native control sequence"));
assert!(String::from_utf8_lossy(&output.stderr).contains("unsupported.tex:1:1"));
assert_eq!(
fs::read(directory.join("existing.pdf")).unwrap(),
b"preserve"
);
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn native_pdf_rejects_overwriting_its_source() {
let directory = directory();
fs::write(directory.join("main.tex"), "Keep this source.").unwrap();
let output = native_fonts::command()
.args(["native", "main.tex", "main.tex"])
.current_dir(&directory)
.output()
.unwrap();
assert!(!output.status.success());
assert_eq!(
fs::read_to_string(directory.join("main.tex")).unwrap(),
"Keep this source."
);
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn native_initex_starts_without_format_category_setup() {
let directory = directory();
fs::write(directory.join("init.tex"), r"\ifnum\catcode123=12 \catcode123=1 \catcode125=2 \message{INITEX-YES}\else\message{WRONG}\fi\end").unwrap();
let output = native_fonts::command()
.args(["native", "--initex", "init.tex", "init.pdf"])
.current_dir(&directory)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stderr).contains("INITEX-YES"));
assert!(!String::from_utf8_lossy(&output.stderr).contains("WRONG"));
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn native_etex_profile_executes_extended_language_without_a_preloaded_format() {
let directory = directory();
fs::write(
directory.join("etex.tex"),
concat!(
r"\catcode123=1 \catcode125=2 \catcode35=6 ",
r"\defaulthyphenchar=45 \font\nativefont=cmr10 \nativefont \hsize=468pt \baselineskip=12pt \parfillskip=0pt plus1fil ",
r"\protected\def\p{EXTENDED}\edef\saved{\p}",
r"\toks300={\saved}\count32767=\numexpr(1+2)*5/2\relax ",
r"\unless\ifnum\count32767=8 \errmessage{bad expression}\fi ",
r"\the\toks300\message{ETEX-SEMANTICS=\the\count32767}\end"
),
)
.unwrap();
let output = native_fonts::command()
.args(["native", "--initex", "--etex", "etex.tex", "etex.pdf"])
.current_dir(&directory)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stderr).contains("ETEX-SEMANTICS=8"));
assert!(
fs::read(directory.join("etex.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
let base = native_fonts::command()
.args(["native", "--initex", "etex.tex", "base.pdf"])
.current_dir(&directory)
.output()
.unwrap();
assert!(!base.status.success());
assert!(!directory.join("base.pdf").exists());
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn unmodified_latex_entry_advances_past_capability_guards_to_a_real_missing_primitive() {
let texmf = std::env::var_os("TEXRRA_ORACLE_TEXMF")
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("/usr/share/texlive/texmf-dist"));
let entry = texmf.join("tex/latex/base/latex.ltx");
if !entry.exists() {
eprintln!("installed LaTeX source absent: real format boundary probe skipped");
return;
}
let directory = directory();
let before = fs::read(&entry).unwrap();
let output = native_fonts::command()
.args(["native", "--job", "--initex", "--etex"])
.arg(&entry)
.arg(directory.join("format.pdf"))
.current_dir(&directory)
.output()
.unwrap();
assert!(
!output.status.success(),
"incomplete native format must fail"
);
let diagnostic = String::from_utf8_lossy(&output.stderr);
assert!(
diagnostic.contains("TeX errmessage: LaTeX requires expl3"),
"{diagnostic}"
);
assert!(diagnostic.contains("latex.ltx:1115:15"), "{diagnostic}");
assert!(!diagnostic.contains("LaTeX requires e-TeX"));
assert!(diagnostic.contains("./texsys.aux found"), "{diagnostic}");
let log = fs::read_to_string(directory.join("format.log")).unwrap();
assert!(log.contains(r"\maxdimen=\dimen10"), "{log}");
assert!(log.contains("parameters,"), "{log}");
let aux = fs::read_to_string(directory.join("texsys.aux")).unwrap();
assert!(aux.contains(':') && aux.ends_with("\n\n"), "{aux}");
assert!(!directory.join("format.pdf").exists());
assert_eq!(fs::read(&entry).unwrap(), before);
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn native_quantities_are_executed_and_printed_into_a_real_pdf() {
let dir = directory();
fs::write(
dir.join("quantities.tex"),
concat!(
"\\catcode123=1 \\catcode125=2 \\catcode35=6\n",
r"\defaulthyphenchar=45 \font\nativefont=cmr10 \nativefont \hsize=468pt \baselineskip=12pt \parfillskip=0pt plus1fil ",
r"\dimendef\width=300 \width=2.5pt \advance\width by1.25pt ",
r"\skipdef\flex=301 \flex=1pt plus2fil minus.5pt ",
r#"\mathchardef\symbol="1234 "#,
r"Native width: \the\width.\par Math character code: \number\symbol.\par",
r"\ifdim\width>3pt\message{QUANTITY-CHECK=OK}\else\errmessage{bad quantity}\fi\end"
),
)
.unwrap();
let output = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"quantities.tex",
"quantities.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stderr).contains("QUANTITY-CHECK=OK"));
assert!(
fs::read(dir.join("quantities.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
match Command::new("pdftotext")
.args(["quantities.pdf", "quantities.txt"])
.current_dir(&dir)
.output()
{
Ok(output) => {
assert!(output.status.success());
let text = fs::read_to_string(dir.join("quantities.txt")).unwrap();
assert!(text.contains("Native width: 3.75pt."), "{text}");
assert!(text.contains("Math character code: 4660."), "{text}");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: PDF text probe skipped")
}
Err(e) => panic!("{e}"),
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn native_initex_measures_multiple_paragraphs_and_renders_fixed_lines() {
let dir = directory();
fs::write(
dir.join("paragraphs.tex"),
include_str!("../examples/native-bootstrap/paragraphs.tex"),
)
.unwrap();
let output = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"paragraphs.tex",
"paragraphs.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(
String::from_utf8_lossy(&output.stderr)
.contains("Native paragraph construction completed.")
);
assert!(
fs::read(dir.join("paragraphs.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
match Command::new("pdftotext")
.args(["paragraphs.pdf", "paragraphs.txt"])
.current_dir(&dir)
.output()
{
Ok(output) => {
assert!(output.status.success());
let text = fs::read_to_string(dir.join("paragraphs.txt")).unwrap();
assert!(text.contains("210.0pt."), "{text}");
assert!(text.contains("previous line depth"), "{text}");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: paragraph PDF extraction skipped")
}
Err(e) => panic!("{e}"),
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn native_boxes_pack_store_copy_and_paint_actual_contents() {
let dir = directory();
fs::write(
dir.join("boxes.tex"),
include_str!("../examples/native-bootstrap/boxes.tex"),
)
.unwrap();
let output = native_fonts::command()
.args(["native", "--initex", "--etex", "boxes.tex", "boxes.pdf"])
.current_dir(&dir)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stderr).contains("Native box packing completed."));
match Command::new("pdftotext")
.args(["boxes.pdf", "boxes.txt"])
.current_dir(&dir)
.output()
{
Ok(output) => {
assert!(output.status.success());
let text = fs::read_to_string(dir.join("boxes.txt")).unwrap();
let text = text.split_whitespace().collect::<Vec<_>>().join(" ");
assert!(text.contains("Vertical top"), "{text}");
assert!(text.contains("Nested native box"), "{text}");
assert!(text.contains("beside native text."), "{text}");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: box PDF extraction skipped")
}
Err(e) => panic!("{e}"),
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn native_math_tokens_noads_families_and_penalties_render_a_real_pdf() {
let dir = directory();
fs::write(
dir.join("math-fonts.tex"),
include_str!("../examples/native-bootstrap/math-fonts.tex"),
)
.unwrap();
fs::write(
dir.join("math.tex"),
include_str!("../examples/native-bootstrap/math.tex"),
)
.unwrap();
let output = native_fonts::command()
.args(["native", "--initex", "--etex", "math.tex", "math.pdf"])
.current_dir(&dir)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(
String::from_utf8_lossy(&output.stderr).contains("Native math noad execution completed.")
);
assert!(
fs::read(dir.join("math.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
match Command::new("pdftotext")
.args(["math.pdf", "math.txt"])
.current_dir(&dir)
.output()
{
Ok(o) => {
assert!(o.status.success());
let s = fs::read_to_string(dir.join("math.txt")).unwrap();
assert!(s.contains("Restricted"), "{s}");
assert!(s.contains("Prohibited"), "{s}");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: math extraction skipped")
}
Err(e) => panic!("{e}"),
};
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn native_interline_penalties_drive_actual_multi_page_pdf_export() {
let directory = directory();
fs::write(
directory.join("interline.tex"),
include_str!("../examples/native-bootstrap/interline.tex"),
)
.unwrap();
let output = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"interline.tex",
"interline.pdf",
])
.current_dir(&directory)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stdout).contains("6 pages, native Route-D"));
assert!(
String::from_utf8_lossy(&output.stderr)
.contains("Native interline page execution completed.")
);
match Command::new("pdftotext")
.args(["-raw", "interline.pdf", "-"])
.current_dir(&directory)
.output()
{
Ok(o) => {
assert!(o.status.success());
let text = String::from_utf8(o.stdout).unwrap();
let pages: Vec<Vec<_>> = text
.split('\u{c}')
.map(|p| p.split_whitespace().collect::<Vec<_>>())
.filter(|p| !p.is_empty())
.collect();
assert_eq!(
pages,
vec![
vec!["First"],
vec!["Second", "Third", "Fourth", "Fifth"],
vec!["Sixth", "Seventh"],
vec!["Eighth"],
vec!["Ninth", "con-"],
vec!["struction", "Kept", "Together", "Here"]
]
);
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: interline PDF text check skipped")
}
Err(e) => panic!("{e}"),
}
fs::remove_dir_all(directory).unwrap();
}
#[test]
fn native_display_transitions_and_penalties_render_actual_multi_page_pdf() {
let directory = directory();
fs::write(
directory.join("display.tex"),
include_str!("../examples/native-bootstrap/display.tex"),
)
.unwrap();
fs::write(
directory.join("math-fonts.tex"),
include_str!("../examples/native-bootstrap/math-fonts.tex"),
)
.unwrap();
let output = native_fonts::command()
.args(["native", "--initex", "--etex", "display.tex", "display.pdf"])
.current_dir(&directory)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stdout).contains("3 pages, native Route-D"));
assert!(
String::from_utf8_lossy(&output.stderr).contains("Native display execution completed.")
);
match Command::new("pdftotext")
.args(["-raw", "display.pdf", "-"])
.current_dir(&directory)
.output()
{
Ok(o) => {
assert!(o.status.success());
let text = String::from_utf8(o.stdout).unwrap();
let pages: Vec<_> = text
.split('\u{c}')
.map(|p| p.split_whitespace().collect::<Vec<_>>().join(" "))
.filter(|p| !p.is_empty())
.collect();
assert_eq!(pages.len(), 3, "{text}");
assert!(pages[0].contains("Before forced page."), "{pages:?}");
assert!(pages[1].contains("After forced page."), "{pages:?}");
assert!(
pages[2].contains("After formula starts another page."),
"{pages:?}"
);
assert!(pages[2].contains("Boxed display."), "{pages:?}");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftotext absent: native display PDF check skipped")
}
Err(e) => panic!("{e}"),
}
fs::remove_dir_all(directory).unwrap();
}
+191
View File
@@ -0,0 +1,191 @@
use std::{
fs,
path::{Path, PathBuf},
process::Command,
time::{Duration, SystemTime},
};
use texrra_tex_core::resources::ResourceTrace;
fn set_modified(path: &Path, seconds: u64) {
fs::File::open(path)
.unwrap()
.set_modified(SystemTime::UNIX_EPOCH + Duration::from_secs(seconds))
.unwrap();
}
const STAMP: u64 = 1_709_210_096;
fn scratch(test: &str) -> PathBuf {
let path = std::env::temp_dir().join(format!("texrra-file-date-{test}-{}", std::process::id()));
fs::create_dir(&path).unwrap();
path.canonicalize().unwrap()
}
const SOURCE: &str = r#"\catcode123=1 \catcode125=2
\def\file{"asset with spaces.dat"}
\edef\stamp{\pdffilemoddate{\file}}
\edef\absent{\pdffilemoddate{absent.dat}}
"#;
#[cfg(unix)]
#[test]
fn file_date_matches_pdftex_and_records_metadata_without_reading_payload() {
let root = scratch("oracle");
let input = root.join("inputs");
fs::create_dir(&input).unwrap();
let asset = input.join("asset with spaces.dat");
fs::write(&asset, [0, 255, 17]).unwrap();
let body = r"\immediate\openout0=result.dat
\immediate\write0{[\stamp][\absent]}
\immediate\closeout0 \end";
let cases = [
("UTC0", false, STAMP, "[D:20240229123456Z][]\n"),
(
"Asia/Kolkata",
false,
STAMP,
"[D:20240229180456+05'30'][]\n",
),
("Asia/Kolkata", true, STAMP, "[D:20240229123456Z][]\n"),
(
"Asia/Kolkata",
false,
STAMP + 97,
"[D:20240229180633+05'30'][]\n",
),
];
for (index, (zone, force_utc, seconds, expected)) in cases.into_iter().enumerate() {
set_modified(&asset, seconds);
for (binary, args) in [
(
"pdftex",
vec![
"-ini",
"-etex",
"-halt-on-error",
"-interaction=nonstopmode",
"probe.tex",
],
),
(
env!("CARGO_BIN_EXE_texrra"),
vec![
"native",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
"probe.tex",
"probe.pdf",
],
),
] {
let native = binary != "pdftex";
let work = root.join(format!("{index}-{native}"));
fs::create_dir(&work).unwrap();
fs::write(work.join("probe.tex"), format!("{SOURCE}{body}\n")).unwrap();
let mut command = Command::new(binary);
command
.args(args)
.current_dir(&work)
.env("TEXINPUTS", format!("{}:", input.display()))
.env("TEXRRA_STATE_DIR", root.join("state"))
.env("TZ", zone)
.env_remove("SOURCE_DATE_EPOCH")
.env_remove("FORCE_SOURCE_DATE");
if force_utc {
command
.env("SOURCE_DATE_EPOCH", "946684800")
.env("FORCE_SOURCE_DATE", "1");
}
let output = command.output().unwrap();
assert!(
output.status.success(),
"{binary}: {}{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
assert_eq!(
fs::read_to_string(work.join("result.dat")).unwrap(),
expected
);
if native {
let trace: ResourceTrace =
serde_json::from_slice(&fs::read(work.join("resources.json")).unwrap())
.unwrap();
let observation = &trace.file_modifications[0];
assert_eq!(trace.file_modifications.len(), 1);
assert_eq!(observation.path, asset);
let date = observation.result.as_ref().unwrap().as_ref().unwrap();
assert_eq!(date.time.unix_seconds, seconds as i64);
assert_eq!(date.time.nanoseconds, 0);
assert_eq!(
date.text,
expected.split(']').next().unwrap().trim_start_matches('[')
);
assert!(!trace.reads.iter().any(|read| read.path == asset));
assert!(
trace
.lookups
.iter()
.any(|lookup| lookup.name == "absent.dat" && lookup.resolved.is_none())
);
}
}
}
fs::remove_dir_all(root).unwrap();
}
#[test]
fn format_load_checks_positive_and_missing_file_date_dependencies() {
let work = scratch("format");
let asset = work.join("asset with spaces.dat");
fs::write(&asset, b"unchanged bytes").unwrap();
set_modified(&asset, STAMP);
fs::write(work.join("seed.tex"), format!("{SOURCE}\\dump\n")).unwrap();
fs::write(work.join("main.tex"), br"\message{[\stamp][\absent]}\end").unwrap();
let run = |args: &[&str]| {
Command::new(env!("CARGO_BIN_EXE_texrra"))
.args(["native", "--etex"])
.args(args)
.current_dir(&work)
.env("TEXRRA_STATE_DIR", work.join("state"))
.env("SOURCE_DATE_EPOCH", "946684800")
.env("FORCE_SOURCE_DATE", "1")
.output()
.unwrap()
};
let dump = run(&["--initex", "--dump-format", "seed.tex", "seed.tfx"]);
assert!(
dump.status.success(),
"{}",
String::from_utf8_lossy(&dump.stderr)
);
let load = || run(&["--load-format", "seed.tfx", "main.tex", "main.pdf"]);
let ok = load();
assert!(
ok.status.success(),
"{}",
String::from_utf8_lossy(&ok.stderr)
);
assert!(
fs::read_to_string(work.join("main.log"))
.unwrap()
.contains("[D:20240229123456Z][]")
);
set_modified(&asset, STAMP + 97);
let changed = load();
assert!(!changed.status.success());
assert!(
String::from_utf8_lossy(&changed.stderr)
.contains("file modification date changed: asset with spaces.dat")
);
assert_eq!(fs::read(&asset).unwrap(), b"unchanged bytes");
set_modified(&asset, STAMP);
fs::write(work.join("absent.dat"), b"new").unwrap();
let appeared = load();
assert!(!appeared.status.success());
assert!(
String::from_utf8_lossy(&appeared.stderr)
.contains("file modification date changed: absent.dat")
);
fs::remove_dir_all(work).unwrap();
}
+238
View File
@@ -0,0 +1,238 @@
//! Real repeated jobs and edits; generated-file ownership is never inferred from suffixes.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use sha2::{Digest, Sha256};
use std::{
fs,
path::{Path, PathBuf},
process::{Command, Output},
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static NEXT: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-generated-cli-{}-{}",
std::process::id(),
NEXT.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
fn hash(bytes: &[u8]) -> String {
format!("{:x}", Sha256::digest(bytes))
}
fn native(root: &Path, entry: &str) -> Output {
native_fonts::command()
.env("TEXRRA_STATE_DIR", root.join("policy"))
.args([
"native",
"--initex",
"--etex",
"--job",
"--resource-manifest",
"trace.json",
entry,
"job.pdf",
])
.current_dir(root)
.output()
.unwrap()
}
fn reference(root: &Path, entry: &str) -> Output {
Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
entry,
])
.current_dir(root)
.output()
.unwrap()
}
fn source(name: &str, tail: &str) -> String {
format!(
r"\catcode123=1\catcode125=2\catcode35=6
\pdfoutput=1\pdfpagewidth=320bp\pdfpageheight=240bp
\output={{\shipout\box255}}\hsize=250pt\vsize=160pt\parindent=0pt
\openin1={name} \ifeof1\count0=0\else\closein1\input {name}\relax\fi
\immediate\openout0={name}\advance\count0 by1
\immediate\write0{{\string\count0=\the\count0\string\relax}}\immediate\closeout0
{tail}
\font\rm=cmr10\rm\noindent Revision \the\count0.\par\end"
)
}
#[test]
fn repeated_jobs_external_artifact_edit_and_sibling_entry_match_real_initex() {
let root = directory();
for (i, name) in ["memo.dat", "generated.source", "not-special.aux"]
.iter()
.enumerate()
{
let n = root.join(format!("native-{i}"));
let r = root.join(format!("reference-{i}"));
fs::create_dir_all(&n).unwrap();
fs::create_dir_all(&r).unwrap();
for dir in [&n, &r] {
fs::write(dir.join("main.tex"), source(name, "")).unwrap();
}
for pass in 0..4 {
if pass == 2 {
for dir in [&n, &r] {
fs::write(dir.join(name), b"\\count0=40\\relax\n").unwrap();
}
}
let entry = if pass == 3 { "sibling.tex" } else { "main.tex" };
if pass == 3 {
for dir in [&n, &r] {
fs::write(dir.join(entry), source(name, "")).unwrap();
}
}
let before = fs::read(n.join(name)).ok();
let actual = native(&n, entry);
let expected = reference(&r, entry);
assert!(
actual.status.success(),
"{}",
String::from_utf8_lossy(&actual.stderr)
);
assert!(
expected.status.success(),
"{}",
String::from_utf8_lossy(&expected.stdout)
);
let bytes = fs::read(n.join(name)).unwrap();
assert_eq!(bytes, fs::read(r.join(name)).unwrap());
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(n.join("trace.json")).unwrap()).unwrap();
let receipts = trace["generated_artifacts"]["writes"].as_array().unwrap();
assert_eq!(receipts.len(), 1);
assert_eq!(receipts[0]["after"]["sha256"], hash(&bytes));
if let Some(previous) = before {
assert_eq!(receipts[0]["before"]["sha256"], hash(&previous));
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|v| v["sha256"] == hash(&previous)
&& v["path"].as_str().unwrap().ends_with(name))
);
} else {
assert!(receipts[0]["before"].is_null());
}
let ledger = fs::read(
trace["generated_artifacts"]["ledger_path"]
.as_str()
.unwrap(),
)
.unwrap();
assert_eq!(
trace["generated_artifacts"]["ledger_current"]["sha256"],
hash(&ledger)
);
assert!(fs::metadata(n.join("job.pdf")).unwrap().len() > 1000);
}
}
fs::remove_dir_all(root).unwrap();
}
#[test]
fn unknown_aux_and_internal_policy_remain_protected_with_existing_pdf() {
let root = directory();
fs::write(root.join("unowned.aux"), b"\\relax\n").unwrap();
fs::write(
root.join("main.tex"),
r"\input unowned.aux\immediate\openout0=unowned.aux \end",
)
.unwrap();
fs::write(root.join("job.pdf"), b"KEEP").unwrap();
let initial = native(&root, "main.tex");
assert!(!initial.status.success());
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(root.join("trace.json")).unwrap()).unwrap();
let ledger = PathBuf::from(
trace["generated_artifacts"]["ledger_path"]
.as_str()
.unwrap(),
);
for body in [
r"\input unowned.aux\immediate\openout0=unowned.aux".into(),
format!(r#"\immediate\openout0="{}""#, ledger.display()),
format!(
r#"\immediate\openout0="{}""#,
ledger.with_extension("lock").display()
),
] {
fs::write(root.join("main.tex"), format!("{body} \\end")).unwrap();
fs::write(root.join("job.pdf"), b"KEEP").unwrap();
let output = native(&root, "main.tex");
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr).contains("overwrite"));
assert_eq!(fs::read(root.join("job.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read(root.join("unowned.aux")).unwrap(), b"\\relax\n");
}
fs::write(root.join("main.tex"),r"\catcode123=1\catcode125=2\immediate\openout0=trace.json \immediate\write0{STREAM}\immediate\closeout0\end").unwrap();
let collision = native(&root, "main.tex");
assert!(
!collision.status.success()
&& String::from_utf8_lossy(&collision.stderr).contains("collides with a TeX stream")
);
assert_eq!(fs::read(root.join("trace.json")).unwrap(), b"STREAM\n");
assert_eq!(fs::read(root.join("job.pdf")).unwrap(), b"KEEP");
let lock = fs::OpenOptions::new()
.read(true)
.write(true)
.open(ledger.with_extension("lock"))
.unwrap();
lock.try_lock().unwrap();
fs::write(root.join("main.tex"), r"\end").unwrap();
let log = fs::read(root.join("job.log")).unwrap();
let blocked = native(&root, "main.tex");
assert!(
!blocked.status.success()
&& String::from_utf8_lossy(&blocked.stderr).contains("already in use")
);
assert_eq!(fs::read(root.join("job.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read(root.join("job.log")).unwrap(), log);
drop(lock);
fs::remove_dir_all(root).unwrap();
}
#[test]
fn error_recovery_preserves_real_side_effect_ownership_and_recompiles() {
let root = directory();
let n = root.join("native");
let r = root.join("reference");
fs::create_dir_all(&n).unwrap();
fs::create_dir_all(&r).unwrap();
for dir in [&n, &r] {
fs::write(
dir.join("main.tex"),
source("state.dat", r"\errmessage{STOP AFTER REAL WRITE}"),
)
.unwrap();
}
fs::write(n.join("job.pdf"), b"KEEP").unwrap();
assert!(!native(&n, "main.tex").status.success());
assert!(!reference(&r, "main.tex").status.success());
assert_eq!(fs::read(n.join("job.pdf")).unwrap(), b"KEEP");
assert_eq!(
fs::read(n.join("state.dat")).unwrap(),
fs::read(r.join("state.dat")).unwrap()
);
for dir in [&n, &r] {
fs::write(dir.join("main.tex"), source("state.dat", "")).unwrap();
}
let result = native(&n, "main.tex");
assert!(
result.status.success(),
"{}",
String::from_utf8_lossy(&result.stderr)
);
assert!(reference(&r, "main.tex").status.success());
assert_eq!(
fs::read(n.join("state.dat")).unwrap(),
fs::read(r.join("state.dat")).unwrap()
);
fs::remove_dir_all(root).unwrap();
}
+111
View File
@@ -0,0 +1,111 @@
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{fs, path::PathBuf, process::Command};
fn group_records(text: &str) -> Vec<String> {
let mut unwrapped = String::new();
for line in text.lines() {
unwrapped.push_str(line);
if line.chars().count() != 79 {
unwrapped.push('\n');
}
}
unwrapped
.split('{')
.skip(1)
.filter_map(|part| {
let (record, _) = part.split_once('}')?;
(record.starts_with("entering ") || record.starts_with("leaving "))
.then(|| record.to_owned())
})
.collect()
}
#[test]
fn group_boundaries_and_restored_channels_match_pdftex() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let fonts = root.join("examples/native-bootstrap/math-fonts.tex");
let dir = std::env::temp_dir().join(format!("texrra-group-trace-{}", std::process::id()));
fs::create_dir_all(&dir).unwrap();
let cases = [
r###"\setbox0=\hbox{A}\hbox{B}\setbox1=\vbox{\hbox{C}}\setbox2=\vtop{\hbox{D}}"###,
r###"\setbox0=\hbox{A\discretionary{B}{C}{D}E}"###,
r###"\hsize=80pt\vsize=500pt\noindent Before display $$x^2+y$$ after display.\par"###,
r###"{\global\tracinggroups=0\relax}"###,
r###"\tracinggroups=0 {\global\tracinggroups=1\relax}"###,
r###"{\begingroup \count0=7{\count0=8}\endgroup}"###,
r###"{\tracinggroups=0 {\count0=7}}{\count0=1}"###,
r###"\tracinggroups=0 {\tracinggroups=1{\count0=7}}"###,
r###"\def\opengroup{{\count0=4}}
\message{BEFORE}\opengroup\message{AFTER}"###,
r###"\delcode40="028300 \delcode41="029301 \setbox0=\hbox{$x_{i}^{j}+\left(a+b\right)$}"###,
r###"{\tracingonline=0\relax{\count0=2}}"###,
r###"\hsize=80pt\vsize=20pt\output={\shipout\box255}\hbox{A}\penalty-10000\hbox{B}"###,
r###"\def\done{\message{AFTER}}
\message{BEFORE}{\aftergroup\done}"###,
r###"\setbox0=\hbox
{A}
\setbox1=\vbox to10pt
{\hbox{B}}"###,
r###"\setbox0=\hbox{$
x_{
i}^{j}$}"###,
r###"\def\f{{\count0=3}}\toks0={{\count0=4}}
\f\the\toks0"###,
];
for online in [0, 1] {
for body in cases {
let source = format!(
"\\input {}\n\\tracingonline={online}\\tracinggroups=1\n{body}\n\\end\n",
fonts.display(),
);
fs::write(dir.join("probe.tex"), &source).unwrap();
let oracle = Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"probe.tex",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
oracle.status.success(),
"{}",
String::from_utf8_lossy(&oracle.stdout)
);
let native = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
native.status.success(),
"{}",
String::from_utf8_lossy(&native.stderr)
);
assert_eq!(
group_records(&fs::read_to_string(dir.join("native.log")).unwrap()),
group_records(&fs::read_to_string(dir.join("probe.log")).unwrap()),
"log: {body}, online={online}",
);
assert_eq!(
group_records(&String::from_utf8_lossy(&native.stderr)),
group_records(&String::from_utf8_lossy(&oracle.stdout)),
"terminal: {body}, online={online}",
);
}
}
fs::remove_dir_all(dir).unwrap();
}
+80
View File
@@ -0,0 +1,80 @@
//! Actual pattern resources pass through the native CLI World and PDF path.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use sha2::{Digest, Sha256};
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-language-cli-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn original_language_sources_produce_native_pdf_and_preserve_exact_resource_versions() {
let dir = directory();
for resource in ["hyph-en-us.tex", "hyph-en-gb.tex"] {
let r = Command::new("kpsewhich")
.arg(resource)
.output()
.expect("actual TeX installation required");
assert!(r.status.success());
let path = String::from_utf8(r.stdout).unwrap().trim().to_owned();
let bytes = fs::read(&path).unwrap();
let source = format!(
r"\catcode123=1\catcode125=2\defaulthyphenchar=45\font\p=cmr10\p\hsize=62pt\parindent=0pt\baselineskip=12pt\parfillskip=0pt plus1fil\pretolerance=-1\tolerance=10000\hbadness=10000\vbadness=10000\lefthyphenmin=2\righthyphenmin=3\language=1\input {path} \uppercase{{\def\A{{native language}}}}\A\par X hyphenation demonstration paragraph construction character algorithm memory parameter\par\end"
);
fs::write(dir.join("probe.tex"), &source).unwrap();
let n = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"trace.json",
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
n.status.success(),
"{resource}:{}",
String::from_utf8_lossy(&n.stderr)
);
let t: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("trace.json")).unwrap()).unwrap();
let record = t["reads"]
.as_array()
.unwrap()
.iter()
.find(|r| r["path"] == path)
.unwrap();
assert_eq!(record["sha256"], format!("{:x}", Sha256::digest(&bytes)));
assert!(
fs::read(dir.join("native.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
let text = Command::new("pdftotext")
.args(["native.pdf", "-"])
.current_dir(&dir)
.output()
.unwrap();
assert!(text.status.success());
let text = String::from_utf8(text.stdout).unwrap();
assert!(text.contains("NATIVE"), "{text}");
assert_eq!(fs::read(&path).unwrap(), bytes);
assert_eq!(fs::read_to_string(dir.join("probe.tex")).unwrap(), source);
}
fs::remove_dir_all(dir).unwrap();
}
+171
View File
@@ -0,0 +1,171 @@
//! End-to-end raw byte jobs, actual read handles and recorder hashes.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use sha2::{Digest, Sha256};
use std::{
fs,
path::{Path, PathBuf},
process::{Command, Output},
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let dir = std::env::temp_dir().join(format!(
"texrra-byte-cli-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&dir).unwrap();
dir
}
fn native(dir: &Path, profile: &str) -> Output {
let mut command = native_fonts::command();
command.args(["native", "--initex", "--etex"]);
if profile != "default" {
command.args(["--input-profile", profile]);
}
command
.args([
"--resource-manifest",
"trace.json",
"probe.tex",
"native.pdf",
])
.current_dir(dir)
.output()
.unwrap()
}
fn reference(dir: &Path) -> Output {
Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"probe.tex",
])
.current_dir(dir)
.output()
.expect("real INITEX required")
}
fn trace(dir: &Path) -> serde_json::Value {
serde_json::from_slice(&fs::read(dir.join("trace.json")).unwrap()).unwrap()
}
fn digest(data: &[u8]) -> String {
format!("{:x}", Sha256::digest(data))
}
#[test]
fn root_nested_input_read_readline_and_real_output_preserve_actual_byte_identity() {
let dir = directory();
let data = b"\x80\xff A\r\n\xc8\x00\x7f B\rC";
let lib = b"\\catcode200=11\\def\\\xc8{LIB}\\message{LIB=\\\xc8}\\endinput\n";
let mut source=b"\\catcode123=1\\catcode125=2\\catcode0=12\\catcode127=12\\endlinechar=-1\\newlinechar=-1\n\\message{ROOT=\\number`\xc8}\\input lib-\xc3\xa9.tex\n\\immediate\\openout1=actual-\xc3\xa9.aux \\openin0=data-\xc3\xb1.tex\n".to_vec();
for (i, primitive) in ["read", "readline", "readline", "readline"]
.iter()
.enumerate()
{
source.extend_from_slice(
format!("\\{primitive}0 to\\R \\immediate\\write1{{R{i}=\\meaning\\R}}\n").as_bytes(),
);
}
source.extend_from_slice(b"\\ifeof0\\immediate\\write1{EOF=YES}\\else\\errmessage{EOF failed}\\fi\\immediate\\closeout1\\end\n");
fs::write(dir.join("probe.tex"), &source).unwrap();
fs::write(dir.join("lib-é.tex"), lib).unwrap();
fs::write(dir.join("data-ñ.tex"), data).unwrap();
fs::write(dir.join("native.pdf"), b"KEEP").unwrap();
let r = reference(&dir);
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stdout));
let expected = fs::read(dir.join("actual-é.aux")).unwrap();
fs::remove_file(dir.join("actual-é.aux")).unwrap();
let n = native(&dir, "default");
assert!(n.status.success(), "{}", String::from_utf8_lossy(&n.stderr));
assert_eq!(fs::read(dir.join("actual-é.aux")).unwrap(), expected);
assert!(String::from_utf8(n.stderr).unwrap().contains("ROOT=200"));
let t = trace(&dir);
let reads = t["reads"].as_array().unwrap();
for (name, bytes) in [
("probe.tex", source.as_slice()),
("lib-é.tex", lib.as_slice()),
] {
let record = reads
.iter()
.find(|r| r["path"].as_str().unwrap().ends_with(name))
.unwrap();
assert_eq!(record["sha256"], digest(bytes));
}
let chunks = [&data[..6], &data[6..12], &data[12..], &[]];
let ranges = t["stream_reads"].as_array().unwrap();
assert_eq!(ranges.len(), 4);
let mut offset = 0;
for (i, (record, chunk)) in ranges.iter().zip(chunks).enumerate() {
assert_eq!(record["offset"], offset);
assert_eq!(record["bytes"], chunk.len());
if i < 3 {
assert_eq!(record["sha256"], digest(chunk));
} else {
assert!(record["eof"].as_bool().unwrap());
}
offset += chunk.len();
}
for (name, bytes) in [
("probe.tex", source.as_slice()),
("lib-é.tex", lib.as_slice()),
("data-ñ.tex", data.as_slice()),
("native.pdf", b"KEEP".as_slice()),
] {
assert_eq!(fs::read(dir.join(name)).unwrap(), bytes);
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn explicit_scalar_input_has_distinct_values_and_invalid_utf8_retains_real_stream_trace() {
let dir = directory();
let source = "\\catcode123=1\\catcode125=2\\immediate\\write16{AUDIT=\\number`é}\\end\n";
fs::write(dir.join("probe.tex"), source).unwrap();
let r = reference(&dir);
assert!(r.status.success());
assert!(
String::from_utf8(r.stdout)
.unwrap()
.contains("AUDIT=195^^a9")
);
for (profile, expected) in [("tex8bit", "AUDIT=195^^a9"), ("unicode", "AUDIT=233")] {
let n = native(&dir, profile);
assert!(n.status.success(), "{}", String::from_utf8_lossy(&n.stderr));
assert!(String::from_utf8(n.stderr).unwrap().contains(expected));
}
let data = b"\xc3(\r\n";
for primitive in ["input", "read", "readline"] {
let source = if primitive == "input" {
"\\input data.tex \\end\n".to_owned()
} else {
format!("\\openin0=data.tex \\{primitive}0 to\\R \\end\n")
};
fs::write(dir.join("probe.tex"), &source).unwrap();
fs::write(dir.join("data.tex"), data).unwrap();
fs::write(dir.join("native.pdf"), b"KEEP").unwrap();
let n = native(&dir, "unicode");
assert!(!n.status.success());
let terminal = String::from_utf8(n.stderr).unwrap();
assert!(terminal.contains("data.tex:1:1"), "{terminal}");
assert!(terminal.contains("invalid UTF-8"), "{terminal}");
let t = trace(&dir);
if primitive == "input" {
assert!(
t["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["sha256"] == digest(data))
);
} else {
let r = &t["stream_reads"][0];
assert_eq!(r["sha256"], digest(data));
assert_eq!(r["bytes"], data.len());
}
assert_eq!(fs::read(dir.join("data.tex")).unwrap(), data);
assert_eq!(fs::read(dir.join("native.pdf")).unwrap(), b"KEEP");
}
fs::remove_dir_all(dir).unwrap();
}
+376
View File
@@ -0,0 +1,376 @@
//! Actual native CLI files versus unmodified pdfTeX INITEX semantics. No
//! preloaded format, source rewrite, or external engine in production.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let path = std::env::temp_dir().join(format!(
"texrra-job-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&path).unwrap();
path
}
const CASES: &[(&str, &str)] = &[
(
r"\def\a{ONE}\immediate\openout0=result.dat \immediate\write0{\a}\def\a{TWO}\immediate\write0{\a}\immediate\closeout0",
"",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \ifeof1\immediate\write0{BAD}\else\immediate\write0{OPEN}\fi \read1 to\a \immediate\write0{\meaning\a}\ifeof1\immediate\write0{BAD}\else\immediate\write0{LAST-LINE}\fi \read1 to\b \immediate\write0{\meaning\b}\ifeof1\immediate\write0{EOF}\fi \closein1",
"ONE\n",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \ifeof1\immediate\write0{BAD}\else\immediate\write0{EMPTY-OPEN}\fi \read1 to\a \immediate\write0{\meaning\a}\ifeof1\immediate\write0{EOF}\fi \openin1=absent.txt \ifeof1\immediate\write0{MISSING}\fi",
"",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \read1 to\a \read1 to\b \immediate\write0{\meaning\a/\meaning\b}",
" {A\nB}\n#1\\missing%comment\n",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \readline1 to\a \immediate\write0{\meaning\a}\immediate\write0{\a}",
"%\\x {^^41 \n",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \endlinechar=-1 \readline1 to\a \immediate\write0{\meaning\a}",
"%\\x {^^41 \n",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \globaldefs=1 {\read1 to\a}\endlinechar=-1 \read1 to\b \immediate\write0{\meaning\a/\meaning\b}",
"A\r\nB\rC\n",
),
(
r"\immediate\openout0=result.dat \openin1=data.txt \read1 to\a \immediate\write0{\meaning\a}",
"A}discarded\n",
),
(
r"\def\a{A}\protected\def\p{P}\toks0={\a}\immediate\openout0=result.dat \immediate\write0{\p/\unexpanded{\a}/\the\toks0}\newlinechar=33 \immediate\write0{ONE!TWO}\immediate\def\b{B}\immediate\write0{\b}",
"",
),
(
r#"\immediate\openout1="a b.dat" \immediate\write1{SPACES}\immediate\closeout1 \openin2="a b.dat" \endlinechar=-1 \read2 to\a \immediate\openout0=result.dat \immediate\write0{\a}"#,
"",
),
(
r"\immediate\openout0=result.dat \immediate\write0{OLD}\immediate\closeout0 \immediate\openout0=result.dat \immediate\write0{NEW}",
"",
),
(
r"\time=123 \year=2032 \month=2 \day=29 {\time=456 \global\advance\year1}\immediate\openout0=result.dat \immediate\write0{\the\time/\the\year/\the\month/\the\day}",
"",
),
];
#[test]
fn actual_stream_file_bytes_match_real_pdftex_initex() {
let root = directory();
let setup = "\\catcode123=1 \\catcode125=2 \\catcode35=6 \\catcode94=7\n";
for (index, (body, data)) in CASES.iter().enumerate() {
let native = root.join(format!("native-{index}"));
let reference = root.join(format!("tex-{index}"));
for dir in [&native, &reference] {
fs::create_dir(dir).unwrap();
fs::write(dir.join("data.txt"), data).unwrap();
fs::write(dir.join("probe.tex"), format!("{setup}{body}\n\\end\n")).unwrap();
}
let tex = match Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"probe.tex",
])
.current_dir(&reference)
.output()
{
Ok(output) => output,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("pdftex unavailable: stream oracle skipped");
fs::remove_dir_all(root).unwrap();
return;
}
Err(e) => panic!("{e}"),
};
assert!(
tex.status.success(),
"pdfTeX case {index}: {body}\n{}",
String::from_utf8_lossy(&tex.stdout)
);
let output = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "native.pdf"])
.current_dir(&native)
.output()
.unwrap();
assert!(
output.status.success(),
"native case {index}: {body}\n{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(
fs::read(native.join("result.dat")).unwrap(),
fs::read(reference.join("result.dat")).unwrap(),
"file bytes case {index}: {body}"
);
if native.join("a b.dat").exists() {
assert_eq!(
fs::read(native.join("a b.dat")).unwrap(),
fs::read(reference.join("a b.dat")).unwrap()
);
}
}
eprintln!("{} real native/pdfTeX filesystem cases passed", CASES.len());
fs::remove_dir_all(root).unwrap();
}
#[test]
fn host_clock_is_real_and_terminal_log_channels_are_distinct() {
use chrono::{Datelike, Timelike};
let dir = directory();
fs::write(dir.join("clock.tex"),r"\immediate\openout0=clock.dat \immediate\write0{\the\year/\the\month/\the\day/\the\time}\immediate\closeout0 \message{FIRST}\immediate\write16{TERMINAL-MARKER}\message{THIRD}\immediate\write-1{LOG-ONLY-MARKER}\end").unwrap();
let before = chrono::Local::now();
let output = native_fonts::command()
.args(["native", "clock.tex", "clock.pdf"])
.current_dir(&dir)
.output()
.unwrap();
let after = chrono::Local::now();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let contents = fs::read_to_string(dir.join("clock.dat")).unwrap();
let stamp = |t: chrono::DateTime<chrono::Local>| {
format!(
"{}/{}/{}/{}\n",
t.year(),
t.month(),
t.day(),
t.hour() * 60 + t.minute()
)
};
assert!(
contents == stamp(before) || contents == stamp(after),
"clock not from job start: {contents}"
);
let terminal = String::from_utf8_lossy(&output.stderr);
assert!(terminal.contains("TERMINAL-MARKER"));
assert!(
terminal.contains("FIRST\nTERMINAL-MARKER\nTHIRD"),
"{terminal}"
);
assert!(!terminal.contains("LOG-ONLY-MARKER"));
let log = fs::read_to_string(dir.join("clock.log")).unwrap();
assert!(log.contains("TERMINAL-MARKER"));
assert!(log.contains("LOG-ONLY-MARKER"));
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn native_cli_reports_io_errors_and_does_not_flush_unshipped_nodes() {
let dir = directory();
for (source, diagnostic) in [
(
r"\immediate\openout0=absent-dir/fail.dat ",
"output directory",
),
(r"\read0 to\x", "closed input stream"),
(r"\openout0=deferred.dat ", "native shipout"),
(r"\immediate\openout0=probe.tex ", "overwrite job source"),
] {
fs::write(dir.join("probe.tex"), source).unwrap();
fs::write(dir.join("keep.pdf"), b"keep").unwrap();
let output = native_fonts::command()
.args(["native", "probe.tex", "keep.pdf"])
.current_dir(&dir)
.output()
.unwrap();
assert!(!output.status.success());
assert!(
String::from_utf8_lossy(&output.stderr).contains(diagnostic),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(fs::read(dir.join("keep.pdf")).unwrap(), b"keep");
assert!(!dir.join("deferred.dat").exists());
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn actual_missing_glyph_log_terminal_and_fatal_pdf_protection() {
let dir = directory();
for trace in [0, 1, 2, 3] {
let after = dir.join("after.dat");
if after.exists() {
fs::remove_file(&after).unwrap();
}
fs::write(dir.join("probe.tex"),format!(r"\catcode123=1\catcode125=2\font\p=cmr10\p\tracinglostchars={trace}\message{{BEFORE}}\hbox{{A\char200 B}}\message{{AFTER}}\immediate\openout1=after.dat \immediate\closeout1\end")).unwrap();
fs::write(dir.join("keep.pdf"), b"preserve").unwrap();
let o = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "keep.pdf"])
.current_dir(&dir)
.output()
.unwrap();
let terminal = String::from_utf8_lossy(&o.stderr);
let log = fs::read_to_string(dir.join("keep.log")).unwrap();
assert_eq!(o.status.success(), trace < 3, "{terminal}");
assert_eq!(log.contains("Missing character:"), trace > 0, "{log}");
assert_eq!(
terminal.contains("Missing character:"),
trace > 1,
"{terminal}"
);
if trace == 3 {
assert_eq!(fs::read(dir.join("keep.pdf")).unwrap(), b"preserve");
// Unread source text is now correctly printed in the context.
// Actual later I/O, rather than absence of that text, proves halt.
assert!(!after.exists());
} else {
assert!(
fs::read(dir.join("keep.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
assert!(log.contains("AFTER"));
assert!(after.exists());
}
if trace == 1 {
assert!(terminal.contains("BEFOREAFTER"), "{terminal}");
}
if trace == 2 {
assert!(
terminal
.contains("BEFORE\nMissing character: There is no ^^c8 in font cmr10!\nAFTER"),
"{terminal}"
);
}
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn showbox_uses_actual_log_terminal_status_and_continues_pdf_output() {
let dir = directory();
for online in [-1, 0, 1] {
let setup = format!(
r"\catcode123=1\catcode125=2\font\p=cmr10 \p\hsize=240pt\baselineskip=12pt\parfillskip=0pt plus1fil\hbadness=10000\showboxbreadth=2\showboxdepth=2\tracingonline={online}"
);
let body = r"\setbox0=\hbox{ABC}\message{BEFORE}\showbox0\message{AFTER}\copy0\end";
fs::write(dir.join("probe.tex"), format!("{setup}{body}")).unwrap();
let o = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "shown.pdf"])
.current_dir(&dir)
.output()
.unwrap();
let terminal = String::from_utf8_lossy(&o.stderr);
let log = fs::read_to_string(dir.join("shown.log")).unwrap();
assert_eq!(o.status.code(), Some(1), "{terminal}");
assert!(
log.contains("\\hbox(")
&& log.contains(".etc.")
&& log.contains("! OK.")
&& log.contains("AFTER"),
"{log}"
);
assert_eq!(terminal.contains("\\hbox("), online > 0, "{terminal}");
assert_eq!(
terminal.contains("see the transcript file"),
online <= 0,
"{terminal}"
);
assert!(!log.contains("see the transcript file"));
if online <= 0 {
assert!(log.contains(".etc.\n\n\n! OK."), "{log}");
}
assert!(!terminal.contains("error:"), "{terminal}");
assert!(
terminal.find("BEFORE").unwrap() < terminal.find("! OK").unwrap()
&& terminal.find("! OK").unwrap() < terminal.find("AFTER").unwrap()
);
fs::write(
dir.join("control.tex"),
format!("{setup}{}", body.replace("\\showbox0", "")),
)
.unwrap();
let control = native_fonts::command()
.args(["native", "--initex", "--etex", "control.tex", "control.pdf"])
.current_dir(&dir)
.output()
.unwrap();
assert!(
control.status.success(),
"{}",
String::from_utf8_lossy(&control.stderr)
);
assert_eq!(
fs::read(dir.join("shown.pdf")).unwrap(),
fs::read(dir.join("control.pdf")).unwrap()
);
}
fs::write(
dir.join("probe.tex"),
r"\catcode123=1\catcode125=2\showbox0\end",
)
.unwrap();
fs::create_dir(dir.join("blocked.log")).unwrap();
fs::write(dir.join("blocked.pdf"), b"preserve").unwrap();
let o = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "blocked.pdf"])
.current_dir(&dir)
.output()
.unwrap();
assert!(!o.status.success());
assert!(String::from_utf8_lossy(&o.stderr).contains("native log"));
assert_eq!(fs::read(dir.join("blocked.pdf")).unwrap(), b"preserve");
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn first_showbox_channel_state_matches_real_initex_without_message() {
let root = directory();
for online in [-1, 0, 1] {
for (i, message) in ["", r"\message{BEFORE}"].iter().enumerate() {
let dir = root.join(format!("first-{online}-{i}"));
fs::create_dir(&dir).unwrap();
fs::write(dir.join("probe.tex"),format!(r"\catcode123=1\catcode125=2\font\rm=cmr10\rm\showboxbreadth=20\showboxdepth=5\tracingonline={online}\setbox0=\hbox{{office AV}}{message}\showbox0\end")).unwrap();
let tex = Command::new("pdftex")
.args(["-ini", "-etex", "-interaction=nonstopmode", "probe.tex"])
.current_dir(&dir)
.output()
.unwrap();
let native = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "native.pdf"])
.current_dir(&dir)
.output()
.unwrap();
assert_eq!(tex.status.code(), Some(1));
assert_eq!(
native.status.code(),
Some(1),
"{}",
String::from_utf8_lossy(&native.stderr)
);
let body = |s: &str| {
let begin = s.find("> \\box0=").unwrap();
let end = s[begin..].find("! OK.").unwrap() + begin;
s[begin..end].to_owned()
};
assert_eq!(
body(&fs::read_to_string(dir.join("native.log")).unwrap()),
body(&fs::read_to_string(dir.join("probe.log")).unwrap()),
"online={online}, message={i}"
);
}
}
fs::remove_dir_all(root).unwrap();
}
+183
View File
@@ -0,0 +1,183 @@
//! Actual online native jobs: output/shipout, auxiliary files and strict errors.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-pages-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn native_job_exports_only_actual_shipouts_with_real_fonts_and_auxiliary_bytes() {
let p = directory();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let source = root.join("examples/native-bootstrap/native-job.tex");
let before = fs::read(&source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
])
.arg(&source)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(
r.status.success(),
"{p:?}: {}",
String::from_utf8_lossy(&r.stderr)
);
let r = Command::new("pdfinfo")
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success());
assert!(
String::from_utf8_lossy(&r.stdout)
.lines()
.any(|s| s.starts_with("Pages:") && s.ends_with('4'))
);
assert_eq!(
fs::read(p.join("pages.aux")).unwrap(),
b"FIRST-PAGE=1\nLAST-PAGE=4\n"
);
let r = Command::new("pdftotext")
.args(["-layout", "native.pdf", "-"])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success());
let text = String::from_utf8(r.stdout).unwrap();
for page in 1..=4 {
assert!(
text.contains(&format!("Native page {page}"))
&& text.contains(&format!("Footer {page}")),
"{text}"
);
}
let r = Command::new("pdffonts")
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success());
for font in ["CMR10", "CMMI10", "CMMI7"] {
assert!(String::from_utf8_lossy(&r.stdout).contains(font));
}
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
for suffix in [
"native-job.tex",
"math-fonts.tex",
"cmr10.tfm",
"cmmi7.tfm",
"cmr10.pfb",
"cmmi7.pfb",
] {
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with(suffix)),
"missing actual read {suffix}"
);
}
assert_eq!(fs::read(source).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn native_job_errors_keep_existing_pdf_and_source_intact() {
let p = directory();
for (body, expected) in [
(
r"\setbox255=\hbox{}\hbox{}\penalty-10000\end",
"box255 is not void",
),
(
r"\output{\relax}\hbox{}\penalty-10000\end",
"did not empty box255",
),
(
r"\maxdeadcycles=2\output{\unvbox255}\hbox{}\penalty-10000\end",
"dead cycles",
),
(
r"\output{\bad}\hbox{}\penalty-10000\end",
"undefined native control sequence",
),
(r"\hbox{}", "end"),
(
r"\documentclass{article}\end",
"undefined native control sequence",
),
] {
let source = format!("\\catcode123=1\\catcode125=2\n{body}\n");
fs::write(p.join("probe.tex"), &source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert_eq!(r.status.code(), Some(1), "{body}");
assert!(
String::from_utf8_lossy(&r.stderr).contains(expected),
"{body}: {}",
String::from_utf8_lossy(&r.stderr)
);
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
}
fs::remove_dir_all(p).unwrap();
}
#[test]
fn initex_page_parameters_are_not_seeded_from_the_pdf_driver() {
let p = directory();
let source = r"\catcode123=1\catcode125=2\message{INITEX-VSIZE=\number\vsize;TOP=\number\topskip;DEPTH=\number\maxdepth}\shipout\hbox{}\end";
fs::write(p.join("probe.tex"), source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let log = fs::read_to_string(p.join("native.log")).unwrap();
assert!(log.contains("INITEX-VSIZE=0;TOP=0;DEPTH=0"), "{log}");
assert!(
fs::read(p.join("native.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
fs::remove_dir_all(p).unwrap();
}
+86
View File
@@ -0,0 +1,86 @@
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{fs, path::PathBuf};
#[test]
fn real_paragraph_channels_pdf_bytes_aux_and_failure_protection() {
let dir = std::env::temp_dir().join(format!(
"texrra-native-paragraph-trace-{}",
std::process::id()
));
fs::create_dir_all(&dir).unwrap();
let original =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/native-bootstrap/native-job.tex");
let before = fs::read(&original).unwrap();
let mut pdf = None;
for level in [0, 1] {
for online in [0, 1] {
let source = format!(
r"\catcode123=1\catcode125=2\pdfoutput=1\pdfpkresolution=600\tracingparagraphs={level}\tracingonline={online}\input {}",
original.display()
);
fs::write(dir.join("probe.tex"), &source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let log = fs::read_to_string(dir.join("native.log")).unwrap();
let terminal = String::from_utf8_lossy(&r.stderr);
assert_eq!(
log.matches("@firstpass").count(),
if level > 0 { 6 } else { 0 }
);
assert_eq!(
terminal.matches("@firstpass").count(),
if level > 0 && online > 0 { 6 } else { 0 }
);
let bytes = fs::read(dir.join("native.pdf")).unwrap();
if let Some(expected) = &pdf {
assert!(
&bytes == expected,
"trace controls changed actual PDF bytes"
);
} else {
pdf = Some(bytes);
}
assert_eq!(
fs::read(dir.join("pages.aux")).unwrap(),
b"FIRST-PAGE=1\nLAST-PAGE=4\n"
);
assert_eq!(fs::read_to_string(dir.join("probe.tex")).unwrap(), source);
}
}
let source = r"\catcode123=1\catcode125=2\font\f=cmr10\f\tracingparagraphs=1\hsize=60pt\parfillskip=0pt plus1fil\noindent Original paragraph with actual trace.\par\badcommand\end";
fs::write(dir.join("probe.tex"), source).unwrap();
fs::write(dir.join("native.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(!r.status.success());
assert!(
fs::read_to_string(dir.join("native.log"))
.unwrap()
.contains("@firstpass")
);
assert_eq!(fs::read(dir.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(dir.join("probe.tex")).unwrap(), source);
assert_eq!(fs::read(&original).unwrap(), before);
fs::remove_dir_all(dir).unwrap();
}
+213
View File
@@ -0,0 +1,213 @@
//! Native PDF file/stream options and explicit unsupported DVI protection.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-pdf-config-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn actual_compressed_pdf_objects_fonts_pages_and_late_writes_reach_the_cli() {
let p = directory();
let source =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/native-bootstrap/pdf-config.tex");
let before = fs::read(&source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
])
.arg(&source)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let pdf = fs::read(p.join("native.pdf")).unwrap();
assert!(pdf.starts_with(b"%PDF-1.7"));
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/Type /ObjStm") && text.contains("/Type /XRef"));
let r = Command::new("pdfinfo")
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success());
let info = String::from_utf8_lossy(&r.stdout);
assert!(
info.lines()
.any(|s| s.starts_with("Pages:") && s.ends_with('2')),
"{info}"
);
let r = Command::new("pdftotext")
.args(["-layout", "native.pdf", "-"])
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success());
assert_eq!(
String::from_utf8_lossy(&r.stdout)
.matches("Native compressed pages")
.count(),
2
);
assert_eq!(
fs::read(p.join("config.aux")).unwrap(),
b"PAGE=1;ZIP=9\nPAGE=2;ZIP=0\n"
);
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
for suffix in ["cmr10.tfm", "cmmi7.tfm", "cmr10.pfb", "cmmi7.pfb"] {
assert!(
trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|v| v["path"].as_str().unwrap().ends_with(suffix))
);
}
assert_eq!(fs::read(source).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn invalid_or_changed_pdf_modes_and_versions_keep_original_pdf_and_source() {
let p = directory();
for (body, expected) in [
(r"\pdfminorversion=10\shipout\hbox{}\end", "PDF version"),
(r"\shipout\hbox{}\pdfminorversion=7\end", "PDF version"),
(r"\pdfcompresslevel=10\shipout\hbox{}\end", "compression"),
(
r"\shipout\hbox{}\pdfoutput=2\shipout\hbox{}\end",
"pdfoutput",
),
(r"\pdfoutput=0\shipout\hbox{}\end", "DVI"),
] {
let source = format!("\\catcode123=1\\catcode125=2\n{body}\n");
fs::write(p.join("probe.tex"), &source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"probe.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert_eq!(r.status.code(), Some(1));
assert!(
String::from_utf8_lossy(&r.stderr).contains(expected),
"{}",
String::from_utf8_lossy(&r.stderr)
);
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
}
fs::remove_dir_all(p).unwrap();
}
#[test]
fn byte_pdf_profile_uses_real_absolute_comparisons_and_device_options() {
let dir = directory();
let source = r"\catcode123=1\catcode125=2
\ifdefined\pdftexversion
\ifnum\pdftexversion=140\message{ABI=\the\pdftexversion}\fi
\let\compare\ifpdfabsnum
\compare-2147483647>2147483646 \message{NUM=YES}\fi
\ifpdfabsnum-7=-8 \message{WRONG}\else\message{UNEQUAL=YES}\fi
\ifpdfabsdim-2pt=2pt \pdfminorversion=7 \message{DIM=YES}\fi
\else
\message{ABI=UNAVAILABLE}
\fi
\shipout\hbox{}\end";
fs::write(dir.join("probe.tex"), source).unwrap();
let reference = Command::new("pdftex")
.args([
"-ini",
"-etex",
"-output-format=pdf",
"-interaction=nonstopmode",
"-halt-on-error",
"probe.tex",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
reference.status.success(),
"{}",
String::from_utf8_lossy(&reference.stdout)
);
assert!(
fs::read(dir.join("probe.pdf"))
.unwrap()
.starts_with(b"%PDF-1.7")
);
for (profile, version) in [("tex8bit", b"%PDF-1.7"), ("unicode", b"%PDF-1.4")] {
if profile == "unicode" {
fs::write(
dir.join("probe.tex"),
r"\catcode123=1\catcode125=2
\ifdefined\pdftexversion\message{ABI=140}\else\message{ABI=UNAVAILABLE}\fi
\shipout\hbox{}\end",
)
.unwrap();
}
let actual = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--input-profile",
profile,
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
actual.status.success(),
"{}",
String::from_utf8_lossy(&actual.stderr)
);
let terminal = String::from_utf8_lossy(&actual.stderr);
if profile == "tex8bit" {
let oracle = String::from_utf8_lossy(&reference.stdout);
for mark in ["ABI=140", "NUM=YES", "UNEQUAL=YES", "DIM=YES"] {
assert!(
terminal.contains(mark) && oracle.contains(mark),
"{terminal}\n{oracle}"
);
}
assert!(!terminal.contains("WRONG"), "{terminal}");
} else {
assert!(terminal.contains("ABI=UNAVAILABLE"), "{terminal}");
}
assert!(
fs::read(dir.join("native.pdf"))
.unwrap()
.starts_with(version)
);
}
fs::remove_dir_all(dir).unwrap();
}
+211
View File
@@ -0,0 +1,211 @@
use lopdf::{Document, Object, Stream, dictionary};
use std::{fs, path::Path, process::Command};
use texrra_engine::native::{CompileRequest, Entry, NativeCompiler};
use texrra_tex_core::{execution::JobTime, resources::WorldConfig};
fn rotated_document(path: &Path) {
let mut pdf = Document::with_version("1.5");
let parents = pdf.new_object_id();
let resources = pdf.add_object(dictionary! {});
let content = [
b"1 0 0 rg 15 22 m 135 22 l 20 70 l h f\n".as_slice(),
b"0 0.7 0 rg 80 42 35 27 re f\n".as_slice(),
]
.map(|bytes| pdf.add_object(Stream::new(dictionary! {}, bytes.to_vec())));
let page = pdf.add_object(dictionary! {
"Type" => "Page", "Parent" => parents, "Rotate" => 90,
"TrimBox" => vec![15.into(),22.into(),140.into(),78.into()],
"Contents" => content.into_iter().map(Object::Reference).collect::<Vec<_>>(),
});
pdf.objects.insert(
parents,
Object::Dictionary(dictionary! {
"Type" => "Pages", "Kids" => vec![Object::Reference(page)], "Count" => 1,
"Resources" => resources,
"MediaBox" => vec![(-20).into(),5.into(),180.into(),105.into()],
"CropBox" => vec![10.into(),20.into(),160.into(),95.into()],
}),
);
let catalog = pdf.add_object(dictionary! {"Type" => "Catalog", "Pages" => parents});
pdf.trailer.set("Root", catalog);
pdf.save(path).unwrap();
}
#[test]
fn rotated_pdf_page_uses_selected_box_real_content_and_source_map() {
let root = std::env::temp_dir().join(format!("texrra-pdf-image-{}", std::process::id()));
fs::create_dir(&root).unwrap();
let source = root.join("vector.pdf");
rotated_document(&source);
let body = r"\catcode123=1 \catcode125=2
\pdfoutput=1 \pdfminorversion=5 \pdfobjcompresslevel=0
\pdfpagewidth=200pt \pdfpageheight=220pt \pdfhorigin=8pt \pdfvorigin=12pt
\pdfximage page 1 trimbox {vector.pdf}
\setbox0=\hbox{\pdfrefximage\pdflastximage}
\message{[w=\number\wd0][h=\number\ht0][pages=\the\pdflastximagepages]}
\shipout\box0
\end
";
let mut artifacts = Vec::new();
for native in [false, true] {
let work = root.join(if native { "native" } else { "reference" });
fs::create_dir(&work).unwrap();
fs::write(work.join("probe.tex"), body).unwrap();
fs::copy(&source, work.join("vector.pdf")).unwrap();
let mut command = if native {
let mut command = Command::new(env!("CARGO_BIN_EXE_texrra"));
command.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
"--layout-manifest",
"layout.json",
"probe.tex",
"probe.pdf",
]);
command
} else {
let mut command = Command::new("pdftex");
command.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"probe.tex",
]);
command
};
let output = command
.current_dir(&work)
.env("TEXINPUTS", ":")
.env("TEXRRA_STATE_DIR", work.join("state"))
.output()
.unwrap();
assert!(
output.status.success(),
"{}{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
let log = fs::read_to_string(work.join("probe.log")).unwrap();
let dims = log
.split_once("[w=")
.unwrap()
.1
.split_once("[pages=1]")
.unwrap()
.0
.to_owned();
let render = Command::new("pdftoppm")
.args(["-r", "144", "-gray", "-singlefile", "probe.pdf", "page"])
.current_dir(&work)
.output()
.unwrap();
assert!(
render.status.success(),
"{}",
String::from_utf8_lossy(&render.stderr)
);
artifacts.push((dims, fs::read(work.join("page.pgm")).unwrap()));
if native {
let layout: serde_json::Value =
serde_json::from_slice(&fs::read(work.join("layout.json")).unwrap()).unwrap();
let image = &layout["pages"][0]["pdf_images"][0];
assert_eq!(image["page"], 1);
assert_eq!(
layout["pages"][0]["paint_order"][0],
serde_json::json!(["pdf_image", 0])
);
let map = &layout["source_map"]["pages"][0]["entries"][0];
assert_eq!(map["kind"]["PdfImage"]["page"], 1);
assert_eq!(map["bounds"]["width"], image["width"]);
}
}
assert_eq!(artifacts[0].0, artifacts[1].0);
assert!(
artifacts[0].1 == artifacts[1].1,
"rotated image pixels differ"
);
fs::remove_dir_all(root).unwrap();
}
#[test]
fn embedded_pdf_preview_uses_current_form_and_retains_the_other_page() {
let root = std::env::temp_dir().join(format!("texrra-pdf-svg-{}", std::process::id()));
fs::create_dir(&root).unwrap();
let vector = root.join("vector.pdf");
rotated_document(&vector);
fs::write(
root.join("probe.tex"),
r"\catcode123=1 \catcode125=2
\pdfoutput=1 \pdfpagewidth=160pt \pdfpageheight=200pt
\pdfhorigin=12pt \pdfvorigin=20pt
\pdfximage page 1 trimbox {vector.pdf}
\shipout\hbox{\pdfsave\pdfsetmatrix{0.75 0 0 0.75}
\hbox to0pt{\pdfrefximage\pdflastximage\hss}\pdfrestore}
\shipout\vbox{\hrule width12pt height20pt depth0pt}\end
",
)
.unwrap();
let mut request = CompileRequest::new(
WorldConfig::new(&root),
"probe.tex",
"probe.pdf",
JobTime::new(2026, 11, 18, 800)
.unwrap()
.with_pdf_clock(0, 0)
.unwrap(),
);
request.entry = Entry::Initex;
request.etex = true;
let compiler = NativeCompiler::default();
let first = compiler.compile(request.clone()).unwrap();
let full = first.preview_since(None).unwrap();
assert_eq!(full.page_count, 2);
let art = full.pages[0].svg.to_ascii_lowercase();
assert!(art.contains("<path"));
assert!(art.contains("#ff0000"));
assert!(full.pages[1].svg.contains("<rect"));
let again = compiler.compile(request.clone()).unwrap();
assert_eq!(first.pdf, again.pdf);
assert!(
again
.preview_since(Some(first.revision()))
.unwrap()
.pages
.is_empty()
);
let mut source = Document::load(&vector).unwrap();
let page = source.get_pages()[&1];
let first_stream = source.get_page_contents(page)[0];
let object = source
.get_object_mut(first_stream)
.unwrap()
.as_stream_mut()
.unwrap();
object.set_content(b"0 0 1 rg 15 22 m 135 22 l 20 70 l h f\n".to_vec());
source.save(&vector).unwrap();
let current = compiler.compile(request.clone()).unwrap();
let patch = current.preview_since(Some(again.revision())).unwrap();
assert_eq!(patch.pages.len(), 1);
assert_eq!(patch.pages[0].index, 0);
assert!(patch.pages[0].svg.to_ascii_lowercase().contains("#0000ff"));
assert_ne!(full.pages[0].svg, patch.pages[0].svg);
let current_full = current.preview_since(None).unwrap();
assert!(std::sync::Arc::ptr_eq(
&full.pages[1].svg,
&current_full.pages[1].svg
));
let independent = NativeCompiler::default().compile(request).unwrap();
assert_eq!(current.pdf, independent.pdf);
assert_eq!(
current_full.pages,
independent.preview_since(None).unwrap().pages
);
assert_eq!(current.source_map.pages, independent.source_map.pages);
fs::remove_dir_all(root).unwrap();
}
File diff suppressed because it is too large. Load diff
+136
View File
@@ -0,0 +1,136 @@
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-pk-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
fn command() -> Command {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let mut c = native_fonts::command();
let pk = root.join("crates/texrra-tex-core/tests/fixtures/pk");
c.env("TEXFONTMAPS", &pk).env("PKFONTS", &pk);
c
}
#[test]
fn actual_pk_fonts_pages_and_late_auxiliary_writes_reach_the_native_cli() {
let p = directory();
let source =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/native-bootstrap/pk-device.tex");
let before = fs::read(&source).unwrap();
let r = command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
])
.arg(&source)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let fonts = Command::new("pdffonts")
.arg(p.join("native.pdf"))
.output()
.unwrap();
assert!(fonts.status.success());
let fonts = String::from_utf8_lossy(&fonts.stdout);
assert_eq!(fonts.matches("Type 3").count(), 3, "{fonts}");
let info = Command::new("pdfinfo")
.arg(p.join("native.pdf"))
.output()
.unwrap();
assert!(info.status.success());
assert!(
String::from_utf8_lossy(&info.stdout)
.lines()
.any(|l| l.starts_with("Pages:") && l.ends_with('2'))
);
assert_eq!(
fs::read(p.join("bitmap.aux")).unwrap(),
b"PAGE=1;DPI=300\nPAGE=2;DPI=1200\n"
);
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
let reads = trace["reads"].as_array().unwrap();
for name in ["cmr10", "cmmi10", "cmex10"] {
assert!(reads.iter().any(|v| {
v["path"]
.as_str()
.unwrap()
.ends_with(&format!("{name}.600pk"))
}));
assert!(reads.iter().any(|v| {
v["path"]
.as_str()
.unwrap()
.ends_with(&format!("{name}.tfm"))
}));
}
assert!(
!reads
.iter()
.any(|v| v["path"].as_str().unwrap().ends_with(".pfb"))
);
assert_eq!(fs::read(&source).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn absent_pk_density_fails_without_substitution_and_keeps_existing_output_and_trace() {
let p = directory();
let source =
br"\catcode123=1\catcode125=2\pdfpkresolution=700\font\F=cmr10\F\shipout\hbox{A}\end";
fs::write(p.join("source.tex"), source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let r = command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
"source.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert!(!r.status.success());
let error = String::from_utf8_lossy(&r.stderr);
assert!(error.contains("cmr10 at 700 dpi not found"), "{error}");
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read(p.join("source.tex")).unwrap(), source);
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
assert!(
trace["lookups"]
.as_array()
.unwrap()
.iter()
.any(|v| v["kind"] == "Pk" && v["resolved"].is_null())
);
assert!(
!trace["reads"]
.as_array()
.unwrap()
.iter()
.any(|v| v["path"].as_str().unwrap().ends_with(".pfb"))
);
fs::remove_dir_all(p).unwrap();
}
+318
View File
@@ -0,0 +1,318 @@
//! Real native resource lookup versus an independently configured INITEX path.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::{Path, PathBuf},
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-resource-cli-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
fn put(path: impl AsRef<Path>, data: impl AsRef<[u8]>) {
let p = path.as_ref();
fs::create_dir_all(p.parent().unwrap()).unwrap();
fs::write(p, data).unwrap();
}
fn native(dir: &Path, paths: &str, args: &[&str]) -> std::process::Output {
native_fonts::command()
.arg("native")
.args(args)
.current_dir(dir)
.env("TEXINPUTS", paths)
.env_remove("TEXRRA_TEXMF")
.output()
.unwrap()
}
#[test]
fn configured_native_paths_and_recorder_choices_match_real_initex() {
let root = directory();
for case in 0..5 {
let dir = root.join(case.to_string());
let a = dir.join("a");
let b = dir.join("b");
fs::create_dir_all(&a).unwrap();
fs::create_dir_all(&b).unwrap();
let (paths, chosen) = match case {
0 => {
put(a.join("choice"), br"\message{CHOSEN=BARE}\endinput");
put(a.join("choice.tex"), br"\message{CHOSEN=TEX}\endinput");
(a.display().to_string(), a.join("choice.tex"))
}
1 => {
put(a.join("choice"), br"\message{CHOSEN=BARE}\endinput");
put(b.join("choice.tex"), br"\message{CHOSEN=TEX}\endinput");
(format!("{}:{}", a.display(), b.display()), a.join("choice"))
}
2 => {
put(a.join("first/choice"), br"\message{CHOSEN=BARE}\endinput");
put(
a.join("second/choice.tex"),
br"\message{CHOSEN=TEX}\endinput",
);
(format!("{}//", a.display()), a.join("second/choice.tex"))
}
3 => {
put(a.join("choice.tex"), br"\message{CHOSEN=WRONG}\endinput");
put(
a.join("pkg/suffix/choice.tex"),
br"\message{CHOSEN=FILTERED}\endinput",
);
(
format!("{}//suffix", a.display()),
a.join("pkg/suffix/choice.tex"),
)
}
_ => {
put(
dir.join("choice.tex"),
br"\message{CHOSEN=DEFAULT}\endinput",
);
(format!("{}:", a.display()), dir.join("choice.tex"))
}
};
put(
dir.join("probe.tex"),
br"\catcode123=1\catcode125=2\input choice \end",
);
let reference = Command::new("pdftex")
.args([
"-ini",
"-etex",
"-interaction=nonstopmode",
"-halt-on-error",
"-recorder",
"./probe.tex",
])
.current_dir(&dir)
.env("TEXINPUTS", &paths)
.output()
.expect("real INITEX required");
assert!(
reference.status.success(),
"{}",
String::from_utf8_lossy(&reference.stdout)
);
let output = native(
&dir,
&paths,
&[
"--initex",
"--etex",
"--input-policy",
"tex",
"--resource-manifest",
"resources.json",
"./probe.tex",
"native.pdf",
],
);
assert!(
output.status.success(),
"case {case}: {}",
String::from_utf8_lossy(&output.stderr)
);
let manifest: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("resources.json")).unwrap()).unwrap();
assert_eq!(
manifest["reads"][1]["path"].as_str().unwrap(),
chosen.canonicalize().unwrap().to_str().unwrap()
);
let fls = fs::read_to_string(dir.join("probe.fls")).unwrap();
let reference_paths: Vec<_> = fls
.lines()
.filter_map(|line| line.strip_prefix("INPUT "))
.filter_map(|name| dir.join(name).canonicalize().ok())
.collect();
assert!(
reference_paths.contains(&chosen.canonicalize().unwrap()),
"{fls}"
);
let text = fs::read_to_string(&chosen).unwrap();
let marker = text
.strip_prefix("\\message{")
.unwrap()
.split('}')
.next()
.unwrap();
assert!(String::from_utf8_lossy(&output.stderr).contains(marker));
assert!(String::from_utf8_lossy(&reference.stdout).contains(marker));
}
fs::remove_dir_all(root).unwrap();
}
#[test]
fn execution_failure_keeps_real_lookup_trace_and_protects_sources_pdf_and_log() {
let dir = directory();
let source = br"\catcode123=1\catcode125=2\input absent \end";
put(dir.join("probe.tex"), source);
put(dir.join("existing.pdf"), b"KEEP");
let o = native(
&dir,
".",
&[
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
"./probe.tex",
"existing.pdf",
],
);
assert!(!o.status.success());
assert_eq!(fs::read(dir.join("existing.pdf")).unwrap(), b"KEEP");
let a: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("resources.json")).unwrap()).unwrap();
assert_eq!(a["reads"].as_array().unwrap().len(), 1);
assert!(a["lookups"].as_array().unwrap().last().unwrap()["resolved"].is_null());
put(dir.join("probe.tex"), br"\end");
let source = fs::read(dir.join("probe.tex")).unwrap();
for target in ["probe.tex", "existing.pdf", "existing.log"] {
let o = native(
&dir,
".",
&[
"--initex",
"--resource-manifest",
target,
"./probe.tex",
"existing.pdf",
],
);
assert!(!o.status.success(), "{target}");
assert!(String::from_utf8_lossy(&o.stderr).contains("overwrite"));
assert_eq!(fs::read(dir.join("probe.tex")).unwrap(), source);
assert_eq!(fs::read(dir.join("existing.pdf")).unwrap(), b"KEEP");
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn original_distribution_entry_resolves_config_then_stops_at_real_pdf_consumer() {
let root = Command::new("kpsewhich")
.arg("--var-value=TEXMFDIST")
.output()
.expect("reference installation required");
assert!(root.status.success());
let root = String::from_utf8(root.stdout).unwrap();
let root = root.trim();
let dir = directory();
put(dir.join("existing.pdf"), b"KEEP");
let o = native(
&dir,
"",
&[
"--initex",
"--etex",
"--input-policy",
"tex",
"--texmf-root",
root,
"--resource-manifest",
"resources.json",
"pdflatex.ini",
"existing.pdf",
],
);
assert_eq!(o.status.code(), Some(1));
let error = String::from_utf8_lossy(&o.stderr);
assert!(
error.contains("native execution step limit exceeded"),
"{error}"
);
assert!(error.contains("expl3-code.tex:3183:1:"), "{error}");
assert!(!error.contains("not found"), "{error}");
assert_eq!(fs::read(dir.join("existing.pdf")).unwrap(), b"KEEP");
let a: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("resources.json")).unwrap()).unwrap();
let reads = a["reads"].as_array().unwrap();
assert!(
reads
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with("/pdflatex.ini"))
);
assert!(
reads
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with("/pdftexconfig.tex"))
);
for r in reads {
assert_eq!(r["sha256"].as_str().unwrap().len(), 64);
assert_eq!(
r["bytes"].as_u64().unwrap(),
fs::read(r["path"].as_str().unwrap()).unwrap().len() as u64
);
}
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn stream_trace_hashes_only_delivered_physical_bytes_and_records_actual_eof() {
let dir = directory();
put(dir.join("data.tex"), b"ONE\r\nTWO");
put(
dir.join("probe.tex"),
br"\openin0=data.tex \read0 to\a \read0 to\b \read0 to\c \end",
);
let o = native(
&dir,
".",
&[
"--initex",
"--resource-manifest",
"resources.json",
"./probe.tex",
"native.pdf",
],
);
assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stderr));
let a: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("resources.json")).unwrap()).unwrap();
let reads = a["stream_reads"].as_array().unwrap();
assert_eq!(reads.len(), 3);
for (range, offset, bytes, eof, digest) in [
(
&reads[0],
0,
5,
false,
"48048b6ec9ff8ea234ec030af5858ea87ea8583ee3a92e0457d8e0d1e965baa7",
),
(
&reads[1],
5,
3,
false,
"a1a8a8cbbed4eb53ae62ee4fb0787504087232c29aa4d817757d06b68d0501ca",
),
(
&reads[2],
8,
0,
true,
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
),
] {
assert_eq!(
range["path"].as_str().unwrap(),
dir.join("data.tex")
.canonicalize()
.unwrap()
.to_str()
.unwrap()
);
assert_eq!(range["offset"], offset);
assert_eq!(range["bytes"], bytes);
assert_eq!(range["eof"], eof);
assert_eq!(range["sha256"], digest);
}
// Opening a stream must not invent a full-file version or read its future bytes.
assert_eq!(a["reads"].as_array().unwrap().len(), 1);
fs::remove_dir_all(dir).unwrap();
}
+179
View File
@@ -0,0 +1,179 @@
//! Real native split output/resources and strict protection at page boundaries.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-splitting-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn original_split_lists_reach_real_pdf_fonts_and_resource_trace() {
let p = directory();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let source = root.join("examples/native-bootstrap/splitting.tex");
let before = fs::read(&source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
])
.arg(&source)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(
r.status.success(),
"{p:?}: {}",
String::from_utf8_lossy(&r.stderr)
);
let log = fs::read_to_string(p.join("native.log")).unwrap();
assert!(log.contains("SPLIT-FIRST=FIRST/FIRST/SEVEN"), "{log}");
let pdf = fs::read(p.join("native.pdf")).unwrap();
assert!(pdf.starts_with(b"%PDF-"));
let text = Command::new("pdftotext")
.args(["-layout", "native.pdf", "-"])
.current_dir(&p)
.output()
.unwrap();
assert!(text.status.success());
let text = String::from_utf8(text.stdout).unwrap();
for expected in [
"Native splitting",
"First fragment:",
"Second fragment:",
"FIRST.",
"SEVEN.",
"The final material",
] {
assert!(text.contains(expected), "{text}");
}
let fonts = Command::new("pdffonts")
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(fonts.status.success());
let fonts = String::from_utf8(fonts.stdout).unwrap();
for f in ["CMR10", "CMMI10", "CMMI7"] {
assert!(fonts.contains(f), "{fonts}");
}
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
let reads = trace["reads"].as_array().unwrap();
for suffix in [
"splitting.tex",
"math-fonts.tex",
"cmr10.tfm",
"cmmi7.tfm",
"cmr10.pfb",
"cmmi7.pfb",
] {
assert!(
reads
.iter()
.any(|r| r["path"].as_str().unwrap().ends_with(suffix)),
"missing actual resource {suffix}: {trace}"
);
}
assert_eq!(fs::read(&source).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn outer_marks_and_invalid_splits_protect_existing_pdf_and_original_source() {
let p = directory();
for (body, diagnostic) in [
(
r"\mark{OUTER}\end",
"outer marks require native page ownership",
),
(
r"\setbox1=\hbox{}\setbox0=\vsplit1 to0pt\end",
"native vsplit needs a vbox",
),
(
r"\setbox1=\vbox{\mark{\noexpand\bad x}\hbox{}}\setbox0=\vsplit1 to0pt\relax\splitfirstmark\end",
"undefined native control sequence",
),
] {
let source = format!("\\catcode123=1\\catcode125=2\n{body}\n");
fs::write(p.join("probe.tex"), &source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "native.pdf"])
.current_dir(&p)
.output()
.unwrap();
assert!(!r.status.success());
assert!(
String::from_utf8_lossy(&r.stderr).contains(diagnostic),
"{}",
String::from_utf8_lossy(&r.stderr)
);
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
}
fs::remove_dir_all(p).unwrap();
}
#[test]
fn actual_high_byte_mark_diagnostics_match_initex_in_both_channels() {
let p = directory();
let source = format!(
r"\catcode123=1\catcode125=2\catcode94=7\catcode200=11\showboxbreadth=100\showboxdepth=30\tracingonline=1\setbox0=\vbox{{\mark{{{}}}\hbox{{}}}}\showbox0\end",
r"\noexpand\^^c8 ".repeat(30)
);
fs::write(p.join("probe.tex"), &source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let n = native_fonts::command()
.args(["native", "--initex", "--etex", "probe.tex", "native.pdf"])
.current_dir(&p)
.output()
.unwrap();
assert_eq!(
n.status.code(),
Some(1),
"{}",
String::from_utf8_lossy(&n.stderr)
);
assert!(!String::from_utf8_lossy(&n.stderr).contains("error:"));
let r = Command::new("pdftex")
.args(["-ini", "-etex", "-interaction=nonstopmode", "probe.tex"])
.current_dir(&p)
.output()
.unwrap();
assert_eq!(r.status.code(), Some(1));
fn body(s: &str) -> &str {
s.split_once("> \\box0=")
.unwrap()
.1
.split_once("! OK.")
.unwrap()
.0
}
let log = fs::read_to_string(p.join("native.log")).unwrap();
let reference = fs::read_to_string(p.join("probe.log")).unwrap();
assert_eq!(body(&log), body(&reference));
assert_eq!(
body(std::str::from_utf8(&n.stderr).unwrap()),
body(std::str::from_utf8(&r.stdout).unwrap())
);
assert_eq!(body(&log).matches(r"\^^c8 ").count(), 12);
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
fs::remove_dir_all(p).unwrap();
}
+113
View File
@@ -0,0 +1,113 @@
#[path = "support/native_fonts.rs"]
mod native_fonts;
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static N: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-native-statistics-{}-{}",
std::process::id(),
N.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn real_core_and_shipout_statistics_reach_actual_channels_and_preserve_outputs() {
let p = directory();
let source =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/native-bootstrap/statistics.tex");
let before = fs::read(&source).unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
])
.arg(&source)
.arg("native.pdf")
.current_dir(&p)
.output()
.unwrap();
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
let terminal = String::from_utf8_lossy(&r.stderr);
let log = fs::read_to_string(p.join("native.log")).unwrap();
assert_eq!(terminal.matches("Route-D resources at shipout:").count(), 2);
assert_eq!(log.matches("Route-D resources at shipout:").count(), 2);
assert!(!terminal.contains("resource usage at core execution end"));
assert_eq!(
log.matches("resource usage at core execution end (success)")
.count(),
1
);
assert!(log.contains("1 font instances"));
assert!(log.contains("host resources: 2 reads"));
assert!(!log.contains("still untouched:"));
let output = Command::new("pdftotext")
.arg(p.join("native.pdf"))
.arg("-")
.output()
.unwrap();
assert!(output.status.success());
assert_eq!(
String::from_utf8_lossy(&output.stdout)
.matches("Native resource statistics")
.count(),
2
);
assert_eq!(
fs::read(p.join("statistics.aux")).unwrap(),
b"PAGE=1\nPAGE=2\n"
);
let trace: serde_json::Value =
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
assert!(
trace["reads"].as_array().unwrap().len() > 2,
"actual PFB/map resolution follows the core statistics boundary"
);
assert_eq!(fs::read(&source).unwrap(), before);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn level_one_is_log_only_and_failed_jobs_keep_real_statistics_and_existing_pdf() {
let p = directory();
for (body, ok) in [
(r"\tracingstats=1\end", true),
(r"\tracingstats=1\relax\badcommand\end", false),
] {
let source = format!(r"\catcode123=1\catcode125=2{body}");
fs::write(p.join("source.tex"), &source).unwrap();
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
let r = native_fonts::command()
.args([
"native",
"--job",
"--initex",
"--etex",
"source.tex",
"native.pdf",
])
.current_dir(&p)
.output()
.unwrap();
assert_eq!(r.status.success(), ok);
let terminal = String::from_utf8_lossy(&r.stderr);
assert!(!terminal.contains("resource usage at core execution end"));
let log = fs::read_to_string(p.join("native.log")).unwrap();
assert!(log.contains(if ok {
"core execution end (success)"
} else {
"core execution end (failure)"
}));
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
assert_eq!(fs::read_to_string(p.join("source.tex")).unwrap(), source);
}
fs::remove_dir_all(p).unwrap();
}
+21 -15
View File
@@ -9,6 +9,7 @@ use std::{
net::{TcpListener, TcpStream},
path::{Path, PathBuf},
process::{Child, Command, Stdio},
sync::Arc,
time::{Duration, SystemTime, UNIX_EPOCH},
};
@@ -39,10 +40,18 @@ impl Response {
struct TestServer {
child: Child,
port: u16,
root: PathBuf,
fixture: Arc<ServerFixture>,
marker: String,
}
struct ServerFixture(PathBuf);
impl Drop for ServerFixture {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
impl TestServer {
fn start(label: &str) -> Self {
Self::start_with_env(label, &[])
@@ -53,10 +62,11 @@ impl TestServer {
.duration_since(UNIX_EPOCH)
.expect("clock")
.as_nanos();
let root = std::env::temp_dir().join(format!(
let fixture = Arc::new(ServerFixture(std::env::temp_dir().join(format!(
"texrra-test-{label}-{}-{stamp}",
std::process::id()
));
))));
let root = &fixture.0;
let web = root.join("web");
fs::create_dir_all(&web).expect("create web dir");
let marker = format!("marker-{stamp}");
@@ -81,7 +91,7 @@ impl TestServer {
.arg("serve")
.arg(root.join("hello.tex"))
.arg(port.to_string())
.current_dir(&root)
.current_dir(root)
.env("TEXRRA_WEB_DIR", &web)
.env("TEXRRA_PROJECTS_DIR", root.join("projects"))
.stdout(Stdio::null())
@@ -93,15 +103,12 @@ impl TestServer {
let mut server = Self {
child,
port,
root: root.clone(),
fixture: Arc::clone(&fixture),
marker: marker.clone(),
};
match server.wait_ready() {
Ok(()) => return server,
Err(message) if message.contains("Address already in use") => {
let _ = server.child.kill();
let _ = server.child.wait();
}
Err(message) if message.contains("Address already in use") => {}
Err(message) => panic!("{message}"),
}
}
@@ -142,7 +149,7 @@ impl TestServer {
}
fn log(&self) -> String {
fs::read_to_string(self.root.join("server.log")).unwrap_or_default()
fs::read_to_string(self.fixture.0.join("server.log")).unwrap_or_default()
}
fn request(&self, method: &str, path: &str, body: &[u8], content_type: &str) -> Response {
@@ -175,7 +182,6 @@ impl Drop for TestServer {
fn drop(&mut self) {
let _ = self.child.kill();
let _ = self.child.wait();
let _ = fs::remove_dir_all(&self.root);
}
}
@@ -468,7 +474,7 @@ fn project_preview_uses_the_engine_default() {
value["durationMs"]
);
let svg = value["pages"][0]["svg"].as_str().unwrap();
assert!(svg.contains("font-style=\"italic\""), "{svg}");
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
assert!(!svg.contains('$'), "{svg}");
let forced = server.request(
@@ -530,7 +536,7 @@ fn engine_parameter_overrides_the_environment_default() {
);
let value: Value = serde_json::from_slice(&default_preview.body).expect("preview JSON");
let svg = value["pages"][0]["svg"].as_str().unwrap();
assert!(svg.contains("font-style=\"italic\""), "{svg}");
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
let v1_preview = route_d.request(
"POST",
@@ -583,7 +589,7 @@ fn engine_parameter_overrides_the_environment_default() {
);
let value: Value = serde_json::from_slice(&forced.body).expect("preview JSON");
let svg = value["pages"][0]["svg"].as_str().unwrap();
assert!(svg.contains("font-style=\"italic\""), "{svg}");
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
let forced_pdf = v1.request(
"POST",
"/api/projects/hello/pdf?engine=route-d",
@@ -2507,7 +2513,7 @@ fn project_preview_defaults_to_route_d_without_env() {
assert_eq!(preview.status, 200, "{}", preview.text());
let value: Value = serde_json::from_slice(&preview.body).expect("preview JSON");
let svg = value["pages"][0]["svg"].as_str().unwrap();
assert!(svg.contains("font-style=\"italic\""), "{svg}");
assert!(svg.contains("data-font=\"CMMI10\""), "{svg}");
assert!(!svg.contains('$'), "{svg}");
}
+23
View File
@@ -0,0 +1,23 @@
//! Native CLI tests explicitly supply real font resources; runtime lookup has
//! no installed-distribution or bundled-font fallback.
use std::{path::PathBuf, process::Command, sync::OnceLock};
pub fn command() -> Command {
static MAP: OnceLock<PathBuf> = OnceLock::new();
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let map = MAP.get_or_init(|| {
let r = Command::new("kpsewhich")
.arg("pdftex.map")
.output()
.expect("reference font map required");
assert!(r.status.success());
PathBuf::from(String::from_utf8(r.stdout).unwrap().trim())
.parent()
.unwrap()
.to_owned()
});
let mut c = Command::new(env!("CARGO_BIN_EXE_texrra"));
c.env("TFMFONTS", root.join("crates/texrra-tex-core/assets"));
c.env("T1FONTS", root.join("assets/fonts"));
c.env("TEXFONTMAPS", map);
c
}
+12
View File
@@ -159,6 +159,12 @@ fn arxiv_fixture_is_three_letter_pages() {
.join("arxiv-template")
.join("template.tex");
let source = std::fs::read_to_string(&path).expect("read arXiv fixture");
// This layout oracle measures an October reference, not the wall clock.
let source = source.replacen(
r"\begin{document}",
r"\date{October 31, 2026}\begin{document}",
1,
);
let file_name = path.to_string_lossy().to_string();
let value = fresh_preview(&source, &file_name);
assert_eq!(value["status"], "ok", "{}", value["message"]);
@@ -607,6 +613,12 @@ fn preprint_metadata_spacing_matches_reference() {
.join("arxiv-template")
.join("template.tex");
let source = std::fs::read_to_string(&path).expect("read arXiv fixture");
// This layout oracle measures an October reference, not the wall clock.
let source = source.replacen(
r"\begin{document}",
r"\date{October 31, 2026}\begin{document}",
1,
);
let value = fresh_preview(&source, &path.to_string_lossy());
assert_eq!(value["status"], "ok", "{}", value["message"]);
let svg = page_svg(&value, 0);