Skip to content

test: convert tempDirWithFiles callers to using tempDir - #36194

Merged
Jarred-Sumner merged 2 commits into
mainfrom
claude/tempdir-using-refactor
Jul 28, 2026
Merged

Jarred-Sumner merged 2 commits into
mainfrom
claude/tempdir-using-refactor

Conversation

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

What does this PR do?

Mechanically converts ~700 const dir = tempDirWithFiles(...) declarations that sit directly inside test/it callbacks to await using dir = tempDir(...) (async callbacks) or using dir = tempDir(...) (sync), so temp directories are removed when the test scope exits instead of leaking under os.tmpdir().

tempDir() returns a String object (DisposableString), so call sites hitting typeof x === "string" checks are wrapped in String(...):

Sink Behavior with a String object
===, expect().toBe/toEqual/toContain mismatch / matcher error
process.chdir, child_process cwd, cwdScope throws
new $.Shell().cwd() throws
glob.scan(dir) silently parsed as an options bag

Deliberately left alone: module/describe/beforeAll-scope dirs, helper functions, let/reassignments, sync callbacks that return a promise or take done, and a loop in bun-install-proxy.test.ts that awaits after the loop body.

How did you verify your code works?

USE_SYSTEM_BUN=1 bun test --parallel --bail over all 141 changed files against 1.4.0-canary.1+d54984555 (matches base commit). One residual: a --parallel worker crash (preload not found) on bun-listen-connect-args.test.ts that doesn't reproduce alone, in ordered pairs, or in small parallel batches — watching CI for it.

Mechanically converts ~700 `const dir = tempDirWithFiles(...)` declarations
that live directly inside test/it callbacks to `await using dir =
tempDir(...)` (async callbacks) or `using dir = tempDir(...)` (sync ones),
so the temp directory is removed when the test scope exits instead of
leaking under os.tmpdir().

tempDir() returns a String object (DisposableString), so call sites that
hit typeof-string checks are wrapped in String(): ===, expect().toBe /
toEqual / toContain, process.chdir, child_process cwd, cwdScope,
`new $.Shell().cwd()`, and glob.scan(cwd).

Left alone: module/describe/beforeAll-scope directories, helper
functions, `let`/reassignments, sync callbacks that return a promise or
take a done callback, and one loop that awaits its work after the loop
body.

No-Verification-Needed: test-only refactor
@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. In our tests, make tempDirWithFiles a disposable string #21031 - Also converts tempDirWithFiles to use the disposable string pattern (using), targeting the same migration in test/harness.ts and test files

🤖 Generated with Claude Code

A hand-applied replaceAll turned `$$.cwd` into `$.cwd` (the `$$`
escape in replacement strings), and writeFile takes a different
validation path when handed a String object as the path.

No-Verification-Needed: test-only fixup
Comment thread test/js/bun/test/done-async.test.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 39 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d4bdc1c6-404e-4bea-a53d-1b7f92a4d140

📥 Commits

Reviewing files that changed from the base of the PR and between b065dd0 and aa29589.

📒 Files selected for processing (3)
  • test/js/bun/test/done-async.test.ts
  • test/js/bun/test/expect-assertions.test.ts
  • test/js/node/fs/fs-promises-writeFile-async-iterator.test.ts

Walkthrough

Changes

Temporary fixture lifecycle migration

