diff options
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig index 42aae524..342913ba 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6079,3 +6079,83 @@ test "a far client's frame drawn under a speculation that rolls back asks a pict r.settle(); try agrees(a, r); } + +// A program that asked for focus events is told of a click into its shell +// by the session's step (Core.reportFocus): a client's own step writes +// nothing. Where the shell's queue is backed up (a 9P write past what the +// effects ring holds, parked until the session's next pump), the session's +// report parks behind it, into `pending_write`, which is digested, where +// the client's speculation skips the write. It cannot differ: a client's +// step settles as the session's does, draining the queue, and what is +// parked is a write into the shell, which stops it (the client holds the +// same queue: the unit that parked it is the session's, which it replays). +test "a far client's click into a shell whose queue is backed up: the session's focus report queues behind what is parked, and the client ends as the session does" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const Told = struct { + var bytes: usize = 0; + var tail: [3]u8 = @splat(0); + fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void { + bytes += b.len; + if (b.len >= 3) @memcpy(&tail, b[b.len - 3 ..]); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_write = write }; + }; + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }, true); + defer a.deinit(); + const shell: u8 = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break @intCast(id); + } else return error.NoShell; + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); + _ = (try a.pending()).?; + _ = try a.local(.{ .command = "New" }); + var screens: Screens = .init(gpa); + defer screens.deinit(a.core); + const peer = try screens.addPeer(); + const r = try joinedFresh(a); + defer r.deinit(); + try deliver(a, &screens, peer, r, .flush); + r.settle(); + // A 9P write into the shell, past the ring: the rest parked, on both. + const big = try gpa.alloc(u8, pardes.memory.limits.effect_cap * pardes.effect_write_cap + 100); + defer gpa.free(big); + @memset(big, 'x'); + { + const was = Stepping.begin(&a.t, null); + defer was.end(); + _ = a.core.serveFs(.{ .tag = 1, .op = .write, .node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_data), .data = big }); + } + a.seq += 1; + r.confirm(try a.unit(0, a.seq)); + r.settle(); + try std.testing.expect(a.core.pending_write[shell] != null and r.core().pending_write[shell] != null); + Told.bytes = 0; + const rect = r.core().view().rects[shell]; + const row = rect.y + r.core().panes[shell].?.tag_rows + 1; + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + r.stats.stops = @splat(.{}); + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x + 2, .row = row } }))); + // The client's own step drains the queue it holds as the session's + // does: what is parked is a write into the shell, so it stops there, + // and waits for the session's step, focus report and all. + try std.testing.expectEqual(@as(usize, 0), r.applied); + for (r.stats.stops) |st| if (st.n > 0) try std.testing.expectEqualStrings("pty_write", st.name); + for (sent.items) |m| { + try deliver(a, &screens, peer, r, .flush); + const u = try gpa.dupe(u8, try a.take(m)); + defer gpa.free(u); + try deliver(a, &screens, peer, r, .fill); + r.confirm(u); + r.settle(); + } + // The program had what was parked, then the focus. + try std.testing.expectEqual(big.len + 3, Told.bytes); + try std.testing.expectEqualStrings("\x1b[I", &Told.tail); + try std.testing.expectEqual(@as(usize, shell), r.core().view().active); + try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); + try agrees(a, r); +} |
