Skip to content

fix(install): create bun.lock instead of bun.lockb if npm/yarn/pnpm migration fails - #24494

Merged
dylan-conway merged 3 commits into
mainfrom
dylan/text-lockfile-if-migration-fails
Nov 8, 2025
Merged

dylan-conway merged 3 commits into
mainfrom
dylan/text-lockfile-if-migration-fails

Conversation

@dylan-conway

Copy link
Copy Markdown
Member

What does this PR do?

How did you verify your code works?

@robobun

robobun commented Nov 8, 2025 •

Copy link
Copy Markdown
Collaborator
Updated 10:52 PM PT - Nov 7th, 2025

❌ @autofix-ci[bot], your commit f46bc10 has 1 failures in Build #31289 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 24494

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

bun-24494 --bun

@coderabbitai

coderabbitai Bot commented Nov 8, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Changed three lockfile migration error-report paths to use text format instead of binary; added tests that verify bun.lock is written and bun.lockb is not when those migrations fail.

Changes

Cohort / File(s) Summary
Lockfile migration error format updates
src/install/migration.zig
Switched .format from .binary to .text for three in-memory migration error paths: package-lock.json, yarn.lock, and pnpm-lock.yaml.
Migration failure tests
test/cli/install/migration/migrate.test.ts
Added tests using tempDirWithFiles to create projects with failing migrations for each lockfile type; asserts bun.lock is created and bun.lockb is not, and exit code is 0.

Possibly related PRs

Suggested reviewers

  • nektro
  • dylan-conway

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is empty, containing only placeholder section headings with no actual content about what the PR does or verification methods. Fill in the 'What does this PR do?' section with explanation of the lockfile format change and add verification details in 'How did you verify your code works?' section.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: creating bun.lock instead of bun.lockb when npm/yarn/pnpm migration fails.

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

📜 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 c7fd474 and f46bc10.

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

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

Place all tests under the test/ directory

Files:

  • test/cli/install/migration/migrate.test.ts
test/cli/**/*.{js,ts}

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

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

Files:

  • test/cli/install/migration/migrate.test.ts
test/**/*.{js,ts}

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

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

Files:

  • test/cli/install/migration/migrate.test.ts
