Skip to content
zit Artifact [0512161717]
Login

Artifact [0512161717]

Artifact 0512161717b52ff476037d0304f156e2e2361ed250bcaca54d4da1aa88d26b8a:


const std = @import("std");
const repeat = @import("zit").repeat;
const logstore = @import("zit").logstore;
const storage = @import("zit").storage;
const support = @import("support.zig");
const addManaged = support.addManaged;
const bareStoreOf = support.bareStoreOf;
const commitHashDup = support.commitHashDup;
const expectExit = support.expectExit;
const expectExitDiag = support.expectExitDiag;
const fileExists = support.fileExists;
const framesTrailer = support.framesTrailer;
const freeResult = support.freeResult;
const freshLoopbackPort = support.freshLoopbackPort;
const initRepo = support.initRepo;
const machineHash = support.machineHash;
const runCommitEnv = support.runCommitEnv;
const runZit = support.runZit;
const runZitEnv = support.runZitEnv;
const runZitStdin = support.runZitStdin;
const spawnServe = support.spawnServe;
const storeHoldsArtifact = support.storeHoldsArtifact;
const storeShunRowCount = support.storeShunRowCount;
const waitForListen = support.waitForListen;
const writeFile = support.writeFile;

// ---------------------------------------------------------------------------
// `zit pack` reclaims deferred shuns (the pack filter). No `zit shun` verb exists
// yet, so these tests append the tombstone through the library — the same frame
// that verb will write — and then drive the REAL binary over it.
// ---------------------------------------------------------------------------

/// Appends a shun row naming the artifact in `dir/.zit` whose reconstructed
/// content equals `body`, and returns that artifact's raw digest (caller frees).
/// Finds the artifact by scanning rather than by recomputing a hash, so the test
/// does not have to know which hash algorithm the repository was initialized
/// with. Fails if no artifact holds those bytes — the premise, not an assertion
/// about pack.
fn shunArtifactByContent(
    gpa: std.mem.Allocator,
    io: std.Io,
    dir: std.Io.Dir,
    body: []const u8,
    reason: []const u8,
) ![]u8 {
    var file = try dir.openFile(io, ".zit", .{ .mode = .read_write });
    defer file.close(io);
    const st = try file.stat(io);
    var fs = storage.FileStorage.init(io, file, st.size);
    var log = try logstore.LogStore.open(gpa, fs.storageFile(), 0);
    defer log.deinit(gpa);

    const rids = try log.ridsInPersistedOrder(gpa);
    defer gpa.free(rids);
    for (rids) |rid| {
        if (log.kindOf(rid) == .config) continue;
        const content = (try log.content(gpa, rid)) orelse continue;
        defer gpa.free(content);
        if (!std.mem.eql(u8, content, body)) continue;
        const digest = try gpa.dupe(u8, log.hashOf(rid));
        errdefer gpa.free(digest);
        try log.putShun(digest, reason, 1753000010);
        try log.commit();
        return digest;
    }
    return error.NoArtifactHoldsThoseBytes;
}

