summaryrefslogtreecommitdiff
path: root/src/addon_test.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 02:31:55 -0300
committerGabriel Schneider <[email protected]>2026-11-06 04:04:25 -0300
commit9c66cdc9049b49f128336dcf5046e2bb1321e281 (patch)
tree7ff664677eb7291558f71a8f824d0ce6a922779a /src/addon_test.zig
parenta6f294ef5b50aeb5b69e486838378654e318ed04 (diff)
downloadpardes-9c66cdc9049b49f128336dcf5046e2bb1321e281.tar.gz
pardes-9c66cdc9049b49f128336dcf5046e2bb1321e281.zip
kinds #5, ABI 2 and the seam: src/kinds/pardes_addon.h is ABI 2 as architecture §16.9 has it (pa_window 24 bytes and no art bytes, pa_placement 80 with at, from and dirty_y/dirty_h and no stride, pa_word 32 with no size and PA_WORD, tick(st, now_ns, flags) with PA_FOCUSED, PA_OK and the conventions, the dump and load rules, pa_put with attrs, pa_copy and PA_POD, whose fragment gcc -Werror refused as written and is ternaries here) and fake.c and image's table speak it; tick is called at its deadline and once after open, a taken key or click, a word, a job's answer, a load and a change of PA_FOCUSED (the pane has the keyboard in some view, its window focused), nextWake folds the deadlines, and a Debug build hashes the kind's allocations across paint and panics naming it; paint runs once a frame, the slot keeps its prefix and whether it placed a picture, the tag is that prefix, the core's art words when it did and the path, and a frame that changes it owes a step to lay the tag out again; Addon load and reload are an addon effect the host performs (memfd, BLAKE3, dlopen, the head checks and init, the bytes a process holds shared and counted) answered by an addon event carrying what the library brings as data, whose update does the collisions, the reload's validate-then-swap at a new generation and the waiting panes deterministically, while unload is the update's alone and lets the library go by effect; a kind's job is Effect.job run on the host's workers (host_io.KindJob: tui and gui on Io.concurrent, macOS and tests on the loop) answered by Event.job, stale generations dropped and a library closed after its last job; each core has its own Registry (16 kinds, their words, leaders and extensions, digested and dumped; their code a local side array a replica has none of), so a test session no longer unloads the world and Restore and -l keep the process's kinds; every call into a kind whose answer the core acts on is taped as an Outcome (its answer, refusal, message, Look, text pane) and the prefix a step reads is taped too, so a replica's core, which runs no kind's code, steps alike; a pane of a kind on a replica is a Shadow drawn from the authority's frames, painted for the peer's view and sent by Screens as row hashes with the rows that changed and each raster once a key (screen_state.Shadow), its keys going to the authority; the tail, reload and the Addon word and event are Addon.zig's, the slot's record dump.zig's, a tail word's run exec.zig's; --addon-test gains focus, blur, dump, body, ctl and the window line, its jobs done as a host does them; fake.out gains its window line, loses a body row once the tag carries the art words and lands FakeJob at once; tests rewritten: the image dump test (the replica-style load keeps the record), the Petscii/Palette/Ascii tag test in ctl.zig and test/panes.zig's image tag test (a picture decoded and shown first), fs_namespace's decode test (the job performed as a host would), Kind.zig's registry test and Addon.zig's crash-mark test, the addons suite's ABI numbers; new: a job under way across a reload (T1), a Shadow's frame codec, and a replica with no code for a kind showing its pane and passing its keys; gates: core-test 958/958 and behaviour-test 249/249 on both, unit-test 1490/1491 tui and 1533/1534 gui, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed on both, addon-test ok, hxdiff 19 and hxparity 6 mismatches by the base's names, hxgolf 0, replicas, gui-golden, monkey-gui, daemon.py main and window-clients, soak local pass, perf medium within 1% of the base
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/addon_test.zig')
-rw-r--r--src/addon_test.zig167
1 files changed, 109 insertions, 58 deletions
diff --git a/src/addon_test.zig b/src/addon_test.zig
index 496b7504..3cbb5a64 100644
--- a/src/addon_test.zig
+++ b/src/addon_test.zig
@@ -1,25 +1,30 @@
//! `pardes --addon-test <addon.so> <script>`: an addon's author's test.
//! The addon is loaded into a session of its own (80x24, no terminal, no
-//! disk, its jobs run at once, its clock virtual and moved by `tick` and
-//! `settle` alone), a pane of it opened, and the
-//! script's lines run in turn, each printed with the pane's cells and
-//! placements after it; a script compares the output with what it wants
-//! as a snapshot script does (`diff`).
+//! disk, its jobs run at once, its clock virtual, starting at 1 s and moved
+//! by `tick` and `settle` alone), a pane of it opened, and the script's
+//! lines run in turn, each printed with the pane's tag (the kind's own
+//! prefix), cells and placements after it; a script compares the output
+//! with what it wants as a snapshot script does (`diff`).
//!
//! open [path] a pane of the kind (the first step opens one bare)
//! key hjkl<up> keys, a character or <up> <down> <left> <right>
//! <enter> <tab> <bs> <esc> <space> each
//! tick 100 the clock 100 ms on, the kind's ticks run
-//! settle ticks until the kind asks for none (at most 1000)
-//! size 60 20 the session's cells, the pane's share of them
+//! settle ticks until the kind asks for none (at most 1000):
+//! a kind that asks for ticks while idle fails it
+//! size 60 20 the session's terminal, the pane's share of it
+//! (`window CxR` says what the kind paints)
//! seed 7 what every pane's seed is made from (before open)
//! click 3 1 a left click at the body's column 3, row 1
+//! focus, blur the window takes the keyboard, or loses it
+//! dump the pane's record (its length) loaded into a
+//! fresh pane, which the script goes on with
+//! body, ctl the pane's body, or its ctl file's read
//! Word arg one of the kind's words, at its pane
//! # anything a comment, not printed
const std = @import("std");
const pardes = @import("pardes.zig");
const Kind = @import("Kind.zig");
-const Addon = @import("Addon.zig");
const Pardes = pardes.Pardes;
pub fn main(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]const u8) u8 {
@@ -35,16 +40,8 @@ pub fn main(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[
}
fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]const u8, out: *std.Io.Writer) !void {
- Kind.inline_jobs = true;
- var why: Kind.Buf(160) = .{};
- if (!Addon.load(lib, &why)) {
- try out.print("addon-test: {s}\n", .{why.slice()});
- return error.KindRefused;
- }
- const ops = Kind.byName(why.slice()).?;
const script = try std.Io.Dir.cwd().readFileAlloc(io, script_path orelse return error.NoScript, gpa, .limited(1 << 20));
defer gpa.free(script);
-
// The regions and the C libraries' allocators a frontend sets up.
const allocs = pardes.memory.init(gpa);
defer pardes.memory.deinit();
@@ -54,6 +51,14 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
defer pardes.syntax.stop();
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory, .image_allocator = allocs.image, .pdf_allocator = allocs.pdf, .tree_sitter_allocator = allocs.tree_sitter, .frame_allocator = allocs.frame });
defer p.deinit();
+ // Loaded as `Addon load` loads it, the host's half here.
+ pardes.Addon.perform(p, .load, 0, lib);
+ const last = &p.kinds.kinds[p.kinds.n - 1];
+ if (last.refused) {
+ try out.print("addon-test: {s}\n", .{last.why.slice()});
+ return error.KindRefused;
+ }
+ const k = p.kinds.n - 1;
var now: u64 = std.time.ns_per_s;
p.advance(now);
var id: ?usize = null;
@@ -65,58 +70,97 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
const verb_end = std.mem.indexOfScalar(u8, line, ' ') orelse line.len;
const verb = line[0..verb_end];
const arg = std.mem.trim(u8, line[verb_end..], " ");
- if (std.mem.eql(u8, verb, "seed")) {
+ const is = struct {
+ fn is(v: []const u8, w: []const u8) bool {
+ return std.mem.eql(u8, v, w);
+ }
+ }.is;
+ if (is(verb, "seed")) {
Kind.seed_base = std.fmt.parseInt(u64, arg, 10) catch 0;
- } else if (std.mem.eql(u8, verb, "open")) {
- id = try open(p, ops, if (arg.len > 0) arg else null);
- } else {
- if (id == null) id = try open(p, ops, null);
- const at = id.?;
- if (std.mem.eql(u8, verb, "key")) {
- try keys(p, arg);
- } else if (std.mem.eql(u8, verb, "tick")) {
- now += (std.fmt.parseInt(u64, arg, 10) catch 0) * std.time.ns_per_ms;
+ continue;
+ }
+ const opened = id == null or is(verb, "open");
+ if (opened) id = try open(p, k, if (is(verb, "open") and arg.len > 0) arg else null);
+ const at = id.?;
+ if (is(verb, "key")) {
+ try keys(p, arg);
+ } else if (is(verb, "tick")) {
+ now += (std.fmt.parseInt(u64, arg, 10) catch 0) * std.time.ns_per_ms;
+ p.advance(now);
+ } else if (is(verb, "settle")) {
+ var n: usize = 0;
+ while (Kind.wake(p) != null and n < 1000) : (n += 1) {
+ now = @max(now + 1, p.nextWake() orelse break);
p.advance(now);
- } else if (std.mem.eql(u8, verb, "settle")) {
- var n: usize = 0;
- while (pardes.Kind.wake(p) != null and n < 1000) : (n += 1) {
- now = @max(now + 1, p.nextWake() orelse break);
- p.advance(now);
- }
- if (n == 1000) try out.writeAll("settle: still asking for frames after 1000 ticks\n");
- } else if (std.mem.eql(u8, verb, "size")) {
- var it = std.mem.tokenizeScalar(u8, arg, ' ');
- const cols = std.fmt.parseInt(u16, it.next() orelse "80", 10) catch 80;
- const rows = std.fmt.parseInt(u16, it.next() orelse "24", 10) catch 24;
- p.update(.{ .resize = .{ .cols = cols, .rows = rows } });
- } else if (std.mem.eql(u8, verb, "click")) {
- var it = std.mem.tokenizeScalar(u8, arg, ' ');
- const col = std.fmt.parseInt(u16, it.next() orelse "0", 10) catch 0;
- const row = std.fmt.parseInt(u16, it.next() orelse "0", 10) catch 0;
- const body = bodyRect(p, at) orelse continue;
- for ([_]pardes.Mouse.Kind{ .press, .release }) |k|
- p.update(.{ .mouse = .{ .button = .left, .kind = k, .col = body.x + col, .row = body.y + row } });
- } else {
- p.active = at;
- if (!p.executeBuiltinLine(at, line)) try out.print("not a word here: {s}\n", .{verb});
}
+ if (n == 1000) try out.writeAll("settle: still asking for frames after 1000 ticks\n");
+ } else if (is(verb, "size")) {
+ var it = std.mem.tokenizeScalar(u8, arg, ' ');
+ const cols = std.fmt.parseInt(u16, it.next() orelse "80", 10) catch 80;
+ const rows = std.fmt.parseInt(u16, it.next() orelse "24", 10) catch 24;
+ p.update(.{ .resize = .{ .cols = cols, .rows = rows } });
+ } else if (is(verb, "click")) {
+ var it = std.mem.tokenizeScalar(u8, arg, ' ');
+ const col = std.fmt.parseInt(u16, it.next() orelse "0", 10) catch 0;
+ const row = std.fmt.parseInt(u16, it.next() orelse "0", 10) catch 0;
+ const body = window(p, at) orelse continue;
+ for ([_]pardes.Mouse.Kind{ .press, .release }) |mk|
+ p.update(.{ .mouse = .{ .button = .left, .kind = mk, .col = body.x + col, .row = body.y + row } });
+ } else if (is(verb, "focus") or is(verb, "blur")) {
+ p.update(.{ .focus = is(verb, "focus") });
+ } else if (is(verb, "dump")) {
+ id = try reloaded(p, gpa, at, out);
+ } else if (is(verb, "body") or is(verb, "ctl")) {
+ drain(p);
+ var fields: [4096]u8 = undefined;
+ const text = if (is(verb, "body")) try Kind.body(p.panes[at].?, p.scratch.allocator()) else Kind.ctlRead(p.panes[at].?, &fields);
+ var rows = std.mem.splitScalar(u8, std.mem.trimEnd(u8, text, "\n"), '\n');
+ while (rows.next()) |row| try out.print("={s}\n", .{row});
+ continue;
+ } else if (!is(verb, "open")) {
+ p.active = at;
+ if (!p.executeBuiltinLine(at, line)) try out.print("not a word here: {s}\n", .{verb});
}
drain(p);
- if (id) |at| try show(p, gpa, at, out);
+ try show(p, gpa, id.?, out, opened or is(verb, "size"));
}
}
-fn open(p: *Pardes, ops: *const Kind.Ops, path: ?[]const u8) !usize {
+fn open(p: *Pardes, k: u8, path: ?[]const u8) !usize {
const free = p.freeSlot() orelse return error.NoPaneSlots;
- _ = if (path) |at| try Kind.openFile(p, free, ops, at) else try Kind.open(p, free, ops, null, null);
+ _ = if (path) |at| try Kind.openFile(p, free, k, at) else try Kind.open(p, free, k, null, null);
pardes.exec.placeNew(p, p.active, null, free, .doc);
p.active = free;
drain(p);
return free;
}
+/// The pane's record loaded into a fresh pane in its place, as a Restore
+/// would: what the script goes on with.
+fn reloaded(p: *Pardes, gpa: std.mem.Allocator, at: usize, out: *std.Io.Writer) !usize {
+ const slot = p.panes[at].?.addon.?;
+ const record = try pardes.dump.slotRecord(slot);
+ defer if (record) |r| slot.gpa.free(r);
+ try out.print("dump {d} bytes\n", .{if (record) |r| r.len else 0});
+ var bytes: std.Io.Writer.Allocating = .init(gpa);
+ defer bytes.deinit();
+ try pardes.dump.slotWrite(slot, gpa, &bytes.writer);
+ const fresh = try slot.gpa.create(Kind.Slot);
+ try pardes.dump.slotRead(fresh, slot.gpa, bytes.written());
+ try p.removePane(at, null);
+ const free = p.freeSlot() orelse return error.NoPaneSlots;
+ const pane = try p.newDocPane(free);
+ pane.addon = fresh;
+ pardes.dump.reviveSlot(p, free, fresh);
+ pardes.exec.placeNew(p, p.active, null, free, .doc);
+ p.active = free;
+ drain(p);
+ return free;
+}
+
+/// Its effects done as a host does them: its jobs here, at once.
fn drain(p: *Pardes) void {
- while (p.nextEffect()) |_| {}
+ while (p.nextEffect()) |e| if (e == .job) p.perform(e);
}
fn keys(p: *Pardes, text: []const u8) !void {
@@ -140,25 +184,32 @@ fn keys(p: *Pardes, text: []const u8) !void {
break :blk c;
};
p.update(.{ .key = .{ .cp = cp } });
+ drain(p);
}
}
-fn bodyRect(p: *Pardes, id: usize) ?pardes.Rect {
+/// The cells the kind paints: its body less the notices over it.
+fn window(p: *Pardes, id: usize) ?pardes.Rect {
var arena: std.heap.ArenaAllocator = .init(p.gpa);
defer arena.deinit();
const s = p.render(arena.allocator()) catch return null;
- const r = s.region(.body, id) orelse return null;
- return r.rect;
+ var r = (s.region(.body, id) orelse return null).rect;
+ const shown = p.panes[id].?.notices.span();
+ r.y += shown;
+ r.h -|= shown;
+ return r;
}
/// The pane's body, a line a row (an unpainted cell a space), then each
-/// placement over it.
-fn show(p: *Pardes, gpa: std.mem.Allocator, id: usize, out: *std.Io.Writer) !void {
+/// placement over it; `window CxR` first when asked.
+fn show(p: *Pardes, gpa: std.mem.Allocator, id: usize, out: *std.Io.Writer, size: bool) !void {
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const s = try p.render(arena.allocator());
const pane = p.panes[id] orelse return out.writeAll("(the pane is gone)\n");
- try out.print("tag {s}\n", .{try pardes.tagline.tagPrefix(p, pane)});
+ const slot = pane.addon.?;
+ if (size) if (window(p, id)) |w| try out.print("window {d}x{d}\n", .{ w.w, w.h });
+ try out.print("tag {s}\n", .{if (slot.prefix.len > 0) slot.prefix.slice() else slot.nameOf()});
const r = (s.region(.body, id) orelse return).rect;
for (r.y..r.y + r.h) |y| {
var row: std.ArrayList(u8) = .empty;