Skip to content

yarn berry migration (and simpler yarn classic) - #25245

Closed
RiskyMH wants to merge 1 commit into
mainfrom
claude/yarn-berry-migration
Closed

RiskyMH wants to merge 1 commit into
mainfrom
claude/yarn-berry-migration

Conversation

@RiskyMH

@RiskyMH RiskyMH commented Nov 30, 2025 •

Copy link
Copy Markdown
Contributor

I did 95% of this months ago, so I don't fully remember it haha

@robobun

robobun commented Nov 30, 2025 •

Copy link
Copy Markdown
Collaborator
Updated 7:20 AM PT - Nov 30th, 2025

❌ @RiskyMH, your commit 2cf9f75 has 3 failures in Build #32713 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 25245

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

bun-25245 --bun

@RiskyMH
RiskyMH force-pushed the claude/yarn-berry-migration branch 8 times, most recently from b4e0c38 to c2b75d4 Compare November 30, 2025 12:56
@RiskyMH
RiskyMH requested a review from dylan-conway November 30, 2025 13:26
@RiskyMH
RiskyMH marked this pull request as ready for review November 30, 2025 13:53
@coderabbitai

coderabbitai Bot commented Nov 30, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds Yarn Berry migration support: new MigrationType enum and yarn_berry state, yarn-berry-aware metadata fetching and resolution parsing, an analytics counter for yarn_berry migrations, pnpm callsite update, and extensive Yarn v1/Berry migration tests.

Changes

Cohort / File(s) Summary
Analytics tracking
src/analytics.zig
Added pub var yarn_berry_migration: usize = 0 to Features.
Lockfile migration infra
src/install/lockfile.zig
Added pub const MigrationType = enum { pnpm, yarn_classic, yarn_berry }; extended LoadResult.ok.migrated with yarn_berry; changed fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration to accept comptime migration_type: MigrationType and consolidated metadata-fetching with migration-type branches; updated chooseConfigVersion to handle .yarn_berry.
PNPM migration callsite
src/install/pnpm.zig
migratePnpmLockfile now calls fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration(..., .pnpm) (comptime MigrationType) instead of the previous boolean parameter.
Resolution parsing
src/install/resolution.zig
Added pub fn fromYarnBerryLockfile(...) and pub fn fromYarnV1Spec(...) plus helpers to parse Yarn Berry and Yarn v1 specs (npm/link/file/portal/github/git/tarball forms, registry decoding, aliasing, committish handling, optional archive URL).
Yarn Berry migration tests
test/cli/install/migration/yarn-berry.test.ts
Added comprehensive tests covering multiple Yarn Berry formats/versions, workspaces/monorepos, registry/tarball/git resolutions, aliases, multi-resolutions, bins/peers, and frozen-lockfile install checks.
Yarn v1 migration tests & fixtures
test/cli/install/migration/yarn-lock-migration.test.ts
Reworked temp-dir usage to tempDir(...) pattern and updated many tests; added scenarios for Yarn v1 quirks: custom registry tarballs, npm aliases, multi-spec consolidation, indentation parsing, optionalDependencies, workspaces, scoped packages, and complex lockfile graphs.

Suggested reviewers

  • dylan-conway
  • nektro

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. It lacks the required sections from the template (What does this PR do? and How did you verify your code works?) and provides only minimal, vague information. Complete the description by addressing both template sections: provide detailed explanation of Yarn Berry support and Yarn Classic improvements; document testing approach and verification steps.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: adding Yarn Berry support and improving Yarn Classic handling.

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: 4

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)

981-1048: Use this consistently for stringBuilder and extern_strings to prevent data corruption

The implementation mixes references to this and manager.lockfile during the migration helper, which creates a critical bug:

  • The problem: Lines 1028-1033 write bin extern_strings to manager.lockfile.buffers.extern_strings, but assign the result to pkg_bin.* in this (the new lockfile being built). This creates dangling references—bin entries in the newly-built lockfile point to string buffers in the old manager.lockfile.
  • Why it matters: When the migration completes and returns this, those bin entries reference strings that live in a different lockfile's buffer, causing data corruption and potential memory safety issues.
  • For yarn_berry: Bins are already populated during parsing (lines 147, 176, 185 of yarn.zig), so this code path isn't executed, masking the bug.
  • For pnpm/yarn_classic: This is a live bug—replace manager.lockfile.stringBuilder(), manager.lockfile.allocator, and &manager.lockfile.buffers.extern_strings with this.stringBuilder(), this.allocator, and &this.buffers.extern_strings respectively.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

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 cc3fc5a and c2b75d4540b8e44a5a8e58794e2701ee34c61eaf.

⛔ Files ignored due to path filters (2)
  • test/cli/install/migration/__snapshots__/yarn-berry.test.ts.snap is excluded by !**/*.snap
  • test/cli/install/migration/__snapshots__/yarn-lock-migration.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • src/analytics.zig (1 hunks)
  • src/install/lockfile.zig (5 hunks)
  • src/install/pnpm.zig (1 hunks)
  • src/install/resolution.zig (2 hunks)
  • test/cli/install/migration/yarn-berry.test.ts (1 hunks)
  • test/cli/install/migration/yarn-lock-migration.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
src/**/*.{cpp,zig}

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

src/**/*.{cpp,zig}: Use bun bd or bun run build:debug to build debug versions for C++ and Zig source files; creates debug build at ./build/debug/bun-debug
Run tests using bun bd test <test-file> with the debug build; never use bun test directly as it will not include your changes
Execute files using bun bd <file> <...args>; never use bun <file> directly as it will not include your changes
Enable debug logs for specific scopes using BUN_DEBUG_$(SCOPE)=1 environment variable
Code generation happens automatically as part of the build process; no manual code generation commands are required

Files:

  • src/analytics.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
src/**/*.zig

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

Use bun.Output.scoped(.${SCOPE}, .hidden) for creating debug logs in Zig code

Implement core functionality in Zig, typically in its own directory in src/

src/**/*.zig: Zig source code should be organized in src/*.zig for core runtime, JavaScript bindings, and package manager
In Zig code, be careful with allocators and use defer for cleanup to manage memory properly
Use BUN_DEBUG_QUIET_LOGS=1 to disable debug logging, or BUN_DEBUG_<scopeName>=1 to enable specific Output.scoped calls in debug builds
Run bun run zig:check-all to compile the Zig code on all platforms when making platform-specific changes

src/**/*.zig: Private fields in Zig are fully supported using the # prefix: struct { #foo: u32 };
Use decl literals in Zig for declaration initialization: const decl: Decl = .{ .binding = 0, .value = 0 };
Prefer @import at the bottom of the file (auto formatter will move them automatically)

Files:

  • src/analytics.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
**/*.zig

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

**/*.zig: Expose generated bindings in Zig structs using pub const js = JSC.Codegen.JS<ClassName> with trait conversion methods: toJS, fromJS, and fromJSDirect
Use consistent parameter name globalObject instead of ctx in Zig constructor and method implementations
Use bun.JSError!JSValue return type for Zig methods and constructors to enable proper error handling and exception propagation
Implement resource cleanup using deinit() method that releases resources, followed by finalize() called by the GC that invokes deinit() and frees the pointer
Use JSC.markBinding(@src()) in finalize methods for debugging purposes before calling deinit()
For methods returning cached properties in Zig, declare external C++ functions using extern fn and callconv(JSC.conv) calling convention
Implement getter functions with naming pattern get<PropertyName> in Zig that accept this and globalObject parameters and return JSC.JSValue
Access JavaScript CallFrame arguments using callFrame.argument(i), check argument count with callFrame.argumentCount(), and get this with callFrame.thisValue()
For reference-counted objects, use .deref() in finalize instead of destroy() to release references to other JS objects

Files:

  • src/analytics.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
src/**/*.{ts,zig,cpp}

📄 CodeRabbit inference engine (CLAUDE.md)

Always use absolute paths in file operations

Files:

  • src/analytics.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
src/**/*.{ts,zig}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid shell commands in code - don't use find or grep; use Bun's Glob and built-in tools instead

Files:

  • src/analytics.zig
  • src/install/pnpm.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
test/**/*.{js,ts,jsx,tsx}

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

test/**/*.{js,ts,jsx,tsx}: Write tests as JavaScript and TypeScript files using Jest-style APIs (test, describe, expect) and import from bun:test
Use test.each and data-driven tests to reduce boilerplate when testing multiple similar cases

Files:

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

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

When testing Bun as a CLI, use the spawn API from bun with the bunExe() and bunEnv from harness to execute Bun commands and validate exit codes, stdout, and stderr

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

For CLI command tests, use the test/cli/ directory (install, run, test, etc.)

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.test.{ts,tsx}: For single-file tests, prefer using -e flag over tempDir
For multi-file tests, prefer using tempDir from harness and Bun.spawn over other temporary directory creation methods
Always use port: 0 for network tests and do not hardcode ports or use custom random port number functions
Use normalizeBunSnapshot to normalize snapshot output of tests
Never write tests that check for no 'panic' or 'uncaught exception' or similar in the test output - that is NOT a valid test
Use tempDir from harness to create temporary directories, do not use tmpdirSync or fs.mkdtempSync
When spawning processes in tests, check stdout/stderr expectations BEFORE checking exit code to get more useful error messages on test failure
Do not write flaky tests - do not use setTimeout in tests, instead await the condition to be met as you are testing the CONDITION not the TIME PASSING
Verify your test fails with USE_SYSTEM_BUN=1 bun test <file> and passes with bun bd test <file> - your test is NOT VALID if it passes with USE_SYSTEM_BUN=1

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}: Use bun:test with files that end in *.test.{ts,js,jsx,tsx,mjs,cjs}
Do not write flaky tests. Never wait for time to pass in tests; always wait for the condition to be met instead of using an arbitrary amount of time
Never use hardcoded port numbers in tests. Always use port: 0 to get a random port
Prefer concurrent tests over sequential tests using test.concurrent or describe.concurrent when multiple tests spawn processes or write files, unless it's very difficult to make them concurrent
When spawning Bun processes in tests, use bunExe and bunEnv from harness to ensure the same build of Bun is used and debug logging is silenced
Use -e flag for single-file tests when spawning Bun processes
Use tempDir() from harness to create temporary directories with files for multi-file tests instead of creating files manually
Prefer async/await over callbacks in tests
When callbacks must be used and it's just a single callback, use Promise.withResolvers to create a promise that can be resolved or rejected from a callback
Do not set a timeout on tests. Bun already has timeouts
Use Buffer.alloc(count, fill).toString() instead of 'A'.repeat(count) to create repetitive strings in tests, as ''.repeat is very slow in debug JavaScriptCore builds
Use describe blocks for grouping related tests
Always use await using or using to ensure proper resource cleanup in tests for APIs like Bun.listen, Bun.connect, Bun.spawn, Bun.serve, etc
Always check exit codes and test error scenarios in error tests
Use describe.each() for parameterized tests
Use toMatchSnapshot() for snapshot testing
Use beforeAll(), afterEach(), beforeEach() for setup/teardown in tests
Track resources (servers, clients) in arrays for cleanup in afterEach()

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
🧠 Learnings (24)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
📚 Learning: 2025-10-16T02:17:35.237Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 23710
File: src/analytics.zig:15-21
Timestamp: 2025-10-16T02:17:35.237Z
Learning: In src/analytics.zig and similar files using bun.EnvVar boolean environment variables: the new EnvVar API for boolean flags (e.g., bun.EnvVar.do_not_track.get(), bun.EnvVar.ci.get()) is designed to parse and return boolean values from environment variables, not just check for their presence. This is an intentional design change from the previous presence-based checks using bun.getenvZ().

Applied to files:

  • src/analytics.zig
📚 Learning: 2025-11-20T19:51:32.288Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24880
File: packages/bun-vscode/package.json:382-385
Timestamp: 2025-11-20T19:51:32.288Z
Learning: In the Bun repository, dependencies may be explicitly added to package.json files (even when not directly imported in code) to force version upgrades on transitive dependencies, particularly as part of Aikido security scanner remediation to ensure vulnerable transitive dependencies resolve to patched versions.

