diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:13:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:40:08 -0300 |
| commit | 684dd340da01a60525d45e5a4f4c64f9fb79be1d (patch) | |
| tree | 7ce1fae0242450cab5d3f0857ca2a7b0ed168474 | |
| parent | 6cf113c8bf86c602669c2cfe0da422988047afaf (diff) | |
| download | pardes-684dd340da01a60525d45e5a4f4c64f9fb79be1d.tar.gz pardes-684dd340da01a60525d45e5a4f4c64f9fb79be1d.zip | |
gui: the headless grid host goes (PARDES_TEST_GRID: runGrid, its host table, its frame dump and its test), with --gui-grid in test/agent_session.py and its test, its only user, run by hand; the test feed now says only whether its input ended
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/gui/gui.zig | 326 | ||||
| -rw-r--r-- | test/agent_session.py | 4 | ||||
| -rw-r--r-- | test/agent_session_test.py | 3 |
3 files changed, 16 insertions, 317 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 2c707e85..96c7254e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1210,12 +1210,10 @@ test "GUI completion failure survives backlog and leaves the document unchanged" shell.gens = &gens; shell.ptys = &ptys; shell.retired_shells = @splat(.{}); - shell.saw_event = false; shell.drainQueue(); try std.testing.expect(core.lsp_wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); - try std.testing.expect(shell.saw_event); } test "GUI completions retain their arrival order across LSP and pipes" { @@ -1985,7 +1983,6 @@ const Dial = struct { path: []const u8, session: []const u8, far: bool }; fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, dial: ?Dial) !void { const gpa = init.gpa; const env = init.environ_map; - if (dial == null and env.get("PARDES_TEST_GRID") != null) return runGrid(init, opts_in); const test_mode = env.get("PARDES_TEST") != null; const capture_dir = env.get("PARDES_TEST_CAPTURE_DIR"); @@ -2690,8 +2687,7 @@ const OwnView = struct { if (v.pointer) refreshPresentedPointer(g, v.in); runDemo(g, v.in, core); if (v.s.test_mode) { - const r = v.s.feed.pump(v.s.gpa, v.in, g) catch return error.TestFeed; - if (r.eof) v.eof = true; + if (v.s.feed.pump(v.s.gpa, v.in, g) catch return error.TestFeed) v.eof = true; } } }; @@ -2879,113 +2875,6 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ const frame_ms: c_int = @intCast(pardes.animation.frame_ns / std.time.ns_per_ms); -fn runGrid(init: std.process.Init, opts_in: pardes.Options) !void { - const io = init.io; - const gpa = init.gpa; - const env = init.environ_map; - - const allocs = pardes.memory.init(gpa); - defer pardes.memory.deinit(); - host_io.startWorkers(io, allocs); - defer host_io.stopWorkers(); - - const grid_cols = envU16(env, "PARDES_TEST_COLS") orelse 80; - const grid_rows = envU16(env, "PARDES_TEST_ROWS") orelse 24; - var opts = opts_in; - opts.image_allocator = allocs.image; - opts.pdf_allocator = allocs.pdf; - opts.tree_sitter_allocator = allocs.tree_sitter; - opts.frame_allocator = allocs.frame; - if (opts.load_path != null) { - opts.cols = grid_cols; - opts.rows = grid_rows; - } - const core = if (opts.load_path) |lp| blk: { - const bytes = try @import("../fs.zig").readFile(gpa, lp); - defer gpa.free(bytes); - break :blk try pardes.dump.initFromDump(allocs.pardes, opts, bytes); - } else try pardes.Pardes.init(allocs.pardes, opts); - defer core.deinit(); - if (opts.load_path == null) - core.update(.{ .resize = .{ .cols = grid_cols, .rows = grid_rows } }); - - var prompt_rcs = host_io.Shell.prepare(); - defer prompt_rcs.deinit(); - - var ptys: [pardes.MAX_PANES]?Pty = @splat(null); - var gens: [pardes.MAX_PANES]u32 = @splat(0); - var queue: Queue = .{ - .io = io, - .gpa = gpa, - .lsp_allocator = allocs.lsp, - }; - defer { - if (queue.lsp_task) |*task| task.future.cancel(io); - // Its worker may be waiting on the queue for room. - core.stream.cancelTask(); - queue.deinit(); - } - var pipe_tasks: PipeTasks = .{}; - defer pipe_tasks.cancelAll(io); - var watches: file_watch.Table = @splat(null); - const fs = ninep_io.start(io, gpa, core); - defer if (fs) |f| f.deinit(gpa); - var shell: Shell = .{ - .core = core, - .io = io, - .gpa = gpa, - .lsp_allocator = allocs.lsp, - .prompt_rcs = &prompt_rcs, - .ptys = &ptys, - .gens = &gens, - .queue = &queue, - .pipe_tasks = &pipe_tasks, - .inotify_fd = -1, - .watches = &watches, - .fs = fs, - .grid = true, - }; - defer shell.shutdownPtys(); - const host = shell.host(); - core.host = host; - while (core.nextEffect()) |e| core.perform(e); - for (&ptys, 0..) |*slot, id| if (slot.*) |*pt| { - pt.reader = try queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), gens[id]); - }; - shell.threads_ok = true; - pardes.lsp.setStatusSink(&queue, Queue.lspStatus); - defer pardes.lsp.setStatusSink(null, null); - host_io.setExitWake(&queue, Queue.wakeForExit); - defer host_io.setExitWake(null, null); - - setStdinRaw() catch {}; // stdin may be a pipe, not a pty — best effort - - { - var first: std.heap.ArenaAllocator = .init(allocs.frame); - defer first.deinit(); - const surface = try core.render(first.allocator()); - try dumpGrid(gpa, surface); - core.acknowledgePanelPresentation(&.{}); - } - while (!core.quit) { - var in: Input = .{ .core = core }; - const r = try shell.feed.pump(gpa, &in, null); - if (r.eof) break; - if (r.n_events != 0) shell.saw_event = true; - shell.drainQueue(); - try core.pump(host); - if (shell.dump_err) |err| return err; - } - if (core.quit) { - gridPollFrame(&shell); - var last: std.heap.ArenaAllocator = .init(allocs.frame); - defer last.deinit(); - gridPresent(&shell, try core.render(last.allocator())); - gridPostPresent(&shell); - if (shell.dump_err) |err| return err; - } -} - const StdinFeed = struct { parser: vaxis.Parser = .{}, /// Inside the driver's bracketed paste: its keys are the paste's text. @@ -2997,10 +2886,9 @@ const StdinFeed = struct { last_cols: u16 = 0, last_rows: u16 = 0, - const Result = struct { eof: bool = false, n_events: usize = 0 }; - - fn pump(f: *StdinFeed, gpa: std.mem.Allocator, in: *Input, g: ?*Gui) !Result { - var out: Result = .{}; + /// The test driver's keys and events since the last call, posted to + /// `in`; true once its input has ended. + fn pump(f: *StdinFeed, gpa: std.mem.Allocator, in: *Input, g: ?*Gui) !bool { var ws: posix.winsize = std.mem.zeroes(posix.winsize); if (posix.system.ioctl(0, posix.T.IOCGWINSZ, @intFromPtr(&ws)) == 0 and ws.col > 0 and ws.row > 0 and ws.col <= 1000 and ws.row <= 1000 and @@ -3009,25 +2897,18 @@ const StdinFeed = struct { f.last_cols = ws.col; f.last_rows = ws.row; applyResize(in, g, ws.col, ws.row); - out.n_events += 1; } var fds = [_]posix.pollfd{.{ .fd = 0, .events = posix.POLL.IN, .revents = 0 }}; pardes.turn.rest(); const polled = posix.poll(&fds, 16); pardes.turn.wake(); - _ = polled catch return out; - if ((fds[0].revents & posix.POLL.IN) == 0) { - if ((fds[0].revents & (posix.POLL.HUP | posix.POLL.ERR)) != 0) out.eof = true; - return out; - } + _ = polled catch return false; + if ((fds[0].revents & posix.POLL.IN) == 0) return (fds[0].revents & (posix.POLL.HUP | posix.POLL.ERR)) != 0; const rn = libc.read(0, f.buf[f.fill..].ptr, f.buf.len - f.fill); - if (rn < 0) return out; + if (rn < 0) return false; if (rn > 0) latencyNote("R {d}\n", .{monoNs()}); - if (rn == 0) { - out.eof = true; - return out; - } + if (rn == 0) return true; const len = f.fill + @as(usize, @intCast(rn)); f.fill = 0; @@ -3107,7 +2988,6 @@ const StdinFeed = struct { c.SDL_SetModState(mods); dispatch(gp, in, &sev); c.SDL_SetModState(before); - out.n_events += 1; } seq_start += mouse_prefix.len + end + 1; continue; @@ -3128,10 +3008,7 @@ const StdinFeed = struct { const win_w: f32 = @floatFromInt(@max(wpw, 1)); const win_h: f32 = @floatFromInt(@max(wph, 1)); handleFinger(&gp.touch, in, finger, win_w, win_h, @floatFromInt(gp.cell_w), @floatFromInt(gp.cell_h), @floatFromInt(gp.tagline_width)); - } else if (in.core) |core| { - handleFinger(&grid_touch, in, finger, @floatFromInt(core.screen_w), @floatFromInt(core.screen_h), 1, 1, 1); } - out.n_events += 1; } seq_start += prefix.len + end + 1; continue; @@ -3159,7 +3036,6 @@ const StdinFeed = struct { f.paste.appendSlice(gpa, text) catch {}; } else { postKey(in, key, if (key.text) |t| f.cache.put(t) else ""); - out.n_events += 1; }, .paste_start => { f.in_paste = true; @@ -3169,7 +3045,6 @@ const StdinFeed = struct { f.in_paste = false; if (f.paste.items.len > 0) in.post(.{ .paste = f.paste.items }); f.paste.clearAndFree(gpa); - out.n_events += 1; }, .mouse => |m| { const button: ?pardes.Mouse.Button = switch (m.button) { @@ -3198,22 +3073,19 @@ const StdinFeed = struct { .shift = m.mods.shift, .alt = m.mods.alt, } }); - out.n_events += 1; } }, .winsize => |vw| { applyResize(in, g, @intCast(vw.cols), @intCast(vw.rows)); - out.n_events += 1; }, .paste => |text| { in.post(.{ .paste = text }); gpa.free(@constCast(text)); - out.n_events += 1; }, else => {}, } } - return out; + return false; } fn applyResize(in: *Input, g: ?*Gui, cols: u16, rows: u16) void { @@ -3226,8 +3098,6 @@ const StdinFeed = struct { } }; -var grid_touch: Touch = .{}; // grid test mode has no Gui to hang it off - fn parseFinger(payload: []const u8) ?Finger { var parts = std.mem.splitScalar(u8, payload, ';'); const type_name = parts.next() orelse return null; @@ -3272,52 +3142,6 @@ fn setStdinRaw() !void { try posix.tcsetattr(0, .NOW, term); } -fn dumpGrid(gpa: std.mem.Allocator, surface: *const pardes.Surface) !void { - if (surface.cols == 0 or surface.rows == 0) return; - const cur_x: u16 = if (surface.cursor) |cu| cu.x else 0; - const cur_y: u16 = if (surface.cursor) |cu| cu.y else 0; - var hdr: [128]u8 = undefined; - const header = std.fmt.bufPrint(&hdr, "\n---FRAME:{d}:{d}:{d}:{d}:{}---\n", .{ - surface.rows, surface.cols, cur_x, cur_y, surface.cursor != null, - }) catch return; - const footer = "---ENDFRAME---\n"; - var total = try std.math.add(usize, header.len, footer.len); - total = try std.math.add(usize, total, surface.rows); - var y: u16 = 0; - while (y < surface.rows) : (y += 1) { - var x: u16 = 0; - while (x < surface.cols) : (x += 1) { - const grapheme = surface.cells[@as(usize, y) * surface.cols + x].grapheme(); - total = try std.math.add(usize, total, if (grapheme.len > 0) grapheme.len else 1); - } - } - const frame = try gpa.alloc(u8, total); - defer gpa.free(frame); - var at: usize = 0; - @memcpy(frame[at..][0..header.len], header); - at += header.len; - y = 0; - while (y < surface.rows) : (y += 1) { - var x: u16 = 0; - while (x < surface.cols) : (x += 1) { - const grapheme = surface.cells[@as(usize, y) * surface.cols + x].grapheme(); - if (grapheme.len > 0) { - @memcpy(frame[at..][0..grapheme.len], grapheme); - at += grapheme.len; - } else { - frame[at] = ' '; - at += 1; - } - } - frame[at] = '\n'; - at += 1; - } - @memcpy(frame[at..][0..footer.len], footer); - at += footer.len; - std.debug.assert(at == frame.len); - _ = host_io.writeFd(1, frame); -} - /// A key parsed from the stdin a test window reads, posted as the tty /// posts one (vaxis_input): F-keys, Insert and the keypad included. `text` /// is the key's text as the feed keeps it. @@ -4103,11 +3927,9 @@ fn pollGamepad(g: *Gui, in: *Input) void { const Shell = struct { core: *pardes.Pardes, /// The window's, while one is open; null while detached (`parked` has - /// it) and in the headless test grid. + /// it). gui: ?*Gui = null, parked: ?*Gui = null, - /// The headless test grid (runGrid): its own loop, no window ever. - grid: bool = false, /// Shells a dead session left (Adopt), each waiting for the spawn of /// the terminal pane made for it. adoptions: host_io.Adoptions = .{}, @@ -4132,8 +3954,6 @@ const Shell = struct { presented: bool = false, skipped_presents: u8 = 0, surface: ?*const pardes.Surface = null, - saw_event: bool = false, - dump_err: ?anyerror = null, retired_shells: [pardes.MAX_PANES]RetiredShell = @splat(.{}), /// PARDES_TEST_CLOCK's virtual time (host_io.testClock), in test mode. test_clock: ?u64 = null, @@ -4245,7 +4065,7 @@ const Shell = struct { } fn host(s: *Shell) pardes.Host { - return .{ .ctx = s, .vtable = if (s.grid) &grid_vtable else &vtable }; + return .{ .ctx = s, .vtable = &vtable }; } /// Detach: the window closed, the session left running with no @@ -4555,22 +4375,6 @@ const Shell = struct { .hand_over = handOver, }; - const grid_vtable: pardes.Host.VTable = vt: { - var v = vtable; - v.wait_input = null; - v.now = null; - v.poll_frame = gridPollFrame; - v.present = gridPresent; - v.post_present = gridPostPresent; - v.set_clipboard = null; - v.read_clipboard = null; - v.watched = null; - v.detach = null; - v.adopt = null; - v.upgrade = null; - break :vt v; - }; - /// The command panes' exits, told once their output is in (host_io). fn takeExits(s: *Shell) void { host_io.takeExits(s.core, s.ptys, s, closeWatched); @@ -4578,7 +4382,6 @@ const Shell = struct { fn closeWatched(s: *Shell, id: usize) void { s.closePty(@intCast(id)); - s.saw_event = true; } fn drainQueue(s: *Shell) void { @@ -4594,7 +4397,6 @@ const Shell = struct { if (s.gens[o.pane] == o.gen) s.core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } }); s.gpa.free(o.bytes); - s.saw_event = true; }, .eof => |e| { if (s.gens[e.pane] == e.gen) eof: { @@ -4623,18 +4425,15 @@ const Shell = struct { if (unwatched or status != null) s.core.update(.{ .exited = .{ .pane = e.pane, .status = status } }); s.core.update(.{ .eof = .{ .pane = e.pane } }); } - s.saw_event = true; }, .lsp => |l| { s.core.update(.{ .lsp_resp = .{ .id = l.id, .rows = l.rows } }); if (l.rows) |rows| s.lsp_allocator.free(rows); - s.saw_event = true; }, .lsp_status => |text| { var mbuf: [256]u8 = undefined; s.core.setStatus(s.core.active, message.stamp(&mbuf, "lsp", text)); s.lsp_allocator.free(text); - s.saw_event = true; }, .pipe => |response_value| { var response = response_value; @@ -4645,29 +4444,20 @@ const Shell = struct { .failure = response.failure, } }); response.deinit(s.gpa); - s.saw_event = true; s.pipe_tasks.finish(s.io, response_value.id); }, .search => |b| { s.core.update(.{ .search = b }); b.deinit(s.gpa); - s.saw_event = true; }, .handed => |h| { s.core.update(.{ .handed = .{ .seq = h.seq, .to = if (h.ok) h.words else "", .failure = if (h.ok) null else h.words } }); s.gpa.free(h.words); - s.saw_event = true; }, .files_changed => check_files = true, .fs_ready => {}, - .window => { - if (s.gui != null) s.openAnotherWindow(null) else s.openTheWindow(); - s.saw_event = true; - }, - .adopted => |a| { - s.adoptions.adoptShell(s.core, a.pid, a.fd); - s.saw_event = true; - }, + .window => if (s.gui != null) s.openAnotherWindow(null) else s.openTheWindow(), + .adopted => |a| s.adoptions.adoptShell(s.core, a.pid, a.fd), }; if (check_files) s.shaders.recheck(); if (check_files and file_watch.reloadChanged(s.core, s.io, s.gpa, s.watches)) @@ -4860,11 +4650,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { if (paced) g.pace_ns = tick; } else waitDetached(core, timeout_ms); if (s.test_mode) { - const r = s.feed.pump(s.gpa, &in, s.gui) catch { - core.quit = true; - return; - }; - if (r.eof) { + if (s.feed.pump(s.gpa, &in, s.gui) catch true) { core.quit = true; return; } @@ -5190,38 +4976,6 @@ fn guiNow(ctx: ?*anyopaque) u64 { return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS(); } -fn gridPollFrame(ctx: ?*anyopaque) void { - const s = shellOf(ctx); - s.reconcilePtys(); - if (s.fs) |f| { - if (f.tick().count != 0) s.saw_event = true; - } - pollCwds(s.core, s.ptys); - // Grid time is virtual: each poll moves it straight to the core's - // next wake, a frame at a time while anything moves. - if (s.core.nextWake()) |due| { - s.core.advance(due); - s.saw_event = true; - } -} - -fn gridPresent(ctx: ?*anyopaque, surface: *const pardes.Surface) void { - const s = shellOf(ctx); - s.presented = s.saw_event; - s.saw_event = false; - if (!s.presented) return; - dumpGrid(s.gpa, surface) catch |err| { - s.dump_err = err; - s.presented = false; - }; -} - -fn gridPostPresent(ctx: ?*anyopaque) void { - const s = shellOf(ctx); - if (!s.presented) return; - s.core.acknowledgePanelPresentation(&.{}); -} - fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void { const s = shellOf(ctx); s.reap(); @@ -5395,58 +5149,6 @@ fn readClipboard(ctx: ?*anyopaque) void { shellOf(ctx).core.update(.{ .paste = text }); } -test "the headless grid host round-trips a yank back as a paste" { - const gpa = std.testing.allocator; - const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); - defer core.deinit(); - core.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); - - var ptys: [pardes.MAX_PANES]?Pty = @splat(null); - var gens: [pardes.MAX_PANES]u32 = @splat(0); - var queue: Queue = .{ - .io = std.testing.io, - .gpa = gpa, - .lsp_allocator = gpa, - }; - defer queue.deinit(); - var pipe_tasks: PipeTasks = .{}; - var watches: file_watch.Table = @splat(null); - var prompt_rcs = host_io.Shell.prepare(); - defer prompt_rcs.deinit(); - var shell: Shell = .{ - .core = core, - .gui = null, - .io = undefined, - .gpa = gpa, - .lsp_allocator = gpa, - .prompt_rcs = &prompt_rcs, - .ptys = &ptys, - .gens = &gens, - .queue = &queue, - .pipe_tasks = &pipe_tasks, - .inotify_fd = -1, - .watches = &watches, - .grid = true, - }; - core.host = shell.host(); - try std.testing.expect(core.host.vtable == &Shell.grid_vtable); - - const pane = core.panes[0].?; - core.update(.{ .key = .{ .cp = ' ' } }); - core.update(.{ .key = .{ .cp = 'y' } }); - while (core.nextEffect()) |e| core.perform(e); - const yanked = core.registers.text(core.gpa, '+') orelse return error.MissingYank; - try std.testing.expect(yanked.len > 0); - - const before = pane.file.?.content.len; - core.update(.{ .key = .{ .cp = ' ' } }); - core.update(.{ .key = .{ .cp = 'p' } }); - try std.testing.expect(core.clip_pending != null); - while (core.nextEffect()) |e| core.perform(e); - try std.testing.expect(core.clip_pending == null); - try std.testing.expectEqual(before + yanked.len, pane.file.?.content.len); -} - test "the clipboard pasted into a terminal reaches its pty as xterm pastes: bracketed when asked, no ESC[201~ smuggled through" { if (comptime !pardes.panes.terminal.enabled) return error.SkipZigTest; const gpa = std.testing.allocator; diff --git a/test/agent_session.py b/test/agent_session.py index aa87c845..ec64c011 100644 --- a/test/agent_session.py +++ b/test/agent_session.py @@ -47,8 +47,7 @@ def run(args, command, status): signal.setitimer(signal.ITIMER_REAL, args.timeout) try: context = session(str(args.binary.resolve()), root, 'agent-session', tty=True, - socket_name='agent-session', launch=['--tty', '--9p=agent-session'], - inherited={'PARDES_TEST_GRID': '1'} if args.gui_grid else {}) + socket_name='agent-session', launch=['--tty', '--9p=agent-session']) client, _ = context.__enter__() try: try: @@ -137,7 +136,6 @@ def main(argv): parser.add_argument('--timeout', type=float, default=60, help='interaction deadline in seconds, at most 600') parser.add_argument('--min-rows', type=int, default=0) parser.add_argument('--prepare-key', help='one hex control byte before history/probe checks; never CR or LF') - parser.add_argument('--gui-grid', action='store_true', help='use the GUI build headless grid host') if '--' not in argv: parser.error('supply the interactive command after --') split = argv.index('--') diff --git a/test/agent_session_test.py b/test/agent_session_test.py index 6dc385ab..6b0d417c 100644 --- a/test/agent_session_test.py +++ b/test/agent_session_test.py @@ -80,10 +80,9 @@ def check(binary, options, command, expected, phase=None, cleanup_failure=False) def main(): parser = argparse.ArgumentParser() parser.add_argument('binary', type=Path) - parser.add_argument('--gui-grid', action='store_true') args = parser.parse_args() binary = str(args.binary.resolve()) - ready = ['--ready', 'AGENT_READY', *(['--gui-grid'] if args.gui_grid else [])] + ready = ['--ready', 'AGENT_READY'] command = ['/bin/sh', '-c', 'printf "AGENT_READY> "; read answer'] for options, argv in [ ([], command), |