Layer / File(s) Summary
Scoped temporary-directory setup
test/bake/*, test/bundler/*, test/cli/*, test/js/*, test/napi/*, test/regression/*
Test fixtures replace tempDirWithFiles with tempDir, using using or await using declarations and preserving existing fixture contents and assertions.
Path and process wiring updates
test/cli/install/migration/*, test/cli/run/*, test/js/bun/glob/*, test/js/bun/test/*, test/js/node/fs/*, test/js/sql/*
Commands, filesystem reads, current-directory changes, and shell calls now use the new temporary-directory handles, including explicit string conversion where required.
Additional test resource management
test/js/bun/http/bun-serve-html-manifest.test.ts, test/js/bun/typescript/type-export.test.ts
Manual cleanup and selected process handling use scoped disposal; compile tests also limit concurrent compile operations.

Possibly related PRs

  • oven-sh/bun#36040: Adds lazy iteration assertions in the same glob scan test file migrated here.
  • oven-sh/bun#36127: Adds INIT_CWD coverage in the same process environment test suite updated here.

Suggested reviewers: robobun

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: migrating test callers from tempDirWithFiles to disposable tempDir usage.
Description check ✅ Passed The description matches the template and includes both the PR purpose and verification details with concrete commands.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@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 (6)
test/js/bun/io/bun-write-leak.test.ts (1)

11-17: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use String(dir) before strict path/process calls.

tempDir() returns a boxed String, and path.join / Bun.spawn({ cwd }) reject boxed strings here.

  • test/js/bun/io/bun-write-leak.test.ts#L11-L17: create const dirPath = String(dir) and use it for both path.join calls.
  • test/js/bun/namespace-prototype-pollution.test.ts#L5-L34: pass cwd: String(dir).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/js/bun/io/bun-write-leak.test.ts` around lines 11 - 17, Convert the
boxed tempDir result to a primitive with a dirPath variable in
test/js/bun/io/bun-write-leak.test.ts lines 11-17, and use it for both path.join
calls. In test/js/bun/namespace-prototype-pollution.test.ts lines 5-34, pass
String(dir) as the cwd value for Bun.spawn.
test/js/bun/resolve/jsonc.test.ts (1)

5-12: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Coerce dir to a primitive before path.join()

tempDir() returns a DisposableString, and path.join() rejects that wrapper object. Use String(dir) (or dir.toString()) in all four calls so these tests reach their assertions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/js/bun/resolve/jsonc.test.ts` around lines 5 - 12, Update all four
path.join calls in the test setup to convert the DisposableString returned by
tempDir to a primitive using String(dir) or dir.toString() before joining, while
preserving the existing path segments and assertions.
test/js/bun/resolve/resolver-permission-denied-ancestor.test.ts (1)

13-21: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Convert the temp dir to a primitive before path.join
tempDir() returns a String object, and path.join() only accepts primitive strings. Use String(dir) before the join() calls in both fixtures.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/js/bun/resolve/resolver-permission-denied-ancestor.test.ts` around lines
13 - 21, Convert the tempDir() result to a primitive string before every
path.join call in both resolver-permission fixtures and the ls test. Update
test/js/bun/resolve/resolver-permission-denied-ancestor.test.ts at lines 13-21
and 39-42, and test/js/bun/shell/commands/ls.test.ts at lines 159-161; make no
other changes.
test/js/node/process/process-on.test.ts (1)

19-28: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Convert tempDir() to String(dir) before strict path/process boundaries.

tempDir() returns a DisposableString wrapper, and these calls pass it directly into path.join(...) or cwd, which reject wrapper objects. Normalize once per fixture and reuse the primitive path.

  • test/js/node/process/process-on.test.ts:19-28, :52-63
  • test/js/node/tls/test-node-extra-ca-certs.test.ts:19-22, :42-44, :73-76, :99
  • test/js/third_party/body-parser/express-bun-build-compile.test.ts:11-13
  • test/js/web/fetch/blob-write.test.ts:33-40
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/js/node/process/process-on.test.ts` around lines 19 - 28, Normalize each
tempDir() result with String() before passing it to path.join or process
cwd/options, then reuse the primitive path within the fixture setup. Apply this
in test/js/node/process/process-on.test.ts at 19-28 and 52-63;
test/js/node/tls/test-node-extra-ca-certs.test.ts at 19-22, 42-44, 73-76, and
99; test/js/third_party/body-parser/express-bun-build-compile.test.ts at 11-13;
and test/js/web/fetch/blob-write.test.ts at 33-40, preserving the existing
fixture behavior.
test/cli/install/bun-run-bunfig.test.ts (2)

21-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer synchronous using for tempDir().

These callbacks only perform synchronous fixture setup and process execution. Replace await using cwd with using cwd; DisposableString supports synchronous disposal, avoiding unnecessary async teardown.

Based on learnings, prefer plain using for tempDir() in Bun tests.

Also applies to: 107-118, 145-156, 184-196, 221-232

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/install/bun-run-bunfig.test.ts` around lines 21 - 32, Replace await
using with synchronous using for each tempDir() fixture declaration in the
affected test cases, including the declarations near the referenced ranges. Keep
the existing fixture setup and test execution unchanged, relying on
DisposableString’s synchronous disposal.

Source: Learnings


184-205: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Coerce cwd before calling pathJoin. tempDir() returns a DisposableString object, and node:path.join() rejects String objects. Both pathJoin(cwd, "./subdir") and pathJoin(cwd, "./my-home") can throw before Bun spawns; use String(cwd) in both places.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/install/bun-run-bunfig.test.ts` around lines 184 - 205, Update the
`Bun.spawnSync` setup in the `where-node` test and the corresponding `./my-home`
setup to pass `String(cwd)` into `pathJoin`, ensuring the `DisposableString`
returned by `tempDir()` is coerced before path construction.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/cli/inspect/inspect.test.ts`:
- Line 466: Update the test setup around tempdir to convert the String object
returned by tempDir() into a primitive string before path operations. Pass
String(tempdir) to randomSocketPathFn(...) and join(...), preserving the
existing temporary-directory behavior.

In `@test/cli/run/tsconfig-override.test.ts`:
- Line 7: Convert each tempDir() result to a primitive string at string-only
boundaries by wrapping the directory value with String(...). Apply this to
path.join inputs, cwd values, and bunRunAsScript arguments across
test/cli/run/tsconfig-override.test.ts lines 7, 73, 114, 161, 210, and 266;
test/cli/run/run-quote.test.ts lines 12-14 and 18;
test/cli/run/sql-preconnect.test.ts lines 25 and 61; and
test/cli/run/workspaces.test.ts lines 5, 45, and 78. Use the existing dir values
and do not change tempDir lifecycle handling.

In `@test/js/bun/io/bun-write-leak.test.ts`:
- Line 11: Replace await using with using for the tempDir() declarations in
test/js/bun/io/bun-write-leak.test.ts lines 11-11,
test/js/bun/namespace-prototype-pollution.test.ts lines 5-5, and every migrated
tempDir() declaration in test/js/bun/patch/patch.test.ts lines 83-88, preserving
synchronous disposal via Symbol.dispose.

In `@test/js/bun/test/done-async.test.ts`:
- Around line 18-21: Use the local Shell instance consistently by changing
$.cwd(String(dir)) to $$.cwd(String(dir)) in test/js/bun/test/done-async.test.ts
lines 18-21 and test/js/bun/test/expect-assertions.test.ts lines 18-21; no other
changes are needed.

---

Outside diff comments:
In `@test/cli/install/bun-run-bunfig.test.ts`:
- Around line 21-32: Replace await using with synchronous using for each
tempDir() fixture declaration in the affected test cases, including the
declarations near the referenced ranges. Keep the existing fixture setup and
test execution unchanged, relying on DisposableString’s synchronous disposal.
- Around line 184-205: Update the `Bun.spawnSync` setup in the `where-node` test
and the corresponding `./my-home` setup to pass `String(cwd)` into `pathJoin`,
ensuring the `DisposableString` returned by `tempDir()` is coerced before path
construction.

In `@test/js/bun/io/bun-write-leak.test.ts`:
- Around line 11-17: Convert the boxed tempDir result to a primitive with a
dirPath variable in test/js/bun/io/bun-write-leak.test.ts lines 11-17, and use
it for both path.join calls. In
test/js/bun/namespace-prototype-pollution.test.ts lines 5-34, pass String(dir)
as the cwd value for Bun.spawn.

In `@test/js/bun/resolve/jsonc.test.ts`:
- Around line 5-12: Update all four path.join calls in the test setup to convert
the DisposableString returned by tempDir to a primitive using String(dir) or
dir.toString() before joining, while preserving the existing path segments and
assertions.

In `@test/js/bun/resolve/resolver-permission-denied-ancestor.test.ts`:
- Around line 13-21: Convert the tempDir() result to a primitive string before
every path.join call in both resolver-permission fixtures and the ls test.
Update test/js/bun/resolve/resolver-permission-denied-ancestor.test.ts at lines
13-21 and 39-42, and test/js/bun/shell/commands/ls.test.ts at lines 159-161;
make no other changes.

In `@test/js/node/process/process-on.test.ts`:
- Around line 19-28: Normalize each tempDir() result with String() before
passing it to path.join or process cwd/options, then reuse the primitive path
within the fixture setup. Apply this in test/js/node/process/process-on.test.ts
at 19-28 and 52-63; test/js/node/tls/test-node-extra-ca-certs.test.ts at 19-22,
42-44, 73-76, and 99;
test/js/third_party/body-parser/express-bun-build-compile.test.ts at 11-13; and
test/js/web/fetch/blob-write.test.ts at 33-40, preserving the existing fixture
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b6deae46-c5eb-4728-b406-1721809d383a

📥 Commits

Reviewing files that changed from the base of the PR and between 0341a4e and b065dd0.

📒 Files selected for processing (141)
  • test/bake/dev/import-meta-inline-negative.test.ts
  • test/bake/dev/response-to-bake-response.test.ts
  • test/bake/framework-router.test.ts
  • test/bundler/bun-build-compile-wasm.test.ts
  • test/bundler/bundler_compile.test.ts
  • test/bundler/bundler_defer.test.ts
  • test/bundler/html-import-manifest.test.ts
  • test/cli/bunfig-test-options.test.ts
  • test/cli/console-depth.test.ts
  • test/cli/hot/watch-many-dirs.test.ts
  • test/cli/hot/watch.test.ts
  • test/cli/init/init.test.ts
  • test/cli/inspect/inspect.test.ts
  • test/cli/install/bun-audit.test.ts
  • test/cli/install/bun-install-patch.test.ts
  • test/cli/install/bun-install-registry.test.ts
  • test/cli/install/bun-install.test.ts
  • test/cli/install/bun-pack.test.ts
  • test/cli/install/bun-patch.test.ts
  • test/cli/install/bun-pm-pkg.test.ts
  • test/cli/install/bun-pm-scan.test.ts
  • test/cli/install/bun-pm-version.test.ts
  • test/cli/install/bun-pm-why.test.ts
  • test/cli/install/bun-run-bunfig.test.ts
  • test/cli/install/bun-security-scanner-workspaces.test.ts
  • test/cli/install/bun-update-security-edge-cases.test.ts
  • test/cli/install/bun-update-security-scan-all.test.ts
  • test/cli/install/bun-update-security-simple.test.ts
  • test/cli/install/migration/migrate.test.ts
  • test/cli/install/migration/pnpm-comprehensive.test.ts
  • test/cli/install/migration/pnpm-lock-migration.test.ts
  • test/cli/install/migration/pnpm-migration-complete.test.ts
  • test/cli/install/migration/yarn-lock-migration.test.ts
  • test/cli/install/test-dev-peer-dependency-priority.test.ts
  • test/cli/run/as-node.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/filter-workspace.test.ts
  • test/cli/run/require-and-import-trailing.test.ts
  • test/cli/run/require-cache.test.ts
  • test/cli/run/run-process-env.test.ts
  • test/cli/run/run-quote.test.ts
  • test/cli/run/sql-preconnect.test.ts
  • test/cli/run/tsconfig-override.test.ts
  • test/cli/run/workspaces.test.ts
  • test/cli/test/bun-test.test.ts
  • test/cli/test/claudecode-flag.test.ts
  • test/cli/test/coverage.test.ts
  • test/cli/test/path-ignore-patterns.test.ts
  • test/cli/test/test-randomize.test.ts
  • test/cli/update_interactive_formatting.test.ts
  • test/cli/update_interactive_snapshots.test.ts
  • test/cli/user-agent.test.ts
  • test/internal/int_from_float.test.ts
  • test/js/bun/bundler/yaml-bundler.test.js
  • test/js/bun/fetch/node-use-system-ca.test.ts
  • test/js/bun/glob/proto.test.ts
  • test/js/bun/glob/scan.test.ts
  • test/js/bun/http/bun-listen-connect-args.test.ts
  • test/js/bun/http/bun-serve-html-405.test.ts
  • test/js/bun/http/bun-serve-html-entry.test.ts
  • test/js/bun/http/bun-serve-html-manifest.test.ts
  • test/js/bun/http/bun-serve-html.test.ts
  • test/js/bun/http/bun-serve-propagate-errors.test.ts
  • test/js/bun/http/bun-server.test.ts
  • test/js/bun/import-attributes/import-attributes.test.ts
  • test/js/bun/ini/ini.test.ts
  • test/js/bun/io/bun-write-leak.test.ts
  • test/js/bun/namespace-prototype-pollution.test.ts
  • test/js/bun/patch/patch.test.ts
  • test/js/bun/resolve/bun-lock.test.ts
  • test/js/bun/resolve/jsonc.test.ts
  • test/js/bun/resolve/resolve.test.ts
  • test/js/bun/resolve/resolver-permission-denied-ancestor.test.ts
  • test/js/bun/s3/s3.leak.test.ts
  • test/js/bun/s3/s3.test.ts
  • test/js/bun/shell/bunshell.test.ts
  • test/js/bun/shell/commands/ls.test.ts
  • test/js/bun/shell/commands/rm.test.ts
  • test/js/bun/shell/lazy.test.ts
  • test/js/bun/shell/leak.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/bun/test/describe.test.ts
  • test/js/bun/test/done-async.test.ts
  • test/js/bun/test/expect-assertions.test.ts
  • test/js/bun/test/expect-extend-preload.test.ts
  • test/js/bun/test/pretty-format-overflow.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/js/bun/typescript/type-export.test.ts
  • test/js/bun/util/bun-file.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/junit-reporter/junit.test.js
  • test/js/node/fs/cp.test.ts
  • test/js/node/fs/fs-birthtime-linux.test.ts
  • test/js/node/fs/fs-promises-writeFile-async-iterator.test.ts
  • test/js/node/fs/fs-stat-seccomp-linux.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/node/fs/glob.test.ts
  • test/js/node/fs/promises.test.js
  • test/js/node/module/require-extensions.test.ts
  • test/js/node/process/process-on.test.ts
  • test/js/node/tls/test-node-extra-ca-certs.test.ts
  • test/js/node/watch/fs.watchFile.test.ts
  • test/js/sql/sql.test.ts
  • test/js/sql/sqlite-sql.test.ts
  • test/js/third_party/body-parser/express-bun-build-compile.test.ts
  • test/js/web/fetch/blob-write.test.ts
  • test/napi/napi.test.ts
  • test/regression/issue/026039.test.ts
  • test/regression/issue/07740.test.ts
  • test/regression/issue/09340.test.ts
  • test/regression/issue/09555.test.ts
  • test/regression/issue/09559.test.ts
  • test/regression/issue/10887.test.ts
  • test/regression/issue/11664.test.ts
  • test/regression/issue/11806.test.ts
  • test/regression/issue/14945-lifecycle-script-crash.test.ts
  • test/regression/issue/14976/14976.test.ts
  • test/regression/issue/17327.test.ts
  • test/regression/issue/20321.test.ts
  • test/regression/issue/21680.test.ts
  • test/regression/issue/21907.test.ts
  • test/regression/issue/22317.test.ts
  • test/regression/issue/23649.test.ts
  • test/regression/issue/24502/bun-pm-ls-all-invalid-package-id.test.ts
  • test/regression/issue/25716.test.ts
  • test/regression/issue/25794.test.ts
  • test/regression/issue/26207.test.ts
  • test/regression/issue/26647.test.ts
  • test/regression/issue/29787.test.ts
  • test/regression/issue/3657.test.ts
  • test/regression/issue/5228.test.js
  • test/regression/issue/comma-operator-this-binding.test.ts
  • test/regression/issue/ctrl-c.test.ts
  • test/regression/issue/cyclic-imports-async-bundler.test.js
  • test/regression/issue/hashbang-still-works.test.ts
  • test/regression/issue/malformed-integrity-base64.test.ts
  • test/regression/issue/patch-bounds-check.test.ts
  • test/regression/issue/test_env_loader_threading.test.ts
  • test/regression/issue/update-interactive-formatting.test.ts
  • test/regression/issue/utf16-encoding-crash.test.ts

let session: InspectorSession;

const tempdir = tempDirWithFiles("junit-reporter", {
await using tempdir = tempDir("junit-reporter", {

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C3 '\btempdir\b' test/cli/inspect/inspect.test.ts
rg -n -C3 'class DisposableString|function tempDir' test/harness.ts

Repository: oven-sh/bun

Length of output: 2790


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '460,530p' test/cli/inspect/inspect.test.ts

python3 - <<'PY'
from pathlib import Path
import re

text = Path("test/cli/inspect/inspect.test.ts").read_text()
for i, line in enumerate(text.splitlines(), 1):
    if "tempdir" in line:
        print(f"{i}:{line}")
PY

node - <<'JS'
const path = require('path');

const tempdirObj = new String('.tmp-demo');
console.log('typeof tempdirObj:', typeof tempdirObj);
console.log('String(tempdirObj):', String(tempdirObj));
console.log('path.join(tempdirObj, "a.test.js"):', path.join(tempdirObj, 'a.test.js'));
console.log('replaceAll on String object result:', tempdirObj.replaceAll('\\', '/'));
console.log('template concat:', `unix://${tempdirObj}`);
JS

Repository: oven-sh/bun

Length of output: 3576


🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline test/cli/inspect/inspect.test.ts --view expanded

Repository: oven-sh/bun

Length of output: 623


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,40p' test/cli/inspect/inspect.test.ts

Repository: oven-sh/bun

Length of output: 1363


Coerce tempdir to a primitive string before the path joins. tempDir() returns a String object; pass String(tempdir) into randomSocketPathFn(...) and join(...).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/inspect/inspect.test.ts` at line 466, Update the test setup around
tempdir to convert the String object returned by tempDir() into a primitive
string before path operations. Pass String(tempdir) to randomSocketPathFn(...)
and join(...), preserving the existing temporary-directory behavior.

describe("bun run --tsconfig-override", () => {
test("should use custom tsconfig for path resolution", async () => {
const dir = tempDirWithFiles("run-tsconfig-override", {
await using dir = tempDir("run-tsconfig-override", {

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate tempDir definition and the affected tests.
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
  'function tempDir|const tempDir|export .*tempDir|class DisposableString|Symbol\.dispose|Symbol\.asyncDispose' \
  test harness packages src . 2>/dev/null || true

echo '--- FILE LIST ---'
git ls-files 'test/cli/run/*.test.ts' 'test/**/*harness*' 'test/**/harness*' 'test/**/*tempDir*' | sed -n '1,200p'

