summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/replica.zig12
-rw-r--r--dev/gui/gui.zig7
-rw-r--r--dev/tui/tui.zig7
-rw-r--r--test/panes.zig84
4 files changed, 102 insertions, 8 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 829972c2..875a7828 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -1911,6 +1911,18 @@ pub const Peers = struct {
return n;
}
+ /// The time the session's pump reads after its wait, when that wait
+ /// took a client's post and nothing else (`only_mail`, the shell's word
+ /// for its wait): the core's clock as it stands, so the pump's unit
+ /// moves nothing a client's speculation stands on; null otherwise (the
+ /// shell's clock). Held only while a post waits (`mail`): a wait that
+ /// ran out took none, and the pump after it is the one its deadline
+ /// asked for (a window's wait that ran out was held, 2026-11-24: a
+ /// deadline never met, the session stepped a millisecond for ever).
+ pub fn heldNow(ps: *const Peers, core: *const Pardes, only_mail: bool) ?u64 {
+ return if (only_mail and ps.recording and ps.mail.load(.acquire) and core.clock.started) core.clock.now_ns else null;
+ }
+
pub fn post(ps: *Peers, note: Note) void {
ps.lock.lockUncancelable(ps.io);
if (note == .join and ps.upgrading.load(.monotonic)) {
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 9ea813fc..8fd8c24c 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -2457,9 +2457,8 @@ const Shell = struct {
/// of their own with no window here; the session loop's
/// (runtime/session.zig), a client's none.
peers: *replica.Peers,
- /// This wait took only a replica's post (its input, its join): the pump
- /// after it reads no new time, so it moves nothing the replicas'
- /// speculations stand on (tui.zig's `mail_only`).
+ /// This wait took nothing but a replica's post, if one (its input, its
+ /// join): the pump after one reads no new time (Peers.heldNow).
mail_only: bool = false,
waited: bool = false,
/// With replica clients, a wait takes one person's input (tui.zig
@@ -3167,7 +3166,7 @@ fn guiNow(ctx: ?*anyopaque) u64 {
const s = shellOf(ctx);
if (s.waited) {
s.waited = false;
- if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns;
+ if (s.peers.heldNow(s.core, s.mail_only)) |held| return held;
}
return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS();
}
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index e2cdd2fa..312a0846 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -1240,9 +1240,8 @@ const Shell = struct {
/// The session's replica clients (core/replica.zig), on sockets: the
/// session loop's (runtime/session.zig); a client's, none.
peers: *replica.Peers,
- /// This wait took only a replica's post (its input, its join): the
- /// pump after it reads no new time, so it moves nothing the replicas'
- /// speculations stand on (a replica takes such a unit as is).
+ /// This wait took nothing but a replica's post, if one (its input, its
+ /// join): the pump after one reads no new time (Peers.heldNow).
mail_only: bool = false,
waited: bool = false,
/// This wait's steps so far, and the input held for the next (`split`).
@@ -1321,7 +1320,7 @@ const Shell = struct {
const s = of(ctx);
if (s.waited) {
s.waited = false;
- if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns;
+ if (s.peers.heldNow(s.core, s.mail_only)) |held| return held;
}
return s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
}
diff --git a/test/panes.zig b/test/panes.zig
index bd39beba..28a3b256 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -4047,6 +4047,90 @@ const PdfAddon = struct {
}
}
+ /// A session's loop with nobody typing: each wait runs out at its
+ /// deadline, and the clock read after it is the shells' (Peers.heldNow,
+ /// as gui.zig `guiNow` and tui.zig `clockNow` read it: a wait that took
+ /// nothing else, `only_mail`).
+ const Idle = struct {
+ now: u64 = std.time.ns_per_s,
+ waited: bool = false,
+ core: ?*Pardes = null,
+ peers: pardes.replica.Peers = .{ .gpa = std.testing.allocator, .io = std.testing.io },
+
+ const vtable: pardes.Host.VTable = .{
+ .wait_input = wait,
+ .now = clock,
+ .watched = host_vtable.watched,
+ .job = host_vtable.job,
+ };
+
+ fn wait(ctx: ?*anyopaque, timeout_ms: u32) void {
+ const h: *Idle = @ptrCast(@alignCast(ctx.?));
+ h.now += @as(u64, timeout_ms) * std.time.ns_per_ms;
+ h.waited = true;
+ }
+
+ fn clock(ctx: ?*anyopaque) u64 {
+ const h: *Idle = @ptrCast(@alignCast(ctx.?));
+ if (!h.waited) return h.now;
+ h.waited = false;
+ return h.peers.heldNow(h.core orelse return h.now, true) orelse h.now;
+ }
+ };
+
+ test "a PDF shown and a client's view its kind was not told: the session's next pump, its wait run out with nobody typing, tells it, and nothing is owed after; a client's post waiting holds the clock" {
+ // 2026-11-24: a window's session showing a PDF, a client attached,
+ // stepped ~700 times a second with nobody typing: the client's view
+ // owed to the kind (Kind.wake: now), a wait of a millisecond that
+ // ran out, and the clock after it held as if a client had posted
+ // (gui.zig guiNow: its wait's `mail_only` is cleared by an event,
+ // and one that ran out had none), so no step met the deadline.
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ var idle: Idle = .{};
+ defer idle.peers.deinit();
+ const a = try R.Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .ctx = &idle, .vtable = &Idle.vtable });
+ defer a.deinit();
+ idle.core = a.core;
+ const Land = struct {
+ a: *R.Authority,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ _ = try l.a.local(ev);
+ }
+ };
+ const id = try opened(a, Land{ .a = a });
+ const slot = a.core.panes[id].?.addon.?;
+ // A client attached (units go to it), its view sized by its input:
+ // a client's step tells no kind (17.2), so its view is owed.
+ idle.peers.recording = true;
+ const k = (try a.openView(2)).view;
+ const was = pardes.tape.on;
+ pardes.tape.on = &a.t;
+ const bytes = try pardes.dump.byteDump(a.core);
+ pardes.tape.resync(&a.t);
+ pardes.tape.on = was;
+ defer a.core.gpa.free(bytes);
+ const win = try R.Replica.initDump(std.testing.allocator, 2, k, bytes, .{ .cols = 80, .rows = 24 });
+ defer win.deinit();
+ _ = try a.take(try win.input(.{ .resize = .{ .cols = 80, .rows = 24 } }));
+ try std.testing.expect(pardes.Kind.viewOwed(a.core, slot, id));
+ // ONE pump, nobody typing: its wait runs out at the wake, the step
+ // it asked for tells the view, and nothing is owed after.
+ a.pump();
+ try std.testing.expect(!pardes.Kind.viewOwed(a.core, slot, id));
+ try std.testing.expect((pardes.Kind.wake(a.core) orelse std.math.maxInt(u64)) > a.core.clock.now_ns);
+ // A client's post waiting (its input, its join): the pump before
+ // the boundary takes it reads the clock as it stands.
+ const at = a.core.clock.now_ns;
+ idle.now += std.time.ns_per_s;
+ idle.peers.mail.store(true, .release);
+ a.pump();
+ try std.testing.expectEqual(at, a.core.clock.now_ns);
+ idle.peers.mail.store(false, .release);
+ a.pump();
+ try std.testing.expectEqual(idle.now, a.core.clock.now_ns);
+ }
+
test "a PDF pane whose file changes on disk opens again from it at its page, its fit kept" {
if (!addons.has_pdf) return error.SkipZigTest;
const gpa = std.testing.allocator;