summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 01:14:34 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:40:44 -0300
commit8e3636661fce945176d45bf74da6a60e5e016e55 (patch)
tree8878c8ee4b52e5cd5f83f218b75b14b7f727c448 /src/gui/gui.zig
parent4f06c3ba5f985267ef589289b2b5e60220eeb4bf (diff)
downloadpardes-8e3636661fce945176d45bf74da6a60e5e016e55.tar.gz
pardes-8e3636661fce945176d45bf74da6a60e5e016e55.zip
host_io.Inbox's own tests move from gui.zig to the end of host_io.zig, where the tui's unit tests run them too (they ran on the window's alone): a completion through a full output queue, the two PTY backpressure cases, the EOF reserve, the completions' order and reset, and the LSP query; PtyTests is host_io's, its waitBlocked pub for the gui test that still waits on a blocked reader
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig229
1 files changed, 1 insertions, 228 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 9768f2de..554b127f 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -848,141 +848,6 @@ fn sdlWake(_: ?*anyopaque) void {
const PipeTasks = selection_pipe.Tasks;
const output_capacity = Queue.output_capacity;
-test "GUI completion survives a full output queue" {
- const gpa = std.testing.allocator;
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 7 };
- defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..output_capacity) |_| queue.push(.{ .output = .{
- .pane = 0,
- .gen = 1,
- .bytes = try gpa.dupe(u8, "output"),
- } });
- for (0..PipeTasks.capacity) |id| queue.push(.{ .pipe = .{
- .id = @intCast(id),
- .success = false,
- .outputs = &.{},
- .failure = .{ .stderr = try gpa.dupe(u8, "pipe failure") },
- } });
- queue.push(.{ .lsp = .{ .id = 7, .rows = try gpa.dupe(u8, "completion") } });
- var batch = queue.take();
- defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(output_capacity + PipeTasks.capacity + 1, batch.len);
- for (batch.items[0..output_capacity]) |msg| {
- try std.testing.expect(msg == .output);
- try std.testing.expectEqualStrings("output", msg.output.bytes);
- }
- for (batch.items[output_capacity..][0..PipeTasks.capacity], 0..) |msg, id| {
- try std.testing.expect(msg == .pipe);
- try std.testing.expectEqual(@as(u32, @intCast(id)), msg.pipe.id);
- }
- var found = false;
- for (batch.slice()) |msg| if (msg == .lsp) {
- try std.testing.expectEqual(@as(u32, 7), msg.lsp.id);
- try std.testing.expectEqualStrings("completion", msg.lsp.rows.?);
- found = true;
- };
- try std.testing.expect(found);
- try std.testing.expectEqual(@as(usize, 0), queue.take().len);
-}
-
-const PtyTests = struct {
- fn waitBlocked(queue: *Queue) !void {
- const until = std.Io.Clock.awake.now(std.testing.io).toMilliseconds() + 2_000;
- while (std.Io.Clock.awake.now(std.testing.io).toMilliseconds() < until) {
- queue.lock();
- const waiting = queue.waiting;
- queue.unlock();
- if (waiting != 0) return;
- try std.testing.io.sleep(.fromMilliseconds(1), .awake);
- }
- return error.ReaderDidNotBlock;
- }
-
- fn tail(queue: *Queue, bytes: []u8) void {
- if (queue.pushOutput(0, 1, bytes)) queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
- }
-};
-
-test "GUI PTY backpressure retains byte order and tail before EOF" {
- const gpa = std.testing.allocator;
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
- defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
- const tail = try gpa.dupe(u8, "tail");
- var thread: ?std.Thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| {
- gpa.free(tail);
- return err;
- };
- defer {
- queue.cancelReader(0, 1);
- if (thread) |owned| owned.join();
- }
- try PtyTests.waitBlocked(&queue);
- queue.push(.files_changed);
- queue.push(.files_changed);
- var first = queue.take();
- defer for (first.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(output_capacity + 1, first.len);
- for (first.items[0..output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes);
- try std.testing.expect(first.items[output_capacity] == .files_changed);
- thread.?.join();
- thread = null;
- var last = queue.take();
- defer for (last.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(@as(usize, 2), last.len);
- try std.testing.expectEqualStrings("tail", last.items[0].output.bytes);
- try std.testing.expect(last.items[1] == .eof);
- try std.testing.expectEqual(@as(usize, 0), queue.waiting);
-}
-
-test "GUI PTY backpressure cancellation and close release owned producers" {
- const gpa = std.testing.allocator;
- for ([_]bool{ false, true }) |close| {
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
- defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
- const tail = try gpa.dupe(u8, "cancelled");
- const thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| {
- gpa.free(tail);
- return err;
- };
- defer {
- queue.cancelReader(0, 1);
- thread.join();
- }
- try PtyTests.waitBlocked(&queue);
- if (close) queue.close() else queue.cancelReader(0, 1);
- if (!close) {
- queue.acceptReader(0, 2);
- queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
- try std.testing.expect(queue.pushOutput(0, 2, try gpa.dupe(u8, "replacement")));
- queue.push(.{ .eof = .{ .pane = 0, .gen = 2 } });
- var batch = queue.take();
- defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(@as(usize, 2), batch.len);
- try std.testing.expectEqualStrings("replacement", batch.items[0].output.bytes);
- try std.testing.expectEqual(@as(u32, 2), batch.items[1].eof.gen);
- } else try std.testing.expectEqual(@as(usize, 0), queue.take().len);
- }
-}
-
-test "GUI PTY EOF reserve cannot evict terminal output" {
- const gpa = std.testing.allocator;
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
- defer queue.deinit();
- for (0..pardes.MAX_PANES) |pane| queue.acceptReader(@intCast(pane), 1);
- for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
- for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = @intCast(pane), .gen = 1 } });
- var batch = queue.take();
- defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(Queue.capacity, batch.len);
- for (batch.items[0..output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes);
- for (batch.items[output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane);
-}
-
test "GUI PTY reader delivers a real shell tail before EOF and joins on close" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .tty_only = true });
@@ -1054,7 +919,7 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
try std.testing.expect(host_io.writeFd(child.file.handle, "printf 'after-full'; exit\n"));
- try PtyTests.waitBlocked(&queue);
+ try host_io.PtyTests.waitBlocked(&queue);
const old_serial = core.panes[0].?.serial;
const replacement = try dump.restore(core, core.dump_out.?, "test");
shell.stopPtys();
@@ -1157,73 +1022,6 @@ test "GUI completion failure survives backlog and leaves the document unchanged"
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
}
-test "GUI completions retain their arrival order across LSP and pipes" {
- const gpa = std.testing.allocator;
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 2 };
- defer queue.deinit();
- queue.push(.{ .pipe = .{ .id = 1, .success = true, .outputs = &.{} } });
- queue.push(.{ .lsp = .{ .id = 2, .rows = try gpa.dupe(u8, "second") } });
- queue.push(.{ .pipe = .{ .id = 3, .success = false, .outputs = &.{} } });
- queue.push(.{ .lsp = .{ .id = 1, .rows = try gpa.dupe(u8, "late") } });
- var batch = queue.take();
- defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(@as(usize, 3), batch.len);
- try std.testing.expectEqual(@as(u32, 1), batch.items[0].pipe.id);
- try std.testing.expectEqual(@as(u32, 2), batch.items[1].lsp.id);
- try std.testing.expectEqual(@as(u32, 3), batch.items[2].pipe.id);
-}
-
-test "GUI completion reset frees queued payloads and rejects late LSP workers" {
- const gpa = std.testing.allocator;
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 9 };
- defer queue.deinit();
- queue.acceptReader(0, 1);
- queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "retained") } });
- queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "current") } });
- queue.push(.{ .lsp = .{ .id = 8, .rows = try gpa.dupe(u8, "late old request") } });
- try std.testing.expectEqualStrings("current", queue.completions[0].lsp.rows.?);
- for (0..PipeTasks.capacity) |id| {
- const outputs = try gpa.alloc([]u8, 1);
- outputs[0] = try gpa.dupe(u8, "cancelled result");
- queue.push(.{ .pipe = .{ .id = @intCast(id), .success = true, .outputs = outputs } });
- }
- queue.discardCompletions();
- queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "late before Restore") } });
- try std.testing.expectEqual(@as(usize, 0), queue.completion_len);
- var batch = queue.take();
- defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(@as(usize, 1), batch.len);
- try std.testing.expectEqualStrings("retained", batch.items[0].output.bytes);
-
- queue.lsp_id = 10;
- queue.push(.{ .lsp = .{ .id = 10, .rows = null } });
- queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "late after Restore") } });
- var next = queue.take();
- defer for (next.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(@as(usize, 1), next.len);
- try std.testing.expectEqual(@as(u32, 10), next.items[0].lsp.id);
- try std.testing.expect(next.items[0].lsp.rows == null);
-
- queue.push(.{ .lsp = .{ .id = 10, .rows = try gpa.dupe(u8, "closing result") } });
- queue.push(.{ .pipe = .{
- .id = 17,
- .success = false,
- .outputs = &.{},
- .failure = .{ .stderr = try gpa.dupe(u8, "closing failure") },
- } });
- queue.close();
- queue.push(.{ .lsp = .{ .id = 10, .rows = try gpa.dupe(u8, "late closed result") } });
- queue.push(.{ .pipe = .{
- .id = 18,
- .success = false,
- .outputs = &.{},
- .failure = .{ .stderr = try gpa.dupe(u8, "late closed failure") },
- } });
- try std.testing.expectEqual(@as(usize, 0), queue.take().len);
-}
-
-
-
fn stopPipe() ![2]c_int {
var fds: [2]c_int = undefined;
if (libc.pipe(&fds) != 0) return error.PipeFailed;
@@ -1253,31 +1051,6 @@ fn watchThread(fd: c_int, stop: c_int, q: *Queue) void {
-test "GUI LSP query answers, and a newer one cancels it" {
- const gpa = std.testing.allocator;
- const io = std.testing.io;
- const core = try pardes.Pardes.init(gpa, .{ .tty_only = true });
- defer core.deinit();
- _ = try core.setTestFile("abc");
- var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
- defer queue.deinit();
- for (0..2) |_| {
- core.lspRequest(core.active, .status, "");
- queue.startLsp(core, .{ .id = core.lsp_wait.?.id, .kind = .status, .pane = @intCast(core.active), .offset = 0, .arg = "" });
- }
- const last = core.lsp_wait.?.id;
- queue.lsp_task.?.future.await(io);
- queue.lsp_task = null;
- var batch = queue.take();
- defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
- try std.testing.expectEqual(@as(usize, 1), batch.len);
- try std.testing.expectEqual(last, batch.items[0].lsp.id);
- try std.testing.expect(batch.items[0].lsp.rows != null);
- core.update(.{ .lsp_resp = .{ .id = last, .rows = batch.items[0].lsp.rows } });
- try std.testing.expect(core.lsp_wait == null);
-}
-
-
test "GUI worker setup failures finish matching LSP and pipe requests" {
const gpa = std.testing.allocator;
var failing_vtable = std.testing.io.vtable.*;