diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 03:20:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 04:13:33 -0300 |
| commit | 4c2125ecf47588d33f9894c1fdf2833d0512f3b4 (patch) | |
| tree | c76510fd390e20187554ea86a3fdabd2dfb65ca5 /test/snapshot.zig | |
| parent | d1d5d3cfb18841604bba2057eeb3598f729b4475 (diff) | |
| download | pardes-4c2125ecf47588d33f9894c1fdf2833d0512f3b4.tar.gz pardes-4c2125ecf47588d33f9894c1fdf2833d0512f3b4.zip | |
client #2, one frontend a session: the daemon answers `other <name>` for an attach to a session attached already (as it did for one of the other kind), so a second `pardes --attach` or `pardes-gui --attach` on this machine is a replica client through the replica socket, the path a remote one takes; a session tells the daemon its clients (SO_PEERCRED on each replica socket, at every join and leave) and `--ps` lists `client <pid> <command>` under it; the tty's per-terminal Screens (Screen.create/drop/destroy, primary, its stub and Killed slot), the Poster and its `from` input, the Gui's window-fields swap (window_fields, GuiWindow, copyWindow, freshWindow, follow, route, openAnotherWindow, closeView, windowsOpen, closeOtherWindows, resumeWindows), drawOthers and every harness's extra terminals (snapshot.zig's `start ... views=N` and `view <k>`, e2e_harness's initView and drainOthers, PARDES_TEST_VIEWS in both frontends, the GUI feed's `view;<k>`, the monkey's --views) go; the pump draws the one view this process shows (views.shown), through drawOne when a client's input was the last; an Upgrade from a build that kept a second terminal of its own lets it go (its stub told it is detached) and closes its view; deleted: views.snap, views-term.snap and views-pan.snap with their goldens (the in-process second terminal they drove is gone; views.zig's unit tests keep the per-view cursor, layout, register, sizing, closing and panning behaviour, test/replicas.zig and the soak the views of clients); the two views.zig tests that drew through drawOthers draw through drawOne; daemon.py's second terminal is a client listed by --ps, typed into in both terminals, detached from inside and closed; its second window a client listed by --ps and closed; the reference and next-daemon.md say so; no golden changes; gates: core-test 956/956 both, behaviour-test 248/248 both, unit-test 1487/1488 tui and 1530/1531 gui, pane-test 171/172 both, snap all 102 ok, process-test 0 of 37 failed on both, hxdiff 19 and hxparity 6 mismatches (the base's names), hxgolf 0, replicas, addon-test, gui-golden and monkey-gui 0 of 1 failed, daemon.py main, --window-clients and --gui ok, soak local pass (differ, mispred, view_bad, lost 0)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/snapshot.zig')
| -rw-r--r-- | test/snapshot.zig | 85 |
1 files changed, 18 insertions, 67 deletions
diff --git a/test/snapshot.zig b/test/snapshot.zig index 02215abd..d93face2 100644 --- a/test/snapshot.zig +++ b/test/snapshot.zig @@ -29,11 +29,7 @@ // lines <name> <n> [tail] create file with n numbered lines, tail on each // dirmk <name> create a subdirectory // run <shell...> run a command in the script's cwd (NOT in a pane) -// start <rows> <cols> [views=N] [arg] fork the app in a pty (optional -// extra CLI arg); views=N gives it N-1 more -// terminals, each a view of the session -// view <k> type into and capture terminal k (1 is the -// app's own; a resize there SIGWINCHes the app) +// start <rows> <cols> [arg] fork the app in a pty (optional extra CLI arg) // wait <ms> <needle...> pump until needle appears on the grid (fails hard) // settle <ms> pump for a fixed duration // stable <quiet_ms> <timeout_ms> pump until the grid stops changing @@ -685,14 +681,6 @@ fn runScript(arena: std.mem.Allocator, exe_z: [:0]const u8, script_path: []const var chunk_len: usize = 0; var h: ?eh.Harness = null; defer if (h) |*hp| hp.deinit(); - // `views=N`: the app's other terminals, and the one driven now. - var others: [3]eh.Harness = undefined; - var nothers: usize = 0; - var group: [4]*eh.Harness = undefined; - var cur: usize = 0; - defer for (others[0..nothers]) |*o| o.deinit(); - // A capture is a delta against the previous one of its terminal's. - var prevs: [4]Prev = @splat(.{}); // captures are deltas against the previous one of the same kind (see Prev) var prev: Prev = .{}; @@ -758,46 +746,16 @@ fn runScript(arena: std.mem.Allocator, exe_z: [:0]const u8, script_path: []const const cols = try std.fmt.parseInt(u16, tok.next() orelse return error.BadScript, 10); var extra: [6]?[*:0]const u8 = @splat(null); var nextra: usize = 0; - var nviews: usize = 1; while (tok.next()) |a| { - if (std.mem.startsWith(u8, a, "views=")) { - nviews = try std.fmt.parseInt(usize, a["views=".len..], 10); - if (nviews < 1 or nviews > 4) return error.BadScript; - continue; - } if (nextra >= extra.len) return error.BadScript; extra[nextra] = (try arena.dupeSentinel(u8, a, 0)).ptr; nextra += 1; } if (h) |*hp| hp.deinit(); // scripts may restart (e.g. dump then -l) - for (others[0..nothers]) |*o| o.deinit(); - nothers = 0; - cur = 0; // a new process is a new screen: capture it whole, or its first // frame would be a delta against a dead instance's rows prev = .{}; - prevs = @splat(.{}); - var paths: std.ArrayList(u8) = .empty; - while (nothers + 1 < nviews) : (nothers += 1) { - var path: [64]u8 = undefined; - others[nothers] = try eh.Harness.initView(gpa, rows, cols, &path); - try paths.print(arena, "{s}{s}", .{ if (paths.items.len > 0) " " else "", std.mem.sliceTo(&path, 0) }); - } - if (nothers > 0) _ = setenv("PARDES_TEST_VIEWS", try arena.dupeSentinel(u8, paths.items, 0), 1); h = try eh.Harness.initArgv(gpa, exe_z.ptr, rows, cols, extra[0..nextra]); - _ = unsetenv("PARDES_TEST_VIEWS"); - group[0] = &h.?; - for (others[0..nothers], 1..) |*o, i| { - o.pid = h.?.pid; - group[i] = o; - } - for (group[0 .. nothers + 1]) |v| v.views = group[0 .. nothers + 1]; - } else if (std.mem.eql(u8, cmd, "view")) { - const k = try std.fmt.parseInt(usize, tok.next() orelse return error.BadScript, 10); - if (k < 1 or k > nothers + 1) return error.BadScript; - prevs[cur] = prev; - cur = k - 1; - prev = prevs[cur]; } else if (std.mem.eql(u8, cmd, "snapfile")) { const label = tok.next() orelse return error.BadScript; const contents = try readFileAlloc(arena, tok.rest()); @@ -807,52 +765,51 @@ fn runScript(arena: std.mem.Allocator, exe_z: [:0]const u8, script_path: []const try appendChunk(chunks, &chunk_len, try snapFile(arena, label, contents)); } else if (std.mem.eql(u8, cmd, "wait")) { const ms = try std.fmt.parseInt(i64, tok.next() orelse return error.BadScript, 10); - try on(&h, &group, nothers, cur).expectWaitFor(tok.rest(), ms, "snapshot wait"); + try live(&h).expectWaitFor(tok.rest(), ms, "snapshot wait"); } else if (std.mem.eql(u8, cmd, "settle")) { - try on(&h, &group, nothers, cur).pump(try std.fmt.parseInt(i64, tok.next() orelse return error.BadScript, 10)); + try live(&h).pump(try std.fmt.parseInt(i64, tok.next() orelse return error.BadScript, 10)); } else if (std.mem.eql(u8, cmd, "stable")) { const quiet = try std.fmt.parseInt(i64, tok.next() orelse return error.BadScript, 10); const timeout = try std.fmt.parseInt(i64, tok.next() orelse return error.BadScript, 10); - try waitStable(on(&h, &group, nothers, cur), quiet, timeout); + try waitStable(live(&h), quiet, timeout); } else if (std.mem.eql(u8, cmd, "text")) { - try on(&h, &group, nothers, cur).send(tok.rest()); + try live(&h).send(tok.rest()); } else if (std.mem.eql(u8, cmd, "send")) { - try on(&h, &group, nothers, cur).send(try unescape(arena, tok.rest())); + try live(&h).send(try unescape(arena, tok.rest())); } else if (std.mem.eql(u8, cmd, "key")) { - while (tok.next()) |name| try on(&h, &group, nothers, cur).send(keyBytes(name) orelse return error.BadKey); + while (tok.next()) |name| try live(&h).send(keyBytes(name) orelse return error.BadKey); } else if (std.mem.eql(u8, cmd, "press") or std.mem.eql(u8, cmd, "release") or std.mem.eql(u8, cmd, "drag")) { const btn = buttonCode(tok.next() orelse return error.BadScript) orelse return error.BadScript; const col_spec = tok.next() orelse return error.BadScript; const row = try std.fmt.parseInt(u16, tok.next() orelse return error.BadScript, 10); - const col = try resolveCol(on(&h, &group, nothers, cur), col_spec, row); + const col = try resolveCol(live(&h), col_spec, row); const b: u16 = if (std.mem.eql(u8, cmd, "drag")) btn + 32 else btn; const fin: u8 = if (std.mem.eql(u8, cmd, "release")) 'm' else 'M'; - try on(&h, &group, nothers, cur).send(try std.fmt.allocPrint(arena, "\x1b[<{d};{d};{d}{c}", .{ b, col, row, fin })); + try live(&h).send(try std.fmt.allocPrint(arena, "\x1b[<{d};{d};{d}{c}", .{ b, col, row, fin })); } else if (std.mem.eql(u8, cmd, "motion")) { const col_spec = tok.next() orelse return error.BadScript; const row = try std.fmt.parseInt(u16, tok.next() orelse return error.BadScript, 10); - const col = try resolveCol(on(&h, &group, nothers, cur), col_spec, row); - try on(&h, &group, nothers, cur).send(try std.fmt.allocPrint(arena, "\x1b[<35;{d};{d}M", .{ col, row })); + const col = try resolveCol(live(&h), col_spec, row); + try live(&h).send(try std.fmt.allocPrint(arena, "\x1b[<35;{d};{d}M", .{ col, row })); } else if (std.mem.eql(u8, cmd, "wheel")) { const dir = tok.next() orelse return error.BadScript; const b: u16 = if (std.mem.eql(u8, dir, "up")) 64 else 65; const col_spec = tok.next() orelse return error.BadScript; const row = try std.fmt.parseInt(u16, tok.next() orelse return error.BadScript, 10); - const col = try resolveCol(on(&h, &group, nothers, cur), col_spec, row); - try on(&h, &group, nothers, cur).send(try std.fmt.allocPrint(arena, "\x1b[<{d};{d};{d}M", .{ b, col, row })); + const col = try resolveCol(live(&h), col_spec, row); + try live(&h).send(try std.fmt.allocPrint(arena, "\x1b[<{d};{d};{d}M", .{ b, col, row })); } else if (std.mem.eql(u8, cmd, "resize")) { const rows = try std.fmt.parseInt(u16, tok.next() orelse return error.BadScript, 10); const cols = try std.fmt.parseInt(u16, tok.next() orelse return error.BadScript, 10); - try on(&h, &group, nothers, cur).resize(rows, cols); + try live(&h).resize(rows, cols); // Another view's terminal is no one's controlling one: the app // is told it changed, as a stub tells it of its own. - if (cur > 0) std.posix.kill(live(&h).pid, std.posix.SIG.WINCH) catch {}; } else if (std.mem.eql(u8, cmd, "snap")) { - try appendChunk(chunks, &chunk_len, try snapText(arena, on(&h, &group, nothers, cur), tok.rest(), &prev)); + try appendChunk(chunks, &chunk_len, try snapText(arena, live(&h), tok.rest(), &prev)); } else if (std.mem.eql(u8, cmd, "snapstyle")) { - try appendChunk(chunks, &chunk_len, try snapStyle(arena, on(&h, &group, nothers, cur), tok.rest(), &prev)); + try appendChunk(chunks, &chunk_len, try snapStyle(arena, live(&h), tok.rest(), &prev)); } else if (std.mem.eql(u8, cmd, "snap9p")) { - try appendChunk(chunks, &chunk_len, try snap9p(arena, on(&h, &group, nothers, cur), tok.rest(), &prev)); + try appendChunk(chunks, &chunk_len, try snap9p(arena, live(&h), tok.rest(), &prev)); } else { std.debug.print("unknown command {s}\n", .{cmd}); return error.BadScript; @@ -967,12 +924,6 @@ fn snapFile(arena: std.mem.Allocator, label: []const u8, contents: []const u8) ! } /// The terminal the script drives now (`view`). -fn on(h: *?eh.Harness, group: *[4]*eh.Harness, nothers: usize, cur: usize) *eh.Harness { - const app = live(h); - if (cur == 0 or cur > nothers) return app; - return group[cur]; -} - fn live(h: *?eh.Harness) *eh.Harness { if (h.*) |*v| return v; fatal("script used the app before `start`", .{}); @@ -1010,7 +961,7 @@ fn waitStable(h: *eh.Harness, quiet: i64, timeout: i64) !void { // and nothing in its process tree is runnable. Held across two probes, // because a pane's shell can write and sleep a scheduler tick before // the app wakes to read it. - if (since >= probe_after_ms and h.pendingAll() == 0 and treeAsleep(h.pid)) { + if (since >= probe_after_ms and h.pending() == 0 and treeAsleep(h.pid)) { if (asleep_since == 0) { asleep_since = now; } else if (now - asleep_since >= probe_hold_ms) { |
