Skip to content

ci: run conversion accuracy tests with cached mozc snapshot#275

Merged
send merged 3 commits into
mainfrom
ci/accuracy-gate
Jul 2, 2026
Merged

ci: run conversion accuracy tests with cached mozc snapshot#275
send merged 3 commits into
mainfrom
ci/accuracy-gate

Conversation

@send

@send send commented Jul 2, 2026

Copy link
Copy Markdown
Owner

概要

プロジェクトで最も重要な回帰スイートである変換精度テスト (mise run accuracy / mise run accuracy-history) を CI に組み込む。辞書ビルドに Mozc の fetch (~90MB) が必要なため見送られていたが、#266 で fetch が commit SHA ピン + .stamp (SHA + マニフェスト) 化されキャッシュが安全になったため導入する。

設計

accuracy ジョブ (ubuntu-latest)

  • 発火条件: core || cli || corpus (changes フィルタに corpus: engine/testcorpus/** + mise.toml を追加)
  • needs: changes のみ (lint に依存させない): corpus-only 変更では lint が skip され、needs 連鎖で accuracy まで skip されてしまうため
  • rust-cache: release プロファイル (dictool / lextool) を使うため shared-key: accuracy を分離。debug 用 engine キャッシュとの相互汚染を避ける

Mozc スナップショットのキャッシュ戦略

actions/cache の restore/save 分割で engine/data/mozc-raw をキャッシュする。

  • restore: restore-keys: mozc-raw- prefix で最新エントリを復元
  • save: 実行後に .stamp 1 行目の上流 commit SHA を読み、mozc-raw-<sha> キーで保存。restore したキーと一致する場合は保存しない → 上流スナップショットごとに 1 エントリのみで、毎 run ~90MB を保存してリポジトリの 10GB キャッシュ枠 (rust-cache 含む) を churn しない
  • stale restore の安全性: dictool の stamp 機構 (fix(cli): pin mozc fetch to a single upstream commit via version stamp #266) が毎回上流と照合する。最新なら Commits API 1 回の fast path で検証のみ、上流が動いていれば staging 経由でトランザクショナルに新スナップショットへ差し替え。古いキャッシュが辞書を汚染することはない
  • mise の staleness: tar が復元する .stamp の mtime は保存時点 (checkout した sources より古い) ため、fetch-dict-mozc タスクは CI では常に実行され、dictool が検証を担う。lexime.dict / lexime.conn はキャッシュせず毎回 compile (数十秒)

GitHub API rate limit 対応

fetch の Commits / Contents API は非認証 ureq で、Actions ランナーの共有 IP では匿名枠 (60 req/h/IP) が事実上常に枯渇している。対応として:

  • dictool 改修 (最小限): GITHUB_TOKEN 環境変数が設定されていれば api.github.com へのリクエストに Authorization: Bearer を付ける (5000 req/h)。raw.githubusercontent.com のダウンロードは API rate limit 対象外のため、資格情報は意図的に送らない。空値は匿名扱い・前後空白 trim。単体テスト追加
  • CI ジョブは GITHUB_TOKEN: ${{ github.token }} を渡す
  • 多重防御: 万一 rate limit に当たっても、キャッシュが完全なら dictool の offline fallback が警告付きでキャッシュを使用するため CI は落ちない

コーパスの上流 drift 再調整 (副次的発見)

ローカルの mozc-raw は 2026-02-21 取得で、最新上流スナップショット (7c1e06d3) では辞書コスト・エントリ変更により 6 ケースが fail、history baseline 1 件がずれていた (まさにこの CI が検出すべき事象)。CLAUDE.md の運用ルールに従い:

テストプラン

  • mise run accuracy — Pass 101 / Fail 0 / Skip 33 (pass rate 100%)
  • mise run accuracy-history — Pass 7 / Fail 0 (pass rate 100%)
  • cargo fmt --all --check / cargo clippy --workspace --all-features -- -D warnings
  • cargo test -p lex-cli (64 passed、github_auth_header の単体テスト含む)
  • ci.yml を ruby -ryaml で構文検証
  • この PR 自体の CI で accuracy ジョブが発火し pass すること (cli + corpus 変更で発火条件を満たす)

🤖 Generated with Claude Code

send and others added 3 commits July 2, 2026 21:59
CI ランナーの匿名 GitHub API 枠 (60 req/h、IP 共有) では
Commits/Contents API が事実上常に rate limit に当たるため、
慣例の GITHUB_TOKEN 環境変数が設定されていれば
api.github.com へのリクエストに Bearer トークンを付ける。
raw.githubusercontent.com のダウンロードは API rate limit の
対象外なので、資格情報は意図的に送らない。

空値・空白のみの値は匿名扱い、前後の空白は trim する
(シェル置換由来の改行でヘッダが壊れないように)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ローカルの mozc-raw キャッシュ (2026-02-21 取得) と最新上流
スナップショット (7c1e06d3) の間の辞書コスト・エントリ変更により
6 ケースが fail、history コーパスの baseline 1 件がずれていた。

- 6 ケースを skip + issue #273 リンクに変更 (上流 drift の再調整は
  #273 で追跡)
- おねがいします の baseline を お願いします に更新
  (CLAUDE.md の運用ルール: baseline がずれた場合は値を更新)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
accuracy ジョブを追加: lex-core / lex-cli / testcorpus / mise.toml の
変更で発火し、mise run accuracy と accuracy-history を実行する。

- Mozc raw スナップショット (~90MB) は actions/cache の
  restore/save 分割でキャッシュ。キーは .stamp 1 行目の
  上流 commit SHA で、上流スナップショットごとに 1 エントリのみ
  保存 (毎 run 保存によるキャッシュ枠の浪費を回避)
- 古いキャッシュが restore されても dictool の stamp 機構 (#266) が
  毎回上流と照合し、最新なら Commits API 1 回の fast path、
  ずれていればトランザクショナルに再取得するため安全
- GITHUB_TOKEN をジョブに渡し、共有ランナー IP の匿名 rate limit
  (60 req/h) を回避 (dictool 側は前コミットで対応)
- needs は changes のみ (lint に依存させると corpus-only 変更で
  lint が skip → accuracy も skip になるため)
- rust-cache は release プロファイル用に shared-key: accuracy を分離

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 2, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the project’s key regression suite (conversion accuracy tests) to CI while making Mozc snapshot fetching practical and reliable by caching the raw Mozc TSV snapshot and authenticating GitHub API requests to avoid anonymous rate-limit failures. It also updates the accuracy corpora to account for upstream Mozc snapshot drift (skipping 6 newly failing cases and updating one history baseline) so the new CI gate can run green while drift is tracked in #273.

Changes:

  • Add a new CI accuracy job that restores/saves engine/data/mozc-raw via actions/cache and runs mise run accuracy + mise run accuracy-history.
  • Update the Mozc fetcher to attach Authorization: Bearer $GITHUB_TOKEN for api.github.com requests (but not for raw downloads), with unit tests.
  • Adjust accuracy corpora for the newer Mozc snapshot: skip 6 drifted cases (linked to #273) and update the accuracy-history baseline for “おねがいします”.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
engine/testcorpus/accuracy-corpus.toml Marks 6 drifted cases as skip = true with issue = "#273" and updates notes to reflect Mozc snapshot drift.
engine/testcorpus/accuracy-corpus-history.toml Updates one baseline to match new Mozc snapshot behavior and annotates the change with #273 context.
engine/crates/lex-cli/src/dict_source/mozc.rs Adds authenticated GitHub API GET helper + github_auth_header to mitigate CI rate limits, plus unit tests.
.github/workflows/ci.yml Adds corpus change filter output and introduces an accuracy job with Mozc snapshot caching and GITHUB_TOKEN wiring.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@send

send commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 37b5bc9879

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@send send merged commit 09c957a into main Jul 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants