Skip to content

feat: proxy 環境で全 fetch を proxy 経由にする(#54)#57

Merged
yk-lab merged 5 commits into
mainfrom
feat/proxy-support
Jun 27, 2026
Merged

feat: proxy 環境で全 fetch を proxy 経由にする(#54)#57
yk-lab merged 5 commits into
mainfrom
feat/proxy-support

Conversation

@yk-lab

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

Copy link
Copy Markdown
Owner

概要

Node 組み込み fetchHTTP_PROXY / HTTPS_PROXY / NO_PROXY を既定で参照しないため、proxy 配下の self-hosted runner では version 解決・checksums 取得が失敗していた(#42 のレビューで判明した既存制約)。本 PR で全 fetch を proxy 経由にする。

設計判断(公式確認 + ローカル smoke 済み)

  • undici setGlobalDispatcher(new EnvHttpProxyAgent()) が正準解。起動時に1回設定で組み込み fetch 全部が proxy 経由になり、secureFetch も既存テスト(global fetch を stub)も無変更
  • Node 24.16 で setGlobalDispatcher が組み込み fetch に効くことをローカル smoke 確認(存在しない proxy → fetch が ECONNREFUSED)
  • http-client 移行案 / NODE_USE_ENV_PROXY は不採用(前者は全書き換え、後者はプロセス起動フラグでコードから使えない)

変更内容

  • src/proxy.ts(新規): configureProxyFromEnv() — proxy env 検出時のみ EnvHttpProxyAgent を global dispatcher に設定(NO_PROXY も解釈、未設定なら no-op)。空文字 unset を後段の実 proxy が潰さないよう || で fallback
  • src/main.ts: run() 冒頭(全ネットワーク前)で呼ぶ
  • package.json: undici を direct dep へ昇格(transitive 6.27.0 と同一、install 増なし)
  • .github/workflows/self-test.yml: proxy E2E job を追加。tinyproxy を立て、range 指定で API 解決を強制し、built-in fetch でしか到達しない api.github.com が proxy ログに出ることを検証(tool-cache は元から proxy 対応なので asset CDN では新挙動を検証できない)。gate の needs / 失敗・キャンセル検出にも proxy 追加
  • docs: README(Proxy-aware)/ CLAUDE.md(proxy.ts seam)/ TODO.md

検証

  • pnpm run all ✅(typecheck / lint / 69 tests / build)/ actionlint ✅ / typos
  • proxy 経由は E2E(tinyproxy + api.github.com アサート)で担保
  • ローカル AI レビュー(CodeRabbit + codex)を push 前に実施し、??||・proxy アサート強化の2点を反映済み

参照

🤖 Generated with Claude Code


Summary by cubic

Route all action fetches through the runner’s HTTP(S) proxy when HTTP_PROXY/HTTPS_PROXY are set, honoring NO_PROXY. Uses an undici-based fetch shim so proxying is reliable across Node versions, fixing version resolution and checksum fetches on proxied self-hosted runners.

  • New Features

    • configureProxyFromEnv() installs undici’s EnvHttpProxyAgent via setGlobalDispatcher; respects HTTP_PROXY/HTTPS_PROXY/NO_PROXY (upper/lowercase), no-op without a proxy, uses || so empty vars don’t mask real values, and fails fast on malformed URLs while naming only the env var (no credential leak).
    • Switch internal fetch to an undici-backed shim (src/fetch.ts) so the dispatcher is always honored; github.ts now imports from it; tests mock ./fetch instead of globalThis.fetch.
    • Hardened proxy E2E job: stop auto-start tinyproxy service, run as the runner user with logs in /tmp, force API resolution with check-latest: true, and assert api.github.com is proxied.
  • Dependencies

    • Add undici as a direct dependency.

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

Review in cubic

yk-lab and others added 2 commits June 26, 2026 01:20
Node 組み込み fetch は HTTP_PROXY/HTTPS_PROXY/NO_PROXY を既定で見ないため、
proxy 配下の self-hosted runner で version 解決・checksums 取得が失敗していた。

- src/proxy.ts(新規): configureProxyFromEnv() が proxy env 検出時に undici の
  EnvHttpProxyAgent を global dispatcher に設定(NO_PROXY も解釈)。組み込み fetch に効く。
  空文字での unset を実 proxy が後段にある場合に潰さないよう || で fallback。
- src/main.ts: run() 冒頭で呼ぶ(全ネットワーク前)。
- package.json: undici を direct dep 昇格(transitive 6.27.0 と同一)。
- self-test.yml: tinyproxy を立て、range 指定で API 解決を強制し、build-in fetch
  でしか到達しない api.github.com が proxy ログに出ることを検証する proxy job 追加
  (tool-cache は元から proxy 対応なので asset CDN では新挙動を検証できない)。
  self-test-gate の needs / 失敗検出にも proxy を追加。

Node 24 で setGlobalDispatcher が組み込み fetch に効くことをローカル smoke 確認済み。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AECzAv2vcdATecuvLjBSa6
- README: Proxy-aware 機能 bullet を追加
- CLAUDE.md: proxy.ts の seam を追記
- TODO.md: #54 を解決済み(#57)へ移動 + #55/#56 を backlog に追加

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AECzAv2vcdATecuvLjBSa6
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa4f3687-484b-4087-b338-5a14283c9f93

📥 Commits

Reviewing files that changed from the base of the PR and between 623dca9 and c3faba4.

⛔ Files ignored due to path filters (1)
  • .github/workflows/self-test.yml is excluded by !**/*.yml
📒 Files selected for processing (9)
  • CLAUDE.md
  • TODO.md
  • src/fetch.ts
  • src/github.ts
  • src/proxy.ts
  • tests/checksum.test.ts
  • tests/download.test.ts
  • tests/github.test.ts
  • tests/proxy.test.ts
✅ Files skipped from review due to trivial changes (3)
  • tests/download.test.ts
  • src/github.ts
  • TODO.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/proxy.ts

📝 Walkthrough

Summary by CodeRabbit

  • 新機能
    • HTTP_PROXY / HTTPS_PROXY / NO_PROXY を考慮し、実行開始後のネットワーク処理をプロキシ経由でルーティングします(未設定相当なら従来どおり)。
    • 不正なプロキシ設定時は、環境変数名を含むエラーメッセージで適切に失敗します。
  • ドキュメント
    • README と内部ドキュメント(Architecture)のプロキシ関連説明を更新しました。
  • テスト
    • プロキシ有無・優先順位・不正URL時の挙動を検証するテストを追加しました。
  • その他
    • バックログの更新を反映しました。

Walkthrough

プロキシ環境変数を読む configureProxyFromEnv() を追加し、run() の開始時に呼び出すようにしました。あわせて、undici.fetch のラッパー導入、関連テストのモック更新、説明文の更新も行われています。

Changes

Proxy-aware fetch bootstrap

Layer / File(s) Summary
Proxy setup and startup wiring
src/proxy.ts, src/main.ts, tests/proxy.test.ts
configureProxyFromEnv()HTTP_PROXY / HTTPS_PROXY / http_proxy / https_proxy を参照して EnvHttpProxyAgent をグローバル dispatcher に設定し、run() が最初のネットワーク処理前にそれを呼び出します。環境変数の分岐とエラー再スローは Vitest で検証されています。
Fetch wrapper and test mock migration
src/fetch.ts, src/github.ts, tests/checksum.test.ts, tests/github.test.ts
undici.fetch をローカルの ./fetch 経由に寄せ、checksum と GitHub 系テストが global fetch ではなくモジュール mock を使う形に置き換わります。secureFetch / listStableVersions の既存検証は同じ観点を保ったまま mock 基盤が更新されています。
Docs and notes updates
CLAUDE.md, README.md, TODO.md, src/download.ts, tests/download.test.ts
Architecture と README に proxy-aware の説明が追加され、TODO に Issue #55 / #56 の追加と Issue #54 の解決記録が追記され、download のリダイレクト事前チェックコメントも更新されます。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yk-lab/setup-task#26: tests/github.test.tsfetchJson / createReleaseApi のテスト更新が共通しており、今回も同系統の mock 置き換えがあります。
  • yk-lab/setup-task#53: secureFetch のリダイレクト検証と Authorization 破棄の挙動が今回の src/github.ts / tests/github.test.ts の変更と直接つながっています。

Poem

ぴょんと起きたら proxy 風
うさぎの fetch がすいすい通る
NO_PROXY の小道もぴかり
にんじん色のログがひとつ
ぼくの耳も global dispatcher 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive [#54] 主要要件の実装は揃っていますが、.github/workflows/self-test.yml が除外されており self-test/E2E の確認はできません。 .github/workflows/self-test.yml をレビュー対象に含めるか、実行結果を共有して proxy E2E と self-test green を確認してください。
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 主要変更であるproxy環境で全fetchをproxy経由にする内容を簡潔かつ具体的に示しています。
Description check ✅ Passed Summary・関連issue・検証内容が揃っており、テンプレートの必須項目は概ね満たしています。
Out of Scope Changes check ✅ Passed README/CLAUDE/TODO/test/src の変更はいずれもproxy対応の目的に沿っており、明らかな脱線は見当たりません。
✨ 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 feat/proxy-support

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 markdownlint-cli2 (0.22.1)
CLAUDE.md

markdownlint-cli2 wrapper config was not available before execution

TODO.md

markdownlint-cli2 wrapper config was not available before execution


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.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.32%. Comparing base (41997cd) to head (c3faba4).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/fetch.ts 0.00% 1 Missing ⚠️
src/main.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #57      +/-   ##
==========================================
+ Coverage   69.91%   70.32%   +0.40%     
==========================================
  Files          11       13       +2     
  Lines         236      246      +10     
  Branches       61       62       +1     
==========================================
+ Hits          165      173       +8     
- Misses         62       64       +2     
  Partials        9        9              
Files with missing lines Coverage Δ
src/download.ts 89.65% <ø> (ø)
src/github.ts 92.42% <ø> (ø)
src/proxy.ts 100.00% <100.00%> (ø)
src/fetch.ts 0.00% <0.00%> (ø)
src/main.ts 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@CLAUDE.md`:
- Line 54: The Host allowlist and preflight documentation in CLAUDE.md is now
inconsistent with the new proxy behavior. Update the `download.ts` preflight
description so it reflects that, after `configureProxyFromEnv()` runs in
`run()`, built-in `fetch` can go through the proxy instead of saying it ignores
runner proxy settings; if needed, adjust the `Host allowlist` wording to match
the new `proxy.ts` note and keep the two entries aligned.

In `@src/proxy.ts`:
- Line 24: Remove the undici-based proxy setup from proxy.ts: the top-level
setGlobalDispatcher(new EnvHttpProxyAgent()) call should be eliminated, along
with the EnvHttpProxyAgent dependency. In run(), initialize Node 24’s native
env-proxy support by setting NODE_USE_ENV_PROXY=true before any fetch usage (or
by applying the equivalent --use-env-proxy runtime flag), so proxy behavior
comes from the built-in fetch environment handling instead of a custom global
dispatcher.

In `@TODO.md`:
- Around line 56-57: The TODO table rows for the `#55` and `#56` entries are
missing the empty `備考` cell, so the column count no longer matches the 5-column
header. Update the Markdown table in `TODO.md` by adding a blank final cell to
each of those rows so they align with the existing table structure and stay
consistent with the other entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eecc7c8f-fb12-4864-bb49-636e76cf4352

📥 Commits

Reviewing files that changed from the base of the PR and between 41997cd and 1e5cc2c.

⛔ Files ignored due to path filters (3)
  • .github/workflows/self-test.yml is excluded by !**/*.yml
  • package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
📒 Files selected for processing (5)
  • CLAUDE.md
  • README.md
  • TODO.md
  • src/main.ts
  • src/proxy.ts

Comment thread CLAUDE.md Outdated
Comment thread src/proxy.ts Outdated
Comment thread TODO.md Outdated

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

1 issue found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread CLAUDE.md Outdated
- proxy.ts: 不正 proxy URL(EnvHttpProxyAgent constructor throw)を
  actionable な Error に変換(cause 付与で preserve-caught-error も満たす)
- download.ts: proxy 対応後に不正確になった stale コメントを修正
- self-test.yml: proxy job に check-latest:true。range が tool-cache に hit
  すると API 解決がスキップされ、api.github.com アサートが空振りするため
- tests/proxy.test.ts: gating / 小文字変数 / || fallback / 不正URL の unit テスト

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AECzAv2vcdATecuvLjBSa6

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@tests/proxy.test.ts`:
- Around line 3-16: `vi.mock('undici', ...)` is hoisted, so the test-scoped
spies used by `setGlobalDispatcher` and `EnvHttpProxyAgent` must be initialized
before mock evaluation to avoid TDZ `ReferenceError`s. Move the spy creation
into `vi.hoisted()` and keep using those hoisted references inside the `undici`
mock in `tests/proxy.test.ts`. Make sure the mocked `setGlobalDispatcher` and
constructor spy still behave the same for `configureProxyFromEnv`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3067ac68-f4b0-4ec0-ade9-1857338831f6

📥 Commits

Reviewing files that changed from the base of the PR and between 1e5cc2c and 623dca9.

⛔ Files ignored due to path filters (1)
  • .github/workflows/self-test.yml is excluded by !**/*.yml
📒 Files selected for processing (3)
  • src/download.ts
  • src/proxy.ts
  • tests/proxy.test.ts
✅ Files skipped from review due to trivial changes (1)
  • src/download.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/proxy.ts

Comment thread tests/proxy.test.ts Outdated

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

3 issues found across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/proxy.test.ts Outdated
Comment thread src/proxy.ts Outdated
Comment thread tests/proxy.test.ts Outdated
yk-lab and others added 2 commits June 27, 2026 11:36
undici 6.x の setGlobalDispatcher が Node 24 組み込み fetch に効くかは
symbol 共有のバージョン依存で脆弱(CodeRabbit Major 指摘)。組み込み fetch
ではなく npm undici の fetch を直接使えば、同一 undici インスタンス上で
dispatcher が確実に適用される。

- src/fetch.ts(新規): undici の fetch を string-URL シグネチャで re-export
- src/github.ts: ./fetch から import(組み込み fetch をやめる)
- tests: globalThis.fetch の stub をやめ ../src/fetch を mock
- CLAUDE.md: fetch shim / proxy の seam を追記

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AECzAv2vcdATecuvLjBSa6
- self-test.yml: proxy job が apt 自動起動サービスと :8888 衝突しログを
  /tmp に残せず assert がコケていた。サービス停止 + User/Group/PidFile を
  runner 側に明示 + ログ生成確認を追加(cubic/CI 失敗の修正)
- proxy.ts: 不正 proxy URL のエラーで値を出さず変数名のみ報告(URL に
  embedded credentials がログ漏洩するのを防止、cubic P2)
- proxy.test.ts: vi.hoisted で spy を宣言(vi.mock hoisting、CodeRabbit
  Critical)+ resetAllMocks で mockImplementation の漏れ防止(cubic P2)
- TODO.md: backlog 表の #55/#56 に空 備考セル(MD056、CodeRabbit)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AECzAv2vcdATecuvLjBSa6
@yk-lab yk-lab merged commit 09231e1 into main Jun 27, 2026
21 checks passed
@yk-lab yk-lab deleted the feat/proxy-support branch June 27, 2026 08:24
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.

[enhancement] HTTP(S) proxy 環境で全 fetch を proxy 経由にする

1 participant