diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 18:58:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-18 19:13:22 -0300 |
| commit | 39ce335d7ca06b8095be2d953c240bac354868e5 (patch) | |
| tree | 8cc8e543ac30f1e57dd0814fea2451a5219e9a81 | |
| parent | 0d870b0f8f2cbbfbc4827dce39b60f367fc97363 (diff) | |
| download | pardes-39ce335d7ca06b8095be2d953c240bac354868e5.tar.gz pardes-39ce335d7ca06b8095be2d953c240bac354868e5.zip | |
replicas: the PDF back in the soak (docs/design.pdf, --pdf from the build), opened at the start beside the picture and used by the session's typist and every client: its keys, the wheel over it (a glide), a search (`/`, a pattern, Enter: the kind's rows and its jobs), a sweep of B1 over it (a selection), a jump by address (`Look file.pdf:3`, `:1:1`, a hit), Del and Look again; each client keeps the kinds it caught breaking PA_PLAIN as its own process does (Proc swaps Addon.distrusted: shared, one client's catch left every other without the kind's code at its next join, never to run it again); and draw.zig gives a kind's pane whose body has no rows no thumb (the soak's session squeezed its PDF to its tag: '@intFromFloat' out of bounds on a track of 0 rows, a panic in Debug); replicas, five clients, 4 seeds, rtt 30/80/207: diverged 0, unequal 0, deltas checked/wrong 1725/0, 1609/0, 1725/0, quiet checks 457/0, 665/0, 757/0, the PDF's panes the session opened 5/4/5; in one seed at rtt 80 the clients' calls into the PDF: key 617 replayed and 497 speculated, mouse 27/37, view 638, tick 929/465, job_done 88, search 12, address 8, ctl 7
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | build/tests.zig | 10 | ||||
| -rw-r--r-- | src/Addon.zig | 6 | ||||
| -rw-r--r-- | src/draw.zig | 3 | ||||
| -rw-r--r-- | test/replicas.zig | 114 |
4 files changed, 102 insertions, 31 deletions
diff --git a/build/tests.zig b/build/tests.zig index ff206438..e0b9235a 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -135,15 +135,19 @@ pub fn add(b: *std.Build, c: struct { const liar_mod = b.createModule(.{ .root_source_file = b.path("test/liar.zig"), .target = c.target, .optimize = c.optimize, .imports = &.{.{ .name = "addon", .module = c.addon_mod }} }); const liar_lib = b.addLibrary(.{ .name = "liar", .linkage = .dynamic, .root_module = liar_mod }); for ([_]*std.Build.Step.Compile{ snake_lib, life_lib, liar_lib }) |lib| addon_test_step.dependOn(&b.addInstallArtifact(lib, .{}).step); - // The replicas' soak, its clients showing a picture and a game of life - // from these libraries, as a user's addons are loaded (the PDF's too, - // whose pane it does not open: round 5's report). + // The replicas' soak, its clients showing a picture, a game of life and + // a PDF (docs/design.pdf) from these libraries, as a user's addons are + // loaded. const replicas = program(b, "pardes-replicas", "test/replicas.zig", c.target, c.optimize, &.{ .{ .name = "pardes", .module = c.core_module }, .{ .name = "term", .module = c.parts.term } }); const run_replicas = b.addRunArtifact(replicas); for ([_]?*std.Build.Step.Compile{ c.image_addon, life_lib, c.pdf_addon }) |l| if (l) |lib| { run_replicas.addArg("--addon"); run_replicas.addArtifactArg(lib); }; + if (c.pdf_addon != null) { + run_replicas.addArg("--pdf"); + run_replicas.addFileArg(b.path("docs/design.pdf")); + } run_replicas.addPassthruArgs(); run_replicas.has_side_effects = true; b.step("replicas", "one authority and several replicas in process, each client typing over a delayed link: digests at quiescence, rollback rate and costs per RTT (-- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207])").dependOn(&run_replicas.step); diff --git a/src/Addon.zig b/src/Addon.zig index 398ec415..3dd48944 100644 --- a/src/Addon.zig +++ b/src/Addon.zig @@ -568,9 +568,9 @@ pub fn plainOps(e: *const Kind.Entry) ?*const Kind.Ops { } /// Kinds a client found breaking PA_PLAIN: shown by the session's line -/// from its next join on. -var distrusted: [Kind.max_kinds][16]u8 = undefined; -var ndistrusted: usize = 0; +/// from its next join on. A process's (test/replicas.zig keeps one a client). +pub var distrusted: [Kind.max_kinds][16]u8 = undefined; +pub var ndistrusted: usize = 0; pub fn distrust(name: []const u8) void { if (ndistrusted == distrusted.len) return; diff --git a/src/draw.zig b/src/draw.zig index 187f2f4e..dbc7069d 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -450,7 +450,8 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: s.fill(rail.rect.x, rail.rect.y, 1, rail.rect.h, .{ .bg = .{ .rgb = chrome.scroll_track } }); s.fill(rail.rect.x + 1, rail.rect.y, 1, rail.rect.h, .{ .bg = pane_bg }); const k = pane.addon.?; - if (k.thumb_span > 0) { + // (a body of no rows has no thumb: a pane squeezed to its tag) + if (k.thumb_span > 0 and rail.rect.h > 0) { const track: f32 = @floatFromInt(rail.rect.h); rail.thumb_y = @intFromFloat(@min(track - 1, @floor(k.thumb_at * track))); rail.thumb_h = @intFromFloat(@min(track - @as(f32, @floatFromInt(rail.thumb_y)), @max(1, k.thumb_span * track))); diff --git a/test/replicas.zig b/test/replicas.zig index 8ae46a31..07557924 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -47,6 +47,8 @@ const Key = pardes.Key; const gpa = std.heap.c_allocator; extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; var trace = false; +/// The PDF the soak opens (`--pdf`), absolute. +var pdf_path: ?[]const u8 = null; const frame_us = 16_667; /// A frontend's workers for pictures' draws (Kind.drawer, tui.zig @@ -242,7 +244,7 @@ const Totals = struct { /// Clients let go by a Detach typed in their view. detach_words: u64 = 0, /// Panes of each plain kind the session opened (image, life). - kind_panes: [2]u64 = @splat(0), + kind_panes: [3]u64 = @splat(0), fn add(t: *Totals, s: *const replica.Stats) !void { t.inputs += s.inputs; @@ -268,13 +270,19 @@ const Totals = struct { /// a wheel over the shell pane, which scrolls its history into view; a /// file looked at (`looks`, its words) and a pane closed, the Panes and /// Recent pickers (the store's and Recent's rows, the authority's), a jump; -/// a picture looked at and a game of life opened (plain kinds a -/// client runs as the session does, `looks` past the texts), the keys -/// after going to its pane; now and then a client's Detach. -fn nextEvent(random: std.Random, buf: *[64]u8, wheel_at: ?[2]u16, looks: []const []const u8) pardes.Event { +/// a picture looked at, a game of life opened and a PDF looked at, at a +/// page and at a search's hit (plain kinds a client runs as the session +/// does, `looks` past the texts), the keys after going to its pane; a +/// search (`/`, a pattern, Enter), a sweep of B1 over the PDF and its +/// wheel; now and then a client's Detach. +fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const u8, script: *Script) pardes.Event { const typed = "abcdefghijklmnopqrstuvwxyz0123456789 -_=+,:;()"; const normal = "hjklwbe0$xpuyoOiaAIdcv.nN%sC"; - switch (random.uintLessThan(u8, 43)) { + if (script.at < script.n) { + script.at += 1; + return script.evs[script.at - 1]; + } + switch (random.uintLessThan(u8, 46)) { 0...15 => { buf[0] = typed[random.uintLessThan(usize, typed.len)]; return .{ .key = .{ .cp = buf[0], .text = buf[0..1] } }; @@ -322,13 +330,44 @@ fn nextEvent(random: std.Random, buf: *[64]u8, wheel_at: ?[2]u16, looks: []const // Out of a shell's tty mode and back: its text, a cursor and // selections over it. 40 => return .{ .key = .{ .cp = 'b', .ctrl = true } }, + // A search in the pane with the keyboard (a PDF's `/` is its own): + // `/`, a pattern, Enter. + 41 => { + script.* = .{ .n = 2, .evs = .{ .{ .paste = ([_][]const u8{ "the", "view", "pardes" })[random.uintLessThan(usize, 3)] }, .{ .key = .{ .cp = Key.enter } }, undefined } }; + return .{ .key = .{ .cp = '/', .text = "/" } }; + }, + // A sweep of B1 over the PDF: a selection (or a page's pan, or nothing). + 42 => { + const at = aim.pdf orelse return .{ .key = .{ .cp = Key.escape } }; + const x = at[0] + random.uintLessThan(u16, at[2]); + const y = at[1] + random.uintLessThan(u16, at[3]); + const x1 = at[0] + random.uintLessThan(u16, at[2]); + const y1 = @min(at[1] + at[3] - 1, y + random.uintLessThan(u16, 3)); + script.* = .{ .n = 2, .evs = .{ .{ .mouse = .{ .button = .left, .kind = .drag, .col = x1, .row = y1 } }, .{ .mouse = .{ .button = .left, .kind = .release, .col = x1, .row = y1 } }, undefined } }; + return .{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = y } }; + }, + // The wheel over the shell, which scrolls its history into view, + // or over the PDF, which glides. else => { - const at = wheel_at orelse return .{ .key = .{ .cp = Key.escape } }; + const over = if (random.boolean()) aim.shell else if (aim.pdf) |p| [2]u16{ p[0] + p[2] / 2, p[1] + p[3] / 2 } else aim.shell; + const at = over orelse return .{ .key = .{ .cp = Key.escape } }; return .{ .mouse = .{ .button = if (random.uintLessThan(u8, 3) == 0) .wheel_down else .wheel_up, .kind = .press, .col = at[0], .row = at[1] } }; }, } } +/// Where a typist's wheel and sweeps land in the session's view: the +/// shell's middle, the PDF's body (x, y, w, h). +const Aim = struct { shell: ?[2]u16, pdf: ?[4]u16 }; + +/// What a typist types in a row, after the first: a search's pattern and +/// Enter, a sweep's drag and release. +const Script = struct { + evs: [3]pardes.Event = undefined, + n: u8 = 0, + at: u8 = 0, +}; + fn writeFile(path: [:0]const u8, lines: usize) !void { const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o644)); if (fd < 0) return error.OpenFailed; @@ -372,16 +411,25 @@ fn screenHash(t: *screen_state.Terminal) u64 { /// client in one: a step writes `config.tab_now` from its core's settings /// (exec.zig's Tab, a dump's load), which a client's process and the /// session's each hold apart. Shared, one core's rollback that left it -/// stale would leave the other cores reading it too, and agree. +/// stale would leave the other cores reading it too, and agree. And the +/// kinds a client caught breaking PA_PLAIN (Addon.distrust): shared, one +/// client's catch would leave every other without the kind's code at its +/// next join, never to run it (and diverge) again. const Proc = struct { tab_now: u16 = pardes.config.tab_width, + distrusted: @TypeOf(pardes.Addon.distrusted) = undefined, + ndistrusted: usize = 0, var current: ?*Proc = null; fn enter(p: *Proc) void { if (current == p) return; - if (current) |was| was.tab_now = pardes.config.tab_now; + if (current) |was| { + was.tab_now = pardes.config.tab_now; + was.distrusted, was.ndistrusted = .{ pardes.Addon.distrusted, pardes.Addon.ndistrusted }; + } pardes.config.tab_now = p.tab_now; + pardes.Addon.distrusted, pardes.Addon.ndistrusted = .{ p.distrusted, p.ndistrusted }; current = p; } }; @@ -427,6 +475,8 @@ const Client = struct { wake_at: u64 = 0, drew: bool = false, resize: ?pardes.Event = null, + /// What it types in a row (a search, a sweep). + script: Script = .{}, /// gui.zig `Client.posted`: a size posted once while it waits. posted: ?@FieldType(pardes.Event, "resize") = null, resizes: u32 = 0, @@ -642,8 +692,8 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { host.echo.deinit(gpa); } var paths: [3][256:0]u8 = undefined; - var look_lines: [5][300]u8 = undefined; - var looks_buf: [5][]const u8 = undefined; + var look_lines: [8][300]u8 = undefined; + var looks_buf: [8][]const u8 = undefined; for (&paths, look_lines[0..3], looks_buf[0..3], 0..) |*p, *l, *look, i| { const path = try std.fmt.bufPrintSentinel(p, "{s}/f{d}.zig", .{ dir, i }, 0); try writeFile(path, 60 + 40 * i); @@ -664,6 +714,15 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { looks_buf[nlooks] = try std.fmt.bufPrint(&look_lines[nlooks], "Look {s}", .{path}); nlooks += 1; }; + // The PDF (`--pdf`, the pdf addon's), and two places in it: a page, a + // search's hit on a page (a miss until a search found one there). + const with_pdf = nlooks > 3 and pdf_path != null and for (kinds) |l| { + if (std.mem.eql(u8, l.name, "pdf")) break true; + } else false; + if (with_pdf) for ([_][]const u8{ "", ":3", ":1:1" }) |at| { + looks_buf[nlooks] = try std.fmt.bufPrint(&look_lines[nlooks], "Look {s}{s}", .{ pdf_path.?, at }); + nlooks += 1; + }; const looks = looks_buf[0..nlooks]; // The tty's own boot (a raw shell, a text pane under it), then three // files looked at: the session's own frontend shows the first view @@ -684,22 +743,25 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { var line: [300]u8 = undefined; _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{std.mem.sliceTo(path, 0)}) }); } - // The picture in a column of its own: every client joins with it (a - // plain kind's pane loaded from a dump, its file read by its path), its - // keys go to it when it has them. Not a PDF: a client of a session that - // shows one diverges at a key into it (round 5's report: `pane N.addon`, - // `views[k].jumps`; `it breaks PA_PLAIN` after a key), open. + // The picture and the PDF in a column of their own: every client joins + // with them (a plain kind's pane loaded from a dump, its file read by + // its path), its keys go to the one it is in when it has them. if (looks.len > 3) { _ = try a.local(.{ .command = "Newcol" }); _ = try a.local(.{ .command = looks[3] }); } + if (with_pdf) _ = try a.local(.{ .command = looks[4] }); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); } else return error.NoShell; // Where a wheel over the shell lands in the session's view, which a - // client's view is a copy of as it joins. + // client's view is a copy of as it joins; and the PDF's body there. const sr = a.core.view().rects[shell]; - const wheel_at: ?[2]u16 = if (sr.h > 2) .{ sr.x + sr.w / 2, sr.y + sr.h / 2 } else null; + const pr = if (with_pdf) a.core.view().rects[a.core.view().active] else pardes.Rect{}; + const aim: Aim = .{ + .shell = if (sr.h > 2) .{ sr.x + sr.w / 2, sr.y + sr.h / 2 } else null, + .pdf = if (pr.h > 4 and pr.w > 8) .{ pr.x + 4, pr.y + 2, pr.w - 8, pr.h - 4 } else null, + }; var net: Net = .{ .random = random, .one_way = r.rtt_ms * 1000 / 2, .jitter = r.rtt_ms * 1000 / 20 }; defer { @@ -772,6 +834,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { // The session's own typist, and every client's, until each is done. var own_left = r.steps; + var own_script: Script = .{}; var typing: usize = r.clients + 1; var next_id: u16 = 1; try net.send(.{ .at = random.uintLessThan(u64, 200_000), .n = 0, .kind = .own, .who = 0, .bytes = &.{} }); @@ -826,7 +889,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { // The kinds' panes it has opened, each counted once. for (s.a.core.panes) |slot| if (slot) |pane| if (pane.addon) |k| if (pane.serial > s.kinds_seen.*) { s.kinds_seen.* = pane.serial; - for ([_][]const u8{ "image", "life" }, &s.totals.kind_panes) |name, *n| n.* += @intFromBool(k.is(name)); + for ([_][]const u8{ "image", "life", "pdf" }, &s.totals.kind_panes) |name, *n| n.* += @intFromBool(k.is(name)); }; var rows: std.ArrayListUnmanaged([]u8) = .empty; defer rows.deinit(gpa); @@ -886,7 +949,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { session.enter(); host.now_ns = std.time.ns_per_s + m.at * 1000; var buf: [64]u8 = undefined; - const ev = nextEvent(random, &buf, wheel_at, looks); + const ev = nextEvent(random, &buf, aim, looks, &own_script); try ses.pending(m.at, flooding); try ses.flush(m.at, null); const u = try a.own(ev); @@ -1128,7 +1191,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void { switch (m.kind) { .input => { var buf: [64]u8 = undefined; - const ev = nextEvent(random, &buf, wheel_at, looks); + const ev = nextEvent(random, &buf, aim, looks, &cl.script); cl.within(); cl.link.input(ev); cl.last_input = m.at; @@ -2371,7 +2434,10 @@ pub fn main(init: std.process.Init) !void { if (i + 1 >= args.len) return error.MissingValue; i += 1; const value = args[i]; - if (std.mem.eql(u8, name, "--seeds")) seeds = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--first")) first = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--steps")) steps = try std.fmt.parseInt(usize, value, 10) else if (std.mem.eql(u8, name, "--clients")) clients = @min(8, try std.fmt.parseInt(u16, value, 10)) else if (std.mem.eql(u8, name, "--flood")) flood_mb = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--screen-state")) screen_dir = value else if (std.mem.eql(u8, name, "--addon")) try addons.append(gpa, value) else if (std.mem.eql(u8, name, "--rtt")) { + if (std.mem.eql(u8, name, "--seeds")) seeds = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--first")) first = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--steps")) steps = try std.fmt.parseInt(usize, value, 10) else if (std.mem.eql(u8, name, "--clients")) clients = @min(8, try std.fmt.parseInt(u16, value, 10)) else if (std.mem.eql(u8, name, "--flood")) flood_mb = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--screen-state")) screen_dir = value else if (std.mem.eql(u8, name, "--addon")) try addons.append(gpa, value) else if (std.mem.eql(u8, name, "--pdf")) { + var whole: [libc.PATH_MAX]u8 = undefined; + pdf_path = try init.arena.allocator().dupe(u8, std.mem.span(libc.realpath(try init.arena.allocator().dupeSentinel(u8, value, 0), &whole) orelse return error.NoPdf)); + } else if (std.mem.eql(u8, name, "--rtt")) { var it = std.mem.tokenizeScalar(u8, value, ','); var k: usize = 0; while (it.next()) |v| : (k += 1) rtt_buf[k] = try std.fmt.parseInt(u64, v, 10); @@ -2448,12 +2514,12 @@ pub fn main(init: std.process.Init) !void { t.screens_checked, t.screens_wrong, }); - try join_lines.print(gpa, "{d:>4} {d:>5} {d:>7} {d:>8} {d:>8} {d:>6} {d:>5}/{d:<5} {d:>5}/{d:<6} {d:>7} {d:>5}/{d}\n", .{ rtt, t.joins, t.refused, t.rejoined, t.detached, t.detach_words, t.agree, t.differ, t.checks, t.units, t.resizes, t.kind_panes[0], t.kind_panes[1] }); + try join_lines.print(gpa, "{d:>4} {d:>5} {d:>7} {d:>8} {d:>8} {d:>6} {d:>5}/{d:<5} {d:>5}/{d:<6} {d:>7} {d:>5}/{d}/{d}\n", .{ rtt, t.joins, t.refused, t.rejoined, t.detached, t.detach_words, t.agree, t.differ, t.checks, t.units, t.resizes, t.kind_panes[0], t.kind_panes[1], t.kind_panes[2] }); if (t.divergences > 0 or t.unequal > 0 or t.screens_wrong > 0 or t.differ > 0) failed = true; } std.debug.print("terminals: deltas a replica applied a second under the flood; a peer's bytes a second under the flood (deltas, units); encode a frame of the flood for every peer, apply a delta (us); rows fetched, KB of rows sent before the step that read them; resets; deltas checked/wrong\n", .{}); std.debug.print(" rtt deltas/s delta B/s unit B/s encode p50/p99 apply p50/p99 fetched filled KB resets checked/wrong\n{s}", .{term_lines.items}); - std.debug.print("clients: joins from a dump, refused (every view taken), joined again after a divergence put on them, left (of them by a Detach); quiet checks of the session's digest agreed/differed; the digests the clients compared (units and quiet), of the units they took; resizes the windows posted; the kinds' panes the session opened (image/life)\n", .{}); + std.debug.print("clients: joins from a dump, refused (every view taken), joined again after a divergence put on them, left (of them by a Detach); quiet checks of the session's digest agreed/differed; the digests the clients compared (units and quiet), of the units they took; resizes the windows posted; the kinds' panes the session opened (image/life/pdf)\n", .{}); std.debug.print(" rtt joins refused rejoined detached detach agree/differ checks/units resizes kinds\n{s}", .{join_lines.items}); if (failed) std.process.exit(1); } |