Repository: oven-sh/bun

Length of output: 50367


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the harness implementation and the exact call sites.
for f in \
  test/cli/run/tsconfig-override.test.ts \
  test/cli/run/run-quote.test.ts \
  test/cli/run/sql-preconnect.test.ts \
  test/cli/run/workspaces.test.ts
do
  echo "--- $f ---"
  sed -n '1,340p' "$f"
done

echo "--- tempDir definition candidates ---"
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
  'tempDir\s*\(' test harness . 2>/dev/null | sed -n '1,200p'

Repository: oven-sh/bun

Length of output: 35731


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find bunRunAsScript and tempDir implementations.
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
  'bunRunAsScript|function tempDir|const tempDir|export .*tempDir|class .*Disposable' \
  test . 2>/dev/null | sed -n '1,220p'

Repository: oven-sh/bun

Length of output: 6793


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '420,540p' test/harness.ts

Repository: oven-sh/bun

Length of output: 3574


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check the exact return type and helper behavior around tempDir/bunRunAsScript.
sed -n '420,540p' test/harness.ts

Repository: oven-sh/bun

Length of output: 3574


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '500,560p' test/harness.ts

Repository: oven-sh/bun

Length of output: 1744


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- test/harness.ts around tempDir and bunRunAsScript ---'
sed -n '424,540p' test/harness.ts