🧠 Learnings (16)
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/js/bun/**/*.{js,ts} : Place Bun API tests under test/js/bun/, separated by category (e.g., test/js/bun/glob/)

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/{dev/*.test.ts,dev-and-prod.ts} : Do not use node:fs APIs in tests; mutate files via dev.write, dev.patch, and dev.delete

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/{dev/*.test.ts,dev-and-prod.ts} : Import testing utilities (devTest, prodTest, devAndProductionTest, Dev, Client) from test/bake/bake-harness.ts

Applied to files:

  • test/cli/install/migration/migrate.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/migrate.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/cli/**/*.{js,ts} : When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/cli/**/*.{js,ts} : Place CLI command tests (e.g., bun install, bun init) under test/cli/

Applied to files:

  • test/cli/install/migration/migrate.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/migrate.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/bundle.test.ts : bundle.test.ts should contain DevServer-specific bundling tests

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Use shared utilities from test/harness.ts where applicable

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/bake-harness.ts : Provide and maintain shared test utilities: devTest, prodTest, devAndProductionTest, Dev, Client, and helpers in the harness

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/*.test.ts : Write Dev Server and HMR tests in test/bake/dev/*.test.ts using devTest from the shared harness

Applied to files:

  • test/cli/install/migration/migrate.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/migrate.test.ts
📚 Learning: 2025-10-08T13:48:02.430Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 23373
File: test/js/bun/tarball/extract.test.ts:107-111
Timestamp: 2025-10-08T13:48:02.430Z
Learning: In Bun's test runner, use `expect(async () => { await ... }).toThrow()` to assert async rejections. Unlike Jest/Vitest, Bun does not require `await expect(...).rejects.toThrow()` - the async function wrapper with `.toThrow()` is the correct pattern for async error assertions in Bun tests.

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: For Node.js compatibility bugs, validate expected behavior in Node.js first, then confirm failure on Bun canary

Applied to files:

  • test/cli/install/migration/migrate.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/js/node/test/** : Vendored Node.js tests under test/js/node/test/ are exceptions and do not follow Bun’s test style

Applied to files:

  • test/cli/install/migration/migrate.test.ts
🧬 Code graph analysis (1)
test/cli/install/migration/migrate.test.ts (1)
test/harness.ts (2)
  • tempDirWithFiles (259-266)
  • bunExe (102-105)
🔇 Additional comments (2)
test/cli/install/migration/migrate.test.ts (2)

3-3: LGTM!

The addition of tempDirWithFiles is appropriate for the new test and follows the guideline to use shared utilities from test/harness.ts.


161-166: The review comment is incorrect. fs.promises.exists() is a valid Bun API explicitly documented and tested in the type definitions at test/integration/bun-types/fixture/fs.ts:10, where it's typed to return Promise<boolean>. The code under review uses this API correctly. No changes are needed.

Likely an incorrect or invalid review comment.

Comment on lines +135 to +168
const lockfiles = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"];

for (const lockfile of lockfiles) {
test(`should create bun.lock if ${lockfile} migration fails`, async () => {
const testDir = tempDirWithFiles("migration-failure", {
"package.json": JSON.stringify({
name: "pkg",
dependencies: {
"dep-1": "file:dep-1",
},
}),
[lockfile]: "{}",
"dep-1/package.json": JSON.stringify({
name: "dep-1",
}),
});

const { exited } = Bun.spawn({
cmd: [bunExe(), "install"],
cwd: testDir,
stderr: "ignore",
stdout: "ignore",
});

expect(await exited).toBe(0);

expect(
await Promise.all([
fs.promises.exists(join(testDir, "bun.lock")),
fs.promises.exists(join(testDir, "bun.lockb")),
]),
).toEqual([true, false]);
});
}

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.

🛠️ Refactor suggestion | 🟠 Major

Prefer test.each for data-driven tests.

The coding guidelines recommend using test.each to reduce boilerplate when testing multiple similar scenarios. As per coding guidelines.

Apply this diff to refactor the test using test.each:

-const lockfiles = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
-
-for (const lockfile of lockfiles) {
-  test(`should create bun.lock if ${lockfile} migration fails`, async () => {
+test.each(["package-lock.json", "yarn.lock", "pnpm-lock.yaml"])(
+  "should create bun.lock if %s migration fails",
+  async (lockfile) => {
     const testDir = tempDirWithFiles("migration-failure", {
       "package.json": JSON.stringify({
         name: "pkg",
         dependencies: {
           "dep-1": "file:dep-1",
         },
       }),
       [lockfile]: "{}",
       "dep-1/package.json": JSON.stringify({
         name: "dep-1",
       }),
     });

     const { exited } = Bun.spawn({
       cmd: [bunExe(), "install"],
       cwd: testDir,
       stderr: "ignore",
       stdout: "ignore",
     });

     expect(await exited).toBe(0);

     expect(
       await Promise.all([
         fs.promises.exists(join(testDir, "bun.lock")),
         fs.promises.exists(join(testDir, "bun.lockb")),
       ]),
     ).toEqual([true, false]);
-  });
-}
+  },
+);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const lockfiles = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
for (const lockfile of lockfiles) {
test(`should create bun.lock if ${lockfile} migration fails`, async () => {
const testDir = tempDirWithFiles("migration-failure", {
"package.json": JSON.stringify({
name: "pkg",
dependencies: {
"dep-1": "file:dep-1",
},
}),
[lockfile]: "{}",
"dep-1/package.json": JSON.stringify({
name: "dep-1",
}),
});
const { exited } = Bun.spawn({
cmd: [bunExe(), "install"],
cwd: testDir,
stderr: "ignore",
stdout: "ignore",
});
expect(await exited).toBe(0);
expect(
await Promise.all([
fs.promises.exists(join(testDir, "bun.lock")),
fs.promises.exists(join(testDir, "bun.lockb")),
]),
).toEqual([true, false]);
});
}
test.each(["package-lock.json", "yarn.lock", "pnpm-lock.yaml"])(
"should create bun.lock if %s migration fails",
async (lockfile) => {
const testDir = tempDirWithFiles("migration-failure", {
"package.json": JSON.stringify({
name: "pkg",
dependencies: {
"dep-1": "file:dep-1",
},
}),
[lockfile]: "{}",
"dep-1/package.json": JSON.stringify({
name: "dep-1",
}),
});
const { exited } = Bun.spawn({
cmd: [bunExe(), "install"],
cwd: testDir,
stderr: "ignore",
stdout: "ignore",
});
expect(await exited).toBe(0);
expect(
await Promise.all([
fs.promises.exists(join(testDir, "bun.lock")),
fs.promises.exists(join(testDir, "bun.lockb")),
]),
).toEqual([true, false]);
},
);
🤖 Prompt for AI Agents
In test/cli/install/migration/migrate.test.ts around lines 135 to 168, the test
currently iterates over lockfiles with a for-loop creating nearly identical
tests; refactor to use test.each to make it data-driven. Replace the for-loop
with test.each(lockfiles) or test.each([["package-lock.json"], ["yarn.lock"],
["pnpm-lock.yaml"]]) and define a single test callback that receives the
lockfile name, constructs the tempDirWithFiles fixtures and runs the same
Bun.spawn and assertions; ensure the test name uses the lockfile value (e.g.,
`should create bun.lock if %s migration fails`) so each case is reported
separately.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants