-
Notifications
You must be signed in to change notification settings - Fork 5k
paths: terminate recursive mkdir walk when a confirmed parent still yields ENOENT #36162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
13
commits into
main
Choose a base branch
from
farm/ea7dbce8/fix-makepath-spin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3fcd2bc
paths: terminate make_path_with when a confirmed parent still yields …
robobun 2f6928d
[autofix.ci] apply automated fixes
autofix-ci[bot] dcf8604
trim comments; drop per-test timeout
robobun 662df16
fold make_path_with termination note into existing doc paragraph
robobun 0b03b0d
drop added doc sentence on make_path_with
robobun fbb5034
paths: update MakePathStep::NotFound doc to match new contract
robobun 5376651
install: name the cache directory when it cannot be created
robobun d2a2740
install: only hard-fail on explicitly configured cache dirs; warn+fal…
robobun ddfc4a2
collapse is_explicit doc to one line
robobun 38ee46c
drop dead cache_directory_path=b"" write in implicit-fallback arm
robobun a23676c
test: cover bunfig install.cache.dir spelling for is_explicit
robobun 5456aa1
gate implicit cache-dir fallback warn on log_level != Silent
robobun 2c2c34b
doc: list --cache-dir among is_explicit sources
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, isWindows, tempDir } from "harness"; | ||
| import { existsSync, symlinkSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| describe.skipIf(isWindows)("install cache directory inside a dangling symlink", () => { | ||
| function setup() { | ||
| const dir = tempDir("cache-dir-dangling", { | ||
| "proj/package.json": JSON.stringify({ | ||
| name: "x", | ||
| version: "1.0.0", | ||
| dependencies: { "any-pkg": "1.0.0" }, | ||
| }), | ||
| }); | ||
| const root = String(dir); | ||
| symlinkSync(join(root, "does-not-exist"), join(root, "dangling")); | ||
| return { dir, root, dangling: join(root, "dangling"), cwd: join(root, "proj") }; | ||
| } | ||
|
|
||
| function explicitEnv(cacheDir: string) { | ||
| return { | ||
| ...bunEnv, | ||
| BUN_INSTALL_CACHE_DIR: cacheDir, | ||
| BUN_CONFIG_REGISTRY: "http://127.0.0.1:1/", | ||
| }; | ||
| } | ||
|
|
||
| test.concurrent("bun install exits with a cache-directory error instead of spinning in mkdirat", async () => { | ||
| const ctx = setup(); | ||
| using _dir = ctx.dir; | ||
| const cacheDir = join(ctx.dangling, "cache"); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "install"], | ||
| cwd: ctx.cwd, | ||
| env: explicitEnv(cacheDir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| timeout: 15_000, | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect({ signalCode: proc.signalCode, stdout, stderr }).toMatchObject({ | ||
| signalCode: null, | ||
| stderr: expect.stringContaining(`error: cache directory "${cacheDir}" is not creatable: ENOENT`), | ||
| }); | ||
| expect(stderr).not.toContain("ConnectionRefused"); | ||
| expect(exitCode).not.toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("bunfig install.cache.dir exits with a cache-directory error instead of spinning", async () => { | ||
| using dir = tempDir("cache-dir-dangling-bunfig", { | ||
| "proj/package.json": JSON.stringify({ name: "x", version: "1.0.0", dependencies: { "any-pkg": "1.0.0" } }), | ||
| }); | ||
| const root = String(dir); | ||
| symlinkSync(join(root, "does-not-exist"), join(root, "dangling")); | ||
| const cacheDir = join(root, "dangling", "cache"); | ||
| await Bun.write( | ||
| join(root, "proj", "bunfig.toml"), | ||
| `[install]\nregistry = "http://127.0.0.1:1/"\n[install.cache]\ndir = ${JSON.stringify(cacheDir)}\n`, | ||
| ); | ||
| const env = { ...bunEnv }; | ||
| delete env.BUN_INSTALL_CACHE_DIR; | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "install"], | ||
| cwd: join(root, "proj"), | ||
| env, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| timeout: 15_000, | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect({ signalCode: proc.signalCode, stdout, stderr }).toMatchObject({ | ||
| signalCode: null, | ||
| stderr: expect.stringContaining(`error: cache directory "${cacheDir}" is not creatable: ENOENT`), | ||
| }); | ||
| expect(stderr).not.toContain("ConnectionRefused"); | ||
| expect(exitCode).not.toBe(0); | ||
| }); | ||
|
robobun marked this conversation as resolved.
|
||
|
|
||
| test.concurrent("runtime auto-install exits with a cache-directory error instead of spinning", async () => { | ||
| const ctx = setup(); | ||
| using _dir = ctx.dir; | ||
| const cacheDir = join(ctx.dangling, "cache"); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "-e", `require("any-pkg")`], | ||
| cwd: ctx.cwd, | ||
| env: explicitEnv(cacheDir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| timeout: 15_000, | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect({ signalCode: proc.signalCode, stdout, stderr }).toMatchObject({ | ||
| signalCode: null, | ||
| stderr: expect.stringContaining(`error: cache directory "${cacheDir}" is not creatable: ENOENT`), | ||
| }); | ||
| expect(exitCode).not.toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("implicit $HOME-derived cache dir warns and falls back to node_modules/.cache", async () => { | ||
| const ctx = setup(); | ||
| using _dir = ctx.dir; | ||
| const env = { ...bunEnv, BUN_CONFIG_REGISTRY: "http://127.0.0.1:1/" }; | ||
| delete env.BUN_INSTALL_CACHE_DIR; | ||
| delete env.BUN_INSTALL; | ||
| delete env.XDG_CACHE_HOME; | ||
| env.HOME = ctx.dangling; | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "install"], | ||
| cwd: ctx.cwd, | ||
| env, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| timeout: 15_000, | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect({ signalCode: proc.signalCode, stdout, stderr }).toMatchObject({ | ||
| signalCode: null, | ||
| stderr: expect.stringContaining(`is not creatable: ENOENT, falling back to node_modules/.cache`), | ||
| }); | ||
| expect(stderr).toContain("warn: cache directory"); | ||
| expect(stderr).toContain("ConnectionRefused"); | ||
| expect(existsSync(join(ctx.cwd, "node_modules", ".cache"))).toBe(true); | ||
| expect(exitCode).not.toBe(0); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.