-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(test): no panic on over-long positional arguments in bun test #38896
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, tempDir } from "harness"; | ||
|
|
||
| describe("over-long positional argument", () => { | ||
| // https://github.com/oven-sh/bun/issues/35728 — a single positional argument | ||
| // of >= 997 bytes used to panic ("range end index ... out of range for slice | ||
| // of length 1023") because the scanner wrote it into a fixed 1024-byte path | ||
| // buffer without a bounds check. | ||
| test("bun test with a 997+ byte positional exits cleanly, no panic", () => { | ||
| using dir = tempDir("overlong-arg", { | ||
| "a.test.ts": ` | ||
| import { test, expect } from "bun:test"; | ||
| test("passes", () => { | ||
| expect(1).toBe(1); | ||
| }); | ||
| `, | ||
| }); | ||
|
|
||
| const longPath = "./x" + "a".repeat(986) + ".test.ts"; | ||
| expect(longPath.length).toBe(997); | ||
|
|
||
| const result = Bun.spawnSync([bunExe(), "test", longPath], { | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdio: [null, "pipe", "pipe"], | ||
| }); | ||
|
|
||
| const stderr = result.stderr.toString("utf-8"); | ||
| expect(stderr).not.toContain("panic"); | ||
| expect(stderr).not.toContain("out of range for slice"); | ||
| // Over-long positional behaves like a non-existent path: reports no matches. | ||
| expect(stderr).toContain("no matches"); | ||
| expect(result.exitCode).not.toBe(0); | ||
|
Comment on lines
+28
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Assert normal completion and the no-match result in both cases. The 997-byte case allows a signal exit because
As per coding guidelines, every assertion must assert the strongest meaningful invariant. 📍 Affects 1 file
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| }); | ||
|
|
||
| test("bun test with a 1200-byte positional also exits cleanly", () => { | ||
| using dir = tempDir("overlong-arg-2", { | ||
| "a.test.ts": ` | ||
| import { test, expect } from "bun:test"; | ||
| test("passes", () => { | ||
| expect(1).toBe(1); | ||
| }); | ||
| `, | ||
| }); | ||
|
|
||
| const longPath = "./x" + "a".repeat(1189) + ".test.ts"; | ||
| expect(longPath.length).toBe(1200); | ||
|
|
||
| const result = Bun.spawnSync([bunExe(), "test", longPath], { | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdio: [null, "pipe", "pipe"], | ||
| }); | ||
|
|
||
| const stderr = result.stderr.toString("utf-8"); | ||
| expect(stderr).not.toContain("panic"); | ||
| expect(stderr).not.toContain("out of range for slice"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff
Run the independent subprocess cases concurrently.
The two cases use separate directories and do not share state. Convert the synchronous subprocess calls to an async spawn pattern, drain outputs with process completion, and use
describe.concurrentortest.concurrent.As per coding guidelines, use
test.concurrentfor independent subprocess tests.🤖 Prompt for AI Agents
Source: Coding guidelines