diff options
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig index 13c1fe46..3aeb21af 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6331,3 +6331,38 @@ test "a far client's step that asks for a search goes on at once, and a session try std.testing.expect(a.core.stream.state == .done); try agrees(a, r); } + +// PARDES_NOTIME (the tests' `--:--:--` clock) is read by `Message.stamp`, +// which only a host calls: between steps, or in its own entry during one. +// The stamped text crosses as the setMessage the host makes, so a client +// whose environment says otherwise replays the session's text. +test "a far client's replay of a message its session's host stamped takes the session's text, whatever its own PARDES_NOTIME says" { + const gpa = std.testing.allocator; + const Stamping = struct { + var core: ?*Pardes = null; + fn yank(_: ?*anyopaque, _: []const u8) void { + var buf: [64]u8 = undefined; + const c = core.?; + c.setMessage(.at(c.view().active), pardes.Messages.Message.stamp(&buf, "yanked", "x")); + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = yank }; + }; + const Shell = @import("dev").host_io.Shell; + const was = if (std.c.getenv("PARDES_NOTIME")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; + defer if (was) |v| gpa.free(v); + defer _ = if (was) |v| Shell.setenv("PARDES_NOTIME", v, 1) else @import("dev").host_io.testUnsetenv("PARDES_NOTIME"); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &Stamping.vtable }, false); + defer a.deinit(); + Stamping.core = a.core; + const r = try joinedFresh(a); + defer r.deinit(); + // The session's machine says `--:--:--`; the client's the time of day. + _ = Shell.setenv("PARDES_NOTIME", "1", 1); + const u = try gpa.dupe(u8, try a.own(.{ .command = "ClipYank" })); + defer gpa.free(u); + _ = @import("dev").host_io.testUnsetenv("PARDES_NOTIME"); + r.confirm(u); + r.settle(); + try agrees(a, r); + try std.testing.expect(try shows(r.core(), "--:--:-- yanked x")); +} |
