From 5e162e2e8b208367720b8be8de3bfe51b010aa68 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 05:50:51 -0300 Subject: core: the reads no tape saw are taped, and a check counts what core/ asks of the machine (the reorganisation's 12b, the design round's step 4 and its finds): DumpDir's check whether its directory may be written (fs.deniedAbove in config.Runtime.apply, two `access` calls in a step) is the session's disk's answer, tape.value(.denied) as a failed save's is, and Font and Fonts, which walked the machine's font directories in a step (dev/fonts.list), ask the session's machine through a new site, `fonts` (a far client's Font or Fonts waits a round trip; its replay takes the session's answer); each was a real fault: a client on another machine diverged at its replay of the session's unit, a test each at the end of core/replica.zig (a directory the session may not write and the client may, the setting refused on both; a face the session's machine has and the client's lacks, its family renamed so no installed face shares it, listed and chosen alike on both), each shown failing on the change before (the digests differ); Edit's pipe environment (host_io.commandEnv) is shown harmless and left as it is: it is kept in Pipe.edit_run, `.authority` state (Pipe.zig:21: in no digest and no copy), read only by the host's `pipe` entry, which a client never calls (a speculation records the void call, a replay answers from the tape); the check, the twin of allowed_vars, at the end of core/root.zig: per file of core/, the lines outside tests naming std.c., libc., std.posix., getenv, std.Io's File, Dir, net or Threaded (not Dir.path, a path's text, nor max_path_bytes) or importing dev or runtime, against one list, machine_lines, 34 files and 313 lines, each file with why; a file whose count moves is named with its lines, shown failing once (a getenv added to Messages.zig: 7 lines against 6, its line 891 named); found by it and not changed: Messages.noTime reads PARDES_NOTIME in a step (a test's knob: set on one side only it would diverge); may_wait gains Font and Fonts at `fonts` in a window's build; Stats.unspeculated is not deleted: its only reader is the soak's (test/replicas.zig: the field, its sum, the view column), a file another agent is rewriting; the semantics word moves again (a site added), 517cd1c276996a3c -> 0900e560fd6395ef; tui core-test 836/979 (143 skipped), shell-test 1014/1017, pane-test 183/184, behaviour-test 275/275 and --replay 275/275, process-test 2 of 144 failed (lspcomplete, lspcompletemoved, the base's), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 (1827/0, 1596/0, 1803/0) quiet differ 0 (422/0, 563/0, 655/0) at 30/80/207 ms, stopped 89/73/108, mispredicted 37/34/36, gui unit-test 1612/1616 (its perf check's BaselineHarnessMismatch the base's), daemon.py plain, --far, --games, --window-clients pass; gate-w seam-b-4 against tree1: 77/77 frames byte-identical in Debug, its unit-test 1612/1616, perfab corpus2x +0.047% (pictures identical in all 10 runs), perfops 97 counts within 0.1% (largest +0.0199%, body-appends on longline) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 2 deletions(-) (limited to 'core/replica.zig') 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); +} -- cgit v1.3