Applied to files:

  • src/install/lockfile.zig
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/bundle.test.ts : Organize bundle tests in bundle.test.ts for tests concerning bundling bugs that only occur in DevServer

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/sourcemap.test.ts : Organize source-map tests in sourcemap.test.ts for tests verifying source-maps are correct

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/esm.test.ts : Organize ESM tests in esm.test.ts for tests about various ESM features in development mode

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: Applies to test/**/*.{js,ts,jsx,tsx} : Write tests as JavaScript and TypeScript files using Jest-style APIs (`test`, `describe`, `expect`) and import from `bun:test`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-14T16:07:01.064Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/js/bun/**/*.test.{ts,tsx} : For Bun-specific API tests, use the `test/js/bun/` directory (for http, crypto, ffi, shell, etc.)

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/ecosystem.test.ts : Organize ecosystem tests in ecosystem.test.ts for tests involving ensuring certain libraries are correct; prefer testing concrete bugs over testing entire packages

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/css.test.ts : Organize CSS tests in css.test.ts for tests concerning bundling bugs with CSS files

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Verify your test fails with `USE_SYSTEM_BUN=1 bun test <file>` and passes with `bun bd test <file>` - your test is NOT VALID if it passes with `USE_SYSTEM_BUN=1`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/bundler/**/*.test.{ts,tsx} : For bundler and transpiler tests, use the `test/bundler/` directory and the `itBundled` helper

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Unit tests for specific features are organized by module (e.g., `/test/js/bun/`, `/test/js/node/`)

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : When spawning Bun processes in tests, use `bunExe` and `bunEnv` from `harness` to ensure the same build of Bun is used and debug logging is silenced

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Use `normalizeBunSnapshot` to normalize snapshot output of tests

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` with files that end in `*.test.{ts,js,jsx,tsx,mjs,cjs}`

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: Applies to test/cli/**/*.{js,ts,jsx,tsx} : When testing Bun as a CLI, use the `spawn` API from `bun` with the `bunExe()` and `bunEnv` from `harness` to execute Bun commands and validate exit codes, stdout, and stderr

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Always use `await using` or `using` to ensure proper resource cleanup in tests for APIs like Bun.listen, Bun.connect, Bun.spawn, Bun.serve, etc

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-10-26T04:50:17.892Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24086
File: src/bun.js/api/server.zig:2534-2535
Timestamp: 2025-10-26T04:50:17.892Z
Learning: In src/bun.js/api/server.zig, u32 is acceptable for route indices and websocket_context_index fields, as the practical limit of 4 billion contexts will never be reached.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-11-24T18:36:08.558Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-11-24T18:36:08.558Z
Learning: Applies to **/*.zig : Expose generated bindings in Zig structs using `pub const js = JSC.Codegen.JS<ClassName>` with trait conversion methods: `toJS`, `fromJS`, and `fromJSDirect`

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-08-30T09:09:18.384Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 22231
File: src/bundler/bundle_v2.zig:48-48
Timestamp: 2025-08-30T09:09:18.384Z
Learning: In Zig, when a module exports a top-level struct, import("./Module.zig") directly returns that struct type and can be used as a type alias without needing to access a field within the module. This is a common pattern in the Bun codebase.

Applied to files:

  • src/install/resolution.zig
🧬 Code graph analysis (2)
test/cli/install/migration/yarn-lock-migration.test.ts (2)
test/harness.ts (3)
  • tempDir (277-284)
  • tempDirWithFiles (259-266)
  • bunExe (102-105)
test/js/node/test_runner/fixtures/02-hooks.js (1)
  • JSON (7-7)
test/cli/install/migration/yarn-berry.test.ts (2)
test/harness.ts (2)
  • tempDir (277-284)
  • bunExe (102-105)
test/js/node/test_runner/fixtures/02-hooks.js (1)
  • JSON (7-7)
🔇 Additional comments (3)
src/install/pnpm.zig (1)

827-827: pnpm migration now uses explicit MigrationType enum

Using .pnpm with fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration matches the new enum-based API and preserves pnpm’s prior behavior (populate npm metadata without yarn-specific os/cpu tweaks). Looks good.

src/install/lockfile.zig (1)

106-212: LoadResult.migrated & config version handling correctly extended for Yarn Berry

Extending ok.migrated with .yarn_berry and updating chooseConfigVersion to treat all migrated-from-other-manager cases as .v0 is consistent with existing .npm/.yarn behavior and preserves current config-version semantics.

src/analytics.zig (1)

29-93: yarn_berry_migration metric is properly wired and incremented

The yarn_berry_migration field is correctly added to the analytics struct and is incremented in src/install/yarn.zig:43 during Yarn Berry migration. The field follows the established pattern alongside yarn_migration and pnpm_migration and will be automatically picked up by the packed_features_list / packedFeatures() introspection.

Comment thread src/install/resolution.zig Resolved
@RiskyMH
RiskyMH force-pushed the claude/yarn-berry-migration branch from c2b75d4 to 1144712 Compare November 30, 2025 14:13

@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: 2

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)

981-1048: Use this instead of manager.lockfile for stringBuilder and buffers operations

Inside fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration, the method reads package data from this but writes string and binary metadata to manager.lockfile:

var builder = manager.lockfile.stringBuilder();
...
var extern_strings_list = &manager.lockfile.buffers.extern_strings;

Since the method receives this: *Lockfile as the lockfile being migrated, but manager.lockfile is initialized independently and never set to this in any of the three call sites (migrateYarnV1, migrateYarnBerry, migratePnpmLockfile), these can be different instances. This causes metadata to be written to the wrong lockfile.

Fix by operating consistently on this:

-    var builder = manager.lockfile.stringBuilder();
+    var builder = this.stringBuilder();
...
-    var extern_strings_list = &manager.lockfile.buffers.extern_strings;
-    try extern_strings_list.ensureUnusedCapacity(manager.lockfile.allocator, bin_extern_strings_count);
+    var extern_strings_list = &this.buffers.extern_strings;
+    try extern_strings_list.ensureUnusedCapacity(this.allocator, bin_extern_strings_count);
♻️ Duplicate comments (3)
test/cli/install/migration/yarn-berry.test.ts (1)

45-52: Normalize bun.lock snapshots and strengthen stderr assertions for spawned installs

These tests rely heavily on expect(lockContents).toMatchSnapshot() / expect(lockfile).toMatchSnapshot(...) on bun.lock, and most Bun.spawn calls only assert exitCode === 0. For long‑lived maintenance:

  • Run bun.lock contents through the usual snapshot normalizer (e.g. normalizeBunSnapshot from the test harness) before toMatchSnapshot() so path/format tweaks don’t cause noisy snapshot churn.
  • For each Bun.spawn call, consistently assert that stderr doesn’t contain obvious error markers (like “failed”, “error”, “lockfile had changes”) alongside the exit code, rather than relying on ad‑hoc console.error blocks only in a few tests.

This will make failures easier to diagnose and snapshots more stable across environments.

Also applies to: 100-105, 160-163, 200-202, 253-255, 290-292, 329-330, 557-560, 604-608, 906-912, 953-958, 1033-1042, 1081-1087, 1143-1151

src/install/resolution.zig (1)

213-475: Align alias normalization in fromYarnV1Spec for @github: and @git+ specs

fromYarnV1Spec now centralizes Yarn v1 spec parsing, but alias handling is still inconsistent:

  • For alias@github:owner/repo#ref you keep real_name as the alias (using the slice before @github:).
  • For alias@git+…github.com/owner/repo.git#ref you derive real_name from the repo name (repo_part) instead of the alias, and similarly for non‑GitHub git+ URLs.

So myalias@github:owner/repo and myalias@git+https://github.com/owner/repo.git#… will end up with different canonical names in the lockfile even though they’re equivalent from Yarn’s perspective.

Consider:

  • Detecting the alias portion for @git+ specs the same way you do for the @github: branch (slice first_spec up to the @git+ occurrence), and
  • Using that alias as real_name (and corresponding hash) whenever one is present, falling back to the repo-derived name only when there is no alias.

This will make alias semantics consistent regardless of whether the spec uses @github: or @git+…github.com.

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

1483-1843: Note: Resource cleanup pattern was addressed in a previous review.

The tests use tempDirWithFiles without await using, which is consistent with existing tests in this file. The past review comment already flagged the opportunity to use tempDir() with await using for automatic cleanup. This is a file-wide pattern that could be addressed in a follow-up refactoring effort.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

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 c2b75d4540b8e44a5a8e58794e2701ee34c61eaf and 1144712db1736eafbd284ffe3af1f1217e18d295.

⛔ Files ignored due to path filters (2)
  • test/cli/install/migration/__snapshots__/yarn-berry.test.ts.snap is excluded by !**/*.snap
  • test/cli/install/migration/__snapshots__/yarn-lock-migration.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • src/analytics.zig (1 hunks)
  • src/install/lockfile.zig (5 hunks)
  • src/install/pnpm.zig (1 hunks)
  • src/install/resolution.zig (2 hunks)
  • test/cli/install/migration/yarn-berry.test.ts (1 hunks)
  • test/cli/install/migration/yarn-lock-migration.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
src/**/*.{cpp,zig}

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

src/**/*.{cpp,zig}: Use bun bd or bun run build:debug to build debug versions for C++ and Zig source files; creates debug build at ./build/debug/bun-debug
Run tests using bun bd test <test-file> with the debug build; never use bun test directly as it will not include your changes
Execute files using bun bd <file> <...args>; never use bun <file> directly as it will not include your changes
Enable debug logs for specific scopes using BUN_DEBUG_$(SCOPE)=1 environment variable
Code generation happens automatically as part of the build process; no manual code generation commands are required

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/resolution.zig
  • src/install/lockfile.zig
src/**/*.zig

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

Use bun.Output.scoped(.${SCOPE}, .hidden) for creating debug logs in Zig code

Implement core functionality in Zig, typically in its own directory in src/

src/**/*.zig: Zig source code should be organized in src/*.zig for core runtime, JavaScript bindings, and package manager
In Zig code, be careful with allocators and use defer for cleanup to manage memory properly
Use BUN_DEBUG_QUIET_LOGS=1 to disable debug logging, or BUN_DEBUG_<scopeName>=1 to enable specific Output.scoped calls in debug builds
Run bun run zig:check-all to compile the Zig code on all platforms when making platform-specific changes

src/**/*.zig: Private fields in Zig are fully supported using the # prefix: struct { #foo: u32 };
Use decl literals in Zig for declaration initialization: const decl: Decl = .{ .binding = 0, .value = 0 };
Prefer @import at the bottom of the file (auto formatter will move them automatically)

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/resolution.zig
  • src/install/lockfile.zig
**/*.zig

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

**/*.zig: Expose generated bindings in Zig structs using pub const js = JSC.Codegen.JS<ClassName> with trait conversion methods: toJS, fromJS, and fromJSDirect
Use consistent parameter name globalObject instead of ctx in Zig constructor and method implementations
Use bun.JSError!JSValue return type for Zig methods and constructors to enable proper error handling and exception propagation
Implement resource cleanup using deinit() method that releases resources, followed by finalize() called by the GC that invokes deinit() and frees the pointer
Use JSC.markBinding(@src()) in finalize methods for debugging purposes before calling deinit()
For methods returning cached properties in Zig, declare external C++ functions using extern fn and callconv(JSC.conv) calling convention
Implement getter functions with naming pattern get<PropertyName> in Zig that accept this and globalObject parameters and return JSC.JSValue
Access JavaScript CallFrame arguments using callFrame.argument(i), check argument count with callFrame.argumentCount(), and get this with callFrame.thisValue()
For reference-counted objects, use .deref() in finalize instead of destroy() to release references to other JS objects

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/resolution.zig
  • src/install/lockfile.zig
src/**/*.{ts,zig,cpp}

📄 CodeRabbit inference engine (CLAUDE.md)

Always use absolute paths in file operations

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/resolution.zig
  • src/install/lockfile.zig
src/**/*.{ts,zig}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid shell commands in code - don't use find or grep; use Bun's Glob and built-in tools instead

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/resolution.zig
  • src/install/lockfile.zig
test/**/*.{js,ts,jsx,tsx}

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

test/**/*.{js,ts,jsx,tsx}: Write tests as JavaScript and TypeScript files using Jest-style APIs (test, describe, expect) and import from bun:test
Use test.each and data-driven tests to reduce boilerplate when testing multiple similar cases

Files:

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

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

When testing Bun as a CLI, use the spawn API from bun with the bunExe() and bunEnv from harness to execute Bun commands and validate exit codes, stdout, and stderr

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

For CLI command tests, use the test/cli/ directory (install, run, test, etc.)

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.test.{ts,tsx}: For single-file tests, prefer using -e flag over tempDir
For multi-file tests, prefer using tempDir from harness and Bun.spawn over other temporary directory creation methods
Always use port: 0 for network tests and do not hardcode ports or use custom random port number functions
Use normalizeBunSnapshot to normalize snapshot output of tests
Never write tests that check for no 'panic' or 'uncaught exception' or similar in the test output - that is NOT a valid test
Use tempDir from harness to create temporary directories, do not use tmpdirSync or fs.mkdtempSync
When spawning processes in tests, check stdout/stderr expectations BEFORE checking exit code to get more useful error messages on test failure
Do not write flaky tests - do not use setTimeout in tests, instead await the condition to be met as you are testing the CONDITION not the TIME PASSING
Verify your test fails with USE_SYSTEM_BUN=1 bun test <file> and passes with bun bd test <file> - your test is NOT VALID if it passes with USE_SYSTEM_BUN=1

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}: Use bun:test with files that end in *.test.{ts,js,jsx,tsx,mjs,cjs}
Do not write flaky tests. Never wait for time to pass in tests; always wait for the condition to be met instead of using an arbitrary amount of time
Never use hardcoded port numbers in tests. Always use port: 0 to get a random port
Prefer concurrent tests over sequential tests using test.concurrent or describe.concurrent when multiple tests spawn processes or write files, unless it's very difficult to make them concurrent
When spawning Bun processes in tests, use bunExe and bunEnv from harness to ensure the same build of Bun is used and debug logging is silenced
Use -e flag for single-file tests when spawning Bun processes
Use tempDir() from harness to create temporary directories with files for multi-file tests instead of creating files manually
Prefer async/await over callbacks in tests
When callbacks must be used and it's just a single callback, use Promise.withResolvers to create a promise that can be resolved or rejected from a callback
Do not set a timeout on tests. Bun already has timeouts
Use Buffer.alloc(count, fill).toString() instead of 'A'.repeat(count) to create repetitive strings in tests, as ''.repeat is very slow in debug JavaScriptCore builds
Use describe blocks for grouping related tests
Always use await using or using to ensure proper resource cleanup in tests for APIs like Bun.listen, Bun.connect, Bun.spawn, Bun.serve, etc
Always check exit codes and test error scenarios in error tests
Use describe.each() for parameterized tests
Use toMatchSnapshot() for snapshot testing
Use beforeAll(), afterEach(), beforeEach() for setup/teardown in tests
Track resources (servers, clients) in arrays for cleanup in afterEach()

Files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
🧠 Learnings (40)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
📚 Learning: 2025-10-16T02:17:35.237Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 23710
File: src/analytics.zig:15-21
Timestamp: 2025-10-16T02:17:35.237Z
Learning: In src/analytics.zig and similar files using bun.EnvVar boolean environment variables: the new EnvVar API for boolean flags (e.g., bun.EnvVar.do_not_track.get(), bun.EnvVar.ci.get()) is designed to parse and return boolean values from environment variables, not just check for their presence. This is an intentional design change from the previous presence-based checks using bun.getenvZ().

Applied to files:

  • src/analytics.zig
📚 Learning: 2025-09-02T17:14:46.924Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 22227
File: src/safety/alloc.zig:93-95
Timestamp: 2025-09-02T17:14:46.924Z
Learning: In bun's Zig codebase, they use a custom extension of Zig that supports private field syntax with the `#` prefix (e.g., `#allocator`, `#trace`). This is not standard Zig syntax but is valid in their custom implementation. Fields prefixed with `#` are private fields that cannot be accessed from outside the defining struct.

