Skip to content

fix(windows): resolve mkdir(".") ENOENT error - #25207

Closed
robobun wants to merge 2 commits into
mainfrom
claude/fix-windows-mkdir-dot-21901
Closed

robobun wants to merge 2 commits into
mainfrom
claude/fix-windows-mkdir-dot-21901

Conversation

@robobun

@robobun robobun commented Nov 29, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes mkdir(".", {recursive: true}) returning ENOENT on Windows
  • Path normalization now returns "." instead of empty string
  • Relative paths are resolved to absolute before passing to Windows kernel APIs

Test plan

  • Added regression test in test/regression/issue/21901.test.ts
  • Test verifies fs.mkdirSync(".", {recursive: true}) succeeds
  • Test verifies fs.promises.mkdir(".", {recursive: true}) succeeds
  • Test verifies Promise.allSettled with mkdir(".") works
  • Test passes with debug build, fails with system bun

Fixes #21901

🤖 Generated with Claude Code

On Windows, mkdir(".", {recursive: true}) was failing with ENOENT
because path normalization was returning an empty string for ".",
which Windows APIs reject.

Two fixes:
1. In resolve_path.zig: Return "." instead of empty string when
   normalizing "." path
2. In types.zig: Resolve relative paths to absolute before passing
   to Windows kernel APIs

Fixes #21901

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

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

robobun commented Nov 29, 2025 •

Copy link
Copy Markdown
Collaborator Author
Updated 7:08 PM PT - Nov 28th, 2025

❌ @autofix-ci[bot], your commit 9b641cf has 10 failures in Build #32621 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 25207

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

bun-25207 --bun

@coderabbitai

coderabbitai Bot commented Nov 29, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR fixes mkdir behavior with the recursive option on Windows by ensuring paths are properly resolved to absolute form and normalized to non-empty values. It includes changes to path normalization logic and a regression test for concurrent mkdir operations.

Changes

Cohort / File(s) Summary
Path normalization and resolution
src/bun.js/node/types.zig, src/resolver/resolve_path.zig
Ensures normalized Windows paths are absolute and non-empty: osPathKernel32 now resolves relative normalized paths against the current working directory, while NormalizeStringGenericTZ replaces empty normalized paths with "."
Regression test
test/regression/issue/21901.test.ts
Adds test validating mkdir with recursive option on Windows, covering synchronous, asynchronous, and concurrent Promise.allSettled operations on the current directory

Possibly related PRs

Suggested reviewers

  • pfgithub
  • nektro

Pre-merge checks

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main fix: resolving mkdir(".") ENOENT error on Windows.
Description check ✅ Passed The description covers the main summary, test plan with checkmarks, and issue reference, though it deviates from the template structure slightly.
Linked Issues check ✅ Passed All code changes directly address issue #21901: path normalization returns "." instead of empty string, relative paths resolved to absolute, and comprehensive regression tests verify mkdir(".", {recursive: true}) succeeds on Windows.
Out of Scope Changes check ✅ Passed All three file changes are directly scoped to fixing mkdir(".") on Windows: path normalization logic, kernel32 path resolution, and regression tests—no unrelated changes present.

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

📜 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 5bdb8ec and 9b641cf.

📒 Files selected for processing (3)
  • src/bun.js/node/types.zig (1 hunks)
  • src/resolver/resolve_path.zig (1 hunks)
  • test/regression/issue/21901.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/resolver/resolve_path.zig
  • src/bun.js/node/types.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/resolver/resolve_path.zig
  • src/bun.js/node/types.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/resolver/resolve_path.zig
  • src/bun.js/node/types.zig
src/**/*.{ts,zig,cpp}

📄 CodeRabbit inference engine (CLAUDE.md)

Always use absolute paths in file operations

Files:

  • src/resolver/resolve_path.zig
  • src/bun.js/node/types.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/resolver/resolve_path.zig
  • src/bun.js/node/types.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/regression/issue/21901.test.ts
test/regression/issue/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

When a test is for a specific numbered GitHub Issue, place it in test/regression/issue/${issueNumber}.test.ts with a REAL issue number, not a placeholder

Files:

  • test/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.test.ts
test/regression/issue/**/*.test.ts

📄 CodeRabbit inference engine (test/CLAUDE.md)

Regression tests for specific issues go in /test/regression/issue/${issueNumber}.test.ts. Do not put tests without issue numbers in the regression directory

