Skip to content

test: fetchJson の content-type ガードと createReleaseApi を検証#26

Merged
yk-lab merged 1 commit into
mainfrom
test/fetch-json-guard
Jun 21, 2026
Merged

test: fetchJson の content-type ガードと createReleaseApi を検証#26
yk-lab merged 1 commit into
mainfrom
test/fetch-json-guard

Conversation

@yk-lab

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

Copy link
Copy Markdown
Owner

概要

src/github.tsfetchJson(content-type ガード)と createReleaseApi のユニットテストを追加します(要求仕様書 §10.1 / 企画 §1.1-3)。HTML "Unicorn" ページを失敗扱いにする本アクションの存在意義が未検証でした。

テストケース(github.test.ts: 3 → 10)

  • fetchJson: 正常 JSON を返す / HTML レート制限ページ → retryable Error(content-type & repo-token を含む)/ 404 → PermanentError / 503 → retryable Error
  • createReleaseApi.getLatestVersion: tag_name をそのまま返す
  • createReleaseApi.listStableVersions: draft/prerelease を除外し、ページングを追従(page1=満杯→page2 取得、部分ページ/空ページで停止)

fetch を URL・呼び出し回数で分岐スタブし、ページングの停止条件まで実検証。

Closes #3

テスト

  • npm run all green(github.test.ts 10 件)
  • CI / self-test pass

🤖 Generated with Claude Code


Summary by cubic

Add unit tests for fetchJson (content-type guard) and createReleaseApi. They verify JSON parsing; treat HTML rate-limit pages as retryable with a repo-token hint; return PermanentError on 404; retry on 503; return tag_name as-is in getLatestVersion; and follow pagination while excluding drafts/prereleases in listStableVersions.

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

Review in cubic

要求仕様書 §10.1 / 企画 §1.1-3。既存の fetchText テストに加え:
- fetchJson: 正常 JSON / HTML レート制限ページ→retryable Error(repo-token 案内)/ 404→PermanentError / 503→Error
- createReleaseApi.getLatestVersion: tag_name をそのまま返す
- createReleaseApi.listStableVersions: draft/prerelease 除外 + ページング追従(page=2 取得→部分ページで停止)+ 空ページ停止
fetch を URL/呼び出し回数で分岐スタブし、ページングを実検証。

Closes #3

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

Summary by CodeRabbit

  • Tests
    • テストスイートが拡充され、API レスポンス処理の信頼性検証が強化されました。

Walkthrough

tests/github.test.ts に共通の stubFetch / afterEach 基盤を整備し、fetchJson の content-type ガード・エラー分類、fetchText の既存テスト再編、および createReleaseApigetLatestVersion / listStableVersions)の新規テストを追加した。

Changes

github.ts テストカバレッジ追加

Layer / File(s) Summary
共通スタブ基盤と fetchJson テスト
tests/github.test.ts
stubFetchafterEach(vi.unstubAllGlobals()) を共通化。fetchJson の正常 JSON パース・HTML 応答の再試行可能 Error(メッセージに content-typerepo-token を含む)・404 PermanentError・その他非 OK の再試行可能 Error を検証するテストスイートを追加。fetchText の既存テストも同一スタブ構成に合わせて再編。
createReleaseApi テスト
tests/github.test.ts
getLatestVersion()tag_name をそのまま返すことを検証。listStableVersions()fetch モックのレスポンス切替でページネーションをたどり、draft / prerelease / 非 SemVer を除外して安定版のみを収集し、空ページでループを終了することを新規テスト群で検証。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 テストを書いて うさぎ跳ね
content-type を チェックして
404 は永遠にダメ 🚫
ページをめくり 安定版だけ 🌿
all green になって にんじん祝い 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR タイトルは主な変更内容である fetchJson の content-type ガードと createReleaseApi のテスト追加を明確に述べており、本体的な変更を正確に要約している。
Description check ✅ Passed PR の説明は概要、テストケース詳細、検証方法を含んでおり、テンプレートの主要セクションを網羅している。ただし Test plan のチェックボックスが部分的に未完了表記(CI は未チェック)だが、本文で確認されている。
Linked Issues check ✅ Passed PR の実装は issue #3 の全ての完了条件を満たしている:HTML エラーを retryable Error として扱い、404 を PermanentError とし、正常 JSON をパースし、listStableVersions で draft/prerelease を除外しページングに対応している。
Out of Scope Changes check ✅ Passed 変更は tests/github.test.ts の追加のみで、issue #3 で指定された fetchJsoncreateReleaseApi のテスト範囲に限定されており、スコープ外の変更はない。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 test/fetch-json-guard

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.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/github.test.ts (1)

21-142: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

github(network/IO)へのユニットテスト追加がテスト方針に反しています。

Line 21〜Line 142 で fetchJson / fetchText / createReleaseApi をユニットテストしていますが、github は network/IO モジュールです。これらは .github/workflows/self-test.yml の E2E 検証へ移し、tests/**/*.test.ts 側は純粋ロジックモジュールに限定してください。
As per coding guidelines, tests/**/*.test.{ts,tsx} では「Write tests only for pure logic modules (version, platform, checksum parsing); validate network/IO modules (github, download, install, main) end-to-end via .github/workflows/self-test.yml」を満たす必要があります。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/github.test.ts` around lines 21 - 142, Remove the three describe blocks
testing fetchJson, fetchText, and createReleaseApi (lines 21-142) from the unit
test file, as these functions are part of the network/IO github module and
should not be validated through unit tests. Instead, these network/IO
validations should be moved to end-to-end tests in the
.github/workflows/self-test.yml workflow file, keeping the tests/**/*.test.ts
file limited to pure logic modules like version, platform, and checksum parsing.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/github.test.ts`:
- Around line 21-142: Remove the three describe blocks testing fetchJson,
fetchText, and createReleaseApi (lines 21-142) from the unit test file, as these
functions are part of the network/IO github module and should not be validated
through unit tests. Instead, these network/IO validations should be moved to
end-to-end tests in the .github/workflows/self-test.yml workflow file, keeping
the tests/**/*.test.ts file limited to pure logic modules like version,
platform, and checksum parsing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcd309e2-1e73-4d67-84ac-2546b1f167a2

📥 Commits

Reviewing files that changed from the base of the PR and between c013caf and daeceaf.

📒 Files selected for processing (1)
  • tests/github.test.ts

@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 1 file

Re-trigger cubic

@yk-lab yk-lab merged commit bc2b944 into main Jun 21, 2026
13 checks passed
@yk-lab yk-lab deleted the test/fetch-json-guard branch June 21, 2026 05:05
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.

[test] fetchJson の content-type ガードのユニットテストを追加する

1 participant