Skip to content

fix: レンジ指定で tool-cache を GitHub 解決より優先する#30

Merged
yk-lab merged 2 commits into
mainfrom
fix/range-cache-first
Jun 21, 2026
Merged

fix: レンジ指定で tool-cache を GitHub 解決より優先する#30
yk-lab merged 2 commits into
mainfrom
fix/range-cache-first

Conversation

@yk-lab

@yk-lab yk-lab commented Jun 21, 2026

Copy link
Copy Markdown
Owner

概要

version がレンジ(3.x 等)かつ check-latest=false のとき、これまで tc.find より先に resolveVersion() で GitHub を叩いていた。合致版がキャッシュ済みでも GitHub 障害/レート制限で失敗しうる、かつ文書化された check-latest=false(キャッシュ優先)の意味に反していた(Codex review 指摘1 / 要求仕様書 §6.1・NFR-3・G1)。

変更

  • src/version.ts: 純粋関数 resolveFromCache(cachedVersions, input, checkLatest) を追加。レンジ + check-latest=false のとき合致する最大キャッシュ版を返し、それ以外(latest/*/exact/check-latest=true)は undefined(=従来どおりネットワーク解決)。
  • src/main.ts: tc.findAllVersions() の結果を resolveFromCache に渡し、合致キャッシュがあれば GitHub 解決をスキップ。無ければ従来の resolveVersion() にフォールバック。
  • tests/version.test.ts: resolveFromCache の回帰テスト(キャッシュ優先 / フォールバック / check-latest / latest*・空 / exact)。
  • dist/ 再ビルド。

設計はプロジェクトの「version.ts=純粋ロジック、IO は main.ts」に沿い、tool-cache をモックせず単体テスト可能。

テスト

  • npm run all green(47 tests)
  • CI / self-test pass

Closes #7

🤖 Generated with Claude Code


Summary by cubic

Prefer cached versions for range specs when check-latest=false, skipping GitHub resolution to improve reliability and match documented cache-first behavior. This avoids failures during GitHub outages or rate limits when a matching version is already cached.

  • Bug Fixes
    • Added resolveFromCache(cachedVersions, input, checkLatest) to return the highest cached version for ranges when check-latest=false; otherwise returns undefined.
    • Updated src/main.ts to try cache first and only call GitHub when needed.
    • Added tests for cache-first, fallback, and unchanged cases (latest, *, exact, check-latest=true).

Written for commit f4561c8. Summary will update on new commits.

Review in cubic

yk-lab and others added 2 commits June 21, 2026 17:30
version.ts に純粋関数 resolveFromCache を追加し、main.ts が tc.findAllVersions の結果を渡す。
レンジ + check-latest=false で合致キャッシュがあれば GitHub 解決をスキップし、GitHub 障害/レート
制限に強くする(FR-7/NFR-3/G1)。latest・exact・check-latest=true は従来どおりネットワーク解決。

Codex review 指摘1。

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

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

src/version.tsresolveFromCache 関数を新規追加し、src/main.tsrun() 内バージョン解決フローをキャッシュ優先に変更。レンジ指定かつ check-latest=false の場合、tc.findAllVersions で列挙したキャッシュ候補から解決を試み、合致がなければ既存のネットワーク解決にフォールバックする。対応するテストも追加。

Changes

キャッシュ優先バージョン解決

Layer / File(s) Summary
resolveFromCache の実装とテスト
src/version.ts, tests/version.test.ts
checkLatest=truelatest*・exact 指定では undefined を返し、範囲指定のみ semver.maxSatisfying でキャッシュ内の最大一致バージョンを返す resolveFromCache を追加。各判定ケースをカバーするテストスイートも追加。
run() へのキャッシュ優先フローの組み込み
src/main.ts
resolveFromCache をインポートし、run() 内で tc.findAllVersionsresolveFromCache によるキャッシュ解決を先行させ、未解決時のみ withRetry(() => resolveVersion(...)) にフォールバックするよう変更。

Sequence Diagram(s)

sequenceDiagram
    participant run as run()
    participant tc as tc.findAllVersions
    participant rfc as resolveFromCache
    participant rv as resolveVersion (withRetry)

    run->>tc: findAllVersions(TOOL_NAME, arch)
    tc-->>run: cachedVersions[]
    run->>rfc: resolveFromCache(cachedVersions, versionSpec, checkLatest)
    alt キャッシュで解決成功
        rfc-->>run: resolvedVersion (string)
        Note over run: "skipped network resolution" ログ
    else キャッシュで未解決
        rfc-->>run: undefined
        run->>rv: withRetry(() => resolveVersion(...))
        rv-->>run: resolvedVersion (string)
        Note over run: "Resolved go-task version" ログ
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 ふわふわキャッシュを耳でぱたぱた、
ネットワークなんて今日はおやすみ〜
semver の範囲にぴったり合えば、
うさぎ足で駆け抜けるよ解決路!
check-latest? そっちは別のお話さ 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは「レンジ指定で tool-cache を GitHub 解決より優先する」であり、キャッシュ優先化という変更の主要な目的を明確に表現しており、変更内容と関連している。
Linked Issues check ✅ Passed PR内容は issue #7 の全ての完了条件を満たしている:レンジ + check-latest=false で合致キャッシュを優先し、キャッシュなし時はGitHubにフォールバック、check-latest=true は既存動作維持、回帰テストも実装されている。
Out of Scope Changes check ✅ Passed 全ての変更(resolveFromCache追加、main.ts統合、テスト実装、dist再ビルド)は issue #7 の要件に直結しており、スコープ外の変更は認められない。
Description check ✅ Passed PR説明は要件テンプレートのすべての必須セクション(Summary、Related issue、Test plan)を含んでおり、変更内容・理由・テスト完了状況が詳細に記述されています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/range-cache-first

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.

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.88%. Comparing base (083005b) to head (f4561c8).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
+ Coverage   65.62%   65.88%   +0.25%     
==========================================
  Files           9        9              
  Lines         160      170      +10     
  Branches       44       50       +6     
==========================================
+ Hits          105      112       +7     
- Misses         48       51       +3     
  Partials        7        7              
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 5 files

Re-trigger cubic

@yk-lab yk-lab merged commit 922e3ca into main Jun 21, 2026
15 checks passed
@yk-lab yk-lab deleted the fix/range-cache-first branch June 21, 2026 17:38
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.

[bug] レンジ指定時に tool-cache より先に GitHub へ解決しに行く

1 participant