summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 14:11:56 -0300
committerGabriel Schneider <[email protected]>2026-11-05 19:16:19 -0300
commit4e096f6dc6db043caa630514fa75bd18438cb15b (patch)
tree2628101ed3a7e432030918b019935e47240b1c64 /test
parent38d21b0cb34ef1f555e5bda8155150bda9bfbaee (diff)
downloadpardes-4e096f6dc6db043caa630514fa75bd18438cb15b.tar.gz
pardes-4e096f6dc6db043caa630514fa75bd18438cb15b.zip
store: Recent is a value of the user's state file, `pardes.xitdb` in the DumpDir (src/Db.zig: the xitdb database the architecture's §14 puts everything pardes keeps on disk in), which every session shares: read at a session's start (now after the startup config, whose DumpDir says where the file is) and again on use when the file's committed size has moved, written at the end of a step that changed it in one transaction under the file's lock, taken without waiting (busy, the next step tries again), another session's commit read and merged under this one's changes first; not fsynced, as the `recent` file was not (a xitdb commit costs 20 us without fsync and 5.2 ms with its two on this btrfs); a file there that is no database of pardes's is kept aside as `pardes.xitdb.broken` and a new one started; Store.zig keeps the closed panes alone (its file half goes: the path and its inode/size/mtime stamp, load, refresh, read, flush and write, and W4's one-time read of the old `store`, which comes back with the migration), Options.recent_path becomes Options.state (off, disk, memory), main.recentPath goes, a Restore's new core takes the old one's database, and the test host's sessions keep theirs in a `.memory` database, the same code; measured (Debug, 200 files listed): flush after an open 133-135 us (W4's file: 124), refresh after another session's write 239-247 us (198), refresh with nothing new 3 us (1), a session started on it 1144-1194 us (1214), and a Recent change adds 12,325 bytes to the file (its 12,089 bytes of lines and 236 of xitdb's); tests: Store.zig's four Recent tests become Db.zig's three (two windows sharing Recent through a busy lock, the newest 200, a file that is no database kept aside; the old store's migration test goes with that read), the closed-pane test keeps its second window on a state file in its DumpDir, the behaviour suite gains 'two sessions on one state file share Recent', and the process tests and the canary look for the state file where they looked for `recent`
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
-rw-r--r--test/behaviour/other_files.zig27
-rw-r--r--test/process/look_and_exec.zig3
-rw-r--r--test/process/other_files.zig14
-rw-r--r--test/session.zig17
4 files changed, 50 insertions, 11 deletions
diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig
index 701f4f14..ae4c2928 100644
--- a/test/behaviour/other_files.zig
+++ b/test/behaviour/other_files.zig
@@ -191,6 +191,33 @@ test "other-files: a closed file is found again: Recent and /recent list it clos
try s.expect(s.at("/pane/{d}/name", .{try s.focused()}), s.at("{s}\n", .{a}));
}
+test "other-files: two sessions on one state file share Recent: what one opened and closed is in the next one's, and each reads the other's on use" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "bee\nsea\n" });
+ var dir_buf: [std.fs.max_path_bytes]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var one = try Session.initShared(std.testing.allocator, dir);
+ defer one.deinit();
+ const a = one.at("{s}/a.txt", .{dir});
+ try one.write("/look", one.at("{s}:3\n", .{a}));
+ try one.write(one.at("/pane/{d}/ctl", .{try one.focused()}), "Del\n");
+ // A session started after it lists the file closed, at its dot.
+ var two = try Session.initShared(std.testing.allocator, dir);
+ defer two.deinit();
+ try std.testing.expect(has(try two.read("/recent"), two.at("closed {s}\n", .{a})));
+ try std.testing.expect(has(try listing(&two, "Recent"), "a.txt:3:"));
+ // What it opens and closes is in the first one's, read there on use.
+ const b = two.at("{s}/b.txt", .{dir});
+ try two.write("/look", two.at("{s}:2\n", .{b}));
+ try std.testing.expect(has(try two.read("/recent"), two.at("open {s}\n", .{b})));
+ try two.write(two.at("/pane/{d}/ctl", .{try two.focused()}), "Del\n");
+ try std.testing.expect(has(try one.read("/recent"), one.at("closed {s}\n", .{b})));
+ try std.testing.expect(has(try one.read("/recent"), one.at("closed {s}\n", .{a})));
+ try std.testing.expect(has(try listing(&one, "Recent"), "b.txt:2:"));
+}
+
test "other-files: Back and Forward over a closed file's entries: one reopen is that file's pane in every entry, so the next step moves" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
diff --git a/test/process/look_and_exec.zig b/test/process/look_and_exec.zig
index 5ad5e25b..9829797b 100644
--- a/test/process/look_and_exec.zig
+++ b/test/process/look_and_exec.zig
@@ -230,7 +230,8 @@ fn canary(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
try check(has(try restored.read(a, "/recent"), try std.fmt.allocPrint(a, "open {s}/after.txt\n", .{root})), "no open in Recent", .{});
{
const deadline = process.nowMs() + 10_000;
- while (!has(d.get(a, ".local/state/pardes/recent") catch "", d.abs("after.txt"))) {
+ // Recent's lines are a value of the state file, as they are.
+ while (!has(d.get(a, ".local/share/pardes/pardes.xitdb") catch "", d.abs("after.txt"))) {
if (process.nowMs() > deadline) return error.RecentNotKept;
process.nap(50);
}
diff --git a/test/process/other_files.zig b/test/process/other_files.zig
index 17cc198c..38aa0bd5 100644
--- a/test/process/other_files.zig
+++ b/test/process/other_files.zig
@@ -28,9 +28,9 @@ fn removeRoot(root: []const u8) void {
_ = system(std.fmt.bufPrintSentinel(&cmd, "rm -rf -- '{s}'", .{root}, 0) catch return);
}
-fn recentExists(root: []const u8) bool {
+fn stateExists(root: []const u8) bool {
var buf: [4200]u8 = undefined;
- return std.c.access(std.fmt.bufPrintSentinel(&buf, "{s}/.local/state/pardes/recent", .{root}, 0) catch return false, 0) == 0;
+ return std.c.access(std.fmt.bufPrintSentinel(&buf, "{s}/.local/share/pardes/pardes.xitdb", .{root}, 0) catch return false, 0) == 0;
}
/// A script types and clicks as the user does: no sleep or poll between a
@@ -90,8 +90,8 @@ fn heldConnection(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
try std.testing.expectError(error.NotFound, c.walk(body));
}
-/// The list is kept under $XDG_STATE_HOME (here HOME's .local/state) across
-/// restarts.
+/// The list is kept in the state file (Db.zig), under $XDG_DATA_HOME (here
+/// HOME's .local/share), across restarts.
fn recentSurvivesRestart(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
@@ -111,7 +111,7 @@ fn recentSurvivesRestart(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
try c.write(try std.fmt.allocPrint(a, "/pane/{d}/ctl", .{serial}), "Del\n");
try std.testing.expect(has(try c.read(a, "/recent"), try std.fmt.allocPrint(a, "closed {s}\n", .{kept})));
}
- try std.testing.expect(recentExists(root));
+ try std.testing.expect(stateExists(root));
var two = try process.Detached.start(gpa, exe, "recent2", .{ .root = root });
defer two.deinit();
const c = try process.Conn.dial(gpa, two.socket());
@@ -139,7 +139,7 @@ fn delTwice(c: *process.Conn, ctl: []const u8) !void {
c.write(ctl, "Del\n") catch try c.write(ctl, "Del\n");
}
-/// Recent's file (Store.zig) shared with no restart; a pane Del'd in one
+/// Recent's state file (Db.zig) shared with no restart; a pane Del'd in one
/// comes back where it was from a look at its @p serial there, its text
/// with it, and only there.
fn recentShared(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
@@ -181,5 +181,5 @@ fn recentShared(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
try std.testing.expect(!has(body, "kept across a Del"));
}
}
- try std.testing.expect(recentExists(root));
+ try std.testing.expect(stateExists(root));
}
diff --git a/test/session.zig b/test/session.zig
index c28c2892..71d723a4 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -25,9 +25,10 @@ pub const Session = struct {
/// through (initLanguage); none, and they go unanswered.
languages: ?std.Io = null,
- /// A session showing one file pane holding `text`.
+ /// A session showing one file pane holding `text`, keeping what outlives
+ /// it in a database in memory (src/Db.zig).
pub fn initFile(gpa: std.mem.Allocator, text: []const u8) !Session {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory });
errdefer p.deinit();
_ = try p.setTestFile(text);
var s: Session = .{ .core = p, .arena = .init(gpa) };
@@ -48,7 +49,17 @@ pub const Session = struct {
/// A session showing its terminal pane, as `pardes` starts.
pub fn initTerm(gpa: std.mem.Allocator) !Session {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .memory });
+ var s: Session = .{ .core = p, .arena = .init(gpa) };
+ s.drain();
+ return s;
+ }
+
+ /// A session showing a scratch pane, keeping its state in the state
+ /// file in `dir` (its DumpDir), as every session of a user shares one.
+ pub fn initShared(gpa: std.mem.Allocator, dir: []const u8) !Session {
+ var config: [4200]u8 = undefined;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24, .state = .disk, .startup_config = try std.fmt.bufPrint(&config, "DumpDir {s}\n", .{dir}) });
var s: Session = .{ .core = p, .arena = .init(gpa) };
s.drain();
return s;