summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig95
1 files changed, 93 insertions, 2 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 80b3ab10..993c1f09 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5262,7 +5262,8 @@ const On = enum { any, file, kind, shell, shell_normal };
/// The test below walks every word of the registry, every key and the
/// gestures between panes against it: what stops and is not here fails
/// it, and a row nothing stopped at says it is stale.
-const may_wait = [_]struct { what: []const u8, on: On, stop: []const u8, why: []const u8 }{
+const Wait = struct { what: []const u8, on: On, stop: []const u8, why: []const u8 };
+const may_wait = [_]Wait{
// A shell's program has the keys: what reaches it is its input (a far
// shell may feel like ssh).
.{ .what = "*", .on = .shell, .stop = "pty_write", .why = "a key into a shell's program" },
@@ -5303,7 +5304,11 @@ const may_wait = [_]struct { what: []const u8, on: On, stop: []const u8, why: []
.{ .what = "DumpConfig", .on = .any, .stop = "the authority's own state", .why = "the config file written" },
.{ .what = "ThemeFile *", .on = .any, .stop = "the authority's own state", .why = "a theme file, the session's" },
.{ .what = "DumpThemes", .on = .any, .stop = "the authority's own state", .why = "the theme files written" },
-};
+} ++ (if (pardes.platform == .gui) [_]Wait{
+ // A window's view (the font words are a window's).
+ .{ .what = "Font *", .on = .any, .stop = "fonts", .why = "the session's machine's fonts, its disk" },
+ .{ .what = "Fonts", .on = .any, .stop = "fonts", .why = "the session's machine's fonts, its disk" },
+} else [_]Wait{});
/// The keys the walk types: every printable one, and the specials a
/// frontend reads; each plain, with Ctrl and with Alt.
@@ -5673,3 +5678,89 @@ test "a far client's own Look of ~/x, bare Shell and a word that runs in the ses
r.dirty = false;
}
}
+
+test "a far client's replay of the session's DumpDir takes the session's answer to whether the directory may be written, not its own disk's" {
+ if (std.c.getuid() == 0) return error.SkipZigTest; // root writes anywhere
+ const gpa = std.testing.allocator;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var ro_buf: [std.Io.Dir.max_path_bytes + 8:0]u8 = undefined;
+ const ro = try std.fmt.bufPrintSentinel(&ro_buf, "{s}/ro", .{dir}, 0);
+ // The session's machine: a directory it may not write in.
+ if (std.c.mkdir(ro, 0o500) != 0) return error.NoDir;
+ defer _ = std.c.chmod(ro, 0o700);
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false);
+ defer a.deinit();
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined;
+ const u = try gpa.dupe(u8, try a.local(.{ .command = try std.fmt.bufPrint(&line, "DumpDir {s}/dumps", .{ro}) }));
+ defer gpa.free(u);
+ try std.testing.expectEqualStrings("", a.core.settings.dump_dir.get());
+ // The client's machine: the same path, and it may.
+ if (std.c.chmod(ro, 0o700) != 0) return error.NoChmod;
+ r.confirm(u);
+ r.settle();
+ try agrees(a, r);
+ try std.testing.expectEqualStrings("", r.core().settings.dump_dir.get());
+}
+
+test "a far client's replay of the session's Fonts and Font takes the session's machine's fonts, not its own" {
+ if (comptime !pardes.builtins.capabilities.font_picker) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const fonts = @import("dev").fonts;
+ const Shell = @import("dev").host_io.Shell;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.createDirPath(std.testing.io, "session/.local/share/fonts");
+ try tmp.dir.createDirPath(std.testing.io, "client");
+ const face = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "assets/MapleMono-NF-Regular.ttf", gpa, .limited(64 << 20));
+ defer gpa.free(face);
+ // Its family renamed, so that no face of this machine's shares its name.
+ for ([_][]const u8{ "Maple", "\x00M\x00a\x00p\x00l\x00e" }, [_][]const u8{ "Qzxjv", "\x00Q\x00z\x00x\x00j\x00v" }) |from, to| {
+ var at: usize = 0;
+ while (std.mem.indexOfPos(u8, face, at, from)) |i| : (at = i + to.len) @memcpy(face[i..][0..to.len], to);
+ }
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "session/.local/share/fonts/seen.ttf", .data = face });
+ var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var homes: [2][std.Io.Dir.max_path_bytes + 16:0]u8 = undefined;
+ const session_home = try std.fmt.bufPrintSentinel(&homes[0], "{s}/session", .{dir}, 0);
+ const client_home = try std.fmt.bufPrintSentinel(&homes[1], "{s}/client", .{dir}, 0);
+ // HOME as it was, after (a test's: runtime never sets the environment).
+ const was = if (std.c.getenv("HOME")) |h| try gpa.dupeSentinel(u8, std.mem.span(h), 0) else null;
+ defer if (was) |h| gpa.free(h);
+ _ = Shell.setenv("PARDES_TEST_ENVIRON_COPIED", "1", 1);
+ defer _ = if (was) |h| Shell.setenv("HOME", h, 1) else @import("dev").host_io.testUnsetenv("HOME");
+ // The face the session's machine has and the client's lacks: its name.
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ _ = Shell.setenv("HOME", session_home, 1);
+ const name = for (fonts.list(arena.allocator(), null)) |f| {
+ if (std.mem.startsWith(u8, f.path, session_home)) break f.name;
+ } else return error.SkipZigTest; // not a face the scan takes
+ // The two machines answer differently, or this one cannot stand for two.
+ const session_first = fonts.list(arena.allocator(), name)[0].path;
+ const session_faces = fonts.list(arena.allocator(), null).len;
+ _ = Shell.setenv("HOME", client_home, 1);
+ const client_named = fonts.list(arena.allocator(), name);
+ if (fonts.list(arena.allocator(), null).len == session_faces and client_named.len > 0 and std.mem.eql(u8, client_named[0].path, session_first)) return error.SkipZigTest;
+ _ = Shell.setenv("HOME", session_home, 1);
+ // A window's view: the font words are a window's.
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .windowed = true }, TestHost.host(), false);
+ defer a.deinit();
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ var line: [256]u8 = undefined;
+ const units = [_][]u8{
+ try gpa.dupe(u8, try a.local(.{ .command = "Fonts" })),
+ try gpa.dupe(u8, try a.local(.{ .command = try std.fmt.bufPrint(&line, "Font {s} 13", .{name}) })),
+ };
+ defer for (units) |u| gpa.free(u);
+ _ = Shell.setenv("HOME", client_home, 1);
+ for (units) |u| r.confirm(u);
+ r.settle();
+ try agrees(a, r);
+}