diff options
| -rw-r--r-- | core/Messages.zig | 3 | ||||
| -rw-r--r-- | core/replica.zig | 35 | ||||
| -rw-r--r-- | core/root.zig | 2 |
3 files changed, 38 insertions, 2 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 1fb232c7..46dab136 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -76,7 +76,8 @@ pub const Message = struct { extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm; /// PARDES_NOTIME set (the tests, a snapshot run): every clock reads - /// `--:--:--`. + /// `--:--:--`. A host's (`stamp`, dev/lsp): no step reads it, the text + /// it stamps crossing as a setMessage's. pub fn noTime() bool { const v = libc.getenv("PARDES_NOTIME") orelse return false; return std.mem.span(v).len != 0; 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")); +} diff --git a/core/root.zig b/core/root.zig index 02deeaa6..632385a0 100644 --- a/core/root.zig +++ b/core/root.zig @@ -614,7 +614,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{ .{ "FrameStats.zig", 7, "a frame's clock and log: frames are local, never digested" }, .{ "Handover.zig", 29, "a window carried to another process over a socket: the session's host" }, .{ "Kind.zig", 1, "host_io's KindJob: a kind's job is the host's" }, - .{ "Messages.zig", 6, "the message clock, read through tape.value(.clock); PARDES_NOTIME, the tests' (a step's read of the environment: set on one side only it would diverge)" }, + .{ "Messages.zig", 6, "the message clock, read through tape.value(.clock); PARDES_NOTIME, the tests', read by a host's `stamp` alone (between steps, or in a host's call), whose text the tape carries in the setMessage it makes: never a step's" }, .{ "Output.zig", 2, "the fonts module (Fonts lists them under tape.site(.fonts)) and the build's version line" }, .{ "Stream.zig", 14, "the disk search's worker: it runs off the step and its batches are inputs" }, .{ "builtins.zig", 2, "Mount's probe (tape.site(.probe)) and Term's shell check (tape.site(.shell))" }, |
