Repository navigation
feat(preview): render PDF pages to PNG previews - #31
Merged
Merged
Conversation
nishide-dev
commented
Sep 30, 2026
nishide-dev
left a comment
Owner
Author
There was a problem hiding this comment.
Verdict: CHANGES_REQUESTED
PR #31(#8 PDF page preview / crates/texrun-preview)のレビューです。全体として、docs/security.md の決定事項(既定 20 ページ・最大 200 ページ・合計 128 MiB・30 秒・shell 不使用・env_clear + allowlist・process group への SIGKILL・正常終了後の killpg)はほぼそのまま実装されています。degraded behavior を notice に寄せる設計や、attach_to で CompileResult に載せる流れも #6 から使いやすい形です。
ただし、§3.2 に追加された「1 枚の長辺 4096 px」の上限が、MuPDF backend では守られないケースを確認しました。これを must-fix とします。
実行結果
- host(macOS、poppler 26.04 のみ):
cargo fmt --check、cargo clippy --workspace --all-targets --all-features --locked -D warnings、cargo test --workspace --locked、cargo deny --locked checkはすべて OK でした。real_tools の mupdf 分は skip されます。 - container:
TEXRUN_REQUIRE_PREVIEW_TOOLS=1 cargo test --workspace --lockedはすべて OK でした(mutool 1.25.1 / poppler 25.03。preview は unit 23、degraded 9、real_tools 12)。 - CI は全 job が pass しています。
- 実文書で試しました。コンテナの pdfLaTeX で 298 ページの文書を作りました。A4 10pt 本文に数式・脚注・表・ベクター図・ラスター図を入れ、pdflscape の横向きページ(
/Rotate 90)、A3、10in×3in、A0 横を混ぜています。これを release build の小さな driver からrenderしました。
| backend | 選択 | 結果 | 合計サイズ | 時間 |
|---|---|---|---|---|
| mupdf | 既定(先頭 20) | rendered 20(page_limit と resolution_reduced の info) | 3.97 MB | 0.76 s |
| mupdf | 1- |
rendered 200(上限 200 で warning) | 50.6 MB | 7.3 s |
| mupdf | 281- |
rendered 18 | 4.7 MB | 0.68 s |
| poppler | 既定(先頭 20) | rendered 20 | 4.77 MB | 3.45 s |
| poppler | 1- |
partial 149(timed_out で停止) | 45.3 MB | 30.0 s |
| poppler のみの PATH(Auto) | 既定 | poppler に fallback し rendered 20 | — | 3.4 s |
| tool なし | — | skipped + tool_unavailable warning |
— | — |
- 解像度: A4 は 1191×1684 px、横向きページは 1684×1191 px(回転が反映されている)、A3 は 1684×2382 px、A0 は 87 DPI に下がって 4073×2881 px でした。両 backend でページ番号・寸法・回転は一致しています。
- 読みやすさ: 10pt 本文、上付き・下付き、分数、脚注(8pt)、表の罫線、図のラベルは、どれも vision 入力として十分に読めました。A4 1 枚は 160〜320 KB です。既定値の 144 DPI と PNG は妥当だと思います。
- poppler で 200 ページを描画すると 30 秒の timeout にかかるのは、PR 本文の見積もりどおりでした。途中まで描画したページを返し、
partial+timed_outになるので、degraded behavior としては一貫しています。
must-fix
M1. MuPDF backend で、長辺 4096 px の上限(§3.2)が守られない場合がある
mutool pagesはページの拡大係数(UserUnit)も出力しますが、parse_mutool_pagesはそれを読んでいません。mutool drawは描画時にこの係数を反映します。- そのため、宣言されたページサイズから計算した DPI と、実際に描画される画像の大きさがずれます。確認したところ、
max_long_edge_pxを 1000 にしても、4000 px の画像が notice なしでrenderedになりました。一方、Poppler(25.03)はこの係数を無視して描画するので、上限内に収まりました。 - security.md §3.2 の新しい行は「PDF が宣言するページサイズ(信頼できない値)に関係なく、1 ページあたりのメモリと出力を抑える」としていますが、この保証が崩れています。tool のメモリは OS では制限していないので、この上限が 1 ページあたりのメモリを抑える唯一の手段です。
- 修正案(1 と 2 の両方を推奨します):
- tool 側に pixel の上限を渡す。
mutool drawに-w <max_long_edge_px> -h <max_long_edge_px>を-rと併用で渡してください。1.25.1 で試したところ、この指定は「この箱に収まるまで縮小する」という意味で動作しました。A4 は 144 DPI のまま 1191×1684 px、A0 は 4096×2898 px になり、拡大係数を持つページも 1000 px 以内に収まりました。小さなページが拡大されることもありません。こうすれば、PDF 由来の値を parse する精度に上限の正しさが依存しなくなります。Poppler は現状の DPI 計算のままでよいです(-scale-toは小さなページも拡大するので、使わない方がよいです)。 - 描画後に IHDR の寸法を検査する。
png::file_dimensionsで得た幅・高さがmax_long_edge_px(丸め分として +1〜2 px の余裕を持たせる)を超えたら、rename せずに捨て、render_failedの warning にしてください。backend や tool の version による差を吸収する、最後の防御になります。
- あわせて、
parse_mutool_pagesでUserUnitを読み、PageInfoの pt に掛けてください(check_dimensionの範囲検査も掛けた後の値に対して行う)。報告するページサイズとeffective_dpiの計算が、実際の描画と一致するようになります。
- tool 側に pixel の上限を渡す。
- test: fixture の
.texで\pdfpageattrを使えば、拡大係数を持つ小さなページを作れます。real_tools に「長辺上限を小さくしても、画像がそれを超えない」ことを確認する test を、両 backend 分追加してください。攻撃的な値は不要で、係数 2〜20 程度で再現できます。
should-fix
S1. preview/ への rename が path ベースで、#21 の collect と脅威モデルが揃っていない
prepare_dirはsymlink_metadataで各 component を確認した後、fs::rename(&tmp, dir.join(name))で path を辿り直しています。この確認と rename の間にpreview/が symlink に差し替えられると、その先に書き込めてしまいます。- #21 の
collectは「compile から残ったプロセスが途中の directory を symlink に差し替える」ことを前提に、workspace root の identity 確認とO_NOFOLLOWの fd 経由で辿る実装にしています。preview は同じ output dir を、compile の直後に扱います。 - 修正案:
prepare_dirでpreview/をO_DIRECTORY | O_NOFOLLOWの fd として開き(rustix のopenat/mkdirat、unsafe 不要)、scratch dir も fd で保持したままrenameat(scratch_fd, "page.png", preview_fd, "page-NNN.png")で移動してください。可能であれば、output root 自体も #21 と同じく identity を確認するとよいです。 - 実際に悪用できる条件は狭い(shell-escape が無効なので、group から抜けるプロセスは通常存在しない)と思いますが、同じ output dir について crate ごとに防御の水準が違うのは避けたいです。対応を別 Issue に分けるなら、security.md の「限界」か PR 本文にその旨を書いてください。
nit
- N1. PR #30 との重複と共通化
process.rsは PR #30 のcrates/texrun-texlive/src/process.rsとほぼ同じ構造です(process_group(0)、try_wait・cancel・deadline・size を 1 つの poll ループで確認、killpg(SIGKILL)、正常終了後のkillpg、reader thread と grace)。- 細部が食い違っています。
- 両方が merge された後に、共通の crate(例:
texrun-process)へ切り出す follow-up Issue を立てることを提案します。この PR では少なくとも、Dropguard とEINTRの retry を揃えておくと安全です。
- N2. rlimit についての記述: PR 本文と lib.rs は「
unsafe_code = "forbid"のためRLIMIT_FSIZE/RLIMIT_ASを設定できない」としています。しかし PR #30 は、Linux では spawn 後にprlimitで子に設定しています(unsafe 不要)。mutool や pdftoppm は起動直後に大きな確保をしないので、spawn 直後のprlimit(RLIMIT_AS / RLIMIT_FSIZE)でも、Linux では実効的な上限になります。今回やらないなら、記述を「Linux では prlimit で可能だが今回は見送り(#25)」のように正確にしてください。 - N3. Auto の fallback 範囲: Auto は「tool があるか」だけで backend を選ぶので、mutool が特定の PDF で
pdf_unreadableや全ページrender_failedになっても、poppler では再試行しません。仕様としては問題ありませんが、rustdoc に明記しておくと #6 で混乱しません(必要になったら、後で「失敗したら他方で再試行」を足せばよいと思います)。 - N4. tool に渡す
PATH: 検出では相対 entry を除外していますが、tool には host のPATHをそのまま渡しています。mutool / pdftoppm は他のプログラムを起動しないので、絶対 entry だけ(または tool の directory だけ)に絞っても困らないはずです。§3.4 の「tool は絶対パスで起動」という趣旨とも揃います。 - N5. SKIPPED の表示:
eprintln!によるSKIPPED:は、cargo testの既定の出力 capture に隠れます。host で実行すると 12 件すべてがokと表示されるだけでした。PR 本文と development.md の「stderr に SKIPPED と表示」は、--nocaptureを付けた場合の話だと書いてください。もしくは、skip した backend 名を test 名に出すなどで見えるようにしてください。TEXRUN_REQUIRE_PREVIEW_TOOLS=1の方針そのものは良いと思います。#10 / #11 の integration job では、確実に設定されるようにしてください。 - N6.
inspectの status: 成功しても常にskippedになるため、JSON だけを見ると失敗と区別しにくいです。#6 がinspectを出力に使うなら、pdfの有無で判定するよう rustdoc に書いておくか、inspectedのような値を検討してください。 - N7. cancel の test: cancel の test は、開始前に cancel 済みのケースだけです。timeout と同じ fake tool を使って、実行中に別 thread から cancel し、process group が止まることを確かめる test があると、§3.6 の「同じ poll ループで確認」を直接 cover できます。
- N8. ライセンスの記述: AGPL について書いてあるのは、PR 本文と lib.rs の rustdoc だけです。README の「Preview tool」の項か docs に、次の 2 点を短く書いておくと利用者に伝わります。
- texrun は mutool / poppler を別プロセスとして起動するだけで、link も同梱もしないこと
- AGPL を避けたい場合は
BackendChoice::Popplerを選べること - dev の Docker image は
mupdf-toolsを含むので、将来 image 自体を配布する場合は、その image の配布について AGPL / GPL の条件を別途確認する必要があります。その旨も一言あると親切です。
- N9.(任意)容量: 本文ページは 8-bit RGB で出力されます。容量を減らしたい場合は、グレースケール出力(mutool
-c gray、pdftoppm-gray)を option にする余地があります。図の色が失われるので、既定は今のままでよいと思います。
決定事項の確認(要約)
- ページ数の上限(既定 20 / 最大 200)、合計 128 MiB、timeout 30 秒(metadata を含む全体)、cancel: 実装どおりで、実文書でも確認しました。
- 長辺 4096 px: Poppler では守られますが、MuPDF では M1 のとおり守られない場合があります。
- 外部コマンド: shell 不使用、絶対パスで起動、
env_clear+PATH/LC_ALL=C/ 空のHOME、PDF 引数の絶対パス化、%展開の回避、stderr 抜粋の制御文字 escape は、いずれも問題ありません。 - degraded behavior:
Errは不正な option だけで、それ以外は notice、という分け方は一貫しています。severity の使い分け(想定内の制限は info、要求したページが欠ける場合は warning)も妥当です。 - API と JSON:
render→attach_to→ #21 のcollect_artifactsの流れで、artifact の path は output root 相対(preview/page-NNN.png)になっており、#6 から素直に使えます。JSON の形(pages[]は artifact を flatten したもの +width_px/height_px/dpi、pdf.pagesの寸法は回転前)も、rustdoc の記述どおりでした。
M1(と、可能なら S1)の対応後に再レビューします。
6 tasks done
nishide-dev
added a commit
that referenced
this pull request
Sep 30, 2026
## 概要 最初の backend として TeX Live + latexmk の engine(`LatexmkEngine`)を新 crate `crates/texrun-texlive` に追加する。`docs/security.md` §3 の決定事項(texrun 管理 rc、env allowlist、名前検査、process group の kill、出力上限)に沿って実装した。main の log は #23 の `texrun-latex-log` で diagnostics に変換する。 ## 変更内容 - 新 crate `texrun-texlive`(Unix 専用) - **crate を分けた理由**: subprocess・rlimit・signal を扱う OS 依存コードなので、`texrun-core`(型だけ)と `texrun-workspace`(入力のコピー)から分けた。将来の sandbox backend(#26)は別の `TypesetEngine` 実装として並べられる。依存: `texrun-core`、`texrun-latex-log`、`tempfile`、`rustix`(`process` feature を追加)。 - `LatexmkEngine` / `LatexmkConfig`(latexmk の明示パス、探索用 `PATH`、rc の親ディレクトリ、既定 timeout 60 s、`Limits`、`SOURCE_DATE_EPOCH`) - `probe()`: `latexmk -norc -v` から version(`latexmk 4.86`)を取得する。以降は `info()` がそれを返す。latexmk が見つからない場合や明示パスが実行ファイルでない場合は `EngineError::Unavailable`。 - `run()`: `compile()` と同じ処理に加え、stdout / stderr の先頭(各 4 MiB)と latexmk の PID を返す。`compile()` は `run()` の結果から `CompileResult` だけを返す。 - 起動(§3.5) - `latexmk -norc -r <rc> -pdf -interaction=nonstopmode -halt-on-error -file-line-error -no-shell-escape -outdir=<絶対パス> ./<entrypoint のファイル名>`(`to_cli_arg()` を使う)。cwd は entrypoint のディレクトリ。shell は使わない。 - 起動前に、entrypoint のディレクトリ配下のディレクトリ構造を output dir に作る。output dir とその祖先、`.texrun` は写さず、symlink はたどらない。 - 名前検査: entrypoint と output dir(workspace 相対)に §3.5 の allowlist を適用する。ASCII は英数字・空白と `. _ - + , = @ /` だけ許可し、非 ASCII は Cf と制御文字だけを拒否する。同じ検査を host 側の絶対パス(workspace root、cwd、output dir、rc パス)にも適用する。 - texrun 管理 rc(`src/rc.rs`) - 内容は固定で、request 由来の値は埋め込まない。compile ごとに workspace 外の `texrun-rc-*` 一時ディレクトリに書き、compile 後に(失敗時を含めて)削除する。rc の親ディレクトリが workspace 内になる設定は拒否する。 - `texrun_run` sub は `system { $prog } @cmd` で実行する。**戻り値の仕様**: latexmk はコマンドの戻り値を `system()` と同じ wait status として扱い、rule では 256 で割る(latexmk 4.86 のソースで確認した)。そこで sub は、終了コード `c` なら `c*256`、signal `s` なら `(128+s)*256`、起動失敗(または引数なし)なら `127*256` を返す。0 を返すのは子プロセスが 0 で終了したときだけ。 - `$pdflatex`(`-no-parse-first-line -no-shell-escape`)、`$bibtex`、`$makeindex`、`$biber` を `internal texrun_run` 経由にする。`$kpsewhich` と、それ以外のコマンド変数(`$hilatex`、`$xdvipdfmx`、`$dvips_landscape`、`$hnt_previewer`、`$*_update_command`、`$pscmd`、`$make`、`$start_NT` など)はすべて `NONE` にする。フック、filter、`$pre_tex_code`、`@cus_dep_list` は空にする。 - env(§3.4): `env_clear()` した上で `PATH`、`HOME=<workspace>/.texrun/home`、`openin_any=p`、`openout_any=p`、`max_print_line=10000`、`MKTEX*=0`、`LC_ALL=C` だけを渡す(`SOURCE_DATE_EPOCH` は opt-in)。**`PATH` からは空の entry と相対パスの entry を除く**。cwd が workspace 内なので、`.` などが残っていると、入力に含まれるファイルが `pdflatex` の代わりに実行されうるため(§3.4 の表を更新した)。 - プロセス管理(§3.2・§3.6) - `process_group(0)` で起動する。stdout / stderr は別スレッドで最後まで読み、先頭 4 MiB だけ保持する。 - 1 つの poll ループで、終了・cancel・timeout・出力サイズ(500 ms ごと)を確認する。 - 停止するとき(timeout・cancel・上限超過)と正常終了後に `killpg(SIGKILL)` を送る。途中の return や panic でも、guard の drop で kill と reap を行う。 - 出力上限を超えたら `Failed` とし、`output limit exceeded: ...` という diagnostic を付ける。対象は output dir と `HOME` の合計(1 GiB)と、1 ファイルの大きさ(256 MiB)。 - 結果 - outcome は `Succeeded`(exit 0 かつ PDF がある)/ `Failed` / `TimedOut` / `Cancelled`。`ProcessExit` と elapsed も入れる。 - artifact は `<stem>.pdf` と `<stem>.log`(regular file のときだけ)。`.fls` / `.fdb_latexmk` / `.aux` は収集しない。 - diagnostics(#23 と接続した) - `LogParser::new().with_workspace_root(<TeX の cwd>).with_max_print_line(10000)` で parse する。file には entrypoint のディレクトリを前置し、workspace root 相対にする。 - log が 16 MiB を超える場合は、末尾 16 MiB だけを parse して info diagnostic を付ける(parser のメモリは log の大きさに比例するため)。 - `Kpsewhich command needed but not set up` は latexmk の stderr に出るだけなので、diagnostics には入らない(test で確認)。 - docs - `docs/security.md`: 次の点を実装に合わせた。`RLIMIT_FSIZE` の設定方法(下記)、rc の全項目と sub の戻り値、`internal` の引数分割と `"` の関係、host パスの検査、cwd と log の相対パス、PATH から相対 entry を除くこと、Kpsewhich のメッセージが stderr に出ること、reader thread の待ち時間。あわせて、#22 からの申し送りどおり §3.3 を #21 の実装値(`fmt`/`base`/`mem`、`.biber.conf`、走査上限 40,000)に揃えた。 - `docs/development.md`: ignored test の実行方法を追記した。 ## 確認方法 host(macOS、TeX Live なし)とコンテナ(Debian trixie arm64、TeX Live 2024 + latexmk 4.86)の両方で、次を実行して成功した。 - [x] `cargo check --workspace --all-targets --all-features --locked` - [x] `cargo fmt --all -- --check` - [x] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`(コンテナでは Linux 用の cfg も確認) - [x] `cargo test --workspace --locked` - [x] `cargo deny --locked check`(host) - [x] コンテナで `cargo test --workspace --all-features --locked -- --include-ignored`: `texrun-texlive` の unit test 47 件(ignored の 1 件を含む)と integration test 16 件がすべて成功した。 TeX Live が無くても動く test(CI の linux / macos で実行される): - rc の内容(全 `NONE` 変数、sub の shell 非経由と戻り値、合図待ちの有無、`%` placeholder) - argv、env が allowlist と完全に一致すること、PATH の sanitize、名前検査(許可 / 拒否 / Cf) - ディレクトリの写し(`.texrun`、output dir の祖先、symlink の扱い)、サイズ集計 - `sh` の孫プロセスを使った timeout / cancel の group kill - stdout の切り詰め - latexmk が無い場合の `Unavailable` - cancel 済みの token では起動しないこと - 偽の latexmk(shell script)を使った end-to-end: 子プロセスに見える env、argv、cwd、rc ディレクトリが削除されること TeX Live が必要な test(`#[ignore]`、`docker compose run --rm dev cargo test -p texrun-texlive -- --ignored`): - 最小の article から PDF ができる(artifact は PDF と log だけ。`.texrun` 配下には `home` と `out` だけが残り、rc は残らない) - 未定義命令で `Failed` になり、`UndefinedControlSequence` の diagnostic が `main.tex:4` を指す - latexmk が無い場合の `Unavailable`(compile と probe) - `\def\x{\x}\x` で timeout 3 s → `TimedOut`(SIGKILL)になり、`ps` で group に生きているプロセスが残っていない - cancel → `Cancelled`。同じく子孫が残らない - process tree: pdflatex の親が latexmk(group leader)で、group 内に `sh` / `dash` / `bash` がいない。pdflatex の argv に `-no-parse-first-line -no-shell-escape` がある - サブディレクトリの entrypoint(`\input` と `\include{chapters/intro}`): `chapters/intro.aux` が output dir にでき、undefined reference の file が `src/chapters/intro.tex` になる - 日本語と空白を含むファイル名(`論文 ドラフト.tex`)、先頭が `-` のファイル名 - bibtex(`.bbl` ができ、引用が解決される。Kpsewhich のメッセージは stderr にだけ出る)、makeindex - `\write18` が無効(`runsystem(...)...disabled`、ファイルは作られない) - output dir の合計の上限と、1 ファイルの上限(Linux では `RLIMIT_FSIZE` によって log がちょうど上限の大きさで止まる) - `HOME` に置いた `.latexmkrc` は読まれない - 合図が無い場合、rc は終了コード 125 で終了し、何も書かない ## レビュー対応(2 回目の commit) - must-fix: `LatexmkConfig::latexmk` の明示パスは、`locate()` で `canonicalize` した絶対パスに解決してから確認・起動する。相対パスは texrun の cwd を基準に解決する。拒否ではなく解決を選んだのは、CLI(#6)で `--latexmk ./bin/latexmk` のように書けると便利だからである。解決できなければ `Unavailable`。test(相対パスが絶対パスになる、解決できない相対パスは `Unavailable`)と §3.4 を追加した。 - should-fix 1: leader の終了を `waitid(P_PID, EXITED | NOHANG | NOWAIT)` で検知して、reap せずに zombie のまま残す。`killpg` の後で `wait` によって reap する。timeout / cancel / 上限超過 / 正常終了のすべてでこの順序になる。§3.6 も改めた。 - should-fix 2: Linux では `RLIMIT_FSIZE` と同時に `RLIMIT_CORE=0`(soft・hard とも)を設定する。§3.2 に追記した。macOS では停止を `SIGKILL` で行うので core は作られない。ignored の per-file test では、test process の soft `RLIMIT_CORE` を hard(dev コンテナでは unlimited)まで上げたうえで、workspace に `core` が無いことを assert する。`RLIMIT_CORE` の設定を外すとこの test が失敗することも確認した。 - nit: 1. host 側の問題は `Unavailable` にした。対象は、host パス(temp dir 名など)が名前検査を通らない場合と、rc の親ディレクトリが workspace 内にある場合。request 自体の問題は従来どおり `InvalidRequest`。 2. `prlimit` で設定する値は、texrun 自身の hard limit との min にした。 3. 起動前に、output dir にある既存の `<stem>.pdf` / `<stem>.log` を削除する。`run()` の doc に明記し、test を追加した。 4. `probe()` を呼ぶまで version が `None` であることを `LatexmkEngine` の doc に書いた。 5. `LatexmkRun::pid` の doc に「診断用。終了後に signal を送る用途に使わない」と書いた。 6. `japanese_and_space_file_names` に全角空白(U+3000)のケースを追加した。unit test では U+00A0 / U+2002 / U+2028 も許可されることを確認している。 7. ignored test の命名は、後続への申し送りとして補足に書いた。 8. rc に `%extra_rule_spec = ();` を追加した(latexmk 4.86 の既定値が空の hash であることを確認した)。 ## 関連 Issue Closes #5 ## 補足 - **実現方法を変えた制限: `RLIMIT_FSIZE`** - `pre_exec` は `unsafe` なので、`unsafe_code = "forbid"` を維持するために使っていない。 - 代わりに、Linux では spawn 直後に親から `prlimit(2)` を latexmk に適用する(`rustix::process::prlimit`)。latexmk がそれより前に書き込みや子プロセスの起動をしないよう、rc の先頭で stdin から合図を 1 行待たせ、`prlimit` の後に親が合図を送る。合図の前に stdin が閉じた場合、rc は何もせずに終了コード 125 で終わる。 - macOS には `prlimit` が無いので、1 ファイルの上限は 500 ms ごとの poll でだけ強制する。検出までの間は上限を超えて書かれうる。`docs/security.md` §3.2 に明記した。 - **timeout の既定値**: `CompileOptions.timeout` が `None` のときは、engine 側でも `LatexmkConfig::default_timeout`(60 s)を適用する。安全側に倒すためで、CLI(#6)が値を入れる前提は変わらない。 - **stdout / stderr の扱い**: backend 非依存の `CompileResult` には field が無いので、engine 固有の `LatexmkRun` で返している。`Transcript` artifact としてファイルに書き出すかは #6 で決めてほしい。 - **既知の制約** - group から抜けたプロセス(新しい session を作ったもの)は追えない。reader thread は kill 後に最大 2 秒だけ待って打ち切る。 - 同じ compile の前の pass で作られた PDF は、後の pass が失敗した場合も artifact として報告される(`Failed` の部分出力として扱う)。以前の compile で残ったものは、起動前に削除する。 - **#10 / #11 への申し送り(ignored test の運用)**: `cargo test -p texrun-texlive -- --ignored` で、unit(`gated_rc_does_nothing_without_the_start_token`)と integration の両方が走る。ignore の理由の文字列は統一してある。ただ、今後ほかの crate に TeX Live 以外の理由で ignored の test が増えると、`--ignored` の対象が混ざる。#10 で方針を決めるときに、test 名の prefix(例 `texlive_`)か nextest の filter に揃えてほしい。 - **後続 Issue 候補(共通化)**: 次の実装は、PR #31(preview)の外部コマンド起動と重複している。後続 Issue で共通化する(今回はしない)。 - process group での起動、`waitid(WNOWAIT)` → `killpg` → reap の順序 - reader thread による出力の保持量の制限 - env allowlist - timeout / cancel の poll - **texrun-workspace は変更していない。** integration test では dev-dependency として `Workspace::create` / `context()` / `request()` を使っている。 - **レビューしてほしい点**: rc の `NONE` 一覧に漏れがないか(latexmk 4.86 のソースから拾った)、`prlimit` と合図待ちによる順序の保証、`PATH` の sanitize。 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Sep 30, 2026
Add the texrun-preview crate: page count, page sizes and PNG page previews via external tools (MuPDF mutool preferred, Poppler pdfinfo/pdftoppm as fallback), returned as Preview artifacts relative to the output root. Tool problems, limits and timeouts are reported as notices, never as compile failures. Tools run without a shell, with a cleared environment and in their own process group. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Honor UserUnit in mutool page sizes, pass the long edge limit to mutool draw as a bounding box and discard any image over the limit. - Create preview/ with mkdirat/openat(O_NOFOLLOW) and move images with renameat between directory descriptors. - Set RLIMIT_AS/RLIMIT_FSIZE on the tools with prlimit on Linux, add a kill-and-reap guard and EINTR retry, pass only absolute PATH entries. - Report metadata-only runs as `inspected`; document Auto selection, licensing and how skipped tool tests are shown. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nishide-dev
force-pushed
the
feat/page-previews
branch
from
September 30, 2026 08:06
d7204ae to
734175e
Compare
Owner
Author
|
レビューありがとうございました。origin/main(#30 を含む)に rebase し、 must-fix
should-fix
nit
確認
|
nishide-dev
commented
Sep 30, 2026
nishide-dev
left a comment
Owner
Author
There was a problem hiding this comment.
Verdict: APPROVE
734175e(main に rebase 済み)を再レビューしました。前回の M1 と S1 はどちらも解消しており、指摘した nit もほぼすべて対応されています。確認した範囲では退行はありませんでした。
実行結果(head 734175e)
- host(macOS、poppler のみ):
cargo fmt --check、cargo clippy --workspace --all-targets --all-features --locked -D warnings、cargo test --workspace --locked、cargo deny --locked checkはすべて OK でした。--nocaptureを付けなくても、texrun-preview real_tools: SKIPPED all mupdf checks ...が表示されることを確認しました。
- container:
TEXRUN_REQUIRE_PREVIEW_TOOLS=1 cargo test --workspace --lockedはすべて OK でした(mutool 1.25.1 / poppler 25.03)。preview は unit 25、degraded 13、real_tools 13 件です。 - CI は全 job が pass しています。
- 前回と同じ実文書(298 ページ。A4 本文、図、横向き、A3、10in×3in、A0 横)で再検証しました。Linux のコンテナなので
prlimitが効いた状態です。
| backend | 選択 | 結果 | 合計サイズ | 時間 | 前回との比較 |
|---|---|---|---|---|---|
| mupdf | 既定(先頭 20) | rendered 20 | 3.97 MB | 0.75 s | 同じ |
| mupdf | 1-(200 ページ) |
rendered 200 | 50.6 MB | 7.3 s | 同じ |
| mupdf | 281- |
rendered 18 | 4.7 MB | 0.75 s | 同じ |
| poppler | 既定(先頭 20) | rendered 20 | 4.77 MB | 3.5 s | 同じ |
| poppler | 1- |
partial 144(timed_out) | 43.8 MB | 30.0 s | 前回と同じく timeout で停止 |
| poppler のみの PATH(Auto) | 既定 | poppler に fallback し rendered 20 | — | 3.6 s | 同じ |
| tool なし | — | skipped + tool_unavailable |
— | — | 同じ |
- 画像の寸法も前回と同じでした。A4 は 1191×1684 px、横向きページは 1684×1191 px、A0 は 87 DPI で 4073×2881 px です。
RLIMIT_AS2 GiB による退行は見つかりませんでした。 通常の大判ページに加えて、約 14000×9900 px のラスター画像(展開すると約 400 MB)を貼った A0 の 3 ページ文書でも試しました。両 backend とも 3 ページすべてが 87 DPI で描画されました(mupdf 2.9 s、poppler 5.5 s)。200 ページの連続描画も上の表のとおり問題ありません。
前回の指摘への対応
- M1(長辺上限): 解消。
- 拡大係数を持つページについて、長辺の上限を 1000 に下げた場合と既定の 4096 の場合を試しました。mupdf では 36 DPI・1000 px と、144 DPI・4000 px で、どちらも上限内です。poppler ではどちらも 200 px でした。
- 3 段の強制(DPI の計算、mutool の bounding box、IHDR の事後検査)はいずれも実装されています。事後検査は fake tool の test(
an_image_over_the_pixel_limit_is_discarded)で、UserUnit の fixture は real_tools で、それぞれ cover されています。security.md にも記述されました。
- S1(fd ベースの保存): 解消。
preview/はmkdiratとopenat(O_NOFOLLOW)で作って開き、画像はrenameatで directory の fd 間で移動しています。書き出したファイルの確認もstatat(SYMLINK_NOFOLLOW)とO_NOFOLLOW | O_NONBLOCKで行っています。- 既存の symlink を置き換えて、その先を辿らないことを確認する test も追加されました。#21 と同じ水準です。
- N1(PR #30 との重複):
Dropguard とEINTRの retry が入りました。共通化は #32 で追跡されています。 - N2(rlimit): Linux では
prlimitでAS2 GiB、FSIZE(残りの画像予算、ただし最低 16 MiB)、CORE0 が設定されます。設定値は texrun 自身の hard limit を超えません。/proc/self/limitsを確認する test もあります。FSIZEでSIGXFSZになった場合も、終了 status より先にサイズを確認してsize_limitとして扱っているので、notice の種類は一貫しています。
- N3〜N8: すべて対応を確認しました。
- Auto の選び方を明記
- tool に渡す
PATHを絶対 entry だけに限定(test あり) - SKIPPED の表示
inspectの status をinspectedに変更- 実行中の cancel で process group が止まることを確かめる test
- README の AGPL / GPL の記載(Docker image を配布する場合の注意を含む)
残る nit(merge を妨げない)
- N-a. scratch dir は、まだ path 経由で扱っている。
.texrun-preview-*の作成(tempdir_in(root))、work/を開く処理、tool の cwd と出力先の指定は、いずれも path 経由です。- 最終的な移動先は fd で守られているので、output root の外に書き込まれることはありません。この間に差し替えが起きた場合に影響するのは、tool が一時ファイルを書く場所だけです。現在の MVP の前提(shell-escape が無効)では、現実的な問題ではないと考えます。
- 必要になったら、#32 の共通化の際に、scratch dir を root の fd から
mkdiratで作り、openatで開く形にそろえられます。
- N-b.
PdfInfo.pagesの寸法が backend によって違う。- 拡大係数を持つページでは、mupdf は係数を掛けた値(例: 2000 pt)を、poppler は係数を掛けない値(100 pt)を返します。描画結果もそれぞれの値と一致しているので、backend ごとには正しいです。
- rustdoc の
width_pt/height_ptに「backend が描画に使うサイズ」と一言書いておくと、#6 の JSON を使う側が混乱しません。
以上から APPROVE とします。
This was referenced Sep 30, 2026
nishide-dev
added a commit
that referenced
this pull request
Sep 30, 2026
## 概要 TeX Live を使う integration test 用の fixture(#10)と、それを CI で実行する `integration` job(#11 の残り)を追加します。 fixture は workspace の作成から latexmk engine の compile までを通して実行し、構造化された結果で検証します。docs/security.md §2 の保証を確かめる security fixture も含みます。 TeX Live が必要な test の選び方は、#31 の `TEXRUN_REQUIRE_PREVIEW_TOOLS` と同じ「実行時に検出し、環境変数で必須にする」方式にそろえました。 ## 変更内容 ### 選別方式(`TEXRUN_REQUIRE_TEXLIVE`) - TeX Live を使う test は `require_texlive!()` で始める。`latexmk` が見つからなければ skip する。skip したことは、test binary ごとに 1 回、stderr に `SKIPPED ... (set TEXRUN_REQUIRE_TEXLIVE=1 to fail instead)` と出す。libtest の capture を通さないので `cargo test` で見える - `TEXRUN_REQUIRE_TEXLIVE=1` のときは skip ではなく失敗にする。preview tool は既存の `TEXRUN_REQUIRE_PREVIEW_TOOLS=1` をそのまま使う(texlive 側の PDF ページ数と preview の確認もこれに従う) - 既存の `#[ignore]`(`tests/latexmk.rs` の全 test と、`src/engine.rs` の unit test 1 件)はこの方式に置き換えた。repo 内に TeX 用の `#[ignore]` は残っていない - `#[ignore]` や cargo feature を採らなかった理由: - #31 と方式が統一できる - tool がある環境では、何も指定しなくても実行される - CI では、環境変数 1 つで「不在なら失敗」にできる - cargo feature にすると、`--all-features` を付けた fast job で TeX 必須になってしまう ### fixture(`crates/texrun-texlive/tests/fixtures/`) - engine crate の中に置いた。repo root には package が無く、fixture を使う test(dev-dependency に `texrun-workspace` / `texrun-preview` を持つ)がここにあるため - fixture のディレクトリは、そのまま project root として `Workspace::create` に渡す。コピーして使うので、test が fixture の隣に書き込むことはない | fixture | 検証内容(`scenarios.rs`) | | --- | --- | | `minimal` | `Succeeded`・exit 0・error 0 件、artifact は PDF と log だけ(size は実ファイルと一致、PDF は 1 ページ)、`collect_artifacts` で host にコピーされる | | `syntax-error` | `\begin{itemize}` を `\end{enumerate}` で閉じる: `Failed`、PDF なし、`latex_error` @ `main.tex:5` | | `undefined-command` | `Failed`、`undefined_control_sequence` @ `main.tex:5` | | `missing-package` | `Failed`、`missing_file`(file = `main.tex`。TeX は停止位置しか出さないので、line は検証しない) | | `references` | bibtex(biber は使わない): `.bbl` に解決した key がある。未定義の `\ref` / `\cite` は warning(@ `main.tex:5`)で、outcome は `Succeeded`。kpsewhich 無効の stderr が diagnostic にならない | | `overfull-box` | `overfull_box` warning @ `main.tex:5` | | `timeout` | `\def\x{\x}\x` を timeout 2 秒で実行: `TimedOut`、SIGKILL、PDF なし、process group が残らない | | `multi-file` | サブディレクトリの `\input` / `\include`: workspace へのコピー、子ファイルの `.aux` が output dir にできる、3 ページ、未定義の参照は `chapters/body.tex:4` に帰属する。`\input` した子ファイルの error は `chapters/broken.tex:2` に帰属する。preview 3 ページを生成し、`attach_to` と `collect_artifacts` まで確認する | | `unicode-names` | `論文 下書き.tex`(日本語 + 空白)と `全角 空白.tex`(U+3000)。artifact 名と、`章/節1.tex:3` への帰属 | ### security fixture(`fixtures/security/`、`security.rs`) docs/security.md §2 の「保証する」項目を、workspace + engine の経路で検証する。 fixture は防御が効いていることを確かめる最小限の内容だけにし、コメントに手法の解説は書いていない。 読み書きの拒否を確かめる test では、workspace 内なら同じ仕組みで読み書きできることを対照として確認する。これで、fixture の誤りによって「拒否された」ように見えることを防ぐ。 | 保証 | 検証 | | --- | --- | | shell escape 無効 | `\write18` と pipe による `\input` で marker file ができない | | latexmkrc を読まない | workspace へのコピーで `latexmkrc` / `.latexmkrc` が `ToolConfig` として除外される。さらに、compile 前に workspace と HOME へ rc を置いても読まれない(読まれたら compile が失敗する内容) | | `%&` 行の無効化 | 存在しない format を指定した先頭行があっても `Succeeded` | | 補助ツールが shell を経由しない | pdflatex / bibtex / makeindex を記録用の wrapper に差し替え、各呼び出しの親プロセスが `latexmk` であることを確認する。空白を含むファイル名が 1 つの引数のまま渡ること、pdflatex に `-no-shell-escape` / `-no-parse-first-line` が付くことも確認する。latexmk 既定の設定では親が `sh` になることを事前に確かめ、この検査で違いを検出できることを確認した | | workspace 外の `\input` / `\openin` / `\openout` を拒否 | 絶対パスと `..` の両方。workspace の親ディレクトリを test 用に指定し(`with_temp_parent`)、そこに probe を置いて使う。書き込みは、その tree のどこにもファイルができないことで確認する | | root 外 symlink を拒否 | 実行時に作った symlink で `SymlinkOutsideRoot` になる(TeX 不要なので常に実行) | docs/security.md に、保証と test の対応表(「保証の検証」)を追加した。 kpathsea の paranoid mode を `a` に戻すと outside-paths の probe が読み書きされることを、コンテナ内で pdflatex を直接実行して確かめた。 ### CI(`integration` job) - `docker/setup-buildx-action` + `docker/build-push-action` で dev image を build する(`cache-from/to: type=gha`、`mode=max`) - その image の中で `TEXRUN_REQUIRE_TEXLIVE=1 TEXRUN_REQUIRE_PREVIEW_TOOLS=1 cargo test --workspace --all-features --locked` を実行する。TeX Live と preview tool のどちらが無くても失敗する。#31 の preview 実ツール test もここで実行される - `target/docker` と cargo registry は `actions/cache` の restore / save で持ち越す(save は main の push のときだけ) - `Tool versions` step で、cargo / latexmk / pdfTeX / mutool / pdfinfo の version を表示する - `ci-success` の `needs` に `integration` を加えた(所要時間は下記)。branch protection の必須 check 名(`ci-success` / `pr-title`)は変えていない - base image を digest で固定した(`rust:1.98.1-slim-trixie@sha256:4cd8…`)。`ARG` を使った `FROM` は Dependabot が解釈できないので、固定値にした - Dependabot に docker ecosystem(`/docker/dev`)を追加した。digest の更新だけを受け取り、Rust の version(tag)は `rust-toolchain.toml` と一緒に手で上げるので、semver の更新は ignore している ### 文書 - `docs/development.md`: 「TeX Live integration test」節を書き直した(環境変数の表、実行コマンド、test と fixture の構成)。base image の digest 固定の説明も追加した - `CONTRIBUTING.md`: integration test の実行方法と、CI の check 表に `integration` を追加した ## 確認方法 - [x] `cargo check --workspace --all-targets --all-features --locked` - [x] `cargo fmt --all -- --check` - [x] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - [x] `cargo test --workspace --locked`(host の macOS、TeX Live なし): TeX の test は `SKIPPED` を表示して pass する - [x] host で `TEXRUN_REQUIRE_TEXLIVE=1` を付けると、TeX の test が失敗することを確認した - [x] `docker compose run --rm -e TEXRUN_REQUIRE_TEXLIVE=1 -e TEXRUN_REQUIRE_PREVIEW_TOOLS=1 dev cargo test --workspace --all-features --locked`: 全件 pass(texlive: unit 47、latexmk 10、scenarios 11、security 14。preview の real_tools 13 を含む) - [x] `docker compose build dev`(digest を固定した Dockerfile) - [x] `actionlint` ## 関連 Issue Closes #10 Closes #11 ## 補足 - PDF のページ数は `texrun-preview` の `inspect` で読む(dev-dependency を追加した)。preview の compile → render → collect の end-to-end は `multi_file_previews` で確認している - parser の既知の制約として、空白を含むファイル名の中で出た warning には file が付かない(TeX がその名前を quote せずに出すため。texrun-latex-log の `unusual-names` fixture と同じ挙動)。そのため、`unicode-names` の子ファイル名には空白を含めていない。entrypoint には空白を含めている - 画像・bibtex の database・pdfTeX のファイル情報系 primitive の経路は、§6 の実験で確認したもので、fixture にはまだ含めていない(security.md に明記した) - `apps/texrun`(#6)と README には触れていない。CLI の end-to-end test は、#6 で同じ fixture(`crates/texrun-texlive/tests/fixtures`)を参照して追加できる 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
nishide-dev
added a commit
that referenced
this pull request
Sep 30, 2026
## 概要 MVP の主要インターフェースとして `texrun compile [OPTIONS] <ENTRYPOINT>` を実装します(#6)。workspace 作成 → latexmk 実行 → 成功時の page preview(#8 / PR #31)→ artifact の収集 → workspace 削除を 1 コマンドで行い、結果を human-readable または JSON(`Versioned<...>`)で返します。exit code を確定し、README とヘルプに記載しました。 ## 変更内容 - **`apps/texrun`**(`cli.rs` / `compile.rs` / `report.rs` / `human.rs` / `escape.rs` / `duration.rs` / `signals.rs`) - option: `--json`、`-o, --output <DIR>`、`--root <DIR>`、`--timeout <DURATION>`(既定 `60s`、`90` / `2m` / `1500ms` 形式、0 は usage error)、`--keep-workspace`、`--source-date-epoch <SECONDS>`、`--no-preview`、`--pages <RANGE>`、`--preview-dpi <DPI>`、`--preview-backend <auto|mupdf|poppler>` - pipeline: `ProjectInput::from_host_entrypoint` → root の安全性チェック → `LatexmkEngine::probe()`(latexmk 不在をコピー前に検出し、version を結果に載せる)→ `Workspace::create` → `engine.run`(`CancelToken` 共有)→ `Succeeded` のときだけ `Previewer::render`(workspace の output dir に描画し `attach_to`)→ `collect_artifacts(.., OverwritePolicy::Replace)` → `ws.close()` - **出力先**: 既定は entrypoint 隣の `texrun-out/`。同名ファイルは atomic に置き換え、destination の symlink は拒否(#21 の collect の挙動)。過去の run の PDF / preview は削除しない(help と README に明記)。`texrun-out` は常に、root 直下の `--output` は `excluded_root_names` で、次回の workspace にコピーしない - 出力先ディレクトリへの経路は 1 component ずつ `symlink_metadata` で辿り(各ディレクトリは canonical な綴りに置き換えて比較するので、大文字小文字や Unicode 正規化を区別しない filesystem でも判定がずれない)、**project root 内にある symlink**(または非ディレクトリ)があれば `unsafe_output_path`(stage `output`、exit 3)で拒否する。compile 前に一度確認し、コピー時に `create_dir` で 1 段ずつ作りながら再確認する(`apps/texrun/src/output.rs`)。project 外の symlink(macOS の `/tmp` や、user が明示した `--output` の link)は辿る - root の 2 段以上下の `--output` は次回の workspace にコピーされるため、warning(`notes[].kind = output_inside_project`)を出す。パスでの除外は #36 - **root の扱い**: `/` は常に拒否。`$HOME` と system temp dir(`TMPDIR`、`/tmp`、`/var/tmp`)は、既定 root になる場合は `unsafe_root`(exit 2)で拒否し、`--root` で明示された場合は stderr に warning を出して続行 - **exit code**(help / README に記載) | code | 意味 | | --- | --- | | 0 | 成功(PDF あり) | | 1 | 文書の compile 失敗(diagnostics あり。output limit 超過も含む) | | 2 | usage / input error(clap の usage error、entrypoint 不在・root 外、symlink が root 外、入力上限、unsafe root、engine の `InvalidRequest`) | | 3 | runtime error(latexmk 不在 / 起動失敗、I/O、artifact の収集失敗) | | 4 | timeout | | 128+N | signal による中断(SIGINT 130 / SIGTERM 143 / SIGHUP 129)。compile 後の preview 中に中断した場合も含む | signal 以外では preview は exit code に影響しない(失敗は notice)。`WorkspaceErrorKind::is_input_error()` を 2、それ以外を 3 にしています - **Ctrl-C**: `signal-hook`(iterator のみ)で SIGINT / SIGTERM / SIGHUP を受け、`CancelToken` を立てるだけにしました。engine と previewer がそれを見て process group を kill し、通常経路で collect・workspace drop を行ってから `main` が `ExitCode` を返します(`process::exit` は使いません)。2 回目以降の signal は「停止中」と表示するだけです - **human-readable**(stdout = 結果、stderr = texrun 自身の warning / error) - diagnostics: `file:line: error: message`。error → warning → note の順で、同一内容は `(xN)` にまとめ、各 20 件まで(残りは件数と `--json` の案内)。file は user が打った root 基準(例 `paper/chapters/intro.tex:3:`) - 状態行(`Compiled` / `Failed to compile` / `Timed out ... (limit 60s; raise it with --timeout)` / `Cancelled`)と経過時間、PDF(失敗時は log)と preview のパス、preview notice - workspace で除外した latexmkrc / biber.conf、`*.fmt`、dangling symlink 等を stderr に warning 表示(docs/security.md §3.3)。`--keep-workspace` のパスは compile 前に stderr に出す - 表示時は制御文字(C0 / DEL / C1、改行を含む)、Unicode Cf(bidi 制御・ゼロ幅・U+FEFF 等)、U+2028/2029 を `\u{XXXX}` で escape(docs/security.md §2)。JSON はそのまま - `MissingFile` の message に `../` がある場合、「`--root` を付けても entrypoint のディレクトリより上は読めない。entrypoint を include 先を含むディレクトリに移す」旨の note を出す(§3.5)。JSON では `notes` に入る - latexmk 不在時は `hint`(PATH に latexmk を入れる / Docker 開発環境)を付ける。entrypoint が root 外を指す symlink の場合は、その旨を hint に出す - **JSON**: stdout には JSON 1 つだけ(成功・失敗・timeout・runtime error・`--json` 付きの usage error いずれも)。 - `texrun_exit_code`(texrun 自身の exit code)と、`CompileResult` を flatten したもの(`outcome` / `engine` / `exit` / `elapsed_ms` / `diagnostics` / `artifacts`)。`exit` は latexmk プロセスの終了状態で、README と doc に明記した(名前は core の `CompileResult` のまま) - `preview`(`PreviewReport`)、`output_dir`(絶対パス)、`artifacts_not_copied`(コピーが途中で失敗したときの未コピー分)、`notes`(`parent_directory_input` / `broad_project_root` / `output_inside_project`)、`project`(canonical root と entrypoint)、`workspace`(excluded / excluded_total / vanished / kept_path)、`error`(`stage` / `kind` / `category` / `message` / `hint`) - artifact は 1 件ずつコピーし、失敗した時点で止める。`artifacts` はコピー済みのものだけ、残りは `artifacts_not_copied` に入る。human 表示では「Compiled ..., but the output could not be copied to DIR」と未コピーの一覧を出す - `error.kind` の一覧(CLI / engine / workspace)を README に記載し、CLI 固有の code が README にあることを unit test で確認する - artifact の path は core の契約どおり output root 相対のままにし、絶対パスは `output_dir` 1 箇所だけに持たせました(preview を含め `output_dir` + `path` で解決できるため、per-artifact の絶対パスは付けていません) - host path は UTF-8 前提です。entrypoint / `--root` / `--output` が UTF-8 でない場合は `non_utf8_path`(exit 2)で拒否します - **`SOURCE_DATE_EPOCH`**: option 指定時だけ `LatexmkConfig::with_source_date_epoch` に渡します。環境変数は読みません(§3.9) - **README**: CLI 節を実装に合わせて書き換え(option 表、出力の方針、JSON 形状、exit code 表)。Status の「未実装」を更新 - **docs/security.md**: §3 冒頭の「timeout 以外を CLI で上書きできるかは #6 で決める」を、決定内容(timeout と preview のページ範囲・DPI のみ)に置き換え - **依存追加**: `signal-hook 0.4.4`(`default-features = false, features = ["iterator"]`、MIT OR Apache-2.0) ## 確認方法 - [x] `cargo check --workspace --all-targets --all-features --locked` - [x] `cargo fmt --all -- --check` - [x] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`(host の macOS と dev container の Linux) - [x] `cargo test --workspace --locked`(host) - [x] `cargo deny --locked check` - [x] dev container: `docker compose run --rm -e TEXRUN_REQUIRE_TEXLIVE=1 -e TEXRUN_REQUIRE_PREVIEW_TOOLS=1 dev cargo test --workspace --all-features --locked` で全件成功(`apps/texrun` の TeX Live E2E 6 件を含む。ignored は 0 件) test: - unit: escape(ANSI / bidi / ゼロ幅 / C1 / タグ文字)、duration の parse / 表示、exit code の対応、error chain、JSON の形(error のみ / flatten)、human 表示(位置付き diagnostics、集約と件数上限、escape、timeout、preview 行と notice)、clap 定義、root の安全性チェック、output dir が root 直下かの判定 - `tests/cli.rs`(TeX 不要。`PATH` を sandbox の bin だけにし、fake の `latexmk` / `pdfinfo` / `pdftoppm` shell script を置く。`TMPDIR` / `HOME` も test ごとに分離): help / version、usage error(JSON あり・なし)、成功時の出力先と JSON 形状、`--output` / `--root`、文書エラー(exit 1、diagnostics の file / line、表示時の escape と JSON の生文字列)、latexmk 不在(exit 3、`stage: probe`、`kind: unavailable`)、入力エラー(exit 2)、`$HOME` / temp dir の root 拒否、latexmkrc の warning、timeout(exit 4、子の停止)、SIGINT / SIGTERM(exit 130 / 143、子の停止、temp dir に何も残らない)、`--keep-workspace`、`--source-date-epoch`(環境変数は渡らない)、出力先の symlink(exit 3 だが `outcome` は残る)、preview の描画と収集・`--pages`・失敗時は preview なし・tool 不在は warning のみで exit 0 - `tests/texlive.rs`(#33 と同じ実行時検出方式。`require_texlive!()` / `require_preview_tools!()`、helper は `tests/common` に最小限複製。名前は `texlive_` prefix): 実 TeX Live での成功(include あり)、`crates/texrun-texlive/tests/fixtures` の `minimal` を `-o` 付きで compile して fixture 側に何も書かないこと、位置付きエラー(`chapters/intro.tex:3`)、preview(3 ページ、`--pages 2 --preview-dpi 72`)、timeout(`timeout` fixture)、SIGINT で exit 130 と temp dir の cleanup - `output.rs` の macOS 専用 unit test: 大文字小文字違い・NFC/NFD 違いの path でも project 内の symlink を拒否すること ## 関連 Issue Closes #6 Refs #12 ## 補足 - **Windows**: `apps/texrun` が `texrun-workspace` / `texrun-texlive` / `texrun-preview` に依存するので、CLI は Unix 専用になります(README の System requirements どおり) - **Ctrl-C のタイミング**: probe 中に signal を受けた場合は workspace を作らずに `cancelled` を返す。workspace のコピー中は中断できないが、コピー後は engine が latexmk を起動しない - **follow-up**: #35(missing package の行番号・fatal error の件数、#7 系)、#36(root 配下の深い出力先をパスで除外) - **#29 からの申し送り(`WorkspaceChanged` の分離)**: CLI 側では `ArtifactNotFile` をそのまま `kind` に出し、分離はしていません。外から区別する手段がないため、分けるなら workspace crate 側に variant を足すのが筋だと考えています(`#[non_exhaustive]` なので追加は非破壊) - **stale な出力**: 失敗した run では過去の `main.pdf` や、ページ数が減ったときの古い `preview/page-NNN.png` が出力先に残ります。user の `--output` を消すのは避け、JSON の `artifacts` / exit code を正とする方針にしました - **preview の cancel**: preview 中の Ctrl-C は preview を止め(notice `cancelled`)、`outcome` は `succeeded` のまま、exit code は 130 になります - **nit 候補(今回は未対応)**: `--latexmk <path>` は出していません(#30 の指摘どおり相対パス解決の罠があるため、必要になったら別 Issue で)。TeX 由来でない上限(出力サイズ等)は CLI から変更できません - **CI**: #33 再レビューの提案どおり、`integration` job の `#[ignore]` 検出を「test 出力に ignored が 1 件でもあれば失敗」(`tee` + `pipefail` で `test result: .* [1-9][0-9]* ignored` を検出)に置き換えました(`git grep` の step は削除)。docs/development.md の該当箇所も更新しています 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
6 tasks done
nishide-dev
added a commit
that referenced
this pull request
Oct 6, 2026
## 概要 `v*` の tag を push するだけで、検証 → engine image の公開 → **release notes 付き** の GitHub release の作成(source tar 添付)まで完了するようにする。release notes は前の版の tag から今回の tag までの commit(= squash merge した PR タイトル、Conventional Commits)を git-cliff で分類して生成し、インストール方法・image の tag / digest・`gh attestation verify`・source tar の説明を定型で付ける。既存 release の notes だけを作り直す workflow も追加する(v0.1.0 の notes を埋めるのに使う)。 ## 変更内容 - `cliff.toml`(新規): git-cliff の設定。type で分類(`feat` → Features / `fix` → Bug fixes / `perf` → Performance / `docs` → Documentation / `refactor`・`test`・`build`・`chore` → Other changes)。`chore(deps)` は Dependencies に「N dependency updates: #a, #b」の 1 行にまとめる(PR 番号はタイトル行の末尾の `(#N)` だけから取る。番号の無いものは件数にだけ数える)。`!` / `BREAKING CHANGE:` は Breaking changes にも載せる。Conventional でない commit も Other changes に残す。**すべての行は commit のタイトル(1 行目 = PR タイトル)だけから作り**、PR 本文や footer の文面は載せない。末尾の `(#N)` を PR へのリンクにし、`@name` は mention にならないよう code にし、前の版との compare リンクを付ける。 - `.github/scripts/release-notes-test.sh` / `release-notes-test.expected.md`(新規): 使い捨ての repository に main の squash merge と同じ形の fixture の commit(PR 本文付き、実際の Dependabot 形式の本文付き(単独・group)、PR 番号の無い `chore(deps)`、日本語の `BREAKING CHANGE:` footer + attribution、GitHub の Revert、`@name` を含むタイトル)を作り、notes の「What's changed」を期待値と比べる。PR の `notes` job で毎回実行する。 - `.github/scripts/release-notes.sh`(新規): `release-notes.sh <tag> [<digest>]` で notes の Markdown を出力する。 - 安定版は前の安定版から(間の prerelease を畳み込む: `--ignore-tags '^v.*-'`)、prerelease は直前の tag から、最初の版は全履歴。git-cliff の `--context` から対象 tag の release だけを選んで `--from-context` で描画するので、HEAD が tag より先(main)でも同じ notes になる。 - tag がまだ無い場合は「最後の tag 〜 HEAD」をその版としてプレビューする。digest を省略すると placeholder。 - tag が HEAD の祖先でない、semver でない、digest の形式が違う、対象の commit が無い、などはエラー。 - `.github/workflows/engine-image.yml` - `publish` が `digest` を output する。 - `release` が checkout(`fetch-depth: 0`)→ git-cliff(`taiki-e/install-action` を SHA pin、`[email protected]`。install-action が checksum を検証)→ notes 生成(job summary にも出す)→ release の作成(`--notes-file`。版に `-` があれば prerelease にする既存の扱いを維持)。 - release が既にある場合(手で作った / 再実行)は、notes を生成したもので **上書き** してから asset を upload する。 - `.github/workflows/release-notes.yml`(新規): notes の生成だけを行う workflow。image の公開・release の作成はしない。 - `pull_request`(`cliff.toml`・script・この workflow の変更時): fixture の test の後、PR の head commit(merge ref ではなく。`Merge … into …` の行が入らない)で、最後の tag(現状 v0.1.0、全履歴)の notes と、次の版(patch + 1)としての「最後の tag 以降」の notes を job summary と artifact `release-notes` に出す。digest は GHCR から引く(未公開の版は placeholder)。 - `workflow_dispatch`(`tag`、`update`): `update=false`(既定)は dry run。`update=true` は `gh release edit --notes-file` で既存 release の notes を置き換える(main か tag 上の実行のみ。image が GHCR に無い版は失敗)。 - 権限: 生成する `notes` job は `contents: read`。書き込む `update` job だけが `contents: write` で、repository の code は実行しない(artifact を受け取って `gh release edit` するだけ)。 - docs - `docs/development.md`: release 手順を「tag を push するだけ」に更新し、「release notes」節(分類の規則、notes の文面は PR タイトルで決まること、ローカルでの生成方法、作り直し方)を追加。 - `CONTRIBUTING.md`: PR タイトルが release notes の 1 行になること、type / description の書き方の注意、notes の PR check を追記。 - `docs/security.md`(権限の記述)、`docs/engine-image.md`(digest は release notes に載る)を追随。 ## 設計判断 - **git-cliff を採用**(GitHub の自動生成 + `.github/release.yml` ではなく): この repo は PR にラベルを付けない運用で、GitHub の自動生成はラベルでしか分類できない。git-cliff は commit の type で分類でき、PR タイトル = commit タイトルの運用にそのまま合う。API を使わず(`--offline`)git の履歴だけで決まるので、PR 上やローカルでも同じ結果を再現できる。 - **既存 release の notes は上書き**: notes は git の履歴と公開済みの digest から決定的に作られるので、再実行で上書きしても結果は同じ。手で先に release を作った場合も、生成した notes に揃える(docs に明記。公開後の手修正は、作り直すと消える)。 - **CHANGELOG.md は置かない**: tag ごとに CHANGELOG 更新の commit / PR が必要になり、運用が増えるため。GitHub release を changelog とし、必要なら同じ `cliff.toml` から `git cliff` でいつでも全履歴を出せる。 - **notes の作り直しは別 workflow**: engine-image.yml の `workflow_dispatch` は image の公開と結び付いているので、notes だけの経路を分けた。image は再公開せず、digest は GHCR にある既存の版から引く。 - **notes の生成は image の公開後**: digest が要るため `release` job で生成する。設定の誤りは PR 上の `Release notes / notes` で先に検出する。万一 `release` で失敗しても image は公開済みで、`gh run rerun --failed` でやり直せる(既存の手順どおり)。 - **git-cliff の版**: `2.14.2` を両 workflow で固定(install-action の manifest の sha256 で検証)。install-action 自体は SHA pin で、Dependabot の対象。 ## 確認方法 - [x] `actionlint`(全 workflow)、`shellcheck .github/scripts/release-notes.sh` - [x] ローカルで git-cliff 2.14.2(公式 release の tar を sha512 で確認)を使って生成 - `release-notes.sh v0.1.0 sha256:b611…` → 下記(v0.1.0 までの全履歴、32 commit) - `release-notes.sh v0.1.1` → v0.1.0 以降の差分(この PR の commit のみ)のプレビュー - 使い捨ての clone で `v0.2.0-rc.1` / `v0.2.0-rc.2` / `v0.2.0` を打って確認: rc.2 は rc.1 からの差分、v0.2.0 は v0.1.0 からの全部(rc の分を畳み込む)。tag が HEAD の祖先でない場合・semver でない tag・不正な digest はエラーになる - `release-notes-test.sh`: 期待値どおり(下記)。修正前の `cliff.toml` に戻して実行すると、Dependabot の行が `3 dependency updates (Dependabot):,,` に、Breaking changes が日本語の footer + `🤖 Generated with …` に、Revert の行が本文付きに、`@octocat` が mention になり、test が失敗することを確認した - レビュー対応の後も v0.1.0 の notes は変わらない(前回の出力と diff なし) - [x] `CONTRIBUTING.md` / `docs/development.md`: タイトルだけが載ること、`@name` を書かないこと、`jq` が要ること、`update` は通常 `--ref main` で実行すること(v0.1.0 の tag の上には workflow が無い)、fixture の test を追記 - [x] PR 上の `Release notes / notes` が、v0.1.0 と v0.1.1(プレビュー)の notes を job summary と artifact に出す(GHCR から v0.1.0 の digest を引く) - `workflow_dispatch` の dry run は、新規 workflow が default branch に入るまで dispatch できないため、merge 後に `gh workflow run release-notes.yml --ref main -f tag=v0.1.0` で確認する(PR 上の `pull_request` の実行が同じ生成を行う) - tag の push・release の作成 / 編集・publish を有効にした実行はしていない - Rust のコードは変更していない(cargo の品質ゲートは CI で確認) ### 生成例: v0.1.0(digest は GHCR の実際の値) <details> <summary>v0.1.0 の notes(全文)</summary> ````markdown ## What's changed ### Features - **core**: Define compile domain model and engine interface ([#20](#20)) - **workspace**: Add isolated compile workspaces ([#21](#21)) - **diagnostics**: Parse LaTeX logs into structured diagnostics ([#23](#23)) - **texlive**: Add latexmk engine ([#30](#30)) - **preview**: Render PDF pages to PNG previews ([#31](#31)) - **cli**: Add compile command ([#34](#34)) - **workspace**: Exclude nested output directories by path ([#38](#38)) - **diagnostics**: Locate missing packages and fold fatal errors ([#40](#40)) - **diagnostics**: Report BibTeX failures ([#42](#42)) - **process**: Apply resource limits before exec through a gate ([#44](#44)) - **process**: Limit CPU, memory and process count ([#45](#45)) - **sandbox**: Add a container backend for the TeX engine ([#50](#50)) - **sandbox**: Render previews inside the container ([#52](#52)) - **sandbox**: Reclaim containers left by killed runs and report the process limit ([#53](#53)) - **sandbox**: Reclaim leftovers from a previous boot ([#58](#58)) ### Bug fixes - **workspace**: Refine exclusion and collection edge cases ([#29](#29)) - **texlive**: Restore the build after #39 and #40 ([#43](#43)) - **sandbox**: Accept engine images without labels ([#55](#55)) - **sandbox**: Support rootless Podman and refuse rootless Docker ([#57](#57)) - **sandbox**: Detect OOM kills reliably on Docker ([#61](#61)) ### Documentation - Add contribution guidelines and MIT license ([#15](#15)) - Add initial README ([#18](#18)) - **security**: Define the MVP security model and execution limits ([#22](#22)) - Update README to reflect the completed MVP ([#37](#37)) - Rewrite the README ([#59](#59)) ### Other changes - Initialize repository - Bootstrap Rust workspace and toolchain ([#16](#16)) - **ci**: Add quality gates and dependency checks ([#19](#19)) - **docker**: Add TeX Live development environment ([#17](#17)) - Add TeX Live integration fixtures and CI job ([#33](#33)) - **process**: Extract shared subprocess execution ([#39](#39)) - **ci**: Publish the engine image to GHCR ([#51](#51)) ## Install ```bash cargo install --locked --git https://github.com/nishide-dev/texrun --tag v0.1.0 texrun ``` See the [README](https://github.com/nishide-dev/texrun/blob/v0.1.0/README.md#installation) for the requirements and the tools each backend needs. ## Engine image The container backend (`--backend container`) runs TeX in the engine image of this version, `ghcr.io/nishide-dev/texrun-engine:0.1.0` (linux/amd64, linux/arm64). texrun never pulls it; pull it once: ```bash docker pull ghcr.io/nishide-dev/texrun-engine:0.1.0 ``` Published versions are never overwritten. To use exactly this image, pin its digest: ```bash docker pull ghcr.io/nishide-dev/texrun-engine@sha256:b611748f16d50c00982da2e52b51939d50167bebbc22b35ab8741d1c39e00d1b texrun compile --backend container --container-image ghcr.io/nishide-dev/texrun-engine@sha256:b611748f16d50c00982da2e52b51939d50167bebbc22b35ab8741d1c39e00d1b main.tex ``` The image has an SBOM, SLSA provenance and a signed GitHub artifact attestation: ```bash gh attestation verify oci://ghcr.io/nishide-dev/texrun-engine:0.1.0 -R nishide-dev/texrun ``` ## Source of the engine image `texrun-engine-0.1.0-sources.tar` (below) has the Debian source packages (`.dsc`, `.orig.tar.*`, `.debian.tar.*`) of every package in the image, for both platforms, at exactly the installed versions (`packages.txt` and `SHA256SUMS` inside): the corresponding source of its GPL / AGPL programs. See [docs/engine-image.md](https://github.com/nishide-dev/texrun/blob/v0.1.0/docs/engine-image.md#licenses). ```` </details> ### 生成例: v0.1.0 以降の main の差分(次の版のプレビュー) ````markdown ## What's changed ### Bug fixes - **ci**: Build release notes lines from commit titles only ### Other changes - **ci**: Generate release notes from conventional commits - **ci**: Write release notes on tag push and add a notes-only workflow **Full diff**: [v0.1.0...v0.1.1](v0.1.0...v0.1.1) ```` (以下の Install / Engine image / Source は v0.1.0 と同じ形で、digest は placeholder。squash merge 後は 1 commit になる) ### 生成例: fixture(`release-notes-test.expected.md`) ````markdown ## What's changed ### Breaking changes - **cli**: Rename --json flag to --format json ([#4](#4)) ### Features - **cli**: Rename --json flag to --format json ([#4](#4)) ### Bug fixes - **diagnostics**: Report the error `@octocat` found ([#7](#7)) ### Other changes - Revert "fix(core): handle empty logs ([#5](#5))" ([#6](#6)) ### Dependencies - 3 dependency updates: [#2](#2), [#3](#3) **Full diff**: [v0.1.0...v0.2.0](v0.1.0...v0.2.0) ```` ## 補足 - merge 後、v0.1.0 の notes を埋めるには: `gh workflow run release-notes.yml --ref main -f tag=v0.1.0`(dry run、summary で確認)の後に `gh workflow run release-notes.yml --ref main -f tag=v0.1.0 -f update=true`。 - notes の文面は PR タイトルで決まる。merge 後に誤りに気付いた場合は release を手で編集できるが、作り直すと消える。 - 推奨(任意): `release-notes.yml` の `update` job にも、engine-image.yml と同様に `environment` を付けることを検討できる(docs/security.md の「release の入口」)。 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
生成 PDF のページ数・ページサイズを取得し、各ページを PNG に rasterize して
ArtifactKind::Previewの artifact として返すcrates/texrun-previewを追加します(#8)。preview の失敗や tool 不在は compile 失敗とは分けて、notice(warning / info)として返します。
#5(TeX Live engine)は並行して実装中のため、入力は「PDF ファイルのパス」を受け取る独立した API にしました。
変更内容
texrun-previewPreviewer::render(pdf, output_root, &PreviewOptions):<output_root>/preview/page-NNN.pngを生成する。artifact の path は output root 相対(例preview/page-001.png)で、pageとsize_bytesを設定するPreviewer::inspect(pdf, &PreviewOptions): metadata だけを取得する(描画はしない)PreviewReport:status(rendered/partial/skipped/inspected)、backend、format(png)、pdf(page_countと、選択したページのwidth_pt/height_pt/rotation)、pages(artifact とwidth_px/height_px/dpi)、notices。Serialize できるので、Add thetexrun compileCLI command #6 が JSON に埋め込めるPreviewReport::attach_to(&mut CompileResult): preview artifact をCompileResult::artifactsに追加する(feat(workspace): add isolated compile workspaces #21 の collect がそのまま使える)PageRange:N/N-M/N-/-Mを parse する(Add thetexrun compileCLI command #6 の--pages用)Toolset):PATHの絶対パスの entry からmutoolとpdfinfo+pdftoppmを探し、検出時に解決した絶対パスで起動する。BackendChoice::{Auto, Mupdf, Poppler}で選べる。Auto は、インストールされているかどうかだけで選ぶ。選んだ tool が失敗しても、もう一方で再試行はしない(rustdoc に明記)process.rs):std::process::Commandで起動し、shell は使わないenv_clear()の後に、PATH(絶対パスの entry だけ)・LC_ALL=C・HOME(preview ごとの空の一時ディレクトリ)だけを渡すprocess_group(0)で起動する。timeout・cancel(CancelToken)・出力サイズ超過のときは、killpg(SIGKILL)で process group ごと止める。正常終了した後も 1 回killpgする。Dropguard を持ち、panic で unwind した場合も kill して reap するprlimit(2)で次の制限を設定する(texrun 自身の hard limit を超えない値にする)RLIMIT_AS2 GiBRLIMIT_FSIZE(残りの予算 + 1 byte、ただし 16 MiB 以上)RLIMIT_CORE0EINTRは retry するfsops.rs):preview/はmkdiratで作成し、openat(O_NOFOLLOW)で 1 component ずつ開く。scratch dir からrenameatで、directory の fd 間で移動する(feat(workspace): add isolated compile workspaces #21 の collect と同じ水準)SKIPPEDの見え方を追記したmupdf-toolsを含むことを追記したtests/fixtures/{sizes,many-pages,spoofed-metadata,user-unit}.pdf(それぞれ 1,005 / 4,208 / 747 / 681 bytes)docker compose run --rm dev crates/texrun-preview/tests/fixtures/regenerate.sh(plain pdfTeX を使う。日付・/ID・banner を出力しないので、同じ TeX Live なら byte 単位で同一になる。再生成して同一になることを確認した)sizes: 300×400 / 400×300 / 200×100 pt(3 ページ目は/Rotate 90)many-pages: 72×72 pt の 25 ページspoofed-metadata: Title に偽のPages: 99行とPage 1 size: 9999 x 9999 pts行を含む 1 ページuser-unit: 100×50 unit のページに/UserUnit 10を付けた 1 ページ確認方法
cargo check --workspace --all-targets --all-features --lockedcargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --locked -- -D warnings(host の macOS と Docker の Linux)cargo test --workspace --locked(host)。host には poppler だけがあり、mupdf の test は skip した。skip したことは stderr にSKIPPEDと 1 回表示されるcargo nextest run --workspace --all-features --locked --no-tests=fail(host、251 passed。skipped の 17 件は feat(texlive): add latexmk engine #30 の ignored test)docker compose run --rm -e TEXRUN_REQUIRE_PREVIEW_TOOLS=1 dev cargo test --workspace --locked: mutool 1.25.1 と poppler 25.03 の両方で、全 test が通った(Linux の prlimit test を含む)cargo deny --locked check(外部依存の追加はない。既存のrustixにprocessfeature を crate 側で追加しただけ)test の内容:
tests/real_tools.rs、インストールされている backend ごとに実行): ページ数・サイズ・回転、PNG の生成(寸法と signature)、既定の 20 ページ上限、範囲指定(22-、末尾の clamp、範囲外)、200 ページ上限(max_pagesを下げて確認)、合計サイズの上限、長辺上限による DPI の引き下げ、DPI の指定、壊れた PDF、timeout、metadata による偽装への耐性、Auto の選択、ページの拡大係数(UserUnit)があっても長辺の上限を超えないこと(上限 500 px と 4096 px で、両 backend について確認)tests/degraded.rs、tool がなくても CI で動く):preview/の拒否、既存の symlink の置き換え(symlink の先には書き込まない)/proc/self/limitsで確認)関連 Issue
Closes #8
CLI への露出(
--pages/--no-preview/ DPI などの option、human-readable / JSON 出力へのPreviewReportの組み込み、compile 成功後の呼び出し)は #6 で行います。この PR はそのための library API までです。補足
backend の選定: 既定は MuPDF、fallback は Poppler
mutool drawの方が約 6 倍速かった(144 DPI でpdftoppm0.21 s、mutool0.034 s)。pdftoppmだと、200 ページで 30 秒の timeout を超える見込みになるmutoolは単一バイナリで、metadata の取得(mutool info -M/mutool pages)と描画ができるBackendChoice::Popplerを指定すれば使わずに済む(Add thetexrun compileCLI command #6 で option として出す想定)DPI の既定値: 144
max_long_edge_px(4096): PDF が宣言するページサイズは信頼できない値である。ページサイズの parse の正しさに依存しないよう、次の 3 段で強制するresolution_reducedの info を出す)。mupdf ではUserUnitを掛けたサイズで計算する。A0 なら 87 DPI になる。1 DPI でも収まらないページは描画せず、render_failedにするmutool drawには、上限を-w/-hの bounding box としても渡す。縮小にだけ効き、小さいページは拡大しないrender_failedにするRLIMIT_ASの下で、A0 の本文ページを mutool(-w/-h 4096 → 2898×4096 px)と pdftoppm(87 DPI)で描画できることを確認した型の置き場所(core を変更しない理由)
PdfInfo/PageInfo/PreviewNotice/PreviewReportは、preview crate に置いたDiagnosticと性質が違う(ページ番号や tool の stderr を持ち、compile の成否には影響しない)。feat(core): define compile domain model and engine interface #20 の N6 で心配されていた、Diagnosticに由来の区別を混ぜる問題を避けられるCompileResultにpreviewfield を足すと、core が preview の型に依存するか、汎用すぎる型が必要になる。Add thetexrun compileCLI command #6 は{...CompileResult, "preview": PreviewReport}の形で出力すればよく、Versionedの flatten とも両立するArtifact(kindpreview、page、size_bytes)で表せるので、core の変更は不要だったtool_unavailable,pdf_unreadable,page_limit,page_range_clamped,page_range_out_of_bounds,resolution_reduced,render_failed,size_limit,timed_out,cancelled,output_error(#[serde(other)] otherあり)。severity は core のSeverityを再利用した。既定の 20 ページ上限や DPI の引き下げは想定内の制限なのでinfo、要求したページが欠ける場合はwarningdegraded behavior
Err(PreviewError))になるのは、PreviewOptionsが不正な場合だけにしたOk(PreviewReport)の notice として返し、描画できたページはそのまま返す。compile の outcome は変えないstatusは次の 4 種類rendered: 選択した全ページを描画したpartial: 一部のページだけ描画したskipped: 1 枚も描画しなかったinspected:inspectで metadata を読めたPDF を信頼できない入力として扱うための対策
mutool draw -oは%dを展開するので、host 側の output root のパスに%が入っていても壊れないようにするためpdfinfoは Title を改行を含めてそのまま出力するので、偽のPages:行を差し込めることを確認した(spoofed-metadata.pdf)。対策として、tool が生成する値は最後に現れたものを採用するmutool show trailer/Root/Pages/Countは、Count が間接参照の場合に4 0 obj ...を出力するので使わず、mutool info -MのPages:を使う.texrun-preview-*。rename を使うため同じ file system に置く)に描画するfstatat(AT_SYMLINK_NOFOLLOW)とopenat(O_NOFOLLOW)で検査する(regular file であること、PNG signature と IHDR、サイズ予算、ピクセル上限)renameatでpreview/page-NNN.pngに移すpreview/はmkdiratとopenat(O_NOFOLLOW)で辿り、途中が symlink / file になっていた場合は拒否するdetail): 制御文字を escape して 2000 文字に切り詰める。message に host の絶対パスは含めない(ファイル名だけ)pre_execがunsafeになるため使えない。代わりに spawn 直後のprlimitで設定するので、起動からの数命令の間は制限されない(tool はこの間に大きな確保をしない)prlimitが無い。1 枚の大きさは長辺の上限と出力ファイルの polling(10 ms ごと、超えたら kill)で抑えるが、tool のメモリ使用量は制限しないtest で tool をどう扱うか(#10 の方針が未決のため)
#[ignore]ではなく、tool を検出して skip する方式にしたSKIPPEDと表示するcargo testでは--nocaptureを付けなくても見える--no-captureを付けた場合にだけ見える#[ignore]にすると、poppler などを入れている開発者の手元で、普段のcargo testでは実行されなくなるためTEXRUN_REQUIRE_PREVIEW_TOOLS=1を設定すると、tool が無いことを失敗にする。Add integration fixtures for common LaTeX scenarios #10 で懸念されていた「skip が黙って成功扱いになる」問題は、integration job(Docker image を使う Set up CI quality gates and dependency checks #11 の後続)でこの変数を設定すれば防げる後続への申し送り
texrun compileCLI command #6:--pages <N|N-M|N->(PageRange::from_str)、--no-preview、必要なら--preview-dpi/--preview-backendを追加するSucceededのときだけPreviewer::render(pdf_host_path, output_dir_host_path, ..)を呼び、attach_toで artifact を追加する。JSON にはpreviewとしてPreviewReportを出力するwarnings()を表示するPreviewOptions::cancelには、compile と同じCancelTokenを渡すdetailに含まれる bidi 文字などを escape するTEXRUN_REQUIRE_PREVIEW_TOOLS=1を設定する🤖 Generated with Claude Code