From ed6581dbf287d8a2fb1c439a88ce7380ee754f75 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 23:50:55 -0300 Subject: Bound a scripted run's memory sessions; check a script records the same twice A scripted run from fresh state records in memory, and a very long one grew without end. It stops at 256 MiB (ten hours or more of play at 60 Hz; a write the memory database cannot make, out of memory included, is the same): once, a warning, and no more frames, while what it holds still reads (marks, clips, past sessions). test-same plays test/past.script twice into two databases and compares them value by value with test/same_sessions.zig, but for a session's started and ended (the wall clock): every frame, keyframe, stretch and mark follows from the script alone. A third run from fresh state leaves its state file and no database. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'build.zig') diff --git a/build.zig b/build.zig index d8da703..9b99597 100644 --- a/build.zig +++ b/build.zig @@ -409,6 +409,36 @@ pub fn build(b: *Build) void { test_step.dependOn(&moved.step); b.step("test-import", "Export a session from one database, import it into another, replay it").dependOn(&moved.step); + // A script run twice records the same database but for the wall clock's + // times: the log and the keyframes follow from the script alone. From + // fresh state it records in memory: no database at all. + const same_sessions = b.addExecutable(.{ .name = "same_sessions", .root_module = b.createModule(.{ + .root_source_file = b.path("test/same_sessions.zig"), + .target = target, + .optimize = optimize, + .imports = &.{.{ .name = "Sessions", .module = b.createModule(.{ .root_source_file = b.path("src/host/Sessions.zig"), .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "xitdb", .module = xitdb } } }) }}, + }) }); + const twice = b.addSystemCommand(&.{ "sh", "-c", + \\set -e + \\mkdir -p "$3"; d=$(realpath "$3"); rm -f "$d"/* + \\"$0" --headless --script "$1" --state "$d/a.state" "$4" + \\"$0" --headless --script "$1" --state "$d/b.state" "$4" + \\"$2" "$d/a.xitdb" "$d/b.xitdb" + \\"$0" --headless --fresh --script "$1" --state "$d/c.state" "$4" + \\test -e "$d/c.state"; test ! -e "$d/c.xitdb" + \\rm -f "$d"/* + }); + twice.setName("a script recorded twice"); + twice.addArtifactArg(host_exe); + twice.addFileArg(b.path("test/past.script")); + twice.addArtifactArg(same_sessions); + _ = twice.addOutputDirectoryArg("twice"); + twice.addArtifactArg(recorded); + twice.has_side_effects = true; + twice.expectExitCode(0); + test_step.dependOn(&twice.step); + b.step("test-same", "A script run twice records the same database but for times").dependOn(&twice.step); + // Where files go. Without --state: the XDG data directory, state and // sessions. In .sketchbook/ (`zig build run`'s): a .gitignore, and an // older build's state moved in, once, never over a file there. -- cgit v1.3