summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 06:21:57 -0300
committerGabriel Schneider <[email protected]>2026-11-21 07:45:21 -0300
commitbbae7225e939daf4b6360d3de7af06c0fd95ce8d (patch)
treedfd4fa1f7db63363a823d44b37aa168584c2ad14 /test
parent744f1029ee2a02a43cb0fc70e32f70b60b100b75 (diff)
downloadpardes-bbae7225e939daf4b6360d3de7af06c0fd95ce8d.tar.gz
pardes-bbae7225e939daf4b6360d3de7af06c0fd95ce8d.zip
pair: the process suite as pairs from 13 of 145 failing to 7 that stay (the goldens of one cause, open): the harness dials a pair's session, the launched client's child (test/process.zig `of`, `childOf`: it dialled the launched pid's socket); a Restore in a pair no daemon keeps is refused in words, as its Upgrade is (P42: runtime/session.zig `restore`: it let the client go and the session ended with its last link), and the three cases that Restore a pair run it with a daemon of their own root's (tty.zig `privateDaemon`, e2e_harness `PARDES_HARNESS_DAEMON`, process.zig `Detached.tty_daemon`, ended by `--kill-all` at its deinit); a pair's launch with no terminal says what the own path says and forks no session (main.zig `pair`, `noTerminal`: it said "pardes: NoDevice" after forking one); a terminal client ended by TERM or HUP dies of the signal once its goodbye is said and its terminal put back, as the own path's stub does (tui.zig `dieOfQuitSignal`: it exited 0 since pair-3), and the kill test takes a pair's hang-up as the close P36 ruled; PARDES_PAIR=1 process-test 8 of 145 (7 goldens of one family: resizes=2, a terminal panned in a view shorter than the one that sized it, a restored terminal's history; winch once), without the variable 0 of 145
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py9
-rw-r--r--test/e2e_harness.zig4
-rw-r--r--test/process.zig35
-rw-r--r--test/process/flags.zig4
-rw-r--r--test/process/root_ctl.zig3
-rw-r--r--test/process/tty_boot.zig2
-rw-r--r--test/tty.zig22
7 files changed, 70 insertions, 9 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 83c024c4..88e11062 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -789,13 +789,14 @@ def pair_rows(binary):
# Not kept: a client's close (its terminal closed, a TERM) ends the
# session when it was the last; a KILL is a loss, it runs on.
t, c, nine, session, pane = started('nk', env)
- assert ended_by('HUP', *attached('nk')) == 0
+ # Dead of the signal, its goodbye said, as the own path's stub dies.
+ assert ended_by('HUP', *attached('nk')) == -signal.SIGHUP
assert alive(session) and state_of('nk') == '(tty)', ('not its last client', listed())
os.kill(c.pid, signal.SIGKILL)
c.wait(timeout=10)
wait_for('the client unlisted', lambda: f'client {c.pid} ' not in listed())
assert alive(session) and state_of('nk') == '(tty)', ('a loss', listed())
- assert ended_by('TERM', *attached('nk')) == 0
+ assert ended_by('TERM', *attached('nk')) == -signal.SIGTERM
wait_for('the session ended at its last client\'s close', lambda: not alive(session), timeout=20)
assert state_of('nk') is None, listed()
nine.socket.close()
@@ -809,7 +810,7 @@ def pair_rows(binary):
nine.socket.close()
t.close()
terms.remove(t)
- assert c.wait(timeout=20) == 0, c.returncode
+ assert c.wait(timeout=20) == -signal.SIGHUP, c.returncode
wait_for('the session ended with its terminal', lambda: not alive(session), timeout=20)
print('pair rows: not kept, upgraded: its terminal closed (exit 0): the session ended')
# Without the variable nothing changes: an attach client's TERM
@@ -817,7 +818,7 @@ def pair_rows(binary):
own_env = {k: v for k, v in env.items() if k != 'PARDES_PAIR'}
t, c, nine, session, pane = started('own', own_env)
assert state_of('own') == '(tty, has a frontend)', listed()
- assert ended_by('TERM', *attached('own')) == 0
+ assert ended_by('TERM', *attached('own')) == -signal.SIGTERM
assert alive(session) and state_of('own') == '(tty, has a frontend)', listed()
nine.socket.close()
t.close()
diff --git a/test/e2e_harness.zig b/test/e2e_harness.zig
index 9481166e..40209af3 100644
--- a/test/e2e_harness.zig
+++ b/test/e2e_harness.zig
@@ -108,7 +108,9 @@ pub const Harness = struct {
if (unsetenv(name) != 0) _exit(126);
// The app is the process this kills and the terminal it hangs
// up (deinit): no daemon to fork it off and keep it (daemon.zig).
- if (setenv("PARDES_DAEMON", "off", 1) != 0) _exit(126);
+ // PARDES_HARNESS_DAEMON (tty.zig `privateDaemon`): a daemon of
+ // the case's own runtime directory, for a pair that is Restored.
+ if (setenv("PARDES_DAEMON", if (std.mem.span(std.c.getenv("PARDES_HARNESS_DAEMON") orelse "").len > 0) "on" else "off", 1) != 0) _exit(126);
_ = execvp(exe, argv.ptr);
_exit(127);
}
diff --git a/test/process.zig b/test/process.zig
index e2a4f592..791a5b8e 100644
--- a/test/process.zig
+++ b/test/process.zig
@@ -496,10 +496,25 @@ pub const Files = struct {
}
};
-/// The files of the app a pty harness started.
+/// The files of the app a pty harness started: its session's, named by
+/// its pid, which is the app's own, or under PARDES_PAIR the app's child's
+/// (the app the client, its session forked off: main.zig `pair`).
pub fn of(gpa: std.mem.Allocator, h: *const eh.Harness) Files {
var digits: [24]u8 = undefined;
- return .init(gpa, std.fmt.bufPrint(&digits, "{d}", .{h.pid}) catch unreachable);
+ return .init(gpa, std.fmt.bufPrint(&digits, "{d}", .{if (std.c.getenv("PARDES_PAIR") != null) childOf(h.pid) else h.pid}) catch unreachable);
+}
+
+/// A process's one child (Linux's /proc), or itself when it has none.
+fn childOf(pid: libc.pid_t) libc.pid_t {
+ var path: [64]u8 = undefined;
+ var buf: [64]u8 = undefined;
+ const fd = libc.open(std.fmt.bufPrintSentinel(&path, "/proc/{d}/task/{d}/children", .{ pid, pid }, 0) catch unreachable, .{}); // two pids fit 64
+ if (fd < 0) return pid;
+ defer _ = libc.close(fd);
+ const n = libc.read(fd, &buf, buf.len);
+ if (n <= 0) return pid;
+ var words = std.mem.tokenizeScalar(u8, buf[0..@intCast(n)], ' ');
+ return std.fmt.parseInt(libc.pid_t, words.next() orelse return pid, 10) catch pid;
}
/// `pardes --detach=<name>` in a throwaway root that is its HOME, runtime
@@ -537,6 +552,9 @@ pub const Detached = struct {
cap_len: usize = 0,
/// Whether deinit removes the root (one passed in is its owner's).
owns_root: bool = true,
+ /// Its tty pair has a daemon of the root's own (`startTty`, a Restored
+ /// pair's): this build, to end them both (`--kill-all`) at deinit.
+ tty_daemon: ?[:0]const u8 = null,
files: Files,
pub const Options = struct {
@@ -697,6 +715,11 @@ pub const Detached = struct {
pub fn deinit(d: *Detached) void {
d.files.deinit();
d.child.deinit();
+ if (d.tty_daemon) |exe| if (Child.spawn(&.{ exe, "--kill-all" }, .{ .root = d.root() })) |k| {
+ var killer = k;
+ _ = killer.wait(10_000);
+ killer.deinit();
+ } else |_| {};
if (d.cap_len > 0) removeDir(d.captures());
if (d.owns_root) d.removeRoot();
}
@@ -800,7 +823,13 @@ pub const Detached = struct {
try argv.appendSlice(a, &.{ exe, "--tty", try std.fmt.allocPrintSentinel(a, "--9p={s}", .{name}, 0) });
try argv.appendSlice(a, args);
try argv.append(a, d.abs(try std.fmt.allocPrint(a, "{s}.txt", .{name})));
- const env = try a.dupe([2][:0]const u8, &.{.{ "PARDES_DUMP", d.abs(try std.fmt.allocPrint(a, "{s}.dump.zon", .{name})) }});
+ // A pair's (PARDES_PAIR) with a daemon of the root's own: a Restore
+ // lets its client go, and it joins again through it.
+ const dump = d.abs(try std.fmt.allocPrint(a, "{s}.dump.zon", .{name}));
+ const env = if (d.tty_daemon != null and std.c.getenv("PARDES_PAIR") != null)
+ try a.dupe([2][:0]const u8, &.{ .{ "PARDES_DUMP", dump }, .{ "PARDES_DAEMON", "on" } })
+ else
+ try a.dupe([2][:0]const u8, &.{.{ "PARDES_DUMP", dump }});
var c = try Child.spawn(argv.items, .{ .root = d.root(), .env = env, .pty = .{ .log = d.abs(try std.fmt.allocPrint(a, "{s}.pty", .{name})) } });
errdefer c.deinit();
try c.waitPath(d.abs(try std.fmt.allocPrint(a, "pardes-9p-{s}.sock", .{name})), 10_000);
diff --git a/test/process/flags.zig b/test/process/flags.zig
index c9aa12fb..cfdb1faf 100644
--- a/test/process/flags.zig
+++ b/test/process/flags.zig
@@ -730,7 +730,9 @@ fn killedTty(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
killed.kill(sig);
try exitsWith(&killed, -@as(c_int, @intCast(@intFromEnum(sig))), 5_000);
const own_z = z(a, "{s}", .{own});
- if (sig == .HUP) {
+ // As a pair (PARDES_PAIR) a hangup is a close (P36): the session,
+ // its last client gone and not kept, ends with it.
+ if (sig == .HUP and std.c.getenv("PARDES_PAIR") == null) {
// A hangup is the terminal's end: the session carries on
// detached (the daemon keeps it) until told to end.
try check(libc.access(own_z, 0) == 0, "a hangup ended the session", .{});
diff --git a/test/process/root_ctl.zig b/test/process/root_ctl.zig
index e3420ac5..979cfc48 100644
--- a/test/process/root_ctl.zig
+++ b/test/process/root_ctl.zig
@@ -127,6 +127,9 @@ fn restore(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
defer d.deinit();
var term: ?process.Child = null;
defer if (term) |*t| t.deinit();
+ // As a pair, with a daemon of the root's own: the Restore lets its
+ // client go, and it joins again through it (P42).
+ if (tty) d.tty_daemon = exe;
if (tty) term = try d.startTty(exe, name, &.{});
const address = d.abs(try std.fmt.allocPrint(a, "pardes-9p-{s}.sock", .{name}));
const old = try Conn.dial(gpa, address);
diff --git a/test/process/tty_boot.zig b/test/process/tty_boot.zig
index 741f6260..51aea53b 100644
--- a/test/process/tty_boot.zig
+++ b/test/process/tty_boot.zig
@@ -271,6 +271,7 @@ fn load(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
fn restore(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "restore");
defer t.deinit();
+ t.privateDaemon();
try t.start(31, 100, &.{ "-n", "1" });
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
@@ -380,6 +381,7 @@ fn headersweep(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
fn headersweep_restored(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "headersweep-restored");
defer t.deinit();
+ t.privateDaemon();
try t.start(21, 120, &.{ "-n", "3" });
try t.wait(8000, "Newcol");
try t.stable(700, 20000);
diff --git a/test/tty.zig b/test/tty.zig
index f26328ca..5cd92887 100644
--- a/test/tty.zig
+++ b/test/tty.zig
@@ -58,6 +58,10 @@ pub var replay_with: ?[]const u8 = null;
const base_dir = "/tmp/pardes-snap";
const gpa = std.heap.page_allocator;
+/// The runner's own runtime directory while a case has one of its own
+/// (`Tty.privateDaemon`).
+var runtime_dir: ?[*:0]const u8 = null;
+
pub const Tty = struct {
arena: std.mem.Allocator,
exe: [:0]const u8,
@@ -139,6 +143,24 @@ pub const Tty = struct {
pub fn deinit(t: *Tty) void {
if (t.h) |*h| h.deinit();
+ // Set back, not unset: an unsetenv compacts the environment block
+ // the runner's std.Io holds (host_io.testUnsetenv's reason).
+ if (runtime_dir) |was| {
+ _ = setenv("PARDES_HARNESS_DAEMON", "", 1);
+ _ = setenv("XDG_RUNTIME_DIR", was, 1);
+ runtime_dir = null;
+ }
+ }
+
+ /// Under PARDES_PAIR, the pair started next has a daemon of its own, in
+ /// the case's directory as its runtime directory (never the user's): a
+ /// Restore lets its client go, and it joins again through it, as with a
+ /// user's daemon. `deinit` puts the runtime directory back.
+ pub fn privateDaemon(t: *Tty) void {
+ if (std.c.getenv("PARDES_PAIR") == null) return;
+ runtime_dir = std.c.getenv("XDG_RUNTIME_DIR") orelse return;
+ _ = setenv("XDG_RUNTIME_DIR", t.arena.dupeSentinel(u8, t.base, 0) catch return, 1);
+ _ = setenv("PARDES_HARNESS_DAEMON", "1", 1);
}
/// The captures against the golden, or written to it under `--update`.