summaryrefslogtreecommitdiff
path: root/test/session.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 16:50:10 -0300
committerGabriel Schneider <[email protected]>2026-11-04 17:04:36 -0300
commit2693c24cf44b8788ec26f98eeedc4d74b5ac98de (patch)
tree4464a03090122f03e221b3d6e6e05577e806625a /test/session.zig
parentbe3985092df1c3388cfa09ca5e989d2fa66f55ec (diff)
downloadpardes-2693c24cf44b8788ec26f98eeedc4d74b5ac98de.tar.gz
pardes-2693c24cf44b8788ec26f98eeedc4d74b5ac98de.zip
test: the 9P monkey at T1 and the agent driver's interaction checks at T2, for the Python ports: test/monkey9p.zig (was test/monkey9p.py) drives an in-process Session with random 9P requests, every op drawn from the seed alone (panes, columns, stale serials and held files as tokens resolved when the op runs), so --seed/--steps replay a run, --only replays any subset of its steps and a failure shrinks by delta debugging over them; each run is a child of the program in a throwaway root (its HOME, XDG directories and dump), so a panic or a hang is a failure reported and shrunk like the rules' (one failure rule, close runs only line files, /index matching /pane, chunked reads equal whole, the log marker); the 9P engine's own refusals and OTRUNC's truncation made by the monkey, Session doing no effects; steps monkey-session and monkey-session-smoke, the smoke part of behaviour-test; Session's mky helpers walk, ask (a raw request answering errno, held or bytes) and ended; test/process/terminals.zig, three cases of test/agent_session_test.py (a prompt that settles, input shown and ^U taking the screen back; history past a screenful in the body; a raw-mode control byte through pty/data), the driver's own argument, output, timeout and cleanup checks left in Python; monkey9p.py deleted; each checked to fail against a break: serveFs not noting a pane file's err (one failure rule), noting it twice (one failure rule's upper bound), a msg beside a refused pane write (its msg clause), /pane leaving out serial 3 (index matching pane dirs), stagedReply skipping a byte past offset 0 on small reads (chunked equals whole), a panic in pty/run's write (a crash, shrunk 377 -> 3 ops), the root ctl taking an unknown word (the log marker), pty/data dropping a lone control byte (raw key), a 4 KiB terminal scrollback (history, raw key), pty/data dropping a write's last byte (all three terminal cases)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/session.zig')
-rw-r--r--test/session.zig71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/session.zig b/test/session.zig
index f572a4b1..41f2c376 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -343,6 +343,77 @@ pub const Session = struct {
const style = json.object.get("styles").?.array.items[@intCast(cell.array.items[1].integer)];
return std.json.Stringify.valueAlloc(a, style.object.get("bg").?, .{});
}
+
+ // mky: the 9P monkey's raw requests (test/monkey9p.zig). Quiet, and
+ // answering what came back rather than failing; the server engine's
+ // own checks (a write on a read-only open, OTRUNC's truncation first)
+ // are the monkey's to make.
+
+ /// A walked fid: its node, its open (`opened`, `fid.handle`), and what
+ /// the walk's last step said of it.
+ pub const Walked = struct { fid: Fid, dir: bool, mode: u16, opened: bool = false };
+ /// `held`: parked (`.again`), as a read with nothing yet is. `bytes`, a
+ /// read's (a readdir's names, a line each), last until the next request.
+ pub const Answer = struct { errno: u16 = 0, held: bool = false, bytes: []const u8 = "" };
+ pub const Ask = enum { open, create, read, readdir, write, clunk, remove, stat, truncate };
+
+ /// `path` walked from the root, not opened; null, its words in `said`,
+ /// when a step is refused.
+ pub fn walk(s: *Session, path: []const u8) !?Walked {
+ var r = s.serve(.{ .tag = 0, .op = .getattr, .node = pardes.ctlfs.root });
+ var node: u64 = pardes.ctlfs.root;
+ var parts = std.mem.tokenizeScalar(u8, path, '/');
+ while (parts.next()) |name| {
+ r = s.serve(.{ .tag = 0, .op = .lookup, .node = node, .data = name });
+ if (r.status != .ok) {
+ s.said = try s.arena.allocator().dupe(u8, r.ename);
+ return null;
+ }
+ node = r.attr.node;
+ }
+ return .{ .fid = .{ .node = node, .handle = 0 }, .dir = r.attr.dir, .mode = r.attr.mode };
+ }
+
+ /// One request on `w` as the engine passes it on (a clunk of an open,
+ /// a remove as a release that removes); `off` is a readdir's entry index.
+ pub fn ask(s: *Session, w: *Walked, what: Ask, a: struct { off: u64 = 0, size: u32 = 0, data: []const u8 = "", omode: u8 = 0, perm: u32 = 0 }) Answer {
+ const f = w.fid;
+ const r = s.serve(switch (what) {
+ .open => .{ .tag = 0, .op = .open, .node = f.node, .omode = a.omode },
+ .create => .{ .tag = 0, .op = .open, .node = f.node, .create = true, .data = a.data, .perm = a.perm, .omode = a.omode },
+ .read => .{ .tag = 0, .op = .read, .node = f.node, .handle = f.handle, .off = a.off, .size = a.size },
+ .readdir => .{ .tag = 0, .op = .readdir, .node = f.node, .handle = f.handle, .off = a.off, .size = a.size },
+ .write => .{ .tag = 0, .op = .write, .node = f.node, .handle = f.handle, .off = a.off, .data = a.data },
+ .clunk, .remove => .{ .tag = 0, .op = .release, .node = f.node, .handle = f.handle, .opened = w.opened, .remove = what == .remove },
+ .stat => .{ .tag = 0, .op = .getattr, .node = f.node, .handle = f.handle },
+ .truncate => .{ .tag = 0, .op = .setattr, .node = f.node, .truncate = true },
+ });
+ if (r.status == .again) return .{ .held = true };
+ if (r.status != .ok) {
+ s.said = s.arena.allocator().dupe(u8, r.ename) catch "";
+ return .{ .errno = if (r.errno == 0) 5 else r.errno };
+ }
+ if (what == .open or what == .create) {
+ w.fid.handle = r.handle;
+ w.opened = true;
+ }
+ if (what == .clunk or what == .remove) w.opened = false;
+ if (what != .readdir) return .{ .bytes = pardesOf(s).fsPayload(r) };
+ // A dirent: node (8), dir (1), name length (1), name.
+ const raw = pardesOf(s).fsPayload(r);
+ var names: std.ArrayList(u8) = .empty;
+ var i: usize = 0;
+ while (i + 10 <= raw.len) : (i += 10 + raw[i + 9]) {
+ names.appendSlice(s.arena.allocator(), raw[i + 10 ..][0..raw[i + 9]]) catch break;
+ names.append(s.arena.allocator(), '\n') catch break;
+ }
+ return .{ .bytes = names.items };
+ }
+
+ /// Whether the session has quit, as closing its last pane quits it.
+ pub fn ended(s: *Session) bool {
+ return pardesOf(s).quit;
+ }
};
fn refusal(path: []const u8, r: Reply) error{Refused} {