Skip to content

Proxy Bun downloads through CocoaPods cache on iOS#3619

Draft
sjchmiela wants to merge 2 commits intomainfrom
stanley/proxy-ios-downloads-via-cocoapods
Draft

Proxy Bun downloads through CocoaPods cache on iOS#3619
sjchmiela wants to merge 2 commits intomainfrom
stanley/proxy-ios-downloads-via-cocoapods

Conversation

@sjchmiela
Copy link
Copy Markdown
Contributor

Summary

  • Route the Bun install script and release ZIP downloads through the CocoaPods cache when available on iOS
  • Retry both steps directly if the proxied request fails
  • Add unit coverage for proxied and fallback paths

Testing

  • yarn test:unit runtimeEnvironment.test.ts --runInBand in packages/worker

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.91%. Comparing base (d6a8a4f) to head (86bde04).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3619      +/-   ##
==========================================
+ Coverage   54.86%   54.91%   +0.05%     
==========================================
  Files         836      836              
  Lines       35903    35955      +52     
  Branches     7494     7504      +10     
==========================================
+ Hits        19694    19740      +46     
- Misses      16114    16120       +6     
  Partials       95       95              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sjchmiela sjchmiela added the no changelog PR that doesn't require a changelog entry label Apr 20, 2026
@github-actions
Copy link
Copy Markdown

⏩ The changelog entry check has been skipped since the "no changelog" label is present.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Routes Bun installation network traffic through the CocoaPods cache proxy (when configured) to improve download performance/reliability on iOS workers, with fallbacks and unit coverage to validate the proxy + retry behavior.

Changes:

  • Proxy Bun install script download (bun.sh/install) via CocoaPods cache URL, with direct-download retry on failure.
  • Proxy Bun GitHub release ZIP downloads by injecting a proxied GITHUB env var into the install script run, with direct-install retry on failure.
  • Add unit tests covering proxied success and both fallback paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/worker/src/runtimeEnvironment.ts Adds proxy URL rewriting + retry logic for Bun install script download and GitHub release downloads.
packages/worker/src/unit/runtimeEnvironment.test.ts Adds unit tests validating proxy behavior and fallback retries.

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

Comment on lines +192 to +199
const proxyUrl = config.cocoapodsCacheUrl;
try {
ctx.logger.info(`Installing bun@${versionToInstall}`);

const bunInstallScriptPath = path.join(os.tmpdir(), `install-bun-${uuidv4()}.sh`);
const proxiedBunInstallScriptUrl = proxyUrl
? rewriteUrlThroughProxy('https://bun.sh/install', proxyUrl)
: null;
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

installBun enables CocoaPods-cache proxying whenever config.cocoapodsCacheUrl is set, without checking that the current job/runner is actually iOS (e.g. process.platform === 'darwin' or ctx.job.platform === Platform.IOS). This doesn’t match the PR intent (“on iOS”) and can add extra failing requests + warnings on non-iOS workers if the config is ever set globally. Consider gating proxy behavior to iOS/darwin explicitly.

Copilot uses AI. Check for mistakes.

function rewriteUrlThroughProxy(url: string, proxy: string): string {
const parsedUrl = new URL(url);
return url.replace(`${parsedUrl.protocol}//${parsedUrl.host}`, `${proxy}/${parsedUrl.host}`);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

rewriteUrlThroughProxy can generate URLs with a double-slash path segment when proxy ends with / (e.g. https://cache/ -> https://cache//github.com). Some caching/proxy layers treat these as different paths. Consider normalizing proxy (trim trailing slashes) and building the rewritten URL via URL components rather than string.replace to avoid subtle formatting issues.

Suggested change
return url.replace(`${parsedUrl.protocol}//${parsedUrl.host}`, `${proxy}/${parsedUrl.host}`);
const proxyUrl = new URL(proxy);
const normalizedProxyPath = proxyUrl.pathname.replace(/\/+$/, '');
proxyUrl.pathname = `${normalizedProxyPath}/${parsedUrl.host}${parsedUrl.pathname}`.replace(
/\/{2,}/g,
'/'
);
proxyUrl.search = parsedUrl.search;
proxyUrl.hash = parsedUrl.hash;
return proxyUrl.toString();

Copilot uses AI. Check for mistakes.
Comment on lines +139 to +156
it('proxies Bun install script and GitHub release ZIP downloads through CocoaPods cache on iOS', async () => {
let isFirstTimeCheckingBunVersion = true;
config.cocoapodsCacheUrl = 'https://cocoapods-cache.example.com';

jest.mocked(spawn).mockImplementation((cmd, _args, _opts) => {
if (cmd === 'bun') {
const stdout = isFirstTimeCheckingBunVersion ? '1.0.0' : '2.0.0';
isFirstTimeCheckingBunVersion = false;
return Promise.resolve({
...spawnResult,
stdout,
});
}
return Promise.resolve(spawnResult);
});

await prepareRuntimeEnvironment(ctx, { bun: '2.0.0' }, false);

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This test asserts proxying “on iOS”, but it never sets ctx.job.platform (or otherwise constrains the runtime to iOS/darwin). As a result it would still pass even if the proxying applied to Android/Linux too. Setting ctx.job.platform to iOS (and ideally adding a negative test for non-iOS) would make the coverage reflect the intended behavior.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog PR that doesn't require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants