From 2ddd5bcbe8d470c00b045af5822418fe429357bc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 15:58:05 -0300 Subject: kinds #37, tests and docs for ABI 3: the image dump tests reopen from the path (through the same /n/os mount, and a file gone waits saying so until a watch or a Look opens it), the PDF view tests assert the art words in every view and each view told, /addons says 3.0 and a 2.2 fake is refused, reference.typ's Addons section and the changelog say ABI 3 Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/addons.zig | 29 +++++++++++++------ test/behaviour/addons_pdf.zig | 2 +- test/fs_namespace.zig | 16 +++++++---- test/panes.zig | 65 ++++++++++++++++++++++++++----------------- test/pdf_scroll_bench.zig | 2 +- 5 files changed, 72 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index b64a6974..3a53766a 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -37,7 +37,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com defer unload(&s, "fake"); // ` `. const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 2.2 0 /")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.0 0 /")); var fields = std.mem.tokenizeScalar(u8, listed[0..std.mem.indexOfScalar(u8, listed, '\n').?], ' '); for (0..5) |_| _ = fields.next(); try std.testing.expectEqual(@as(usize, 64), fields.next().?.len); @@ -51,7 +51,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com // A pane of it open, it stays; closed, it goes. try s.write("/ctl", "Fake\n"); const pane = try paneOf(&s, "fake"); - try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 2.2 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.0 1 /")); try std.testing.expect(try s.refused("/ctl", "Addon unload fake\n") != 0); try std.testing.expect(has(s.said, "1 fake pane is open")); try s.write(s.at("/pane/{d}/ctl", .{pane}), "Del\n"); @@ -65,10 +65,10 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose defer s.deinit(); for ([_][]const u8{ fake.abi, fake.no_export, fake.core_word }) |path| try load(&s, path); const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 3.0 0 /")); - try std.testing.expect(has(listed, " refused: wants abi 3, this pardes speaks 2\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 2.2 0 /")); + try std.testing.expect(has(listed, " refused: wants abi 2, this pardes speaks 3\n")); try std.testing.expect(has(listed, " refused: it has no pardes_addon\n")); - try std.testing.expect(has(listed, "\nfakeword 1 2.2 0 /")); + try std.testing.expect(has(listed, "\nfakeword 1 3.0 0 /")); try std.testing.expect(has(listed, " refused: word Save is the core's\n")); // A file that is no library at all: listed with what the loader said. var tmp = std.testing.tmpDir(.{}); @@ -115,12 +115,12 @@ test "addons: a pane of an addon's kind shows its cells and its picture, takes i try std.testing.expect(try s.focused() != pane); } -test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and keeps a picture's bytes through a dump" { +test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and a dump's pane reads its file again" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try load(&s, Session.image_addon); const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 2.2 0 /") and has(listed, " loaded\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.0 0 /") and has(listed, " loaded\n")); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var buf: [4096]u8 = undefined; @@ -134,6 +134,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the .{ "red.jpeg", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wgARCAAIABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAVAQEBAAAAAAAAAAAAAAAAAAAGCP/aAAwDAQACEAMQAAABkIC1V//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAQUCP//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEABj8CP//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8hP//aAAwDAQACAAMAAAAQA//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8QP//Z", 16, 8 }, .{ "pixel.ppm", "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7", 2, 1 }, }; + var red: []const u8 = ""; for (pictures) |pic| { const bytes = if (std.mem.endsWith(u8, pic[0], ".ppm")) pic[1] else blk: { const out = try s.arena.allocator().alloc(u8, try b64.calcSizeForSlice(pic[1])); @@ -141,6 +142,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the break :blk out; }; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = pic[0], .data = bytes }); + if (red.len == 0) red = bytes; try s.write("/look", s.at("{s}/{s}\n", .{ dir, pic[0] })); try std.testing.expect(has(try s.read("/screen"), s.at("\"serial\":{d},\"rect\":", .{try s.focused()}))); try std.testing.expect(has(try s.read("/screen"), s.at("\"src\":[0,0,{d},{d}]", .{ pic[2], pic[3] }))); @@ -160,8 +162,8 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the try std.testing.expect(try s.refused("/look", s.at("{s}/bad.png\n", .{dir})) != 0); try std.testing.expect(has(s.said, "bad.png: not an image pardes can read")); try std.testing.expectEqual(panes, (try s.read("/index")).len); - // Its record is the file's bytes: restored without the addon it waits - // as a placeholder holding them, and shows them again when it comes. + // A dump keeps its path, not its bytes: restored without the addon it + // waits as a placeholder, and reads its file again when the addon comes. try s.write("/ctl", "Dump\n"); const label = try s.arena.allocator().dupe(u8, std.mem.sliceTo(try s.read("/dumps"), ' ')); var lines = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); @@ -172,6 +174,15 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the try load(&s, Session.image_addon); defer unload(&s, "image"); try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]")); + // Its file gone, a restore waits saying so; back, a Look of it opens it. + try tmp.dir.deleteFile(std.testing.io, "red.png"); + try s.write("/ctl", s.at("Restore {s}\n", .{label})); + const said = s.at("{s}/red.png is not here", .{dir}); + try std.testing.expect(has(try s.screen(), said[0..@min(said.len, 40)])); + try std.testing.expect(!has(try s.read("/screen"), "\"src\":[0,0,4,2]")); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "red.png", .data = red }); + try s.write("/look", s.at("{s}/red.png\n", .{dir})); + try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]")); } test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused naming one not loaded, and with its kind gone the look falls through to text" { diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index 60379457..7b92b84c 100644 --- a/test/behaviour/addons_pdf.zig +++ b/test/behaviour/addons_pdf.zig @@ -38,7 +38,7 @@ test "addons: a PDF is the pdf addon's pane, its pages pictures, its page in its s.graphics(); const n = try s.lookFile("docs/design.pdf"); try std.testing.expect(has(try s.read("/index"), " pdf ")); - try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 2.2 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 3.0 1 /")); const pages = (try s.pdfPage(n))[1]; try std.testing.expectEqual(@as(u32, 16), pages); // Its first page, a picture over its body. diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig index 22ce27fe..fa6657eb 100644 --- a/test/fs_namespace.zig +++ b/test/fs_namespace.zig @@ -285,7 +285,7 @@ test "owned cwd failed file opens never publish a pane or retain a reservation" try std.testing.expect(succeeded); } -test "images decode through explicit filesystem mounts, and a dump reads one on disk from there" { +test "images decode through explicit filesystem mounts, and a dump's pane reads its file again through the same mount" { if (!filesystem.platform_has_fs) return error.SkipZigTest; const gpa = std.testing.allocator; var tmp = std.testing.tmpDir(.{}); @@ -310,13 +310,19 @@ test "images decode through explicit filesystem mounts, and a dump reads one on try std.testing.expectEqual(@as(usize, 1), shown.len); try std.testing.expectEqual(@as(u32, 1), shown[0].raster.w); try std.testing.expectEqual(@as(u32, 1), shown[0].raster.h); - // The picture's bytes are in the dump: it comes back as it was shown - // (a placeholder holding them, as a core without the addon keeps it). + // The dump keeps its path, not its bytes: restored, it reads the file + // again through the mount its path names, and shows the same pixel. try pardes.dump.dumpState(p); - const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?); + var words: [64]pardes.Kind.LoadedWord = undefined; + const k = p.kinds.byName("image").?; + const brought = [_]pardes.Kind.Loaded{pardes.Kind.loadedOf(p.kinds.ops[k].?, p.kinds.kinds[k].path.slice(), p.kinds.kinds[k].hash, &words)}; + const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?); defer restored.deinit(); const slot = for (restored.panes) |pane| { if (pane) |each| if (each.addon) |s| break s; } else return error.NoImagePane; - try std.testing.expectEqualStrings(bytes, slot.record.?); + try std.testing.expect(slot.record == null and slot.live and std.mem.eql(u8, slot.path, path)); + while (restored.nextEffect()) |e| if (e == .job) restored.perform(e); + _ = try restored.render(arena.allocator()); + try std.testing.expectEqual(@as(u32, 1), restored.surface.placements.items[0].raster.w); } diff --git a/test/panes.zig b/test/panes.zig index d1c8af02..28256495 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2266,16 +2266,22 @@ const ImageTests = struct { try std.testing.expectEqualStrings("img petscii:on palette:terminal ascii:off /tmp/picture.ppm", try pardes.tagline.tagPrefix(p, pane)); } - test "an image's dump keeps its file's bytes, its renderer choices and its tag's tail" { + test "an image's dump keeps its path, its renderer choices and its tag's tail, and reopens from the file; a file gone waits as a placeholder saying so" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); try pardes.panes.deinitPane(p, p.panes[0].?); p.panes[0] = null; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); const source = "P6\n1 1\n255\n\x0d\x4d\xe7"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "restored-image.ppm", .data = source }); + var dir_buf: [4096]u8 = undefined; + const file = try std.fmt.allocPrint(gpa, "{s}/restored-image.ppm", .{dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]}); + defer gpa.free(file); const k = load(p); - const pane = try pardes.Kind.open(p, 0, k, "/missing/restored-image.ppm", source); + const pane = try pardes.Kind.open(p, 0, k, file, source); pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false }; if (pane.tag.own) |own| p.gpa.free(own); pane.tag.own = try p.gpa.dupe(u8, " Keep Del"); @@ -2294,16 +2300,21 @@ const ImageTests = struct { try std.testing.expect(!art.ascii); try std.testing.expect(restored_pane.tag.own != null); try std.testing.expectEqualStrings(" Keep Del", pardes.tagline.curTail(restored_pane)); - var kept: [64]u8 = undefined; + // No record: opened from its file, as a Look reads it. const slot = restored_pane.addon.?; - try std.testing.expectEqualSlices(u8, source, kept[0..slot.ops.?.dump.?(slot.st, &kept, kept.len)]); - - // And dumped again, its bytes still there. - try dump.dumpState(restored); - const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null); - defer again.deinit(); - // Loaded as a replica loads it: a placeholder holding the record. - try std.testing.expectEqualSlices(u8, source, again.panes[0].?.addon.?.record.?); + try std.testing.expect(slot.record == null and slot.live); + try std.testing.expectEqual(std.hash.Wyhash.hash(0, source), slot.opened); + + // Its file gone, a restore waits saying so; back, a watch opens it. + try tmp.dir.deleteFile(std.testing.io, "restored-image.ppm"); + const gone = try dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?); + defer gone.deinit(); + const waiting = gone.panes[0].?.addon.?; + try std.testing.expect(!waiting.live); + try std.testing.expect(std.mem.endsWith(u8, waiting.refused.slice(), "restored-image.ppm is not here")); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "restored-image.ppm", .data = source }); + try std.testing.expect(pardes.Kind.fileChanged(gone, 0, "")); + try std.testing.expect(waiting.live and waiting.refused.len == 0); } }; @@ -3917,7 +3928,7 @@ const PdfAddon = struct { try std.testing.expect(r.stats.stopped >= 1); } - test "the tag a step lays out for a PDF's pane is of the frame its tick left, not the frame before it" { + test "a PDF's tag has the core's art words from its first step, in a view without graphics and with them" { if (!addons.has_pdf) return error.SkipZigTest; const R = pardes.replica; const gpa = std.testing.allocator; @@ -3932,19 +3943,16 @@ const PdfAddon = struct { const land: Land = .{ .a = a }; const id = try opened(a, land); const slot = a.core.panes[id].?.addon.?; - // A view without graphics: the page's text layer, no picture. - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null); - // A window's: its tick lays the pages out as pictures and asks - // for them; the step their answers land in ticks it again, and its - // tag says what that tick placed, as the next step's will (a - // replica's guess of its next input is the tag this step laid out). + // A view without graphics: the page's text layer, its pictures' + // words glyph art's (PA_PICTURES: the kind's, not the frame's). + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null); + // A window's: the pages as pictures, the same words, its own. try land.step(.{ .frontend = .{ .windowed = true, .native_images = true } }); try jobs(a.core, land); - try std.testing.expect(slot.placed); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:off ") != null); } - test "a PDF's pane in a window's view and a terminal's in turn: each one's step lays its tag out as its frame shows it" { + test "a PDF's pane in a window's view and a terminal's in turn: each is told its view, its tag its page and art words in both" { if (!addons.has_pdf) return error.SkipZigTest; const R = pardes.replica; const gpa = std.testing.allocator; @@ -3973,15 +3981,19 @@ const PdfAddon = struct { defer win.deinit(); _ = try a.take(try win.input(.{ .frontend = .{ .windowed = true, .native_images = true } })); try jobs(a.core, land); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null); + // Both views told (by id, the session's 1 and the window's), each + // with its own frontend's facts. + try std.testing.expect(slot.views[0] != 0 and slot.views[k] != 0 and slot.views[0] != slot.views[k]); for (0..2) |_| { - // The terminal's key: its view's tick, the page's text layer. + // The terminal's key, the strip laid out for its view, and the + // window's: the same tag whichever view's step laid it out (the + // session's first view's art words, a terminal's: glyph art). _ = try a.take(try tty.input(.{ .key = .{ .cp = 'j', .text = "j" } })); try jobs(a.core, land); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null); - // The window's: the pages as pictures again, in its tag at once. + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null); _ = try a.take(try win.input(.{ .key = .{ .cp = 'j', .text = "j" } })); - try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null); try jobs(a.core, land); } } @@ -4013,6 +4025,7 @@ const PdfAddon = struct { // again, on the page it can still be on, as height-fitted. try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "live.pdf", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", p.scratch.allocator(), .unlimited) }); try std.testing.expect(p.reloadWatchedFile(@intCast(id), &.{})); + p.update(.tick); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); _ = try p.render(arena.allocator()); diff --git a/test/pdf_scroll_bench.zig b/test/pdf_scroll_bench.zig index 93067d03..58e7cfb0 100644 --- a/test/pdf_scroll_bench.zig +++ b/test/pdf_scroll_bench.zig @@ -228,7 +228,7 @@ fn probeTravel(config: Config) Travel { const slot = pdfPane(core).addon.?; if (slot.thumb_span <= 0) fatal("{s}: the strip never laid out", .{config.path}); // The strip is the window over the share of it shown. - const window_px = @as(f64, @floatFromInt(pardes.Kind.viewOf(core, core.view().active).rows)) * @as(f64, @floatFromInt(config.cell.h)); + const window_px = @as(f64, @floatFromInt(pardes.Kind.viewOf(core, core.live, core.view().active).rows)) * @as(f64, @floatFromInt(config.cell.h)); var pages: u32 = 0; const prefix = slot.prefix.slice(); if (std.mem.indexOfScalar(u8, prefix, '/')) |slash| pages = std.fmt.parseInt(u32, prefix[slash + 1 .. prefix.len - 1], 10) catch 0; -- cgit v1.3