Skip to content

feat(reference): reference fetch に zip fallback を追加(Phase 4-D / Refs #191)#196

Merged
akiojin merged 1 commit into
developfrom
work/20260511-0223
May 11, 2026
Merged

feat(reference): reference fetch に zip fallback を追加(Phase 4-D / Refs #191)#196
akiojin merged 1 commit into
developfrom
work/20260511-0223

Conversation

@akiojin
Copy link
Copy Markdown
Owner

@akiojin akiojin commented May 11, 2026

Summary

Changes

  • Cargo.toml: zip = "2"[dependencies] に追加(default features で deflate 含む、圧縮済み GitHub archive を解凍可能)。
  • src/reference/fetcher.rs::run_clone: ensure_git_available() が OK なら従来の git clone、Err なら fetch_via_zip に切り替える分岐を追加。
  • 新規関数:
    • archive_url_for_branch(branch): https://github.com/Unity-Technologies/UnityCsReference/archive/refs/heads/<branch>.zip を構築。
    • fetch_via_zip(branch, dest): ureq でアーカイブを取得し、GITHUB_TOKEN / GH_TOKEN を透過注入。
    • extract_zip_to(archive_bytes, dest): GitHub archive の top-level prefix (UnityCsReference-<branch>/) を strip して dest に展開。.. を含む entry は安全のため reject。
    • detect_top_level_prefix / strip_prefix: helpers。
  • 新規 RED テスト 3 件:
    • archive_url_uses_unity_cs_reference_org
    • extract_zip_to_strips_top_level_prefix_and_writes_files (ZipWriter で生成した buffer を使う)
    • extract_zip_to_rejects_entries_with_parent_segments

Testing

  • cargo fmt -- --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test --bin unity-cli389 passed / 0 failed
  • cargo llvm-cov --all-targets --summary-only -- --test-threads=1 — TOTAL line coverage 90.88%
  • unity-cli skills lint --severity error — 15 skills / 0 violations

Closing Issues

Related Issues / Links

Checklist

  • Tests added/updated (3 件 + ZipWriter ベースの fixture helper)
  • Lint/format passed (cargo clippy, cargo fmt, unity-cli skills lint)
  • Documentation updated — none required (run_clone の public API は不変)
  • Migration/backfill plan included — Not applicable: zip fallback は git 不在時のみ動作。既存ユーザーには影響なし
  • CHANGELOG impact considered — minor bump per Conventional Commits (feat)

Context

Phase 1 (SPEC #185) で reference fetchgit clone --depth 1 前提で実装し、Phase 1.5 として zip fallback を保留していた。本 PR はその保留分を land する。git バイナリ不在の CI runner や slim Docker image でも unity-cli reference fetch が動くようになる。

Out of Scope

umbrella SPEC #191 で継続管理する範囲:

  • ネットワーク経由の実 download integration test(CI flake になりやすいため、本 PR では ZipWriter で生成したローカル buffer での test のみ)
  • GitHub API レート制限のリトライ・バックオフ
  • Unix 権限ビット (chmod) の保持
  • Phase 4-A (member-level シンボル抽出) / Phase 4-E (vector embedding) は未着手

Notes

  • zip = "2" の default features は bzip2 / lzma / zstd / aes-crypto / deflate を含むため、target サイズが多少増える。size sensitive な配布向けに後追いで feature を絞る検討余地あり。
  • fetch_via_zip 内の ureq::Agent::new_with_defaults は既存 src/core/managed_binaries.rs の HTTP 利用に揃えた。リトライは未実装で、ネットワーク失敗時はエラーをそのまま伝播する。

SPEC #191 (Phase 4 umbrella) のサブタスク D として、git バイナリ不在
環境向けの archive 経由 fallback を追加する。`run_clone` が git の
有無を判定し、利用可能なら従来の `git clone --depth 1 ...`、そう
でなければ GitHub の archive zip を ureq でダウンロードして展開する。

主な変更:

- Cargo.toml に zip = "2" を追加(default features で deflate 含む)
- src/reference/fetcher.rs::run_clone: git があれば既存ルート、無け
  れば fetch_via_zip に切り替える分岐を追加
- 新規 archive_url_for_branch / fetch_via_zip / extract_zip_to /
  detect_top_level_prefix / strip_prefix を実装
- extract_zip_to は GitHub archive 形式 (UnityCsReference-<branch>/
  プレフィックス) を strip して dest に直接展開し、`..` を含む entry
  は安全のため reject
- 新規 RED テスト 3 件:
  - archive_url_uses_unity_cs_reference_org
  - extract_zip_to_strips_top_level_prefix_and_writes_files
  - extract_zip_to_rejects_entries_with_parent_segments

スコープ外(umbrella #191 で継続管理):

- ネットワーク経由の実 download テスト(CI flake になりやすいため
  ローカル archive 生成のみ)
- GitHub API レート制限への対応(既存の GITHUB_TOKEN / GH_TOKEN 透過
  注入のみ)
- 解凍済みファイルへの権限ビット保持(Unix 限定の chmod は未対応)

ローカル検証:

- cargo fmt -- --check: clean
- cargo clippy --all-targets -- -D warnings: clean
- cargo test --bin unity-cli: 389 passed / 0 failed
- cargo llvm-cov --all-targets: TOTAL line coverage 90.88%
- unity-cli skills lint --severity error: 15 skills / 0 violations

Refs #191

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4e92f57b-bcf7-4fac-97cd-025e29852a2b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch work/20260511-0223

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant