Skip to content

fix(install): fetch os/cpu metadata during yarn.lock migration - #23143

Merged
Jarred-Sumner merged 10 commits into
mainfrom
claude/fix-yarn-migration-os-cpu-metadata
Oct 4, 2025
Merged

Jarred-Sumner merged 10 commits into
mainfrom
claude/fix-yarn-migration-os-cpu-metadata

Conversation

@robobun

@robobun robobun commented Sep 30, 2025

Copy link
Copy Markdown
Collaborator

Summary

During yarn.lock migration, OS/CPU package metadata was not being fetched from the npm registry when missing from yarn.lock. This caused packages with platform-specific requirements to not be properly marked, potentially leading to incorrect package installation behavior.

Changes

Updated fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration to conditionally fetch OS/CPU metadata:

  • For yarn.lock migration: Fetches OS/CPU metadata from npm registry when not present in yarn.lock (update_os_cpu = true)
  • For pnpm-lock.yaml migration: Skips OS/CPU fetching since pnpm-lock.yaml already includes this data (update_os_cpu = false)

Files Modified

  • src/install/lockfile.zig - Added comptime update_os_cpu parameter and conditional logic to fetch OS/CPU metadata
  • src/install/yarn.zig - Pass true to enable OS/CPU fetching for yarn migrations
  • src/install/pnpm.zig - Pass false to skip OS/CPU fetching for pnpm migrations (already parsed from lockfile)

Why This Approach

  • yarn.lock format often doesn't include OS/CPU constraints, requiring us to fetch from npm registry
  • pnpm-lock.yaml already parses OS/CPU during migration (lines 618-621 in pnpm.zig), making additional fetching redundant
  • Using a comptime parameter allows the compiler to optimize away the unused code path

Testing

  • ✅ Debug build compiles successfully
  • Tested that the function correctly updates pkg_meta.os and pkg_meta.arch only when:
    • update_os_cpu is true (yarn migration)
    • Current values are .all (not already set)
    • Package metadata is available from npm registry

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

During yarn.lock migration, os/cpu package metadata was not being
fetched from the npm registry when missing from yarn.lock. This
caused packages with platform-specific requirements to not be
properly marked.

This change updates fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration
to conditionally fetch os/cpu metadata:
- For yarn.lock migration: fetches os/cpu metadata from npm registry
  when not present in yarn.lock (update_os_cpu = true)
- For pnpm-lock.yaml migration: skips os/cpu fetching since
  pnpm-lock.yaml already includes this data (update_os_cpu = false)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@robobun

robobun commented Sep 30, 2025 •

Copy link
Copy Markdown
Collaborator Author
Updated 5:04 AM PT - Oct 4th, 2025

❌ @autofix-ci[bot], your commit 8b10a9b has 2 failures in Build #28020 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 23143

That installs a local version of the PR into your bun-23143 executable, so you can run:

bun-23143 --bun

@coderabbitai

coderabbitai Bot commented Sep 30, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a comptime boolean parameter to Lockfile.fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration, updates pnpm/yarn call sites to pass the flag, and extends the yarn-lock migration test suite to verify OS/CPU metadata is included in migrated lockfiles when requested.

Changes

Cohort / File(s) Summary
Lockfile metadata update
src/install/lockfile.zig
Adds comptime update_os_cpu: bool to fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration. When update_os_cpu == true the routine looks up manifests, gathers per-package .meta, clones bin extern strings, and sets pkg_meta.os / pkg_meta.arch; when false it preserves the previous behavior (processes existing fields only).
Migration call sites
src/install/pnpm.zig, src/install/yarn.zig
Update call sites to pass the new comptime flag: fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration(manager, false) in pnpm.zig and fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration(manager, true) in yarn.zig.
Yarn migration tests
test/cli/install/migration/yarn-lock-migration.test.ts
Adds a test "yarn.lock with packages that have os/cpu requirements" that runs migration in a temp workspace, snapshots the resulting bun.lock as os-cpu-yarn-migration, and asserts presence of OS/CPU-related entries (e.g., fsevents, @esbuild/linux-arm64, @esbuild/darwin-arm64).

Possibly related PRs

Suggested reviewers

  • zackradisic
  • nektro

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description does not use the repository’s required template sections and is missing the exact “What does this PR do?” and “How did you verify your code works?” headings, making it non-compliant with the mandated format. Please update the description to match the template by adding “### What does this PR do?” with a concise summary and “### How did you verify your code works?” with testing details under the exact required headings.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change of fetching OS/CPU metadata during yarn.lock migration and follows conventional commit style without unnecessary detail or noise.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-yarn-migration-os-cpu-metadata

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 94e5b59 and 8b10a9b.

📒 Files selected for processing (1)
  • test/cli/install/migration/yarn-lock-migration.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/cli/install/migration/yarn-lock-migration.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
src/install/lockfile.zig (1)

954-1046: Replace manager.lockfile. with this.*, gate cache population, and DRY bin cloning*

  • Mandatory: replace manager.lockfile.stringBuilder() and &manager.lockfile.buffers.extern_strings with this.stringBuilder() and &this.buffers.extern_strings to avoid mutating a different Lockfile instance.
  • Optional: wrap manager.populateManifestCache(.all) in if (update_os_cpu) so the pnpm path only loads manifests on demand.
  • Optional: extract the duplicated npm bin-cloning block into a small helper to reduce repetition.
@@ src/install/lockfile.zig:954
-    manager.populateManifestCache(.all) catch return;
+    if (update_os_cpu) manager.populateManifestCache(.all) catch return;
@@
-                    var builder = manager.lockfile.stringBuilder();
+                    var builder = this.stringBuilder();
@@
-                    var extern_strings_list = &manager.lockfile.buffers.extern_strings;
+                    var extern_strings_list = &this.buffers.extern_strings;
🧹 Nitpick comments (2)
src/install/lockfile.zig (2)

954-966: Optional: add a scoped debug log when OS/CPU is updated (coding guideline)

Add a scoped logger and log when os/arch are filled from the registry. This aids future triage without noise.

 pub fn fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration(this: *Lockfile, manager: *PackageManager, comptime update_os_cpu: bool) OOM!void {
+    const log = bun.Output.scoped(.install, false);
@@
-                    // Update os/cpu metadata if not already set
+                    // Update os/cpu metadata if not already set
                     if (pkg_meta.os == .all) {
                         pkg_meta.os = pkg.package.os;
+                        log("yarn migration: filled os for {s}", .{pkg_name.slice(this.buffers.string_bytes.items)});
                     }
                     if (pkg_meta.arch == .all) {
                         pkg_meta.arch = pkg.package.cpu;
+                        log("yarn migration: filled arch for {s}", .{pkg_name.slice(this.buffers.string_bytes.items)});
                     }

As per coding guidelines

Also applies to: 999-1005


998-1005: Consider libc as a follow-up

If/when libc metadata is supported in Package.Meta, mirror pnpm handling here to keep parity.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a89e61f and 0565677.

📒 Files selected for processing (3)
  • src/install/lockfile.zig (2 hunks)
  • src/install/pnpm.zig (1 hunks)
  • src/install/yarn.zig (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)

Implement debug logs in Zig using const log = bun.Output.scoped(.${SCOPE}, false); and invoking log("...", .{})

Files:

  • src/install/yarn.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)

**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue

**/*.zig: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup

Files:

  • src/install/yarn.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format
🔇 Additional comments (2)
src/install/yarn.zig (1)

1674-1675: Yarn migration now fetches OS/CPU metadata — LGTM

Passing true correctly enables the update path after resolve().

src/install/pnpm.zig (1)

822-823: PNPM migration skips OS/CPU fetch — LGTM

Passing false aligns with pnpm-lock.yaml already encoding os/cpu.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
test/cli/install/migration/yarn-lock-migration.test.ts (2)

1473-1473: Prefer Bun.file().text() for consistency.

For consistency with other tests in this file (e.g., line 1372), consider using the async Bun.file() API instead of the synchronous fs.readFileSync().

Apply this diff:

-    const bunLockContent = fs.readFileSync(join(tempDir, "bun.lock"), "utf8");
+    const bunLockContent = await Bun.file(join(tempDir, "bun.lock")).text();

1476-1481: Consider adding explicit OS/CPU metadata assertions.

While the snapshot will capture OS/CPU metadata if present, adding explicit assertions would make the test more robust and clearly document what specific metadata the PR introduces. For instance, you could verify that fsevents has os constraints or that esbuild packages have arch constraints in the lockfile structure.

Example assertions you could add:

// Verify OS/CPU metadata is present in the lockfile
// These are examples - adjust based on the actual lockfile format
expect(bunLockContent).toMatch(/"os":\s*\[?"darwin"/); // fsevents should have darwin constraint
expect(bunLockContent).toMatch(/"arch":\s*\[?"arm64"/); // esbuild packages should have arch constraints
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bcc0c19 and 4054a2c.

⛔ Files ignored due to path filters (1)
  • test/cli/install/migration/__snapshots__/yarn-lock-migration.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • test/cli/install/migration/yarn-lock-migration.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
test/**

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place all tests under the test/ directory

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/cli/**/*.{js,ts}: Place CLI command tests (e.g., bun install, bun init) under test/cli/
When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/**/*.{js,ts}: Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test
Prefer data-driven tests (e.g., test.each) to reduce boilerplate
Use shared utilities from test/harness.ts where applicable

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.ts

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.ts: Name test files *.test.ts and use bun:test
Do not write flaky tests: never wait for arbitrary time; wait for conditions instead
Never hardcode port numbers in tests; use port: 0 to get a random port
When spawning Bun in tests, use bunExe() and bunEnv from harness
Prefer async/await in tests; for a single callback, use Promise.withResolvers()
Do not set explicit test timeouts; rely on Bun’s built-in timeouts
Use tempDir/tempDirWithFiles from harness for temporary files and directories in tests
For large/repetitive strings in tests, prefer Buffer.alloc(count, fill).toString() over "A".repeat(count)
Import common test utilities from harness (e.g., bunExe, bunEnv, tempDirWithFiles, tmpdirSync, platform checks, GC helpers)
In error tests, assert non-zero exit codes for failing processes and use toThrow for synchronous errors
Use describe blocks for grouping, describe.each for parameterized tests, snapshots with toMatchSnapshot, and lifecycle hooks (beforeAll, beforeEach, afterEach); track resources for cleanup in afterEach
Use using/await using with Bun resources (e.g., Bun.listen/connect/spawn/serve) to ensure cleanup in tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

