Skip to content

fix(workspace): refine exclusion and collection edge cases - #29

Merged
nishide-dev merged 1 commit into
mainfrom
fix/workspace-edge-cases
Sep 30, 2026
Merged

nishide-dev merged 1 commit into
mainfrom
fix/workspace-edge-cases

Conversation

@nishide-dev

Copy link
Copy Markdown
Owner

概要

PR #21 の 2 回目のレビューで残った nit(N1〜N4)に対応します。除外判定と artifact 回収の細かなケースを直し、それぞれに回帰テストを追加しました。公開 API は後方互換を保っています(MaterializeReport へのフィールド追加のみで、この struct は #[non_exhaustive] です)。

変更内容

  • N1: 除外拡張子を file / symlink だけに適用: excluded_extensions(fmt / base / mem)の判定はディレクトリ以外にだけ適用します。これで data.base/ や fig.fmt/ のようなディレクトリは中身ごとコピーされます。symlink 先の判定(excludes_path)でも、途中の component には拡張子を適用しません。最後の component は、target がディレクトリの場合に限り適用しません。.base / .mem がほかの用途のファイル名と衝突し得ることを doc に書きました。
  • N2: collect で out root を fd から辿る: collect は、まず workspace root を開いて fstat し、Workspace::create のときに記録した (dev, ino) と一致するかを確認します。その fd から output_dir を component ごとに openat(DIR_FLAGS)(O_NOFOLLOW)で開きます。中間の .texrun が symlink にすり替えられた場合や、workspace ディレクトリ自体が置き換えられた場合は ArtifactNotFile になり、ディレクトリがなくなった場合は ArtifactMissing になります。どちらの error も、最初の artifact について報告します。artifact が 0 件のときは何も開きません。
  • N3: KeptAfterFailure で原因を二重に表示しない: Display を workspace creation failed (partial workspace kept at ...) に変え、原因の message を含めないようにしました。原因は明示した #[source] から取得できます。
  • N4: 列挙後に消えた entry を数える: MaterializeReport::vanished を追加しました。列挙の後、statat の時点で ENOENT になった entry の件数を記録します。テストで決定的に再現できるように、copy_dir を「列挙(list)」と「コピー(copy_entries)」に分けました。

確認方法

  • cargo check --workspace --all-targets --all-features --locked
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --locked(texrun-workspace は unit 11 件 / integration 34 件)

追加した回帰テスト:

  • N1: excluded_extensions_do_not_apply_to_directories(integration)、excluded_extensions_apply_to_files_and_symlinks_only(unit)、excludes_path_checks_every_component_and_output_relation に追加したケース
  • N2: collection_refuses_a_symlinked_output_dir_ancestor(パスで辿ると外部の secret が見える状態でも回収されないことを確認)、collection_refuses_a_replaced_workspace_directory
  • N3: kept_after_failure_does_not_repeat_its_source(unit。error chain を辿っても原因は 1 回しか出ない)、kept_after_failure_message_shows_the_cause_once(integration)
  • N4: entries_vanished_after_listing_are_counted(unit)

関連 Issue

Closes #28

補足

  • 挙動の変更: 出力先 dest は、out dir を開けるかどうかに関係なく先に作成されます(以前は out dir を開けないと dest を作る前に Io error になっていました)。
  • 以前は x.fmt/main.tex のように、途中のディレクトリの拡張子でも除外していました。N1 の方針に合わせて、現在は除外しません。

🤖 Generated with Claude Code

- apply excluded extensions (fmt/base/mem) to files and symlinks only
- reach the output directory from the workspace root fd component by
  component with O_NOFOLLOW, and check the root's (dev, ino) on collect
- stop repeating the source in KeptAfterFailure's Display
- count entries that vanished after listing in MaterializeReport::vanished

Closes #28

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@nishide-dev nishide-dev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

PR #21 の 2 回目のレビューで挙げた nit N1〜N4 への対応を確認しました。4 件とも解消されています。退行や新しい抜け道も見つかりませんでした。以下の nit は任意対応です。

実行結果

最新 head(05f1067)を clone して実行:

  • cargo check --workspace --all-targets --all-features --locked: OK
  • cargo fmt --all -- --check: OK
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: OK
  • cargo test --workspace --locked: 全 pass(texrun-workspace は unit 11 件 / integration 34 件)
  • gh pr checks: 全 pass(linux / macos)。mergeable: CLEAN(branch は main の texrun-latex-log の merge より前から分岐していますが、conflict はありません)

既存の probe を macOS(APFS)で再実行しました(ローカルのみ。commit はしていません)。前回と同じ結果で、退行はありません:

  • Kelvin 表記の latexmkrc: コピーされない。.GIT / LATEXMKRC は除外される
  • rename race(60 秒): 63,829 回成功して leaked=0(InputChanged 2,506 件、SymlinkOutsideRoot 73,749 件)。旧来型の race 3000 回も leaked=0
  • dangling symlink 10 万個: LimitExceeded(ScannedEntries)(約 25 ms)
  • symlink chain / loop、collect での symlink 拒否(dest 側 / artifact / 中間 component)、keep 時の KeptAfterFailure: いずれも変化なし

N1: 拡張子除外をディレクトリ以外に限定

追加 probe の結果:

入力 結果
data.base/a.tex(ディレクトリ内の通常ファイル) コピーされる
data.base/pdflatex.fmt(ディレクトリ内の format) 除外(ExcludedExtension)
pdflatex.fmt/(ディレクトリ) コピーされる(下記)
real.fmt 除外
alias.tex -> real.fmt 除外(SymlinkToExcluded)
deep.tex -> data.base/pdflatex.fmt 除外(SymlinkToExcluded)
dl -> data.base(ディレクトリへの link) 作り直される
lualatex.fmt -> main.tex(link 名が .fmt) 除外(link 自身の名前で判定)
dang.tex -> x.FMT(dangling) UnresolvableSymlink
  • symlink 先の判定(excludes_path(rel_target, target_is_dir))の扱いは妥当です。途中の component には拡張子を適用せず、最後の component も target がディレクトリの場合だけ適用しない、という規則になっています。target_is_dir を path ベースの metadata で取っている点は race の余地がありますが、失敗したときは file 扱い(厳しい側)に倒れます。また workspace に何が入るかは fd ベースの走査で各 entry を自身の名前で判定して決まるので、link 先の *.fmt がそもそも workspace に存在しません。抜け道にはならないと判断しました。
  • pdflatex.fmt/ というディレクトリがコピーされるようになりましたが、kpathsea は探索でディレクトリを採用しない(readable file の判定で弾く)ので、format として読まれることはありません。問題ないと考えます。

N2: collect で workspace root から fd で辿る

攻撃 結果
.texrun を外部への symlink にすり替える(path で辿ると外部の out/main.pdf が見える) ArtifactNotFile、dest にはコピーされない
.texrun/out 自体を外部への symlink にする ArtifactNotFile
workspace ディレクトリを rename して、同じ path に偽の dir と main.pdf を作る ArtifactNotFile((dev, ino) の不一致を検出)、コピーされない
workspace path を元の dir への symlink に置き換える ArtifactNotFile(O_NOFOLLOW)
artifact 0 件 Ok(0)(何も開かない)

open_output_dir は、root を open(NOFOLLOW|DIRECTORY) で開いて fstat で (dev, ino) を照合し、その後 component ごとに openat(DIR_FLAGS) で辿ります。以降の読み込みはすべてその fd からなので、途中で rename されても workspace の外は読みません。正しいと判断しました。

N3 / N4

  • N3: Display は workspace creation failed (partial workspace kept at ...) になり、原因は source() から 1 回だけ取れます(probe でも確認)。kind() は引き続き内側の error の kind(LimitExceeded)を返します。
  • N4: vanished の件数を数えています。list と copy_entries を分けて決定的にテストできるようにした点も良いです。

nit(任意対応)

  • n1: workspace の置き換えを検出したときの error 種別。workspace root の (dev, ino) 不一致、つまり workspace 自体が置き換えられた場合も ArtifactNotFile になります。原因の切り分けには、InputChanged 相当(例: WorkspaceChanged)の方が分かりやすいです。JSON / exit code の観点でも、「artifact が変」と「workspace が改ざんされた」は区別できる方が望ましいです。#6 で error を対応付けるときに検討する程度で構いません。
  • n2: materialize() は Workspace::create の直後に workspace root を path で開き直しています。そこで root_id とも照合しておくと、create と collect で扱いが揃います(実害はほぼありません)。

N1〜N4 はすべて解消し、前回の probe でも退行がないことを確認したので APPROVE とします。

@nishide-dev
nishide-dev merged commit a8576a0 into main Sep 30, 2026
8 checks passed
@nishide-dev
nishide-dev deleted the fix/workspace-edge-cases branch September 30, 2026 07:09
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refine workspace exclusion and artifact collection edge cases

1 participant