echo '--- node path.join with String objects ---'
node - <<'JS'
const path = require('node:path');
for (const value of [new String('/tmp/x'), Object(new String('/tmp/y'))]) {
  try {
    console.log('join', String(value), '=>', path.join(value, 'file.txt'));
  } catch (e) {
    console.log('join-error', String(value), e.name, e.code, e.message);
  }
}
JS

Repository: oven-sh/bun

Length of output: 3895


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
  'function join|join\s*=\s*function|validateString|invalid arg type|ERR_INVALID_ARG_TYPE|PathLike' \
  src/js/node test/harness.ts | sed -n '1,220p'

Repository: oven-sh/bun

Length of output: 20181


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- tempDir and bunRunAsScript ---'
sed -n '424,540p' test/harness.ts

Repository: oven-sh/bun

Length of output: 3581


Convert tempDir() values to plain strings at string-only boundaries.
tempDir() returns a disposable String object, and path.join(...) / cwd validation reject that shape at runtime. Wrap these call sites in String(...), including bunRunAsScript(dir, ...) and every cwd: dir use.

  • test/cli/run/tsconfig-override.test.ts#L7-L7, L73-L73, L114-L114, L161-L161, L210-L210, L266-L266
  • test/cli/run/run-quote.test.ts#L12-L14, L18-L18
  • test/cli/run/sql-preconnect.test.ts#L25-L25, L61-L61
  • test/cli/run/workspaces.test.ts#L5-L5, L45-L45, L78-L78
