summaryrefslogtreecommitdiff
path: root/test/behaviour/addons.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 03:03:20 -0300
committerGabriel Schneider <[email protected]>2026-11-26 03:03:25 -0300
commit280306ed779368d7e20e9678eca45e4b81e0ccbf (patch)
tree9278534f32a3724b289761594ca658cb6549b227 /test/behaviour/addons.zig
parent1ce3bcb6178b720058518a12e45f25769be7d39c (diff)
downloadpardes-280306ed779368d7e20e9678eca45e4b81e0ccbf.tar.gz
pardes-280306ed779368d7e20e9678eca45e4b81e0ccbf.zip
Pick, Kind, look, draw, mouse: a picker previews a file an addon's kind takes through that kind in the pane it lands in, a binary no kind takes as one line naming it, and Enter on such a row lands as a Look does, never the file's bytes as text (the user: "the file preview wasn't working for images (maybe pdfs too? Didn't test)", "It should be a generic logic for addons btw, and I saw the bytes rendered as ascii"; the coordinator's W7 under SPEC principle 2); REPRODUCED with the installed build (install74, the S kit, 26 px): SPC f f from a reading main.zig, the cursor on photo.png left main.zig in the body (the previous row's file), on paper.pdf showed `%PDF-1.7 %âãÏÓ 1 0 obj …` as text (a PDF has no NUL in its first 8000 bytes, so Pick.preview's binary guard let it through), and Enter on photo.png put `�PNG … IHDR …` in the reading pane: THE BYTES-AS-TEXT PATH the user saw: Pick.land → look.open → walk → Trail.step → Trail.show → File.open, which reads any path as a text (look.resolve sends a typed or clicked `photo.png` to Kind.openFile, but look.open, every jump's way, had no kind route); THE FIX: look.open routes a path a kind takes (`kinds.forPath`, the routing resolve uses) to openKind, lookAt's kind branch made a function (the pane of it focused, else opened and placed as a Look places it), so a picker's Enter, the Walk queue and a held pane's step land as a Look; Find's row of a kind's file is the file whole (a place in it is its kind's address: line 1 made the image refuse it); Pick.preview: a file a kind takes is shown by a slot of that kind over the landing pane's text (Kind.newSlot, split from Kind.open; Pick.showKind), which stays under it unseen until the next row or the roll-up closes the slot (putBack, restore: Esc exact, nothing left), no per-kind code; any other file with a NUL is one read-only line, `blob.bin · binary · 3.0 kB` (Pick.nameLine); until the kind draws (its paint places nothing yet) the body shows `photo.png · image · 24.8 kB` (draw.zig; Kind.draw says whether it painted); a refused one is that line with its kind's why; the kind does its own work as for its pane (the image decoded on a worker); only the row the cursor rests on at a frame opens (the preview's existing tick rule), and a draw of a row passed by is dropped when it lands (Kind.Slot.drawn_from: this process's draw count when the slot was made; Kind.deliver drops older answers, which went to the next slot of the same kind on the same pane); a previewed kind says, looks at, runs and lists nothing (Kind.Call.end returns before them while Pick.previewing) and takes no mouse (mouse.kindMouse); RUN (TEST FIRST): test/behaviour/addons.zig, four tests through 9P with the fake addon (addons/fake: no kind code in Pick) and the image addon, and addons_pdf.zig one with the pdf addon: a `.fake` file previews as the fake's paint (`count 7`) and not its bytes, Esc puts the screen and /index back, Enter opens the fake's pane with the reading pane's text kept; blob.bin's one line, never other.txt's text after it, a kind's paint after the binary's; three pictures, two rows down with no frame between: one draw held per rested row (2, not 3), and the rested picture shown after the passed one's answer came last; Enter on a picture opens the image pane, the reading pane `the notes`; a PDF's pages as pictures in the landing pane, none after Esc; Session.tick (a host frame) added, as previews wait for the frame after the key; on the base they fail (the bytes `1234567` shown, no line, no image pane, `%PDF` on the screen): core-test 1128/1301 (173 skipped; the kept_out list names Kind.Slot's drawn_from and size), shell-test 1349/1352 (3 skipped), pane-test 183/184, behaviour-test 285/285 (+5) and --replay 285/285, process-test 0 of 147 failed (3 skipped), term-test 17/17, kitty-test 45/45; the gui unit-test on the stack's top (W8); no dump change (the two Slot fields are local, out of the digest and the dump); the S kit with this change's Debug gui at 26 px: the PNG and 9p.pdf previewing in the landing pane, blob.bin's line, Enter on photo.png an `img` pane with main.zig kept (.scratch/walkui/W78/png a02-a05, before r03 r05); no frame or perf gate (the user's rule of 2026-11-26); load 3.7 to 10
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'test/behaviour/addons.zig')
-rw-r--r--test/behaviour/addons.zig146
1 files changed, 146 insertions, 0 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index ce3c7b02..25b1e523 100644
--- a/test/behaviour/addons.zig
+++ b/test/behaviour/addons.zig
@@ -371,3 +371,149 @@ test "addons: an image pane whose file changes on disk shows the new picture, un
try std.testing.expectEqual(n, try s.focused());
try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,3,1]"));
}
+
+/// A tmp directory's real path, kept in the session's arena.
+fn dirOf(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ var buf: [4096]u8 = undefined;
+ return s.arena.allocator().dupe(u8, buf[0..try tmp.dir.realPath(std.testing.io, &buf)]);
+}
+
+test "addons: a picker shows a file of an addon's kind through its kind in the pane it lands in, Esc puts that pane back as it was, and Enter lands as a Look does" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try load(&s, fake.ok);
+ defer unload(&s, "fake");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ const body = s.at("/pane/{d}/body", .{pane});
+ const a = s.arena.allocator();
+ const screen = try a.dupe(u8, try s.screen());
+ const index = try a.dupe(u8, try s.read("/index"));
+ // Its kind's paint in the reading pane's body (the fake counts the
+ // file's 7 bytes), not the pane's own text, nor the file's bytes.
+ try s.keys(" ffseven");
+ s.tick();
+ const shown = try s.screen();
+ try std.testing.expect(has(shown, "count 7"));
+ try std.testing.expect(!has(shown, "the notes") and !has(shown, "1234567"));
+ // Esc: the pane exactly as it was, and no pane more or less.
+ try s.keys("\x1b");
+ s.tick();
+ // (The notice row says the Find ran: the session's, not the pane's.)
+ const after = try s.screen();
+ try std.testing.expectEqualStrings(screen[0..std.mem.lastIndexOfScalar(u8, screen, '\n').?], after[0..std.mem.lastIndexOfScalar(u8, after, '\n').?]);
+ try s.expect(body, "the notes\n");
+ try std.testing.expectEqualStrings(index, try s.read("/index"));
+ // Enter: the kind's pane where a Look puts it; the reading pane keeps
+ // its text.
+ try s.keys(" ffseven\n");
+ s.tick();
+ const opened = try paneOf(&s, "fake");
+ try std.testing.expect(opened != pane);
+ try s.expect(body, "the notes\n");
+ try std.testing.expect(has(try s.screen(), "count 7"));
+}
+
+test "addons: a picker's row of a file no kind takes and not text shows one line naming it, and the row before's file never stays in the body" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.txt", .data = "other text\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" });
+ var blob: [3000]u8 = undefined;
+ for (&blob, 0..) |*b, i| b.* = @truncate(i *% 7);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "blob.bin", .data = &blob });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try load(&s, fake.ok);
+ defer unload(&s, "fake");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ try s.keys(" ffother");
+ s.tick();
+ try std.testing.expect(has(try s.screen(), "other text"));
+ // Onto the binary: its one line, never its bytes, nor other.txt.
+ try s.keys("\x08\x08\x08\x08\x08blob");
+ s.tick();
+ var shown = try s.screen();
+ try std.testing.expect(has(shown, "blob.bin · binary · 3.0 kB"));
+ try std.testing.expect(!has(shown, "other text"));
+ // Onto a kind's file: its kind's paint, not the binary's line.
+ try s.keys("\x08\x08\x08\x08seven");
+ s.tick();
+ shown = try s.screen();
+ try std.testing.expect(has(shown, "count 7"));
+ try std.testing.expect(!has(shown, "blob.bin · binary"));
+ // Back onto text, then Esc: the pane's own.
+ try s.keys("\x08\x08\x08\x08\x08other");
+ s.tick();
+ shown = try s.screen();
+ try std.testing.expect(has(shown, "other text") and !has(shown, "count 7"));
+ try s.keys("\x1b");
+ s.tick();
+ try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n");
+ try std.testing.expect(has(try s.screen(), "the notes"));
+}
+
+test "addons: moving the cursor over pictures in a picker draws only the one it rests on, and a draw of one passed by is dropped whenever it comes back" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const png = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\xc9\xfe\x92\xef\x00\x00\x00\x00IEND\xaeB`\x82";
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic1.png", .data = png });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic2.png", .data = png });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic3.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ try load(&s, Session.image_addon);
+ defer unload(&s, "image");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ s.holdJobs();
+ try s.keys(" ffpic");
+ s.tick();
+ // Until its picture is drawn, one line names it.
+ const first = try s.screen();
+ try std.testing.expect(has(first, " · image · "));
+ try std.testing.expectEqual(1, s.held.items.len);
+ // Two rows down with no frame between: only the row it rests on draws.
+ try s.keys("\u{F800}\u{F800}");
+ s.tick();
+ _ = try s.screen();
+ try std.testing.expectEqual(2, s.held.items.len);
+ const rested = if (has(try s.screen(), "▶ pic3.ppm")) "\"src\":[0,0,2,1]" else "\"src\":[0,0,1,1]";
+ const passed = if (std.mem.eql(u8, rested, "\"src\":[0,0,2,1]")) "\"src\":[0,0,1,1]" else "\"src\":[0,0,2,1]";
+ // The rested one's answer first, the passed one's after: dropped.
+ std.mem.reverse(@TypeOf(s.held.items[0]), s.held.items);
+ s.releaseJobs();
+ const screen = try s.read("/screen");
+ try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{pane})) and has(screen, rested));
+ try std.testing.expect(!has(screen, passed));
+}
+
+test "addons: Enter on a picture in a picker opens its kind's pane, never its bytes as text in the reading pane (the user's report)" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ try load(&s, Session.image_addon);
+ defer unload(&s, "image");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ try s.keys(" ffpic\n");
+ s.tick();
+ try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n");
+ const image = try paneOf(&s, "image");
+ try std.testing.expect(image != pane);
+ const screen = try s.read("/screen");
+ try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{image})) and has(screen, "\"src\":[0,0,2,1]"));
+ try std.testing.expect(!has(try s.screen(), "1 P6"));
+}