Files:

  • test/regression/issue/21901.test.ts
🧠 Learnings (17)
📚 Learning: 2025-10-08T13:56:00.875Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 23373
File: src/bun.js/api/BunObject.zig:2514-2521
Timestamp: 2025-10-08T13:56:00.875Z
Learning: For Bun codebase: prefer using `bun.path` utilities (e.g., `bun.path.joinAbsStringBuf`, `bun.path.join`) over `std.fs.path` functions for path operations.

Applied to files:

  • src/bun.js/node/types.zig
📚 Learning: 2025-09-12T18:16:50.754Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 22606
File: src/glob/GlobWalker.zig:449-452
Timestamp: 2025-09-12T18:16:50.754Z
Learning: For Bun codebase: prefer using `std.fs.path.sep` over manual platform separator detection, and use `bun.strings.lastIndexOfChar` instead of `std.mem.lastIndexOfScalar` for string operations.

Applied to files:

  • src/bun.js/node/types.zig
📚 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 src/**/*.{ts,zig,cpp} : Always use absolute paths in file operations

Applied to files:

  • src/bun.js/node/types.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/regression/issue/**/*.test.ts : Regression tests for specific issues go in `/test/regression/issue/${issueNumber}.test.ts`. Do not put tests without issue numbers in the regression directory

Applied to files:

  • test/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/**/*.test.{ts,tsx} : When a test is for a specific numbered GitHub Issue, place it in `test/regression/issue/${issueNumber}.test.ts` with a REAL issue number, not a placeholder

Applied to files:

  • test/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.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/regression/issue/21901.test.ts
🧬 Code graph analysis (1)
test/regression/issue/21901.test.ts (1)
test/harness.ts (1)
  • bunExe (102-105)
🔇 Additional comments (2)
test/regression/issue/21901.test.ts (2)

69-109: Good test coverage of the concurrent mkdir scenario.

This test block correctly reproduces the original issue scenario where multiple concurrent mkdir('.') calls with Promise.allSettled would fail. The test validates that all promises are fulfilled, which is exactly what was broken before the fix.

The error handling in the spawned script (lines 85-92) is well done, providing clear failure messages if any promise is rejected.


1-110: Verify test behavior with system vs debug build.

According to the coding guidelines and PR description, you should verify:

  1. The test fails when run with: USE_SYSTEM_BUN=1 bun test test/regression/issue/21901.test.ts
  2. The test passes when run with: bun bd test test/regression/issue/21901.test.ts

The PR description mentions this has been verified ("Test passes with debug build, fails with system bun"), but please confirm this is the case before merging.

Based on coding guidelines: "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"

Comment thread src/bun.js/node/types.zig
Comment on lines +637 to +642
// If the normalized path is still relative (like "."), resolve it to an absolute path
if (!std.fs.path.isAbsoluteWindows(normal)) {
const cwd_path = std.posix.getcwd(buf) catch @panic("Error getting cwd");
const resolved = path_handler.joinAbsStringBuf(cwd_path, b, &.{normal}, .windows);
return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), resolved);
}

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.

⚠️ Potential issue | 🔴 Critical

Critical: Replace panic with graceful error handling for getcwd failure.

Using @panic("Error getting cwd") on line 639 will crash the entire Bun process if getcwd() fails. This can occur in legitimate scenarios such as:

  • The current directory has been deleted
  • Permission issues
  • Filesystem errors

While the fix for resolving relative paths is correct, the error handling needs improvement. Consider one of these approaches:

  1. Return a fallback path: If cwd retrieval fails, return the normalized path as-is (it may fail later in the kernel call, but with a proper error code).
  2. Propagate the error: Change the function signature to return an error type if feasible.
  3. Use a default fallback: Fall back to a known safe path like the executable's directory.

Example fix:

-        const cwd_path = std.posix.getcwd(buf) catch @panic("Error getting cwd");
+        const cwd_path = std.posix.getcwd(buf) catch {
+            // Fallback: return the normalized path as-is and let Windows APIs handle it
+            return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), normal);
+        };

Additionally, check if similar panic calls elsewhere in this function (like line 576, 583, 632) should be addressed consistently.

🤖 Prompt for AI Agents
In src/bun.js/node/types.zig around lines 637 to 642, replace the direct
@panic("Error getting cwd") on getcwd failure with graceful error handling: call
std.posix.getcwd(buf) and if it fails, either (a) return the normalized path
as-is, (b) propagate an error by changing the function signature to return an
error union so callers can handle it, or (c) use a safe fallback path (e.g.,
executable directory); ensure the chosen approach logs or surfaces the original
OS error code/message rather than aborting, and apply the same non-panic pattern
to other @panic calls in this function (lines ~576, 583, 632) for consistent
error handling.

Comment on lines +934 to +940
// If normalization resulted in an empty path, return "."
// This happens when the input is just "." or consists only of dots/separators that get normalized away
if (buf_i == buf_start and path_.len > 0) {
buf[buf_i] = '.';
buf_i += 1;
}

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

LGTM! Essential fix to prevent empty normalized paths.

This guard correctly addresses the root cause where path normalization could produce an empty string from inputs like "." or paths consisting only of separators and dots. The condition buf_i == buf_start and path_.len > 0 properly detects when normalization produced no output despite having input, and returning "." is the correct POSIX convention for the current directory.

This change works in conjunction with the types.zig modifications to fully resolve the mkdir(".") issue on Windows.

🤖 Prompt for AI Agents
In src/resolver/resolve_path.zig around lines 934 to 940, normalization can
produce an empty output for inputs like "." or strings made only of
dots/separators; add a guard that if buf_i == buf_start and path_.len > 0 then
write a single '.' into buf and increment buf_i so the function returns "."
instead of an empty string, ensuring POSIX current-directory behavior (this
change prevents mkdir(".") issues on Windows).

Comment on lines +5 to +9
test("mkdir('.') should succeed with recursive option on Windows", async () => {
if (!isWindows) {
test.skip();
return;
}

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 using test.skipIf for cleaner platform skipping.

The current skip logic is correct, but you can simplify it using test.skipIf:

-test("mkdir('.') should succeed with recursive option on Windows", async () => {
-  if (!isWindows) {
-    test.skip();
-    return;
-  }
+test.skipIf(!isWindows)("mkdir('.') should succeed with recursive option on Windows", async () => {

This is more idiomatic and doesn't require the early return.

📝 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
test("mkdir('.') should succeed with recursive option on Windows", async () => {
if (!isWindows) {
test.skip();
return;
}
test.skipIf(!isWindows)("mkdir('.') should succeed with recursive option on Windows", async () => {
🤖 Prompt for AI Agents
In test/regression/issue/21901.test.ts around lines 5 to 9, replace the current
manual platform skip (if (!isWindows) { test.skip(); return; }) with the more
idiomatic test.skipIf(!isWindows) at the start of the test so the test is
skipped on non-Windows without an early return; remove the if block and keep the
rest of the test body unchanged.

Comment on lines +11 to +37
// Test mkdirSync with recursive option
{
await using proc = Bun.spawn({
cmd: [
bunExe(),
"-e",
`
const fs = require('fs');
try {
fs.mkdirSync('.', { recursive: true });
console.log('mkdirSync success');
} catch (err) {
console.error('mkdirSync error:', err.message);
process.exit(1);
}
`,
],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});

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

expect(stdout.trim()).toBe("mkdirSync success");
expect(exitCode).toBe(0);
}

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 validating or logging stderr for better debugging.

The test captures stderr but never checks or logs it. Consider adding stderr validation or logging it when the test fails:

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

+expect(stderr.trim()).toBe(""); // or log stderr on failure
 expect(stdout.trim()).toBe("mkdirSync success");
 expect(exitCode).toBe(0);

This would make debugging easier if the test fails unexpectedly.

Apply this suggestion to all three test blocks (lines 11-37, 39-67, and 69-109).

🤖 Prompt for AI Agents
In test/regression/issue/21901.test.ts around lines 11-37 (and similarly apply
to blocks at 39-67 and 69-109), the test captures stderr but never asserts or
surfaces it on failure; update each test block to check stderr and surface its
contents when the test does not pass by asserting stderr is empty or by
appending stderr to the failure message—specifically, read proc.stderr.text() as
already done, and include a conditional that fails the test or logs the stderr
output when exitCode !== 0 or when stdout/unexpected values occur so that test
failures show the captured stderr for easier debugging.

@github-actions

Copy link
Copy Markdown
Contributor

Closing this PR because it has been inactive for more than 90 days.

@github-actions github-actions Bot closed this Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An error occurs when Promise.all is used with mkdir(".", {recursive: true}) from node:fs/promises.

1 participant