📍 Affects 4 files
  • test/cli/run/tsconfig-override.test.ts#L7-L7 (this comment)
  • test/cli/run/run-quote.test.ts#L12-L14
  • test/cli/run/run-quote.test.ts#L18-L18
  • test/cli/run/sql-preconnect.test.ts#L25-L25
  • test/cli/run/sql-preconnect.test.ts#L61-L61
  • test/cli/run/tsconfig-override.test.ts#L73-L73
  • test/cli/run/tsconfig-override.test.ts#L114-L114
  • test/cli/run/tsconfig-override.test.ts#L161-L161
  • test/cli/run/tsconfig-override.test.ts#L210-L210
  • test/cli/run/tsconfig-override.test.ts#L266-L266
  • test/cli/run/workspaces.test.ts#L5-L5
  • test/cli/run/workspaces.test.ts#L45-L45
  • test/cli/run/workspaces.test.ts#L78-L78
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/run/tsconfig-override.test.ts` at line 7, Convert each tempDir()
result to a primitive string at string-only boundaries by wrapping the directory
value with String(...). Apply this to path.join inputs, cwd values, and
bunRunAsScript arguments across test/cli/run/tsconfig-override.test.ts lines 7,
73, 114, 161, 210, and 266; test/cli/run/run-quote.test.ts lines 12-14 and 18;
test/cli/run/sql-preconnect.test.ts lines 25 and 61; and
test/cli/run/workspaces.test.ts lines 5, 45, and 78. Use the existing dir values
and do not change tempDir lifecycle handling.

"Bun.write should not leak the output data",
async () => {
const dir = tempDirWithFiles("bun-write-leak-fixture", {
await using dir = tempDir("bun-write-leak-fixture", {

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.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use synchronous disposal for tempDir().

tempDir() implements Symbol.dispose, so plain using avoids unnecessary asynchronous cleanup.

  • test/js/bun/io/bun-write-leak.test.ts#L11-L11: replace await using with using.
  • test/js/bun/namespace-prototype-pollution.test.ts#L5-L5: replace await using with using.
  • test/js/bun/patch/patch.test.ts#L83-L88: apply the same change to every migrated tempDir() declaration.
📍 Affects 3 files
  • test/js/bun/io/bun-write-leak.test.ts#L11-L11 (this comment)
  • test/js/bun/namespace-prototype-pollution.test.ts#L5-L5
  • test/js/bun/patch/patch.test.ts#L83-L88
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/js/bun/io/bun-write-leak.test.ts` at line 11, Replace await using with
using for the tempDir() declarations in test/js/bun/io/bun-write-leak.test.ts
lines 11-11, test/js/bun/namespace-prototype-pollution.test.ts lines 5-5, and
every migrated tempDir() declaration in test/js/bun/patch/patch.test.ts lines
83-88, preserving synchronous disposal via Symbol.dispose.

Source: Learnings

Comment thread test/js/bun/test/done-async.test.ts
@Jarred-Sumner
Jarred-Sumner merged commit d042b30 into main Jul 28, 2026
49 of 50 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the claude/tempdir-using-refactor branch July 28, 2026 08:54
robobun added a commit that referenced this pull request Aug 13, 2026
The readdir promise completion moved into AsyncReaddirRecursiveTask::then
on main, so the WithFileTypesBuffer arm now lives there; DirentBuffer
follows the narrowed visibility of Dirent; the new cp tests use the
tempDir helper that cp.test.ts switched to in #36194.
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.

1 participant