Applied to files:

  • src/analytics.zig
📚 Learning: 2025-10-16T17:32:03.074Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 23710
File: src/install/PackageManager/PackageManagerOptions.zig:187-193
Timestamp: 2025-10-16T17:32:03.074Z
Learning: In Bun's codebase (particularly in files like src/install/PackageManager/PackageManagerOptions.zig), mixing bun.EnvVar.*.get() and bun.EnvVar.*.platformGet() for environment variable lookups is intentional and safe. The code is protected by compile-time platform checks (Environment.isWindows, etc.), and compilation will fail if the wrong function is used on the wrong platform. This pattern should not be flagged as a consistency issue.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-09-06T03:37:41.154Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 22229
File: src/bundler/LinkerGraph.zig:0-0
Timestamp: 2025-09-06T03:37:41.154Z
Learning: In Bun's codebase, when checking import record source indices in src/bundler/LinkerGraph.zig, prefer using `if (import_index >= self.import_records.len)` bounds checking over `isValid()` checks, as the bounds check is more robust and `isValid()` is a strict subset of this condition.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-10-26T04:50:17.892Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24086
File: src/bun.js/api/server.zig:2534-2535
Timestamp: 2025-10-26T04:50:17.892Z
Learning: In src/bun.js/api/server.zig, u32 is acceptable for route indices and websocket_context_index fields, as the practical limit of 4 billion contexts will never be reached.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-11-24T18:36:08.558Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-11-24T18:36:08.558Z
Learning: Applies to **/*.zig : Expose generated bindings in Zig structs using `pub const js = JSC.Codegen.JS<ClassName>` with trait conversion methods: `toJS`, `fromJS`, and `fromJSDirect`

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-08-30T09:09:18.384Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 22231
File: src/bundler/bundle_v2.zig:48-48
Timestamp: 2025-08-30T09:09:18.384Z
Learning: In Zig, when a module exports a top-level struct, import("./Module.zig") directly returns that struct type and can be used as a type alias without needing to access a field within the module. This is a common pattern in the Bun codebase.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/bundle.test.ts : Organize bundle tests in bundle.test.ts for tests concerning bundling bugs that only occur in DevServer

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/sourcemap.test.ts : Organize source-map tests in sourcemap.test.ts for tests verifying source-maps are correct

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/esm.test.ts : Organize ESM tests in esm.test.ts for tests about various ESM features in development mode

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/ecosystem.test.ts : Organize ecosystem tests in ecosystem.test.ts for tests involving ensuring certain libraries are correct; prefer testing concrete bugs over testing entire packages

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: Applies to test/**/*.{js,ts,jsx,tsx} : Write tests as JavaScript and TypeScript files using Jest-style APIs (`test`, `describe`, `expect`) and import from `bun:test`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Use `normalizeBunSnapshot` to normalize snapshot output of tests

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/js/bun/**/*.test.{ts,tsx} : For Bun-specific API tests, use the `test/js/bun/` directory (for http, crypto, ffi, shell, etc.)

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/css.test.ts : Organize CSS tests in css.test.ts for tests concerning bundling bugs with CSS files

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Always use `await using` or `using` to ensure proper resource cleanup in tests for APIs like Bun.listen, Bun.connect, Bun.spawn, Bun.serve, etc

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-06T00:58:23.965Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24417
File: test/js/bun/spawn/spawn.test.ts:903-918
Timestamp: 2025-11-06T00:58:23.965Z
Learning: In Bun test files, `await using` with spawn() is appropriate for long-running processes that need guaranteed cleanup on scope exit or when explicitly testing disposal behavior. For short-lived processes that exit naturally (e.g., console.log scripts), the pattern `const proc = spawn(...); await proc.exited;` is standard and more common, as evidenced by 24 instances vs 4 `await using` instances in test/js/bun/spawn/spawn.test.ts.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : For multi-file tests, prefer using `tempDir` from `harness` and `Bun.spawn` over other temporary directory creation methods

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `tempDir()` from harness to create temporary directories with files for multi-file tests instead of creating files manually

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Use `tempDir` from `harness` to create temporary directories, do not use `tmpdirSync` or `fs.mkdtempSync`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Prefer async/await over callbacks in tests

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-08T04:06:33.198Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24491
File: test/js/bun/transpiler/declare-global.test.ts:17-17
Timestamp: 2025-11-08T04:06:33.198Z
Learning: In Bun test files, `await using` with Bun.spawn() is the preferred pattern for spawned processes regardless of whether they are short-lived or long-running. Do not suggest replacing `await using proc = Bun.spawn(...)` with `const proc = Bun.spawn(...); await proc.exited;`.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : When spawning Bun processes in tests, use `bunExe` and `bunEnv` from `harness` to ensure the same build of Bun is used and debug logging is silenced

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: Applies to test/cli/**/*.{js,ts,jsx,tsx} : When testing Bun as a CLI, use the `spawn` API from `bun` with the `bunExe()` and `bunEnv` from `harness` to execute Bun commands and validate exit codes, stdout, and stderr

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : For single-file tests, prefer using `-e` flag over `tempDir`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Verify your test fails with `USE_SYSTEM_BUN=1 bun test <file>` and passes with `bun bd test <file>` - your test is NOT VALID if it passes with `USE_SYSTEM_BUN=1`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/bundler/**/*.test.{ts,tsx} : For bundler and transpiler tests, use the `test/bundler/` directory and the `itBundled` helper

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Unit tests for specific features are organized by module (e.g., `/test/js/bun/`, `/test/js/node/`)

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-20T19:51:32.288Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24880
File: packages/bun-vscode/package.json:382-385
Timestamp: 2025-11-20T19:51:32.288Z
Learning: In the Bun repository, dependencies may be explicitly added to package.json files (even when not directly imported in code) to force version upgrades on transitive dependencies, particularly as part of Aikido security scanner remediation to ensure vulnerable transitive dependencies resolve to patched versions.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
  • src/install/lockfile.zig
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` with files that end in `*.test.{ts,js,jsx,tsx,mjs,cjs}`

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-10-26T01:32:04.844Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24082
File: test/cli/test/coverage.test.ts:60-112
Timestamp: 2025-10-26T01:32:04.844Z
Learning: In the Bun repository test files (test/cli/test/*.test.ts), when spawning Bun CLI commands with Bun.spawnSync for testing, prefer using stdio: ["inherit", "inherit", "inherit"] to inherit stdio streams rather than piping them.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : When spawning processes in tests, check stdout/stderr expectations BEFORE checking exit code to get more useful error messages on test failure

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-09-30T22:53:19.887Z
Learnt from: pfgithub
Repo: oven-sh/bun PR: 23117
File: src/bun.js/test/snapshot.zig:265-276
Timestamp: 2025-09-30T22:53:19.887Z
Learning: In Bun's snapshot testing (src/bun.js/test/snapshot.zig), multiple inline snapshots at the same line and column (same call position) must have identical values. However, multiple inline snapshots on the same line at different columns are allowed to have different values. The check is position-specific (line+col), not line-wide.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Do not set a timeout on tests. Bun already has timeouts

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Do not write flaky tests. Never wait for time to pass in tests; always wait for the condition to be met instead of using an arbitrary amount of time

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Do not write flaky tests - do not use `setTimeout` in tests, instead `await` the condition to be met as you are testing the CONDITION not the TIME PASSING

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/js/node/test/{parallel,sequential}/*.js : For test/js/node/test/{parallel,sequential}/*.js files without a .test extension, use `bun bd <file>` instead of `bun bd test <file>` since these expect exit code 0 and don't use bun's test runner

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
🧬 Code graph analysis (2)
test/cli/install/migration/yarn-lock-migration.test.ts (2)
test/harness.ts (3)
  • tempDir (277-284)
  • tempDirWithFiles (259-266)
  • bunExe (102-105)
test/js/node/test_runner/fixtures/02-hooks.js (1)
  • JSON (7-7)
test/cli/install/migration/yarn-berry.test.ts (1)
test/harness.ts (2)
  • tempDir (277-284)
  • bunExe (102-105)
🔇 Additional comments (8)
src/install/pnpm.zig (1)

825-838: Pnpm migration correctly updated to use MigrationType API

The new call to fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration(manager, .pnpm) matches the updated API and clearly communicates the pnpm-specific path without changing behavior.

src/analytics.zig (1)

88-92: Analytics feature flag for Yarn Berry migrations fits existing pattern

Adding yarn_berry_migration alongside yarn_migration and pnpm_migration is consistent with the current analytics design and will be picked up automatically by packed_features_list and the formatter.

test/cli/install/migration/yarn-berry.test.ts (1)

1-1152: Comprehensive Yarn Berry migration coverage looks solid

The new CLI tests exercise a wide range of Yarn Berry scenarios (formats v4/v6/v8, workspaces, aliases, git/VCS URLs, custom registries, multi‑version/conflict cases, and --frozen-lockfile installs) using tempDir, bunExe, bunEnv, and await using Bun.spawn(...), all aligned with the harness guidelines. I don’t see functional issues here.

src/install/resolution.zig (2)

103-211: Yarn Berry resolution parsing matches expected lockfile formats

fromYarnBerryLockfile cleanly handles the Yarn Berry resolution formats used in the new tests:

  • Splits name@… correctly using the last @, so scoped packages work.
  • Strips ::__archiveUrl= metadata and percent‑decodes the URL into the npm resolution, preserving custom registries while keeping a safe fixed buffer.
  • Maps npm:, link:, file:, and portal: to the appropriate Resolution tags.
  • Normalizes https?://…*.git#commit=… to .github for GitHub and .git for other hosts, and falls back to npm versions for bare name@version cases (Yarn 2 v4/v5).

I don’t see correctness issues here; the behavior lines up with the Yarn Berry fixtures in the tests.


916-927: Percent-decoding import for __archiveUrl is appropriate

Importing PercentEncoding from url.zig to decode Yarn Berry __archiveUrl metadata is a good reuse of existing URL tooling and keeps the resolution logic self-contained in this module.

src/install/lockfile.zig (1)

115-121: LoadResult.ok.migrated and config version handling correctly extended for Yarn Berry

Expanding migrated to include yarn_berry and mapping it to { .v0, true } in chooseConfigVersion is consistent with the existing behavior for npm/yarn migrations, and the saveFormat logic already treats any non‑.none value as a migrated lockfile.

Also applies to: 195-213

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

1483-1544: LGTM - Good coverage for custom registry tarball URLs.

This test properly validates that custom registry URLs are preserved during migration. The assertions for both URL domains (my-custom-registry.com and packages.example.com) ensure the migration handles non-standard registries correctly.


1546-1719: Excellent comprehensive test covering yarn v1 edge cases.

This test effectively validates multiple yarn v1 quirks in a single realistic scenario: multi-spec consolidation, npm aliases, scoped packages, long build tags, multiple package versions, and workspace dependencies. The inline comments documenting each test case improve maintainability.

@RiskyMH
RiskyMH force-pushed the claude/yarn-berry-migration branch from 1144712 to 67b1591 Compare November 30, 2025 14:30
@RiskyMH
RiskyMH force-pushed the claude/yarn-berry-migration branch from 67b1591 to 2cf9f75 Compare November 30, 2025 14:37

@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

Caution

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

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

3-137: Temp directory/scoped cwd refactor looks correct and follows harness patterns.

Using tempDir(...) with using dir = ... and passing cwd: String(dir) plus join(String(dir), "bun.lock") (or Bun.file(join(String(dir), ...))) is consistent with the harness tempDir API and ensures per-test isolation and cleanup.

New Yarn v1 migration edge-case tests are comprehensive and exercise the new resolution logic.

The additional tests for custom registry tarballs, combined “yarn v1 quirks”, indentation handling, and optionalDependencies correctly:

  • Build realistic package.json + yarn.lock fixtures in temp dirs.
  • Use await using proc = Bun.spawn(...) for the new long-running pm migrate invocations so processes are cleaned up with the test scope.
  • Assert on stderr before exit code where they care about errors, and validate bun.lock via snapshots plus targeted toContain checks for aliases, workspaces, long build tags, and optional deps.

These should give good coverage over the new Yarn migration paths without introducing obvious flakiness.

Also applies to: 1483-1805

src/install/lockfile.zig (1)

981-1048: MigrationType-based metadata fetch is sound; consider decoupling from manager.lockfile for clarity.

Function behavior by migration_type looks correct:

  • All three paths go through manifests so that npm resolutions get consistent bin metadata.
  • .yarn_berry only backfills pkg_meta.integrity if it was unknown.
  • .yarn_classic additionally backfills os / arch from the manifest when they are currently .all.
  • .pnpm reuses the existing bin-clone path without touching os/cpu.

One small robustness tweak would be to avoid hard-coding manager.lockfile inside this method and instead use this for the string builder and extern_strings buffer:

-            var builder = manager.lockfile.stringBuilder();
+            var builder = this.stringBuilder();
...
-                    var extern_strings_list = &manager.lockfile.buffers.extern_strings;
-                    try extern_strings_list.ensureUnusedCapacity(manager.lockfile.allocator, bin_extern_strings_count);
+                    var extern_strings_list = &this.buffers.extern_strings;
+                    try extern_strings_list.ensureUnusedCapacity(this.allocator, bin_extern_strings_count);

That keeps the helper correct even if manager.lockfile ever diverges from the this lockfile it’s operating on.

♻️ Duplicate comments (1)
test/cli/install/migration/yarn-berry.test.ts (1)

900-903: Consider removing ad-hoc console.error debugging blocks.

These conditional logging blocks are inconsistent with other tests in the file. Instead of:

if (exitCode !== 0) {
  console.error("STDOUT:", stdout);
  console.error("STDERR:", stderr);
}

Consider asserting on stderr content before exitCode (as done in lines 577-579), which provides better diagnostics without manual debug logging:

expect(stderr).not.toContain("error");
expect(exitCode).toBe(0);

Also applies to: 947-950

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

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 1144712db1736eafbd284ffe3af1f1217e18d295 and 2cf9f75.

⛔ Files ignored due to path filters (2)
  • test/cli/install/migration/__snapshots__/yarn-berry.test.ts.snap is excluded by !**/*.snap
  • test/cli/install/migration/__snapshots__/yarn-lock-migration.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • src/analytics.zig (1 hunks)
  • src/install/lockfile.zig (5 hunks)
  • src/install/pnpm.zig (1 hunks)
  • src/install/resolution.zig (2 hunks)
  • test/cli/install/migration/yarn-berry.test.ts (1 hunks)
  • test/cli/install/migration/yarn-lock-migration.test.ts (28 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
src/**/*.{cpp,zig}

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

src/**/*.{cpp,zig}: Use bun bd or bun run build:debug to build debug versions for C++ and Zig source files; creates debug build at ./build/debug/bun-debug
Run tests using bun bd test <test-file> with the debug build; never use bun test directly as it will not include your changes
Execute files using bun bd <file> <...args>; never use bun <file> directly as it will not include your changes
Enable debug logs for specific scopes using BUN_DEBUG_$(SCOPE)=1 environment variable
Code generation happens automatically as part of the build process; no manual code generation commands are required

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
src/**/*.zig

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

Use bun.Output.scoped(.${SCOPE}, .hidden) for creating debug logs in Zig code

Implement core functionality in Zig, typically in its own directory in src/

src/**/*.zig: Zig source code should be organized in src/*.zig for core runtime, JavaScript bindings, and package manager
In Zig code, be careful with allocators and use defer for cleanup to manage memory properly
Use BUN_DEBUG_QUIET_LOGS=1 to disable debug logging, or BUN_DEBUG_<scopeName>=1 to enable specific Output.scoped calls in debug builds
Run bun run zig:check-all to compile the Zig code on all platforms when making platform-specific changes

src/**/*.zig: Private fields in Zig are fully supported using the # prefix: struct { #foo: u32 };
Use decl literals in Zig for declaration initialization: const decl: Decl = .{ .binding = 0, .value = 0 };
Prefer @import at the bottom of the file (auto formatter will move them automatically)

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
**/*.zig

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

**/*.zig: Expose generated bindings in Zig structs using pub const js = JSC.Codegen.JS<ClassName> with trait conversion methods: toJS, fromJS, and fromJSDirect
Use consistent parameter name globalObject instead of ctx in Zig constructor and method implementations
Use bun.JSError!JSValue return type for Zig methods and constructors to enable proper error handling and exception propagation
Implement resource cleanup using deinit() method that releases resources, followed by finalize() called by the GC that invokes deinit() and frees the pointer
Use JSC.markBinding(@src()) in finalize methods for debugging purposes before calling deinit()
For methods returning cached properties in Zig, declare external C++ functions using extern fn and callconv(JSC.conv) calling convention
Implement getter functions with naming pattern get<PropertyName> in Zig that accept this and globalObject parameters and return JSC.JSValue
Access JavaScript CallFrame arguments using callFrame.argument(i), check argument count with callFrame.argumentCount(), and get this with callFrame.thisValue()
For reference-counted objects, use .deref() in finalize instead of destroy() to release references to other JS objects

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
src/**/*.{ts,zig,cpp}

📄 CodeRabbit inference engine (CLAUDE.md)

Always use absolute paths in file operations

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
src/**/*.{ts,zig}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid shell commands in code - don't use find or grep; use Bun's Glob and built-in tools instead

Files:

  • src/install/pnpm.zig
  • src/analytics.zig
  • src/install/lockfile.zig
  • src/install/resolution.zig
test/**/*.{js,ts,jsx,tsx}

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

test/**/*.{js,ts,jsx,tsx}: Write tests as JavaScript and TypeScript files using Jest-style APIs (test, describe, expect) and import from bun:test
Use test.each and data-driven tests to reduce boilerplate when testing multiple similar cases

Files:

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

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

When testing Bun as a CLI, use the spawn API from bun with the bunExe() and bunEnv from harness to execute Bun commands and validate exit codes, stdout, and stderr

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

For CLI command tests, use the test/cli/ directory (install, run, test, etc.)

Files:

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

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.test.{ts,tsx}: For single-file tests, prefer using -e flag over tempDir
For multi-file tests, prefer using tempDir from harness and Bun.spawn over other temporary directory creation methods
Always use port: 0 for network tests and do not hardcode ports or use custom random port number functions
Use normalizeBunSnapshot to normalize snapshot output of tests
Never write tests that check for no 'panic' or 'uncaught exception' or similar in the test output - that is NOT a valid test
Use tempDir from harness to create temporary directories, do not use tmpdirSync or fs.mkdtempSync
When spawning processes in tests, check stdout/stderr expectations BEFORE checking exit code to get more useful error messages on test failure
Do not write flaky tests - do not use setTimeout in tests, instead await the condition to be met as you are testing the CONDITION not the TIME PASSING
Verify your test fails with USE_SYSTEM_BUN=1 bun test <file> and passes with bun bd test <file> - your test is NOT VALID if it passes with USE_SYSTEM_BUN=1

Files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}: Use bun:test with files that end in *.test.{ts,js,jsx,tsx,mjs,cjs}
Do not write flaky tests. Never wait for time to pass in tests; always wait for the condition to be met instead of using an arbitrary amount of time
Never use hardcoded port numbers in tests. Always use port: 0 to get a random port
Prefer concurrent tests over sequential tests using test.concurrent or describe.concurrent when multiple tests spawn processes or write files, unless it's very difficult to make them concurrent
When spawning Bun processes in tests, use bunExe and bunEnv from harness to ensure the same build of Bun is used and debug logging is silenced
Use -e flag for single-file tests when spawning Bun processes
Use tempDir() from harness to create temporary directories with files for multi-file tests instead of creating files manually
Prefer async/await over callbacks in tests
When callbacks must be used and it's just a single callback, use Promise.withResolvers to create a promise that can be resolved or rejected from a callback
Do not set a timeout on tests. Bun already has timeouts
Use Buffer.alloc(count, fill).toString() instead of 'A'.repeat(count) to create repetitive strings in tests, as ''.repeat is very slow in debug JavaScriptCore builds
Use describe blocks for grouping related tests
Always use await using or using to ensure proper resource cleanup in tests for APIs like Bun.listen, Bun.connect, Bun.spawn, Bun.serve, etc
Always check exit codes and test error scenarios in error tests
Use describe.each() for parameterized tests
Use toMatchSnapshot() for snapshot testing
Use beforeAll(), afterEach(), beforeEach() for setup/teardown in tests
Track resources (servers, clients) in arrays for cleanup in afterEach()

Files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
🧠 Learnings (49)
📚 Learning: 2025-10-16T02:17:35.237Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 23710
File: src/analytics.zig:15-21
Timestamp: 2025-10-16T02:17:35.237Z
Learning: In src/analytics.zig and similar files using bun.EnvVar boolean environment variables: the new EnvVar API for boolean flags (e.g., bun.EnvVar.do_not_track.get(), bun.EnvVar.ci.get()) is designed to parse and return boolean values from environment variables, not just check for their presence. This is an intentional design change from the previous presence-based checks using bun.getenvZ().

Applied to files:

  • src/analytics.zig
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/bundle.test.ts : Organize bundle tests in bundle.test.ts for tests concerning bundling bugs that only occur in DevServer

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/ecosystem.test.ts : Organize ecosystem tests in ecosystem.test.ts for tests involving ensuring certain libraries are correct; prefer testing concrete bugs over testing entire packages

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: Applies to test/**/*.{js,ts,jsx,tsx} : Write tests as JavaScript and TypeScript files using Jest-style APIs (`test`, `describe`, `expect`) and import from `bun:test`

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/esm.test.ts : Organize ESM tests in esm.test.ts for tests about various ESM features in development mode

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:59.706Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/bun.js/bindings/v8/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:59.706Z
Learning: Applies to src/bun.js/bindings/v8/test/v8/v8.test.ts : Add corresponding test cases to test/v8/v8.test.ts using checkSameOutput() function to compare Node.js and Bun output

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/js/bun/**/*.test.{ts,tsx} : For Bun-specific API tests, use the `test/js/bun/` directory (for http, crypto, ffi, shell, etc.)

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/sourcemap.test.ts : Organize source-map tests in sourcemap.test.ts for tests verifying source-maps are correct

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Use `normalizeBunSnapshot` to normalize snapshot output of tests

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:08.612Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:08.612Z
Learning: Applies to test/bake/dev/plugins.test.ts : Organize plugin tests in plugins.test.ts for tests concerning plugins in development mode

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : When spawning Bun processes in tests, use `bunExe` and `bunEnv` from `harness` to ensure the same build of Bun is used and debug logging is silenced

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: Applies to test/cli/**/*.{js,ts,jsx,tsx} : When testing Bun as a CLI, use the `spawn` API from `bun` with the `bunExe()` and `bunEnv` from `harness` to execute Bun commands and validate exit codes, stdout, and stderr

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-10-26T01:32:04.844Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24082
File: test/cli/test/coverage.test.ts:60-112
Timestamp: 2025-10-26T01:32:04.844Z
Learning: In the Bun repository test files (test/cli/test/*.test.ts), when spawning Bun CLI commands with Bun.spawnSync for testing, prefer using stdio: ["inherit", "inherit", "inherit"] to inherit stdio streams rather than piping them.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : When spawning processes in tests, check stdout/stderr expectations BEFORE checking exit code to get more useful error messages on test failure

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-06T00:58:23.965Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24417
File: test/js/bun/spawn/spawn.test.ts:903-918
Timestamp: 2025-11-06T00:58:23.965Z
Learning: In Bun test files, `await using` with spawn() is appropriate for long-running processes that need guaranteed cleanup on scope exit or when explicitly testing disposal behavior. For short-lived processes that exit naturally (e.g., console.log scripts), the pattern `const proc = spawn(...); await proc.exited;` is standard and more common, as evidenced by 24 instances vs 4 `await using` instances in test/js/bun/spawn/spawn.test.ts.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-08T04:06:33.198Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24491
File: test/js/bun/transpiler/declare-global.test.ts:17-17
Timestamp: 2025-11-08T04:06:33.198Z
Learning: In Bun test files, `await using` with Bun.spawn() is the preferred pattern for spawned processes regardless of whether they are short-lived or long-running. Do not suggest replacing `await using proc = Bun.spawn(...)` with `const proc = Bun.spawn(...); await proc.exited;`.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-09-30T22:53:19.887Z
Learnt from: pfgithub
Repo: oven-sh/bun PR: 23117
File: src/bun.js/test/snapshot.zig:265-276
Timestamp: 2025-09-30T22:53:19.887Z
Learning: In Bun's snapshot testing (src/bun.js/test/snapshot.zig), multiple inline snapshots at the same line and column (same call position) must have identical values. However, multiple inline snapshots on the same line at different columns are allowed to have different values. The check is position-specific (line+col), not line-wide.

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Always use `await using` or `using` to ensure proper resource cleanup in tests for APIs like Bun.listen, Bun.connect, Bun.spawn, Bun.serve, etc

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Do not set a timeout on tests. Bun already has timeouts

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Do not write flaky tests. Never wait for time to pass in tests; always wait for the condition to be met instead of using an arbitrary amount of time

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Do not write flaky tests - do not use `setTimeout` in tests, instead `await` the condition to be met as you are testing the CONDITION not the TIME PASSING

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Verify your test fails with `USE_SYSTEM_BUN=1 bun test <file>` and passes with `bun bd test <file>` - your test is NOT VALID if it passes with `USE_SYSTEM_BUN=1`

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/js/node/test/{parallel,sequential}/*.js : For test/js/node/test/{parallel,sequential}/*.js files without a .test extension, use `bun bd <file>` instead of `bun bd test <file>` since these expect exit code 0 and don't use bun's test runner

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Unit tests for specific features are organized by module (e.g., `/test/js/bun/`, `/test/js/node/`)

Applied to files:

  • test/cli/install/migration/yarn-berry.test.ts
📚 Learning: 2025-11-20T19:51:32.288Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 24880
File: packages/bun-vscode/package.json:382-385
Timestamp: 2025-11-20T19:51:32.288Z
Learning: In the Bun repository, dependencies may be explicitly added to package.json files (even when not directly imported in code) to force version upgrades on transitive dependencies, particularly as part of Aikido security scanner remediation to ensure vulnerable transitive dependencies resolve to patched versions.

Applied to files:

  • src/install/lockfile.zig
📚 Learning: 2025-10-16T17:32:03.074Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 23710
File: src/install/PackageManager/PackageManagerOptions.zig:187-193
Timestamp: 2025-10-16T17:32:03.074Z
Learning: In Bun's codebase (particularly in files like src/install/PackageManager/PackageManagerOptions.zig), mixing bun.EnvVar.*.get() and bun.EnvVar.*.platformGet() for environment variable lookups is intentional and safe. The code is protected by compile-time platform checks (Environment.isWindows, etc.), and compilation will fail if the wrong function is used on the wrong platform. This pattern should not be flagged as a consistency issue.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-09-06T03:37:41.154Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 22229
File: src/bundler/LinkerGraph.zig:0-0
Timestamp: 2025-09-06T03:37:41.154Z
Learning: In Bun's codebase, when checking import record source indices in src/bundler/LinkerGraph.zig, prefer using `if (import_index >= self.import_records.len)` bounds checking over `isValid()` checks, as the bounds check is more robust and `isValid()` is a strict subset of this condition.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-10-26T04:50:17.892Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24086
File: src/bun.js/api/server.zig:2534-2535
Timestamp: 2025-10-26T04:50:17.892Z
Learning: In src/bun.js/api/server.zig, u32 is acceptable for route indices and websocket_context_index fields, as the practical limit of 4 billion contexts will never be reached.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-11-24T18:36:08.558Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-11-24T18:36:08.558Z
Learning: Applies to **/*.zig : Expose generated bindings in Zig structs using `pub const js = JSC.Codegen.JS<ClassName>` with trait conversion methods: `toJS`, `fromJS`, and `fromJSDirect`

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-08-30T09:09:18.384Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 22231
File: src/bundler/bundle_v2.zig:48-48
Timestamp: 2025-08-30T09:09:18.384Z
Learning: In Zig, when a module exports a top-level struct, import("./Module.zig") directly returns that struct type and can be used as a type alias without needing to access a field within the module. This is a common pattern in the Bun codebase.

Applied to files:

  • src/install/resolution.zig
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `tempDir()` from harness to create temporary directories with files for multi-file tests instead of creating files manually

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : For multi-file tests, prefer using `tempDir` from `harness` and `Bun.spawn` over other temporary directory creation methods

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : Use `tempDir` from `harness` to create temporary directories, do not use `tmpdirSync` or `fs.mkdtempSync`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to **/*.test.{ts,tsx} : For single-file tests, prefer using `-e` flag over `tempDir`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/js/node/**/*.test.{ts,tsx} : For Node.js compatibility tests, use the `test/js/node/` directory

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Prefer async/await over callbacks in tests

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Always check exit codes and test error scenarios in error tests

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `beforeAll()`, `afterEach()`, `beforeEach()` for setup/teardown in tests

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-09-03T01:30:58.001Z
Learnt from: markovejnovic
Repo: oven-sh/bun PR: 21728
File: test/js/valkey/valkey.test.ts:264-271
Timestamp: 2025-09-03T01:30:58.001Z
Learning: For test/js/valkey/valkey.test.ts PUB/SUB tests, avoid arbitrary sleeps and async-forEach. Instead, resolve a Promise from the subscriber callback when the expected number of messages is observed and await it with a bounded timeout (e.g., withTimeout + Promise.withResolvers) to account for Redis server→subscriber propagation.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Prefer concurrent tests over sequential tests using `test.concurrent` or `describe.concurrent` when multiple tests spawn processes or write files, unless it's very difficult to make them concurrent

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Track resources (servers, clients) in arrays for cleanup in `afterEach()`

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/bundler/**/*.test.{ts,tsx} : For bundler and transpiler tests, use the `test/bundler/` directory and the `itBundled` helper

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Write JS builtins for Bun's Node.js compatibility and APIs, and run `bun bd` after changes

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `-e` flag for single-file tests when spawning Bun processes

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-20T01:27:21.509Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 0
File: :0-0
Timestamp: 2025-11-20T01:27:21.509Z
Learning: In Bun's documentation, curl-based install commands should use `bun.com/install`, while Windows PowerShell irm (Invoke-RestMethod) commands should use `bun.sh/install` due to a bug with .com on Windows.

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:36:33.069Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T18:36:33.069Z
Learning: Applies to test/napi/**/*.test.{ts,tsx} : For N-API compatibility tests, use the `test/napi/` directory

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : When callbacks must be used and it's just a single callback, use `Promise.withResolvers` to create a promise that can be resolved or rejected from a callback

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
📚 Learning: 2025-11-24T18:35:50.422Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-11-24T18:35:50.422Z
Learning: When fixing a Node.js compatibility bug, first verify the expected behavior works in Node.js before testing against Bun's canary version

Applied to files:

  • test/cli/install/migration/yarn-lock-migration.test.ts
🧬 Code graph analysis (2)
test/cli/install/migration/yarn-berry.test.ts (1)
test/harness.ts (2)
  • tempDir (277-284)
  • bunExe (102-105)
test/cli/install/migration/yarn-lock-migration.test.ts (1)
test/harness.ts (2)
  • tempDir (277-284)
  • bunExe (102-105)
🔇 Additional comments (11)
src/analytics.zig (1)

89-91: New yarn_berry_migration counter is correctly wired into analytics.

Placing this immediately after yarn_migration keeps the feature set coherent, and the existing meta-based formatter/packing logic will automatically pick it up, so no extra wiring is needed.

src/install/pnpm.zig (1)

825-829: Updated pnpm migration metadata fetch aligns with new MigrationType API.

Switching to fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration(manager, .pnpm) matches the new enum-based API and keeps pnpm on the non-Yarn-specific path. Other migration callsites should now consistently pass .yarn_classic / .yarn_berry as appropriate.

src/install/lockfile.zig (1)

117-121: Extended migrated enum and config-version logic correctly incorporate Yarn Berry.

Adding .yarn_berry to ok.migrated and wiring it into chooseConfigVersion as .v0 keeps behavior consistent with npm/yarn classic while still distinguishing pnpm (which gets .v1). The saveFormat logic will continue to force text or binary formats appropriately for all migrated lockfiles.

Also applies to: 195-213

test/cli/install/migration/yarn-berry.test.ts (8)

1-6: LGTM!

Imports are correct and follow the coding guidelines - using bun:test for test APIs and harness for bunExe, bunEnv, and tempDir.


55-163: Tests follow correct patterns.

Both tests properly use using/await using for resource cleanup and capture process output. The same optional improvement for stderr assertions before exitCode applies here as noted above.


165-330: LGTM!

These tests correctly cover bin definitions, workspace protocol, and different Yarn Berry lockfile format versions (v4, v6). The workspace test properly creates the nested package structure after the temp directory setup.


332-580: Comprehensive test with good verification pattern.

This test demonstrates excellent coverage by:

  1. Testing the migration itself
  2. Verifying the migrated lockfile works with --frozen-lockfile
  3. Asserting stderr doesn't contain error indicators (lines 577-579)

Consider adding similar stderr assertions after the migration phase (around line 557) for consistency.


582-848: LGTM! Important test for version conflict resolution.

This test validates that Bun correctly preserves multiple versions of the same package (React 16, 17, 18) during migration - a critical edge case for monorepos with mixed dependency versions. The explicit version assertions (lines 826-828) and frozen-lockfile verification are valuable.


960-1042: LGTM!

Good coverage of npm alias syntax (npm:lodash@^4.17.0). The assertions correctly verify both the alias names are preserved and the underlying packages are resolved.


1044-1087: LGTM!

This test correctly validates that custom/private registry URLs (via __archiveUrl in Berry format) are preserved during migration - essential for enterprise environments with private package registries.


1089-1152: LGTM!

This test cleanly demonstrates multiple resolution handling with a minimal example - direct dependency on is-number@^7.0.0 and transitive dependency via is-odd requiring is-number@^6.0.0. The assertions correctly verify both versions are preserved.

Comment thread src/install/resolution.zig Resolved
Comment on lines +45 to +52
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

expect(exitCode).toBe(0);

const lockContents = await Bun.file(join(String(dir), "bun.lock")).text();
expect(lockContents).toContain("fsevents");
expect(lockContents).toContain("@esbuild/darwin-arm64");
expect(lockContents).toMatchSnapshot();

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.

🧹 Nitpick | 🔵 Trivial

Consider asserting stderr before exitCode for better diagnostics.

Per coding guidelines, checking stdout/stderr expectations before exit code provides more useful error messages on test failure. The stdout and stderr variables are captured but not used. Consider adding assertions like:

     const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

+    expect(stderr).not.toContain("error");
     expect(exitCode).toBe(0);

This pattern is already applied in some later tests (lines 577-578, 846-847) but not consistently throughout.

🤖 Prompt for AI Agents
In test/cli/install/migration/yarn-berry.test.ts around lines 45 to 52, the test
captures stdout and stderr but asserts exitCode first and never asserts on
stderr/stdout; change the order to assert stderr (and optionally stdout) before
asserting exitCode so test failures show useful logs, and add an assertion using
the captured variables (e.g., expect(stderr).toBe("") or
expect(stderr).toContain(...), and/or expect(stdout).toContain(...)) so the
output is validated and available for diagnostics prior to checking exitCode.

@djamaile

Copy link
Copy Markdown

@RiskyMH will you push this through?

@RiskyMH

RiskyMH commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

@RiskyMH will you push this through?

Sadly I no longer work at bun, but I would like it to be merged!

@djamaile

Copy link
Copy Markdown

@RiskyMH do you know whats left to get this in? Seems complete to me, but I might be missing some context. If needed, I can take it over and push it through.

@RiskyMH

RiskyMH commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the offer, it seems complete to me personally. I'd say it just needs a review from dylan or someone on the team and then to merge!

(I'm fine to do edits, but prob cannot anymore because branch permissions lol)

@djamaile

Copy link
Copy Markdown

@dylan-conway @Jarred-Sumner are you up for a review? Would be great to have this in, so I can migrate a internal mono-repo to use bun instead 😄

@robobun

robobun commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Closing as stale: this PR predates the Rust rewrite. Every src/ file it modifies has since been removed or relocated on main (Zig sources deleted; src/bun.js/ reorganized into src/jsc/), so it can no longer merge.

If the underlying change is still wanted, it will need to be redone against the current Rust/C++ tree. Apologies for the churn, and thank you for the contribution.

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

Labels

None yet

Projects

None yet

3 participants