summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig49
1 files changed, 49 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index a52061f4..14757d9a 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -4427,6 +4427,55 @@ test "bytes: a session's output past a unit's bound is cut into units under it,
try sameTerminals(b.a, b.r);
}
+test "bytes: a kitty image shown by a file, a temporary file or shared memory is the session's read, and the replica is handed its bytes: the same image, the cursor moved past it, the temporary file and the shared memory gone once, a missing file refused alike" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const shm = struct {
+ extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: std.c.mode_t) c_int;
+ extern "c" fn shm_unlink(name: [*:0]const u8) c_int;
+ extern "c" fn ftruncate(fd: c_int, len: i64) c_int;
+ };
+ // ghostty warns of the missing file, on the session alone.
+ const level = std.testing.log_level;
+ std.testing.log_level = .err;
+ defer std.testing.log_level = level;
+ const b = try BytesPair.init();
+ defer b.deinit();
+ const pixels: [12]u8 = @splat(0x7f); // 2 by 2, RGB
+ const pid = std.c.getpid();
+ var names: [4][80]u8 = undefined;
+ const file = try std.fmt.bufPrintSentinel(&names[0], "/tmp/pardes-replica-{d}-file.rgb", .{pid}, 0);
+ const temp = try std.fmt.bufPrintSentinel(&names[1], "/tmp/tty-graphics-protocol-pardes-replica-{d}.rgb", .{pid}, 0);
+ const object = try std.fmt.bufPrintSentinel(&names[2], "/pardes-replica-{d}", .{pid}, 0);
+ const missing = try std.fmt.bufPrintSentinel(&names[3], "/tmp/pardes-replica-{d}-missing.rgb", .{pid}, 0);
+ for ([_][:0]const u8{ file, temp }) |path| {
+ const fd = std.c.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(std.c.mode_t, 0o600));
+ try std.testing.expect(fd >= 0);
+ defer _ = std.c.close(fd);
+ try std.testing.expectEqual(@as(isize, pixels.len), std.c.write(fd, &pixels, pixels.len));
+ }
+ defer for ([_][:0]const u8{ file, temp }) |path| {
+ _ = std.c.unlink(path);
+ };
+ {
+ const fd = shm.shm_open(object, @bitCast(std.c.O{ .ACCMODE = .RDWR, .CREAT = true, .TRUNC = true }), 0o600);
+ try std.testing.expect(fd >= 0);
+ defer _ = std.c.close(fd);
+ try std.testing.expectEqual(@as(c_int, 0), shm.ftruncate(fd, pixels.len));
+ try std.testing.expectEqual(@as(isize, pixels.len), std.c.write(fd, &pixels, pixels.len));
+ }
+ defer _ = shm.shm_unlink(object);
+ const enc = std.base64.standard.Encoder;
+ var line: [256]u8 = undefined;
+ var b64: [128]u8 = undefined;
+ for ([_][:0]const u8{ file, temp, object, missing }, "ftsf", 7..) |path, medium, id|
+ try b.output(try std.fmt.bufPrint(&line, "\x1b_Ga=T,t={c},i={d},f=24,s=2,v=2;{s}\x1b\\ shown\r\n", .{ medium, id, enc.encode(&b64, path) }));
+ try agrees(b.a, b.r);
+ try sameTerminals(b.a, b.r);
+ try std.testing.expect(std.c.access(file, std.c.F_OK) == 0);
+ try std.testing.expect(std.c.access(temp, std.c.F_OK) != 0);
+ try std.testing.expect(shm.shm_open(object, @bitCast(std.c.O{ .ACCMODE = .RDONLY }), 0) < 0);
+}
+
test "a replica joined from the session's dump replays the units after it" {
const gpa = std.testing.allocator;
const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false);