test "cli: zit pack reclaims a deferred shun, reports the count, and keeps the tombstone" {
    // A shun masks; a pack RECLAIMS. Between the two the bytes are still in the
    // store, which is the whole reason `zit pack` grew a filter — an operator who
    // was ordered to remove content needs one command that actually removes it,
    // and needs to be told how much it removed rather than inferring it from a
    // byte count that shrinks on an ordinary re-deltify too.
    const gpa = std.testing.allocator;
    const io = std.testing.io;
    var tmp = std.testing.tmpDir(.{});
    defer tmp.cleanup();

    // Two files so a pack that dropped everything cannot pass by accident.
    try initRepo(gpa, io, tmp.dir);
    try writeFile(io, tmp.dir, "doomed.txt", "content an operator was ordered to remove\n");
    try writeFile(io, tmp.dir, "keep.txt", "content with nothing against it\n");
    try addManaged(gpa, io, tmp.dir, &.{ "doomed.txt", "keep.txt" });
    const root = try commitHashDup(gpa, io, tmp.dir, "root");
    defer gpa.free(root);

    const doomed = try shunArtifactByContent(
        gpa,
        io,
        tmp.dir,
        "content an operator was ordered to remove\n",
        "takedown notice 4717",
    );
    defer gpa.free(doomed);

    // The premise: masked but STILL STORED. `cat` refuses it (the shun mask),
    // while the frame is physically there for the pack to reclaim.
    {
        var res = try runZit(gpa, io, tmp.dir, &.{ "cat", "doomed.txt", root });
        defer freeResult(gpa, &res);
        try expectExit(res.term, 8);
    }

    {
        var res = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &res);
        try expectExit(res.term, 0);
        try std.testing.expectEqualStrings("", res.stderr);
        // THE OPERATOR-VISIBLE PIN: the run says what it removed. Substring, not
        // the whole line — the artifact/byte counts are environment-dependent
        // and the exact wording is unit-tested in cmd/pack.zig.
        if (std.mem.indexOf(u8, res.stdout, "1 shunned reclaimed") == null) {
            std.debug.print("pack did not report the reclaim: {s}\n", .{res.stdout});
            return error.ReclaimCountNotReported;
        }
    }

    // The on-disk oracle, read back through the library: the bytes are gone from
    // the packed store — not merely masked — and the tombstone that named them is
    // not, so the artifact still reads as absent and a sync will not fetch it back.
    {
        var file = try tmp.dir.openFile(io, ".zit", .{ .mode = .read_only });
        defer file.close(io);
        const st = try file.stat(io);
        var fs = storage.FileStorage.init(io, file, st.size);
        var log = try logstore.LogStore.openReadOnly(gpa, fs.storageFile());
        defer log.deinit(gpa);
        try std.testing.expect(log.lookup(doomed) == null);
        try std.testing.expect(log.isShunned(doomed));
        const rows = log.shunList();
        try std.testing.expectEqual(@as(usize, 1), rows.len);
        try std.testing.expectEqualStrings("takedown notice 4717", rows[0].reason);
    }

    // The unshunned neighbour is still readable through the real binary, so the
    // reclaim removed exactly what it was told to and nothing adjacent.
    {
        var res = try runZit(gpa, io, tmp.dir, &.{ "cat", "keep.txt", root });
        defer freeResult(gpa, &res);
        try expectExit(res.term, 0);
        try std.testing.expectEqualStrings("content with nothing against it\n", res.stdout);
    }

    // A second pack has nothing left to reclaim and must say nothing about it.
    {
        var res = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &res);
        try expectExit(res.term, 0);
        try std.testing.expect(std.mem.indexOf(u8, res.stdout, "shunned reclaimed") == null);
    }
}

test "cli pack -R: a bare store packs in place, reclaiming deferred shuns with the same generation swap" {
    const gpa = std.testing.allocator;
    const io = std.testing.io;
    var tmp = std.testing.tmpDir(.{});
    defer tmp.cleanup();
    try tmp.dir.createDir(io, "src", .default_dir);
    var src = try tmp.dir.openDir(io, "src", .{});
    defer src.close(io);
    try initRepo(gpa, io, src);
    try bareStoreOf(gpa, io, src, tmp.dir, "s.zit");
    var bare = try tmp.dir.openDir(io, "s.zit", .{});
    defer bare.close(io);

    try writeFile(io, tmp.dir, "v1.txt", "a page to keep\n");
    try writeFile(io, tmp.dir, "n1.txt", "a technote to take down\n");
    var w1 = try runZitStdin(gpa, io, tmp.dir, "v1.txt", &.{ "wiki", "commit", "Page", "-R", "s.zit", "--user", "u" });
    defer freeResult(gpa, &w1);
    try expectExitDiag(w1.term, 0, w1);
    var t1 = try runZitStdin(gpa, io, tmp.dir, "n1.txt", &.{ "technote", "add", "-R", "s.zit", "--user", "u" });
    defer freeResult(gpa, &t1);
    try expectExitDiag(t1.term, 0, t1);
    const v1 = machineHash(w1.stdout);
    const n1 = machineHash(t1.stdout);

    var sh = try runZit(gpa, io, tmp.dir, &.{ "shun", "-R", "s.zit", "--defer", "--force", n1 });
    defer freeResult(gpa, &sh);
    try expectExitDiag(sh.term, 0, sh);
    try std.testing.expect(try storeHoldsArtifact(gpa, io, bare, n1));

    var boot = try runZit(gpa, io, tmp.dir, &.{ "frames", "-R", "s.zit" });
    defer freeResult(gpa, &boot);
    try expectExitDiag(boot.term, 0, boot);
    const t0 = try framesTrailer(gpa, boot.stdout);
    defer gpa.free(t0.cursor);
    defer gpa.free(t0.token);
    const since0 = try std.fmt.allocPrint(gpa, "--since={s}", .{t0.cursor});
    defer gpa.free(since0);
    const verify0 = try std.fmt.allocPrint(gpa, "--verify={s}", .{t0.token});
    defer gpa.free(verify0);

    {
        // The deferred row's bytes go; the row and everything else stay.
        var res = try runZit(gpa, io, tmp.dir, &.{ "pack", "-R", "s.zit" });
        defer freeResult(gpa, &res);
        try expectExitDiag(res.term, 0, res);
        try std.testing.expect(!try storeHoldsArtifact(gpa, io, bare, n1));
        try std.testing.expect(try storeHoldsArtifact(gpa, io, bare, v1));
        try std.testing.expectEqual(@as(usize, 1), try storeShunRowCount(gpa, io, bare));
    }
    {
        // A new generation, signalled exactly as a checkout's pack signals it.
        var poll = try runZit(gpa, io, tmp.dir, &.{ "frames", "-R", "s.zit", since0, verify0 });
        defer freeResult(gpa, &poll);
        try expectExitDiag(poll.term, 4, poll);
        var verified = try runZit(gpa, io, tmp.dir, &.{ "verify", "-R", "s.zit" });
        defer freeResult(gpa, &verified);
        try expectExitDiag(verified.term, 0, verified);
    }
    {
        var res = try runZit(gpa, io, tmp.dir, &.{ "pack", "-R", "s.zit" });
        defer freeResult(gpa, &res);
        try expectExitDiag(res.term, 0, res);
        try std.testing.expectEqualStrings("already packed; nothing to do\n", res.stdout);
    }
    {
        // --drop-elided keeps its refusal: a bare store with no cone has
        // nothing elided.
        var res = try runZit(gpa, io, tmp.dir, &.{ "pack", "-R", "s.zit", "--drop-elided" });
        defer freeResult(gpa, &res);
        try expectExitDiag(res.term, 1, res);
        try std.testing.expect(std.mem.indexOf(u8, res.stderr, "needs a store cone") != null);
    }
    {
        var res = try runZit(gpa, io, tmp.dir, &.{ "pack", "-R", "absent" });
        defer freeResult(gpa, &res);
        try expectExitDiag(res.term, 1, res);
    }
}

test "cli pack: a repeat pack over an unchanged log is a no-op, and an append re-arms it" {
    const gpa = std.testing.allocator;
    const io = std.testing.io;
    var tmp = std.testing.tmpDir(.{});
    defer tmp.cleanup();
    try initRepo(gpa, io, tmp.dir);
    try writeFile(io, tmp.dir, "a.txt", repeat("alpha ", 200) ++ "\n");
    try writeFile(io, tmp.dir, "b.txt", repeat("alpha ", 199) ++ "beta\n");
    try addManaged(gpa, io, tmp.dir, &.{ "a.txt", "b.txt" });
    var c1 = try runCommitEnv(gpa, io, tmp.dir, .{ .user = "t" }, &.{ "commit", "-m", "r" });
    defer freeResult(gpa, &c1);
    try expectExit(c1.term, 0);
    const t_ = std.testing;

    {
        var p = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
        // A tiny store may pack to identical size, which renderPackStats
        // reports as "already packed: N artifacts walked ..." — still a REAL
        // walk. The stats line is the discriminator; the no-op gate prints
        // no stats at all.
        try t_.expect(std.mem.indexOf(u8, p.stdout, "artifacts walked") != null);
    }
    // Unchanged log: the recorded generation key matches, nothing is walked.
    {
        var p = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
        try t_.expect(std.mem.indexOf(u8, p.stdout, "already packed; nothing to do") != null);
        try t_.expect(std.mem.indexOf(u8, p.stdout, "artifacts walked") == null);
    }
    // Any append (a commit here; a shun row or a pull equally) changes the
    // key, so the next pack runs for real — and re-records.
    try writeFile(io, tmp.dir, "a.txt", repeat("alpha ", 200) ++ "more\n");
    var c2 = try runCommitEnv(gpa, io, tmp.dir, .{ .user = "t" }, &.{ "commit", "-m", "r2" });
    defer freeResult(gpa, &c2);
    try expectExit(c2.term, 0);
    {
        var p = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
        try t_.expect(std.mem.indexOf(u8, p.stdout, "artifacts walked") != null);
    }
    // The ladder rule for the memo: deleting the advisory tier costs a real
    // pack, never an answer — and the repository still reads identically.
    try tmp.dir.deleteTree(io, ".zit-cache");
    {
        var p = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
        try t_.expect(std.mem.indexOf(u8, p.stdout, "artifacts walked") != null);
    }
    var ls = try runZit(gpa, io, tmp.dir, &.{ "ls", "trunk" });
    defer freeResult(gpa, &ls);
    try expectExitDiag(ls.term, 0, ls);
    try t_.expect(std.mem.indexOf(u8, ls.stdout, "a.txt") != null);
    try t_.expect(std.mem.indexOf(u8, ls.stdout, "b.txt") != null);
}

