summaryrefslogtreecommitdiff
path: root/test/replicas.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 03:44:57 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commita22b579ad2df8d1811f0e194fa1bbc06e2282cf8 (patch)
tree9dcaaa6d17c6c67048b58456dcd9dbdb74b9fc9a /test/replicas.zig
parenta3509e4df5efc94b0deee3b06dd72f85b0d96647 (diff)
downloadpardes-a22b579ad2df8d1811f0e194fa1bbc06e2282cf8.tar.gz
pardes-a22b579ad2df8d1811f0e194fa1bbc06e2282cf8.zip
term: the terminal a module of its own (docs/next-terminal.md, Phase 1): src/term/term.zig roots it, importing std, ghostty-vt, wuffs, zstbi and plain, never the core, and gives the core one table, `ops` (plain.term.Ops: about 60 entries, the records they take and give and the opaque handles State, Encoder, Track and Replica, in src/plain/term.zig), its own functions put in it through a cast refused at compile time unless each parameter and result matches the table's but for the handles and every error is one the table names; src/Term.zig, the core's side, takes `ops` from the term module when the build's term_options say the core has one (every core module but core-test's), null otherwise, and Term.State is a handle with the walk's hooks, so a dump keeps a terminal as it did (its Parts by name through walk.save, then ghostty's snapshot) and the digest is the emulator's; echo.zig comes back to the core (src/echo.zig: predicted echo is the replica's presentation, its five reads of the emulator through Term.grid, modes, prompt and Term.echoCell); screen_state's Peer is a plain record both sides name (its noteSent a function of screen_state's), its Encoder, Track and Replica handles made and freed through the table (replica.Screens makes its encoder at the first encode); a prompt's cut is told in columns and measured in its row's text by the core (Term.promptPrefix, File.rawAtDisplay); TerminalImages' decode bound moves from memory.limits to the decoder it bounds; build.zig: core_lean, the core module without the terminal, is core-test's, and wireCore no longer gives any core module ghostty-vt, wuffs or zstbi (the term module has them), so core-test's compile names none of ghostty, wuffs, zstbi, simdutf, highway or -lc++ (from --verbose); term-test runs the module's own tests (the pager's, screen_state's, the luminance table's); the tests of a terminal through a core move as they were to test/terminal.zig, in pane-test, which imports both (`of` reads the emulator behind a handle; the dump round trip frees through State.dumpFree), and tests elsewhere that read the emulator do it through Term.emulatorOf, a test in core-test skipping first; core-test skips a test whose terminal Term.open refuses; Authority.init releases its tape when the core it boots fails (it leaked); tests: core-test (no terminal) 409 of 941, 532 skipped, shell-test (the same tests with the terminal) 984 of 984, pane-test 180 of 181 (1 skipped, as before), term-test 15 of 15, kitty-test 45 of 45, replicas checked/wrong 0, hxdiff 658 cases 0 mismatches, behaviour-test 268 of 272 (the base's four addon ABI tests), lib-test
Diffstat (limited to 'test/replicas.zig')
-rw-r--r--test/replicas.zig48
1 files changed, 29 insertions, 19 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index c100a8c1..f6aa2af2 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -35,8 +35,8 @@ const std = @import("std");
const libc = std.c;
const pardes = @import("pardes");
const replica = pardes.replica;
-const screen_state = pardes.Term.screen_state;
-const Echo = pardes.Term.Echo;
+const screen_state = @import("term").screen_state;
+const Echo = pardes.Echo;
const Key = pardes.Key;
const gpa = std.heap.c_allocator;
@@ -223,7 +223,17 @@ fn writeText(path: [:0]const u8, text: []const u8) !void {
const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, shared: bool, flood_mb: u64 };
/// The terminal pane's screen as a hash of screen_state's dump of it.
-fn screenHash(t: *pardes.Term.screen_state.Terminal) u64 {
+/// The module's own replica behind the core's handle (Replica.screens).
+fn replicaOf(r: *pardes.Term.Replica) *screen_state.Replica {
+ return @ptrCast(@alignCast(r));
+}
+
+/// The module's own track behind the core's handle (Screens.tracks).
+fn trackOf(t: *pardes.Term.Track) *screen_state.Track {
+ return @ptrCast(@alignCast(t));
+}
+
+fn screenHash(t: *screen_state.Terminal) u64 {
var buf: [8192]u8 = undefined;
var h: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(.init(0), &buf);
screen_state.dumpScreen(t, &h.writer) catch {};
@@ -416,12 +426,12 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
if (reply[5] == 1) {
// Applied: the screen is the authority's at that version.
const sc = rp.screens[pane].?;
- const vt = &rp.core().panes[pane].?.terminal.?.vt;
+ const vt = &pardes.Term.emulatorOf(rp.core().panes[pane].?.terminal.?).vt;
totals.screens_checked += 1;
- if (versions.get(@as(u64, sc.serial) << 32 | sc.rep.seq)) |want| {
+ if (versions.get(@as(u64, sc.serial) << 32 | replicaOf(sc.rep).seq)) |want| {
if (want != screenHash(vt)) {
totals.screens_wrong += 1;
- std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at version {d} is not the authority's\n", .{ r.seed, r.rtt_ms, m.who, pane, sc.rep.seq });
+ std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at version {d} is not the authority's\n", .{ r.seed, r.rtt_ms, m.who, pane, replicaOf(sc.rep).seq });
}
} else totals.screens_wrong += 1;
// Deltas while the flood runs (an RTT/2 behind it).
@@ -459,7 +469,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
totals.unequal += 1;
continue;
}).terminal orelse continue;
- if (screenHash(&state.vt) != screenHash(&mine.vt)) {
+ if (screenHash(&pardes.Term.emulatorOf(state).vt) != screenHash(&pardes.Term.emulatorOf(mine).vt)) {
totals.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at quiescence is not the authority's\n", .{ r.seed, r.rtt_ms, id, pid });
}
@@ -567,10 +577,10 @@ fn flushAll(sc: *replica.Screens, core: *pardes.Pardes, ps: []const u16, list: *
}
// Each version as the authority's screen showed it.
for (&sc.tracks, 0..) |*slot, id| if (slot.*) |*tr| {
- const key = @as(u64, tr.serial) << 32 | tr.track.version;
- if (tr.track.version == 0 or vs.contains(key)) continue;
+ const key = @as(u64, tr.serial) << 32 | trackOf(tr.track).version;
+ if (trackOf(tr.track).version == 0 or vs.contains(key)) continue;
_ = core.panes[id] orelse continue;
- try vs.put(gpa, key, screenHash(&tr.state.vt));
+ try vs.put(gpa, key, screenHash(&pardes.Term.emulatorOf(tr.state).vt));
};
}
@@ -976,7 +986,7 @@ const EchoTotals = struct {
};
fn cellCp(state: *pardes.Term.State, x: u16, y: u16) u21 {
- const ci = state.vt.screens.active.pages.getCell(.{ .active = .{ .x = x, .y = y } }) orelse return 0x10ffff;
+ const ci = pardes.Term.emulatorOf(state).vt.screens.active.pages.getCell(.{ .active = .{ .x = x, .y = y } }) orelse return 0x10ffff;
const cp = ci.cell.codepoint();
return if (cp == 0) ' ' else cp;
}
@@ -1071,7 +1081,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
for (made.items) |pr| {
const k = &typed.items[pr.seq - 1];
if (trace) {
- const sc = rp.core().panes[shell].?.terminal.?.vt.screens.active.cursor;
+ const sc = pardes.Term.emulatorOf(rp.core().panes[shell].?.terminal.?).vt.screens.active.cursor;
std.debug.print("{d} ms ({t}): key {d} predicted {any} cursor {d}; acked {d} wait {d} nd {d}; the screen's cursor {d},{d}\n", .{ m.at / 1000, m.kind, pr.seq, pr.cell, pr.cursor.x, rp.echo.acked, rp.echo.wait, rp.echo.nd, sc.x, sc.y });
}
if (pr.cell) |cell| k.pred = .{ .x = cell.x, .y = @intCast(cell.row - top), .cp = cell.cp };
@@ -1106,7 +1116,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
const state = a.core.panes[shell].?.terminal.?;
if (ty) |k| {
k.mode = sh.mode;
- k.version_before = if (screens.tracks[shell]) |*tr| tr.track.version else 0;
+ k.version_before = if (screens.tracks[shell]) |*tr| trackOf(tr.track).version else 0;
}
sh.key(m.bytes);
if (sh.out.items.len > 0) {
@@ -1115,7 +1125,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
if (ty) |k| k.echoed = true;
}
if (ty) |k| {
- const cur = state.vt.screens.active.cursor;
+ const cur = pardes.Term.emulatorOf(state).vt.screens.active.cursor;
k.after = .{ .x = @intCast(cur.x), .y = @intCast(cur.y), .row = undefined };
for (&k.after.?.row, 0..) |*cp, x| cp.* = cellCp(state, @intCast(x), @intCast(cur.y));
judgeTruth(k);
@@ -1157,11 +1167,11 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
k.first_visible = m.at;
if (trace) {
const st = core.panes[shell].?.terminal.?;
- std.debug.print("{d} ms: key {d} ('{u}') drawn: trusted {} doubt {} phase {t} sem {t}\n", .{ m.at / 1000, cell.seq, cell.cp, rp.echo.trusted, rp.echo.doubt, st.stream.handler.phase, st.vt.screens.active.cursor.semantic_content });
+ std.debug.print("{d} ms: key {d} ('{u}') drawn: trusted {} doubt {} phase {t} sem {t}\n", .{ m.at / 1000, cell.seq, cell.cp, rp.echo.trusted, rp.echo.doubt, pardes.Term.emulatorOf(st).stream.handler.phase, pardes.Term.emulatorOf(st).vt.screens.active.cursor.semantic_content });
}
}
};
- const applied = if (rp.screens[shell]) |sc| sc.rep.seq else 0;
+ const applied = if (rp.screens[shell]) |sc| replicaOf(sc.rep).seq else 0;
for (typed.items) |*k| if (k.echoed and k.seen == null and applied > k.version_before) {
k.seen = m.at;
};
@@ -1178,8 +1188,8 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
const pane = m.bytes[0];
if (reply[5] == 1) {
const sc = rp.screens[pane].?;
- if (versions.get(@as(u64, sc.serial) << 32 | sc.rep.seq)) |want| {
- if (want != screenHash(&rp.core().panes[pane].?.terminal.?.vt)) t.screens_wrong += 1;
+ if (versions.get(@as(u64, sc.serial) << 32 | replicaOf(sc.rep).seq)) |want| {
+ if (want != screenHash(&pardes.Term.emulatorOf(rp.core().panes[pane].?.terminal.?).vt)) t.screens_wrong += 1;
} else t.screens_wrong += 1;
}
try push(&queue, &n, .{ .at = up[0].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_up, .who = 1, .bytes = try gpa.dupe(u8, reply) });
@@ -1238,7 +1248,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
et.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: the replica at quiescence: {s}\n", .{ seed, rtt_ms, if (rp.quiet()) "another digest" else "inputs still pending" });
}
- if (screenHash(&a.core.panes[shell].?.terminal.?.vt) != screenHash(&rp.core().panes[shell].?.terminal.?.vt)) {
+ if (screenHash(&pardes.Term.emulatorOf(a.core.panes[shell].?.terminal.?).vt) != screenHash(&pardes.Term.emulatorOf(rp.core().panes[shell].?.terminal.?).vt)) {
et.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: the shell at quiescence is not the authority's\n", .{ seed, rtt_ms });
}