summaryrefslogtreecommitdiff
path: root/build/snap.zig
blob: 2c135fef869a514eaa6d8f01aa078d9e2817abdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Build-time wiring for the two snapshot suites — the `snap` step (scripted
//! pty traces diffed against test/snapshots/*.golden) and the `web-snap` step
//! (the same idea driven through headless Chromium). Kept out of build.zig so
//! the test harness's plumbing is not tangled with the shell/platform build.
//!
//! Both steps forward `-- <args>` to their runner: `--update` regenerates
//! goldens, `--jobs=N` / `--idle=MS` tune the tty runner's parallelism.

const std = @import("std");

/// TTY parity suite: pardes-snap forks the real binary in a pty per script.
/// The runner handles its own locking and fan-out, so this is just a run step.
pub fn addTty(b: *std.Build, opts: struct {
    exe: *std.Build.Step.Compile,
    target: std.Build.ResolvedTarget,
    optimize: std.builtin.OptimizeMode,
    ghostty_vt: ?*std.Build.Module,
}) void {
    const snap = b.addExecutable(.{
        .name = "pardes-snap",
        .root_module = b.createModule(.{
            .target = opts.target,
            .optimize = opts.optimize,
            .root_source_file = b.path("test/snapshot.zig"),
            .link_libc = true,
        }),
    });
    if (opts.ghostty_vt) |vt| snap.root_module.addImport("ghostty-vt", vt);
    switch (opts.target.result.os.tag) {
        .freebsd, .netbsd, .openbsd => snap.root_module.linkSystemLibrary("util", .{}),
        else => {},
    }
    b.installArtifact(snap);
    const run_snap = b.addRunArtifact(snap);
    run_snap.addArtifactArg(opts.exe);
    if (b.args) |args| run_snap.addArgs(args);
    // scripts fork children and drive real ptys: never cached, never "up to date"
    run_snap.has_side_effects = true;
    b.step("snap", "run the snapshot parity suite (-- --update regenerates goldens)").dependOn(&run_snap.step);
}

/// Browser regression suite: make an isolated freestanding web build from the
/// real TTY dump captured after running `git ls-files '*.zig'`. The
/// dependency-free Chrome/CDP driver then exercises real DOM pointer events.
/// This recursive build selects `web`, not `web-snap`, so it bottoms out.
pub fn addWeb(b: *std.Build) void {
    const build_web_snap = b.addSystemCommand(&.{
        b.graph.zig_exe,
        "build",
        "web",
        "-Dplatform=web",
        "-Dtarget=wasm32-freestanding",
        "-Dtree-sitter=zig",
        "-Ddump=test/web-snapshots/source-list.dump.zon",
        "-p",
        "zig-out/web-snap-test",
    });
    build_web_snap.setCwd(b.path("."));
    const run_web_snap = b.addSystemCommand(&.{
        "node",
        "test/web_snapshot.mjs",
        "zig-out/web-snap-test/web",
        "test/web-snapshots/source-list.snap",
    });
    run_web_snap.setCwd(b.path("."));
    run_web_snap.step.dependOn(&build_web_snap.step);
    if (b.args) |args| run_web_snap.addArgs(args);
    b.step("web-snap", "run browser touch/LOOK snapshots (-- --update regenerates goldens)").dependOn(&run_web_snap.step);
    b.step("web-e2e", "run the Chrome-driven DOM end-to-end suite").dependOn(&run_web_snap.step);
}