test "cli pack --drop-elided: narrow-then-compact shrinks the store and harms nothing kept" {
    // Sparse-cone RFC section 5.4, the spec's only deletion. A sparse clone
    // (store cone src+tools) narrows to src via update --cone -- store policy
    // follows the worktree BECAUSE the store is already sparse -- then an
    // explicit pack --drop-elided reclaims tools' blob. The store shrinks,
    // verify stays healthy, in-cone content is untouched, and on a DENSE
    // store the flag refuses rather than guesses.
    const gpa = std.testing.allocator;
    const io = std.testing.io;
    var tmp_a = std.testing.tmpDir(.{});
    defer tmp_a.cleanup();
    try initRepo(gpa, io, tmp_a.dir);
    try tmp_a.dir.createDir(io, "src", .default_dir);
    try tmp_a.dir.createDir(io, "tools", .default_dir);
    try writeFile(io, tmp_a.dir, "src/a.zig", "keep me\n");
    try writeFile(io, tmp_a.dir, "tools/big.bin", repeat("x", 4096) ++ "\n");
    try addManaged(gpa, io, tmp_a.dir, &.{ "src/a.zig", "tools/big.bin" });
    const head = try commitHashDup(gpa, io, tmp_a.dir, "seed");
    defer gpa.free(head);

    // Refusal on the dense origin: nothing is "elided" without a store cone.
    var refuse = try runZit(gpa, io, tmp_a.dir, &.{ "pack", "--drop-elided" });
    defer freeResult(gpa, &refuse);
    try expectExit(refuse.term, 1);
    try std.testing.expect(std.mem.indexOf(u8, refuse.stderr, "needs a store cone") != null);

    const port = try freshLoopbackPort(io);
    var server = try spawnServe(gpa, io, tmp_a.dir, port);
    defer server.kill(io);
    try waitForListen(io, port);
    const url = try std.fmt.allocPrint(gpa, "http://127.0.0.1:{d}/", .{port});
    defer gpa.free(url);
    var tmp_b = std.testing.tmpDir(.{});
    defer tmp_b.cleanup();
    var clone = try runZit(gpa, io, tmp_b.dir, &.{ "clone", "--no-open", "--cone=src", "--cone=tools", url, "repo" });
    defer freeResult(gpa, &clone);
    try expectExitDiag(clone.term, 0, clone);
    var b_dir = try tmp_b.dir.openDir(io, "repo", .{});
    defer b_dir.close(io);
    var op = try runZit(gpa, io, b_dir, &.{ "open", "--cone=src", "--cone=tools" });
    defer freeResult(gpa, &op);
    try expectExitDiag(op.term, 0, op);

    // Narrow to src: store policy follows (the store is sparse); tools'
    // blob is now elided-by-policy though still physically held.
    var nr = try runZit(gpa, io, b_dir, &.{ "update", "--cone=src", head });
    defer freeResult(gpa, &nr);
    try expectExitDiag(nr.term, 0, nr);
    try std.testing.expect(!fileExists(io, b_dir, "tools/big.bin"));
    const size_before = blk: {
        const st = try b_dir.statFile(io, ".zit", .{});
        break :blk st.size;
    };

    var compact = try runZit(gpa, io, b_dir, &.{ "pack", "--drop-elided" });
    defer freeResult(gpa, &compact);
    try expectExitDiag(compact.term, 0, compact);
    const size_after = blk: {
        const st = try b_dir.statFile(io, ".zit", .{});
        break :blk st.size;
    };
    try std.testing.expect(size_after < size_before);

    var cat_keep = try runZit(gpa, io, b_dir, &.{ "cat", "src/a.zig" });
    defer freeResult(gpa, &cat_keep);
    try expectExitDiag(cat_keep.term, 0, cat_keep);
    try std.testing.expectEqualStrings("keep me\n", cat_keep.stdout);
    var ver = try runZit(gpa, io, b_dir, &.{"verify"});
    defer freeResult(gpa, &ver);
    try expectExitDiag(ver.term, 0, ver);
    try std.testing.expect(std.mem.indexOf(u8, ver.stdout, "sparse store") != null);
}

