Compare commits

...

3 Commits

Author SHA1 Message Date
claude[bot]
12cf1fd074 bun run prettier 2025-06-22 07:43:28 +00:00
claude[bot]
65f4586217 test: add event loop task processing tests for Yes command
Add comprehensive tests using TestBuilder pattern to verify YesTask
handling in the event loop. These tests would have caught the crash
that was fixed in the event loop's tickQueueWithCount function.

Tests cover:
- Basic YesTask event loop processing with head
- Custom string output in event loop
- YesTask cancellation/timeout scenarios
- High volume output for event loop stability

Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-22 07:39:53 +00:00
Cursor Agent
024ffd6847 Fix YesTask handling in event loop task processing 2025-06-21 07:25:46 +00:00
2 changed files with 37 additions and 2 deletions

View File

@@ -489,8 +489,11 @@ pub fn tickQueueWithCount(this: *EventLoop, virtual_machine: *VirtualMachine) u3
var any: *FlushPendingFileSinkTask = task.get(FlushPendingFileSinkTask).?;
any.runFromJSThread();
},
.@"shell.builtin.yes.YesTask", .@"bun.js.api.Timer.ImmediateObject", .@"bun.js.api.Timer.TimeoutObject" => {
@field(Task.Tag, @typeName(shell.Interpreter.Builtin.Yes.YesTask)) => {
var yes_task: *shell.Interpreter.Builtin.Yes.YesTask = task.get(shell.Interpreter.Builtin.Yes.YesTask).?;
yes_task.runFromMainThread();
},
.@"bun.js.api.Timer.ImmediateObject", .@"bun.js.api.Timer.TimeoutObject" => {
bun.Output.panic("Unexpected tag: {s}", .{@tagName(task.tag())});
},
_ => {

View File

@@ -1,5 +1,8 @@
import { $ } from "bun";
import { describe, expect, test } from "bun:test";
import { createTestBuilder } from "../test_builder";
const TestBuilder = createTestBuilder(import.meta.path);
$.throws(false);
@@ -22,3 +25,32 @@ describe("yes", async () => {
expect(buffer.toString()).toEqual("ab\nab\nab\nab\nab\nab");
});
});
describe("yes - event loop task processing", async () => {
TestBuilder.command`yes | head -3`
.exitCode(0)
.stdout("y\ny\ny\n")
.stderr("")
.runAsTest("basic yes with head - tests YesTask event loop processing");
TestBuilder.command`yes hello | head -2`
.exitCode(0)
.stdout("hello\nhello\n")
.stderr("")
.runAsTest("custom string yes with head - tests YesTask with custom output");
TestBuilder.command`timeout 0.1 yes`
.exitCode(124)
.stdout(stdout => {
expect(stdout.length).toBeGreaterThan(0);
expect(stdout.split("\n").filter(line => line === "y").length).toBeGreaterThan(0);
})
.stderr("")
.runAsTest("yes with timeout - tests YesTask cancellation in event loop");
TestBuilder.command`yes test | head -1000 | wc -l`
.exitCode(0)
.stdout("1000\n")
.stderr("")
.runAsTest("high volume yes output - tests YesTask event loop stability");
});