diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-16 23:31:18 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | b2f7c605c279b2dea0c25180730c3d2e7b4b7d45 (patch) | |
| tree | 142f0258cefd71ed210c64ae73f852e386f71991 /src/host/script.zig | |
| parent | 57e254470e11ab40b6bae31b2cbf62aebca27ce4 (diff) | |
| download | sketchbook-b2f7c605c279b2dea0c25180730c3d2e7b4b7d45.tar.gz sketchbook-b2f7c605c279b2dea0c25180730c3d2e7b4b7d45.zip | |
Make snapshots named marks and recordings named clips of sessions
The state file keeps live state only (SKETCH03, one slot). save NAME is a
keyframe and a mark in the sessions database, synced to disk; load, diff,
snapshot and expect-snapshot take mark names, through the keyframe's own
layout migrated to today's, compared over the leaves migration kept. A
file from before (SKETCH01/02) has its used snapshot slots imported as
marks "1".."7" at open, then drops them; a run that records nothing
leaves them alone.
record NAME, stop and play NAME make and play clips: a frame range of a
session and its start keyframe, nothing overwritten, nothing invalidated
by a later save, no capacity. The 64 MiB .inputs file, its --fresh memset
and Timeline's Bank are gone; numbers still work as names, so every
existing script runs unchanged. Event times in a clip are the session's,
not restarted at record. reload.script also checks that a field a reload
drops is still in the keyframe taken before it (expect-key).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/host/script.zig')
| -rw-r--r-- | src/host/script.zig | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/host/script.zig b/src/host/script.zig index 12774b6..9e1dddf 100644 --- a/src/host/script.zig +++ b/src/host/script.zig @@ -18,8 +18,13 @@ //! await FIELD VALUE [~T] run frames until it holds (a minute at most) //! print FIELD write a field's value to stderr (a vector, //! array or struct: every value in it), no frame -//! expect-snapshot N live state equals snapshot N, leaf by leaf -//! (padding ignored), exactly +//! expect-snapshot NAME live state equals the newest mark NAME, leaf +//! by leaf (padding ignored, and leaves a layout +//! change reset), exactly +//! expect-key WHY FIELD VALUE +//! the newest keyframe of this session taken for +//! WHY (`Sessions.Why`: before_reload, mark...) +//! holds VALUE, read in its own layout //! expect-log TEXT a recent console line contains TEXT //! expect-no-log TEXT no recent console line does //! expect-audio KEY stream KEY has received samples @@ -49,6 +54,8 @@ const abi = @import("abi"); const Host = @import("Host.zig"); const fields = @import("fields.zig"); const memory = @import("memory.zig"); +const Console = @import("Console.zig"); +const Sessions = @import("Sessions.zig"); pub const frame_ns: u64 = std.time.ns_per_s / 60; /// The most frames `await` plays: a minute. @@ -150,10 +157,31 @@ fn step(host: *Host, arena: std.mem.Allocator, command: []const u8, rest: []cons } return; } else if (eq(u8, command, "expect-snapshot")) { - const index = std.fmt.parseInt(usize, rest, 10) catch return error.InvalidSlot; - if (!host.timeline.bank.hasSnapshot(index)) return error.EmptySnapshot; - if (!same(host, index)) return error.ExpectationFailed; + const saved = try Console.markState(host, arena, rest); + if (!same(host, saved.layout, saved.bytes, rest)) return error.ExpectationFailed; return; + } else if (eq(u8, command, "expect-key")) { + const why = std.meta.stringToEnum(Sessions.Why, words.next() orelse "") orelse return error.UnknownWhy; + const path = words.next() orelse return error.ExpectedField; + const want = std.mem.trim(u8, words.rest(), " \t"); + const s = &host.sessions; + try s.commit(.none); + var k = s.keys; + while (k > 0) { + k -= 1; + const key = try s.load(s.session, k); + defer key.free(host.gpa); + if (key.why != why) continue; + const leaf = (try memory.layoutOf(arena, key.layout)).find(path) orelse return error.UnknownField; + if (fields.matches(leaf, key.state, want)) return; + var buf: [128]u8 = undefined; + var w: std.Io.Writer = .fixed(&buf); + fields.format(leaf, key.state, &w) catch {}; + std.debug.print(" {s} keyframe {d}: {s} expected {s}, found {s}\n", .{ @tagName(why), k, path, want, w.buffered() }); + return error.ExpectationFailed; + } + std.debug.print(" no {s} keyframe in this session\n", .{@tagName(why)}); + return error.ExpectationFailed; } else if (eq(u8, command, "expect-log") or eq(u8, command, "expect-no-log")) { var found = false; for (&host.console.lines) |*l| { @@ -263,15 +291,14 @@ fn holds(host: *Host, path: []const u8, want: []const u8, tolerance: ?f64) bool return @abs(value - target) <= t; } -/// Live state against snapshot `index`, leaf by leaf; prints the first few -/// differences. -fn same(host: *Host, index: usize) bool { +/// Live state against mark `name`'s (`saved`, taken in layout `from`), leaf +/// by leaf over the leaves migration kept; prints the first few differences. +fn same(host: *Host, from: memory.Layout, saved: []const u8, name: []const u8) bool { const layout = host.state.layout; const live = host.live(); - const saved = host.timeline.bank.slot(index); var count: usize = 0; for (layout.fields) |leaf| { - if (leaf.whole()) continue; + if (leaf.whole() or (from.hash != layout.hash and !memory.keeps(from, leaf))) continue; var it = leaf.elements(); while (it.next()) |offset| { if (std.mem.eql(u8, live[offset..][0..leaf.size], saved[offset..][0..leaf.size])) continue; @@ -282,7 +309,7 @@ fn same(host: *Host, index: usize) bool { leaf.name(offset, &w) catch {}; w.writeAll(": live ") catch {}; fields.format(leaf.at(offset), live, &w) catch {}; - w.print(", snapshot {d} ", .{index}) catch {}; + w.print(", snapshot {s} ", .{name}) catch {}; fields.format(leaf.at(offset), saved, &w) catch {}; std.debug.print(" {s}\n", .{w.buffered()}); } |