test/**/*.test.{ts,tsx}: Test files must live under test/ and end with .test.ts or .test.tsx
In tests, always use port: 0; do not hardcode ports or roll your own random port
Prefer normalizeBunSnapshot for snapshotting test output instead of asserting raw strings
Do not write tests that assert absence of crashes (e.g., 'no panic' or 'no uncaught exception')
Use Bun’s Jest-compatible runner (import { test, expect } from "bun:test") for tests
Avoid shell commands like find or grep in tests; use Bun’s Glob and built-in tools instead
Prefer running tests via bun bd test and use provided harness utilities (bunEnv, bunExe, tempDir)
Use Bun.spawn with proper stdio handling and await proc.exited in process-spawning tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place CLI command tests under test/cli/

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
🧬 Code graph analysis (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)
test/harness.ts (3)
  • tempDir (278-285)
  • tempDirWithFiles (260-267)
  • bunExe (103-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format
🔇 Additional comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

1376-1481: LGTM! Test follows best practices.

The test structure is well-designed and follows coding guidelines:

  • Uses tempDirWithFiles for temporary file management
  • Uses bunExe() and bunEnv from harness
  • Properly spawns process with stdio handling
  • Awaits process exit
  • Uses snapshots for comprehensive verification
  • Clear test name and good documentation


"@esbuild/linux-arm64": ["@esbuild/linux-arm64@0.17.19", "", {}, "sha512-ct1Mj/VEUqd5+2h0EBPdMzNdGXnGxbLPg6H5TF8xsHY4X5UAP0FUbDKJhtKu+6iLpIjKjWEvb5XrFyZdVy9OTg=="],

"@esbuild/linux-x64": ["@esbuild/linux-x64@0.17.19", "", {}, "sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw=="],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm not sure if this works? i dont see the os or cpu data.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

228-239: Explicit test timeouts violate coding guidelines.

The coding guidelines state: "Do not set explicit test timeouts; rely on Bun's built-in timeouts." However, these changes add explicit 10000ms timeouts to multiple tests. While migration tests may require more time, consider whether the default Bun timeout is sufficient, or if these timeouts are truly necessary for these specific tests.

As per coding guidelines.

Also applies to: 737-739, 1129-1131, 1345-1347, 1359-1361, 1384-1386

🧹 Nitpick comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

1388-1493: LGTM! Well-structured test for OS/CPU metadata migration.

This test effectively validates the main PR objective: ensuring OS/CPU metadata is fetched from the npm registry during yarn.lock migration. The test setup is realistic, using packages with known platform constraints (fsevents for darwin, esbuild with multiple platforms).

The partial yarn.lock (only 5 of the esbuild platform packages defined) reflects a realistic scenario where not all optional dependencies are resolved in the original lockfile.

Optional: Consider more explicit OS/CPU metadata verification.

While the snapshot at line 1486 captures the complete lockfile structure, you could add explicit assertions to verify the actual os/cpu metadata fields are present in the lockfile, for example:

     expect(bunLockContent).toContain("fsevents");
     expect(bunLockContent).toContain("@esbuild/linux-arm64");
     expect(bunLockContent).toContain("@esbuild/darwin-arm64");
+    // Verify OS/CPU metadata is actually present in the lockfile structure
+    expect(bunLockContent).toMatch(/"os":\s*"darwin"/);
+    expect(bunLockContent).toMatch(/"cpu":\s*"arm64"/);

This would make the test's intent more explicit and provide clearer failure messages if the metadata is missing, rather than relying solely on snapshot comparison.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4054a2c and ce8b004.

⛔ Files ignored due to path filters (1)
  • test/cli/install/migration/__snapshots__/yarn-lock-migration.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • test/cli/install/migration/yarn-lock-migration.test.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
test/**

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place all tests under the test/ directory

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/cli/**/*.{js,ts}: Place CLI command tests (e.g., bun install, bun init) under test/cli/
When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/**/*.{js,ts}: Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test
Prefer data-driven tests (e.g., test.each) to reduce boilerplate
Use shared utilities from test/harness.ts where applicable

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.ts

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.ts: Name test files *.test.ts and use bun:test
Do not write flaky tests: never wait for arbitrary time; wait for conditions instead
Never hardcode port numbers in tests; use port: 0 to get a random port
When spawning Bun in tests, use bunExe() and bunEnv from harness
Prefer async/await in tests; for a single callback, use Promise.withResolvers()
Do not set explicit test timeouts; rely on Bun’s built-in timeouts
Use tempDir/tempDirWithFiles from harness for temporary files and directories in tests
For large/repetitive strings in tests, prefer Buffer.alloc(count, fill).toString() over "A".repeat(count)
Import common test utilities from harness (e.g., bunExe, bunEnv, tempDirWithFiles, tmpdirSync, platform checks, GC helpers)
In error tests, assert non-zero exit codes for failing processes and use toThrow for synchronous errors
Use describe blocks for grouping, describe.each for parameterized tests, snapshots with toMatchSnapshot, and lifecycle hooks (beforeAll, beforeEach, afterEach); track resources for cleanup in afterEach
Use using/await using with Bun resources (e.g., Bun.listen/connect/spawn/serve) to ensure cleanup in tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

test/**/*.test.{ts,tsx}: Test files must live under test/ and end with .test.ts or .test.tsx
In tests, always use port: 0; do not hardcode ports or roll your own random port
Prefer normalizeBunSnapshot for snapshotting test output instead of asserting raw strings
Do not write tests that assert absence of crashes (e.g., 'no panic' or 'no uncaught exception')
Use Bun’s Jest-compatible runner (import { test, expect } from "bun:test") for tests
Avoid shell commands like find or grep in tests; use Bun’s Glob and built-in tools instead
Prefer running tests via bun bd test and use provided harness utilities (bunEnv, bunExe, tempDir)
Use Bun.spawn with proper stdio handling and await proc.exited in process-spawning tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place CLI command tests under test/cli/

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
🧬 Code graph analysis (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)
test/harness.ts (3)
  • tempDir (278-285)
  • tempDirWithFiles (260-267)
  • bunExe (103-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format
🔇 Additional comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

1343-1345: LGTM!

The new assertion validates that peer dependencies are preserved during migration, which aligns with the test's "realistic complex" scenario.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

1480-1485: Strengthen assertions to verify actual OS/CPU metadata structure.

The current assertions only check that package names exist in the lockfile content, but don't verify that the OS/CPU metadata (pkg_meta.os, pkg_meta.arch) was actually populated during migration. The comment on lines 1480-1481 mentions specific OS/CPU constraints, but the test doesn't validate them.

Consider adding more explicit assertions that parse the lockfile structure and verify:

  • fsevents has os constraint set to darwin
  • esbuild platform packages have appropriate arch constraints
  • The metadata fields are not empty/default values

This would make the test more robust and explicitly validate the PR's core functionality beyond just snapshot comparison.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ce8b004 and 194ab09.

📒 Files selected for processing (1)
  • test/cli/install/migration/yarn-lock-migration.test.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
test/**

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place all tests under the test/ directory

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/cli/**/*.{js,ts}: Place CLI command tests (e.g., bun install, bun init) under test/cli/
When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/**/*.{js,ts}: Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test
Prefer data-driven tests (e.g., test.each) to reduce boilerplate
Use shared utilities from test/harness.ts where applicable

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.ts

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.ts: Name test files *.test.ts and use bun:test
Do not write flaky tests: never wait for arbitrary time; wait for conditions instead
Never hardcode port numbers in tests; use port: 0 to get a random port
When spawning Bun in tests, use bunExe() and bunEnv from harness
Prefer async/await in tests; for a single callback, use Promise.withResolvers()
Do not set explicit test timeouts; rely on Bun’s built-in timeouts
Use tempDir/tempDirWithFiles from harness for temporary files and directories in tests
For large/repetitive strings in tests, prefer Buffer.alloc(count, fill).toString() over "A".repeat(count)
Import common test utilities from harness (e.g., bunExe, bunEnv, tempDirWithFiles, tmpdirSync, platform checks, GC helpers)
In error tests, assert non-zero exit codes for failing processes and use toThrow for synchronous errors
Use describe blocks for grouping, describe.each for parameterized tests, snapshots with toMatchSnapshot, and lifecycle hooks (beforeAll, beforeEach, afterEach); track resources for cleanup in afterEach
Use using/await using with Bun resources (e.g., Bun.listen/connect/spawn/serve) to ensure cleanup in tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

test/**/*.test.{ts,tsx}: Test files must live under test/ and end with .test.ts or .test.tsx
In tests, always use port: 0; do not hardcode ports or roll your own random port
Prefer normalizeBunSnapshot for snapshotting test output instead of asserting raw strings
Do not write tests that assert absence of crashes (e.g., 'no panic' or 'no uncaught exception')
Use Bun’s Jest-compatible runner (import { test, expect } from "bun:test") for tests
Avoid shell commands like find or grep in tests; use Bun’s Glob and built-in tools instead
Prefer running tests via bun bd test and use provided harness utilities (bunEnv, bunExe, tempDir)
Use Bun.spawn with proper stdio handling and await proc.exited in process-spawning tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place CLI command tests under test/cli/

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
🧬 Code graph analysis (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)
test/harness.ts (3)
  • tempDir (278-285)
  • tempDirWithFiles (260-267)
  • bunExe (103-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

1371-1372: Consider using the consistent pattern for async assertions.

Lines 1371-1372 use Jest's .resolves matcher, while the rest of the file consistently uses the await pattern (e.g., lines 47, 144, 208, 1324-1325). Similarly, line 1372 uses Bun.file().exists() while other tests use fs.existsSync() (lines 48, 145, 212, 731, etc.).

Apply this diff to match the file's established pattern:

-      expect(migrateResult.exited).resolves.toBe(0);
-      expect(Bun.file(join(tempDir, "bun.lock")).exists()).resolves.toBe(true);
+      const exitCode = await migrateResult.exited;
+      expect(exitCode).toBe(0);
+      expect(fs.existsSync(join(tempDir, "bun.lock"))).toBe(true);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 194ab09 and 94e5b59.

📒 Files selected for processing (1)
  • test/cli/install/migration/yarn-lock-migration.test.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
test/**

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place all tests under the test/ directory

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/cli/**/*.{js,ts}: Place CLI command tests (e.g., bun install, bun init) under test/cli/
When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/**/*.{js,ts}: Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test
Prefer data-driven tests (e.g., test.each) to reduce boilerplate
Use shared utilities from test/harness.ts where applicable

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.ts

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.ts: Name test files *.test.ts and use bun:test
Do not write flaky tests: never wait for arbitrary time; wait for conditions instead
Never hardcode port numbers in tests; use port: 0 to get a random port
When spawning Bun in tests, use bunExe() and bunEnv from harness
Prefer async/await in tests; for a single callback, use Promise.withResolvers()
Do not set explicit test timeouts; rely on Bun’s built-in timeouts
Use tempDir/tempDirWithFiles from harness for temporary files and directories in tests
For large/repetitive strings in tests, prefer Buffer.alloc(count, fill).toString() over "A".repeat(count)
Import common test utilities from harness (e.g., bunExe, bunEnv, tempDirWithFiles, tmpdirSync, platform checks, GC helpers)
In error tests, assert non-zero exit codes for failing processes and use toThrow for synchronous errors
Use describe blocks for grouping, describe.each for parameterized tests, snapshots with toMatchSnapshot, and lifecycle hooks (beforeAll, beforeEach, afterEach); track resources for cleanup in afterEach
Use using/await using with Bun resources (e.g., Bun.listen/connect/spawn/serve) to ensure cleanup in tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

test/**/*.test.{ts,tsx}: Test files must live under test/ and end with .test.ts or .test.tsx
In tests, always use port: 0; do not hardcode ports or roll your own random port
Prefer normalizeBunSnapshot for snapshotting test output instead of asserting raw strings
Do not write tests that assert absence of crashes (e.g., 'no panic' or 'no uncaught exception')
Use Bun’s Jest-compatible runner (import { test, expect } from "bun:test") for tests
Avoid shell commands like find or grep in tests; use Bun’s Glob and built-in tools instead
Prefer running tests via bun bd test and use provided harness utilities (bunEnv, bunExe, tempDir)
Use Bun.spawn with proper stdio handling and await proc.exited in process-spawning tests

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
test/cli/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place CLI command tests under test/cli/

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-03T17:10:13.486Z
Learnt from: CR
PR: oven-sh/bun#0
File: test/CLAUDE.md:0-0
Timestamp: 2025-09-03T17:10:13.486Z
Learning: Applies to test/**/*.test.ts : Do not set explicit test timeouts; rely on Bun’s built-in timeouts

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
🧬 Code graph analysis (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)
test/harness.ts (3)
  • tempDir (278-285)
  • tempDirWithFiles (260-267)
  • bunExe (103-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format
🔇 Additional comments (1)
test/cli/install/migration/yarn-lock-migration.test.ts (1)

1378-1483: LGTM! Well-structured test for OS/CPU metadata migration.

The new test correctly validates the PR's objective of fetching OS/CPU metadata during yarn.lock migration. It:

  • Creates a realistic test case with platform-specific packages (fsevents, esbuild)
  • Uses consistent patterns with the rest of the file (await Promise.all, fs.existsSync)
  • Employs snapshot-based verification for lockfile format validation
  • Includes sanity checks for platform-specific packages in the migrated lockfile

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants