summaryrefslogtreecommitdiff
path: root/test/behaviour/other_files.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:19:12 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:19:46 -0300
commitd20a480e5d556b522aedfc7ec67fa423f37c8d1d (patch)
tree8b5e333fef2f37997b1420831aaf204f20e346a3 /test/behaviour/other_files.zig
parent023793be1112bc35b50551580d273f4cf611b3da (diff)
downloadpardes-d20a480e5d556b522aedfc7ec67fa423f37c8d1d.tar.gz
pardes-d20a480e5d556b522aedfc7ec67fa423f37c8d1d.zip
test: four more of src/ninep/ctl.zig's tests through the 9P tree alone, on opens a test holds: Session's hold, readFid, writeFid and clunk (and truncate, readAt and stat for the pane files' tests next), an open kept as an event reader or a lock holder keeps one; lock and unlock on one ctl open against another (test/behaviour/panes), the event reader taking a pane's look, exec and tag clicks and acting on them written back, a refused Del written back EIO (new test/behaviour/event), /pager answering on the open that asked (other_files); each checked to fail against a break: another open's lock taken, a reader never taking a click, an event write-back's failure not captured, /pager answering the session's last result; the old pager test's two-line write refused is a handle-less write's alone (an open takes the second line as the text) and is gone
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/other_files.zig')
-rw-r--r--test/behaviour/other_files.zig42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig
index c0f9c08f..8625df3b 100644
--- a/test/behaviour/other_files.zig
+++ b/test/behaviour/other_files.zig
@@ -28,3 +28,45 @@ test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Al
try s.keys("i\u{F015}zy\x1b");
try s.expect(s.at("/pane/{d}/body", .{try s.focused()}), "yx\n");
}
+
+test "other-files: pager answers its +Pager on the open that asked, whatever another client exec'd meanwhile, and refuses a directory it cannot page in" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const asked = try s.hold("/pager", 2);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(asked, "/tmp\n"));
+ // Another client execs between the request and its read: a pane of its own.
+ const racer = try s.hold("/exec", 2);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(racer, "New\n"));
+ s.clunk(racer);
+ const paged = try s.readFid(asked);
+ s.clunk(asked);
+ // A fresh open reads the session's last answer, the racer's pane.
+ try std.testing.expect(!std.mem.eql(u8, paged, try s.read("/exec")));
+ try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, paged, "\n")}), "/tmp/+Pager\n");
+ // Refused, an open answers nothing, not the session's last answer.
+ const refused = try s.hold("/pager", 2);
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(refused, "relative\n"));
+ try std.testing.expectEqualStrings("", try s.readFid(refused));
+ s.clunk(refused);
+ // Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the
+ // one made above, which keeps its page.
+ const resolved = try s.hold("/pager", 2);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(resolved, "/tmp/../tmp/.\n"));
+ const second = try s.readFid(resolved);
+ s.clunk(resolved);
+ try std.testing.expect(!std.mem.eql(u8, paged, second));
+ try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, second, "\n")}), "/tmp/+Pager\n");
+ try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, paged, "\n")}), "/tmp/+Pager\n");
+ // One that may not be written is refused, permission denied (Linux's /proc/1).
+ try std.testing.expectEqual(@as(u16, 1), try s.refused("/pager", "/proc/1\n"));
+ // One directory an open: one refused is not followed by another, as a
+ // mount sends two lines in two writes.
+ const twice = try s.hold("/pager", 2);
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(twice, "relative\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(twice, "/tmp\n"));
+ s.clunk(twice);
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/pager", "relative\n"));
+ try std.testing.expectEqualStrings("pager: invalid directory \"relative\": must be absolute", s.said);
+ try std.testing.expectEqual(@as(u16, 2), try s.refused("/pager", "/tmp/pardes-surely-missing-dir\n"));
+ try std.testing.expectEqual(@as(u16, 20), try s.refused("/pager", "/etc/passwd\n"));
+}