test "cli pack: an unclustered store gains clusters, so a clone's first pull announces them rather than every artifact" {
    const gpa = std.testing.allocator;
    const io = std.testing.io;
    var tmp = std.testing.tmpDir(.{});
    defer tmp.cleanup();
    try tmp.dir.createDir(io, "origin", .default_dir);
    var origin = try tmp.dir.openDir(io, "origin", .{});
    defer origin.close(io);
    try initRepo(gpa, io, origin);
    try origin.createDir(io, "d", .default_dir);
    var d = try origin.openDir(io, "d", .{});
    defer d.close(io);
    // A commit mints no clusters, so these 120 files and their check-in are
    // the unclustered store an older import or a long commit history leaves.
    for (0..120) |i| {
        var name_buf: [16]u8 = undefined;
        var body_buf: [16]u8 = undefined;
        try writeFile(io, d, try std.fmt.bufPrint(&name_buf, "f{d}.txt", .{i}), try std.fmt.bufPrint(&body_buf, "{d}\n", .{i}));
    }
    try addManaged(gpa, io, origin, &.{"d"});
    var c1 = try runCommitEnv(gpa, io, origin, .{ .user = "t" }, &.{ "commit", "-m", "many" });
    defer freeResult(gpa, &c1);
    try expectExit(c1.term, 0);

    {
        var p = try runZit(gpa, io, origin, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
        try std.testing.expect(std.mem.indexOf(u8, p.stdout, "added 1 cluster(s)\n") != null);
        try std.testing.expect(std.mem.indexOf(u8, p.stdout, "artifacts walked") != null);
    }
    // Clustered and packed: the next pack adds nothing and is the no-op.
    {
        var p = try runZit(gpa, io, origin, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
        try std.testing.expect(std.mem.indexOf(u8, p.stdout, "cluster") == null);
        try std.testing.expect(std.mem.indexOf(u8, p.stdout, "already packed; nothing to do") != null);
    }

    const port = try freshLoopbackPort(io);
    var server = try spawnServe(gpa, io, origin, port);
    defer server.kill(io);
    try waitForListen(io, port);
    const url = try std.fmt.allocPrint(gpa, "http://127.0.0.1:{d}/", .{port});
    defer gpa.free(url);
    var cloned = try runZit(gpa, io, tmp.dir, &.{ "clone", url, "clone" });
    defer freeResult(gpa, &cloned);
    try expectExitDiag(cloned.term, 0, cloned);
    var clone_dir = try tmp.dir.openDir(io, "clone", .{});
    defer clone_dir.close(io);
    var pulled = try runZitEnv(gpa, io, clone_dir, &.{.{ "ZIT_SYNC_STATS", "1" }}, &.{ "pull", url });
    defer freeResult(gpa, &pulled);
    try expectExitDiag(pulled.term, 0, pulled);
    // One cluster announced instead of over 120 igot cards (8000+ bytes).
    try std.testing.expect(std.mem.indexOf(u8, pulled.stderr, "cluster index 1 clusters") != null);
    const at = std.mem.indexOf(u8, pulled.stderr, "sent ").? + "sent ".len;
    const end = std.mem.indexOfScalarPos(u8, pulled.stderr, at, ' ').?;
    try std.testing.expect(try std.fmt.parseInt(u64, pulled.stderr[at..end], 10) < 1000);
}

/// Counts, over the artifacts of the store in `dir/.zit` whose bytes are one of
/// `versions`, how many are stored whole, and how many deltas sit on a chain
/// whose accumulated delta bytes exceed their own estimated whole size (the
/// chain cost bound, `LogStore.chainAdmits`).
fn versionFrames(gpa: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, versions: []const []const u8) !struct { whole: usize, found: usize, over_bound: usize } {
    var file = try dir.openFile(io, ".zit", .{});
    defer file.close(io);
    const st = try file.stat(io);
    var fs = storage.FileStorage.initReadOnly(io, file, st.size);
    var log = try logstore.LogStore.open(gpa, fs.storageFile(), 0);
    defer log.deinit(gpa);
    const rids = try log.ridsInPersistedOrder(gpa);
    defer gpa.free(rids);
    var whole: usize = 0;
    var found: usize = 0;
    var over_bound: usize = 0;
    for (rids) |rid| {
        if (log.kindOf(rid) == .config) continue;
        const content = (try log.content(gpa, rid)) orelse continue;
        defer gpa.free(content);
        for (versions) |v| {
            if (!std.mem.eql(u8, v, content)) continue;
            found += 1;
            if (log.kindOf(rid) != .delta) {
                whole += 1;
            } else {
                const cost = log.chainCostOf(rid) orelse return error.TestUnexpectedResult;
                if (cost.acc > cost.wholeEstimate(content.len)) over_bound += 1;
            }
            break;
        }
    }
    return .{ .whole = whole, .found = found, .over_bound = over_bound };
}

test "cli pack: a file committed 64 times is stored as parent deltas within the chain cost bound, through pack, and checks out byte-exact" {
    // Each version is a delta of the one before, as Fossil stores it, until
    // the chain's delta bytes would pass the version's own whole size; that
    // version is stored whole and the next chain starts from it. Depth is no
    // reason for a whole copy, and pack keeps the same rule.
    const gpa = std.testing.allocator;
    const io = std.testing.io;
    var tmp = std.testing.tmpDir(.{});
    defer tmp.cleanup();
    var arena_state = std.heap.ArenaAllocator.init(gpa);
    defer arena_state.deinit();
    const arena = arena_state.allocator();
    try initRepo(gpa, io, tmp.dir);

    const n = 64;
    var versions: [n][]const u8 = undefined;
    var hashes: [n][]const u8 = undefined;
    defer for (hashes) |h| gpa.free(h);
    for (0..n) |v| {
        var body: std.ArrayList(u8) = .empty;
        for (0..120) |line| try body.print(arena, "line {d} of a long-lived file{s}\n", .{ line, if (line <= v) " touched" else "" });
        versions[v] = body.items;
        try writeFile(io, tmp.dir, "a.txt", versions[v]);
        if (v == 0) try addManaged(gpa, io, tmp.dir, &.{"a.txt"});
        hashes[v] = try commitHashDup(gpa, io, tmp.dir, "edit");
    }
    const t_ = std.testing;

    const committed = try versionFrames(gpa, io, tmp.dir, &versions);
    try t_.expectEqual(@as(usize, n), committed.found);
    try t_.expect(committed.whole < n / 2);
    try t_.expectEqual(@as(usize, 0), committed.over_bound);

    {
        var p = try runZit(gpa, io, tmp.dir, &.{"pack"});
        defer freeResult(gpa, &p);
        try expectExitDiag(p.term, 0, p);
    }
    const packed_frames = try versionFrames(gpa, io, tmp.dir, &versions);
    try t_.expectEqual(@as(usize, n), packed_frames.found);
    try t_.expect(packed_frames.whole < n / 2);
    try t_.expectEqual(@as(usize, 0), packed_frames.over_bound);

    {
        var cat = try runZit(gpa, io, tmp.dir, &.{ "cat", "a.txt" });
        defer freeResult(gpa, &cat);
        try expectExitDiag(cat.term, 0, cat);
        try t_.expectEqualStrings(versions[n - 1], cat.stdout);
    }
    for ([_]usize{ 1, 17, 33, n - 1 }) |v| {
        var up = try runZit(gpa, io, tmp.dir, &.{ "update", hashes[v] });
        defer freeResult(gpa, &up);
        try expectExitDiag(up.term, 0, up);
        const got = try tmp.dir.readFileAlloc(io, "a.txt", gpa, .limited(1 << 20));
        defer gpa.free(got);
        try t_.expectEqualStrings(versions[v], got);
    }
}