diff --git a/CLAUDE.md b/CLAUDE.md index e0c0bbb18f..c2d03fb20e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,8 +59,8 @@ test("my feature", async () => { }); const [stdout, stderr, exitCode] = await Promise.all([ - new Response(proc.stdout).text(), - new Response(proc.stderr).text(), + proc.stdout.text(), + proc.stderr.text(), proc.exited, ]); @@ -69,6 +69,8 @@ test("my feature", async () => { }); ``` +- Always use `port: 0`. Do not hardcode ports. Do not use your own random port number function. + ## Code Architecture ### Language Structure @@ -219,16 +221,16 @@ bun ci ## Important Development Notes 1. **Never use `bun test` or `bun ` directly** - always use `bun bd test` or `bun bd `. `bun bd` compiles & runs the debug build. -2. **Use `await using`** for proper resource cleanup with Bun APIs (Bun.spawn, Bun.serve, Bun.connect, etc.) -3. **Follow existing code style** - check neighboring files for patterns -4. **Create tests in the right folder** in `test/` and the test must end in `.test.ts` or `.test.tsx` -5. **Use absolute paths** - Always use absolute paths in file operations -6. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools -7. **Memory management** - In Zig code, be careful with allocators and use defer for cleanup -8. **Cross-platform** - Run `bun run zig:check-all` to compile the Zig code on all platforms when making platform-specific changes -9. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_=1` to enable specific scopes -10. **Be humble & honest** - NEVER overstate what you got done or what actually works in commits, PRs or in messages to the user. -11. **Transpiled source** - Find transpiled files in `/tmp/bun-debug-src/` for debugging +2. **All changes must be tested** - if you're not testing your changes, you're not done. +3. **Get your tests to pass**. If you didn't run the tests, your code does not work. +4. **Follow existing code style** - check neighboring files for patterns +5. **Create tests in the right folder** in `test/` and the test must end in `.test.ts` or `.test.tsx` +6. **Use absolute paths** - Always use absolute paths in file operations +7. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools +8. **Memory management** - In Zig code, be careful with allocators and use defer for cleanup +9. **Cross-platform** - Run `bun run zig:check-all` to compile the Zig code on all platforms when making platform-specific changes +10. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_=1` to enable specific scopes +11. **Be humble & honest** - NEVER overstate what you got done or what actually works in commits, PRs or in messages to the user. ## Key APIs and Features diff --git a/src/crash_handler.zig b/src/crash_handler.zig index 3755b676a2..18fcd80546 100644 --- a/src/crash_handler.zig +++ b/src/crash_handler.zig @@ -903,6 +903,12 @@ extern "c" fn gnu_get_libc_version() ?[*:0]const u8; export var Bun__reported_memory_size: usize = 0; pub fn printMetadata(writer: anytype) !void { + if (comptime bun.Environment.isDebug) { + if (Output.isAIAgent()) { + return; + } + } + if (Output.enable_ansi_colors) { try writer.writeAll(Output.prettyFmt("", true)); } @@ -1629,10 +1635,12 @@ pub fn dumpStackTrace(trace: std.builtin.StackTrace, limits: WriteStackTraceLimi return; }, .linux => { - // Linux doesnt seem to be able to decode it's own debug info. - // TODO(@paperclover): see if zig 0.14 fixes this - WTF__DumpStackTrace(trace.instruction_addresses.ptr, trace.instruction_addresses.len); - return; + if (!bun.Environment.isDebug) { + // Linux doesnt seem to be able to decode it's own debug info. + // TODO(@paperclover): see if zig 0.14 fixes this + WTF__DumpStackTrace(trace.instruction_addresses.ptr, trace.instruction_addresses.len); + return; + } }, else => { // Assume debug symbol tooling is reliable. @@ -1682,25 +1690,31 @@ pub fn dumpStackTrace(trace: std.builtin.StackTrace, limits: WriteStackTraceLimi argv.append(std.fmt.allocPrint(alloc, "0x{X}", .{line.address}) catch return) catch return; } - // std.process is used here because bun.spawnSync with libuv does not work within - // the crash handler. - const proc = std.process.Child.run(.{ - .allocator = alloc, - .argv = argv.items, - }) catch { + var child = std.process.Child.init(argv.items, alloc); + child.stdin_behavior = .Inherit; + child.stdout_behavior = .Inherit; + child.stderr_behavior = .Inherit; + + child.expand_arg0 = .expand; + child.progress_node = std.Progress.Node.none; + + child.spawn() catch { stderr.print("Failed to invoke command: {s}\n", .{bun.fmt.fmtSlice(argv.items, " ")}) catch return; if (bun.Environment.isWindows) { stderr.print("(You can compile pdb-addr2line from https://github.com/oven-sh/bun.report, cd pdb-addr2line && cargo build)\n", .{}) catch return; } return; }; - if (proc.term != .Exited or proc.term.Exited != 0) { + + const result = child.spawnAndWait() catch { stderr.print("Failed to invoke command: {s}\n", .{bun.fmt.fmtSlice(argv.items, " ")}) catch return; + return; + }; + + if (result.term != .Exited or result.term.Exited != 0) { + stderr.print("Failed to invoke command: {s}\n", .{bun.fmt.fmtSlice(argv.items, " ")}) catch return; + return; } - defer alloc.free(proc.stderr); - defer alloc.free(proc.stdout); - stderr.writeAll(proc.stdout) catch return; - stderr.writeAll(proc.stderr) catch return; } pub fn dumpCurrentStackTrace(first_address: ?usize, limits: WriteStackTraceLimits) void { diff --git a/test/CLAUDE.md b/test/CLAUDE.md index e528fbaaba..f0f112ed62 100644 --- a/test/CLAUDE.md +++ b/test/CLAUDE.md @@ -81,6 +81,14 @@ await promise; If it's several callbacks, it's okay to use callbacks. We aren't a stickler for this. +### No timeouts + +**CRITICAL**: Do not set a timeout on tests. Bun already has timeouts. + +### Use port 0 to get a random port + +Most APIs in Bun support `port: 0` to get a random port. Never hardcode ports. Avoid using your own random port number function. + ### Creating temporary files Use `tempDirWithFiles` to create a temporary directory with files.