summaryrefslogtreecommitdiff
path: root/test/process
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 09:14:00 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitaf127a88b03a4bd1b859993594a34b434e5e59d3 (patch)
tree2c98f46f78f14b4ff9c9143dee4e7b99f0ecb8ff /test/process
parent6535f3a59bb2454a0e945d840c083b2423a80b44 (diff)
parent2e6777e06e3f3e9d59ec847b98e0cb676d04296a (diff)
downloadpardes-af127a88b03a4bd1b859993594a34b434e5e59d3.tar.gz
pardes-af127a88b03a4bd1b859993594a34b434e5e59d3.zip
integration: the command line as commands that describe themselves, with the editor library, the GPU move, the terminal, the plumber and the diff work
A merge of pardes-next (nsyzqrms) and pardes-cli (xurkunwk). One conflict, the changelog (both sides' entries kept); docs/typ/command-line.txt written again by builtins-json on the merge (the tree's README and words gained the plumber's files and a pane's rows). pardes builds beside a cloud9 at c9-cli (by path, until that cloud9 is published). Gated against the integration line's baseline (.scratch/sketch/gpu/mbase): frame corpus 77/77 identical in Debug and in ReleaseFast, the gated window +0.160% instructions (spread 0.39%, threshold 0.5%), unit-test on gui 1587/1595 with no failure the baseline has not; on tui core-test 811/950 (139 skipped), shell-test 993/996, behaviour-test 269/273 and unit-test 1528/1536 (the four addon ABI tests the base fails, and the perf baseline's harness mismatch), process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's; ttytaken failed once under load and passed its retry), lib-test, hxdiff 658, parity 738 and hxlib 538 with 0 mismatches, replicas pass. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/process')
-rw-r--r--test/process/cli.zig144
1 files changed, 144 insertions, 0 deletions
diff --git a/test/process/cli.zig b/test/process/cli.zig
new file mode 100644
index 00000000..083ba368
--- /dev/null
+++ b/test/process/cli.zig
@@ -0,0 +1,144 @@
+//! docs/typ/reference.typ, The pardes command <command-line>: the commands
+//! of a real pardes, against a session started for the case and against
+//! none (a core the command makes in its own process).
+const std = @import("std");
+const libc = std.c;
+const process = @import("../process.zig");
+const Conn = process.Conn;
+const has = process.has;
+const check = process.check;
+
+pub const cases = .{
+ .{ "cli: help prints the map, a command, a builtin and a file of the tree, with no session", helpOffline },
+ .{ "cli: fs with no session reads README, commands and ctl from a core made here, and says the rest is a session's", fsOffline },
+ .{ "cli: do, words and fs act on the session -s names, or the only one", againstSession },
+ .{ "cli: completion prints a script per shell and answers each word back", completion },
+ .{ "cli: version, skill, and the old spellings", versionAndOld },
+};
+
+extern "c" fn mkdtemp(template: [*:0]u8) ?[*:0]u8;
+
+/// A root of no session: HOME, runtime and config directories that hold none.
+fn emptyRoot(buf: *[64]u8) ![]const u8 {
+ const template = "/tmp/pardes-cli-XXXXXX";
+ @memcpy(buf[0..template.len], template);
+ buf[template.len] = 0;
+ _ = mkdtemp(buf[0..template.len :0]) orelse return error.NoTempDir;
+ return buf[0..template.len];
+}
+
+/// `pardes args...` in `root`: its exit, and stdout and stderr together.
+fn pardes(a: std.mem.Allocator, exe: [:0]const u8, root: []const u8, args: []const [:0]const u8) !process.Ran {
+ var argv: std.ArrayList([:0]const u8) = .empty;
+ try argv.appendSlice(a, &.{ "/bin/sh", "-c", "exec \"$0\" \"$@\" 1>&2", exe });
+ try argv.appendSlice(a, args);
+ return process.run(a, argv.items, .{ .root = root });
+}
+
+fn expectRan(r: process.Ran, code: c_int, said: []const u8, what: []const u8) !void {
+ try check(r.code == code and has(r.said, said), "{s}: exit {d}, not {d}; wanted '{s}' in: {s}", .{ what, r.code, code, said, r.said });
+}
+
+fn helpOffline(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var buf: [64]u8 = undefined;
+ const root = try emptyRoot(&buf);
+ defer process.removeDir(root);
+ const first = try pardes(a, exe, root, &.{"help"});
+ try expectRan(first, 0, "\nSessions:\n ps ", "help");
+ try expectRan(first, 0, "\nFiles:\n fs VERB [PATH]", "help");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "attach" }), 0, "\n pardes attach box:notes ", "help attach");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "new" }), 0, " --detach[=NAME]", "help new");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "fs" }), 0, "usage: fs ls [PATH]", "help fs");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "Newcol" }), 0, "Newcol (the root ctl; SPC c n; column)", "help Newcol");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "Save" }), 0, "pardes do Save", "help Save");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "pane/3/addr" }), 0, "pane/<n>/ name body tag", "help pane/3/addr");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "nowhere" }), 1, "is not a command, a builtin", "help nowhere");
+ const all = try pardes(a, exe, root, &.{ "help", "--all" });
+ try expectRan(all, 0, "== pardes help version", "help --all");
+ try expectRan(all, 0, "Pardes virtual filesystem", "help --all");
+ // The same map, by its old spelling.
+ try check(std.mem.eql(u8, first.said, (try pardes(a, exe, root, &.{"--help"})).said), "--help is not help", .{});
+}
+
+fn fsOffline(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var buf: [64]u8 = undefined;
+ const root = try emptyRoot(&buf);
+ defer process.removeDir(root);
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "ls" }), 0, "README\n", "fs ls");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "ls" }), 0, "pane/\n", "fs ls");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "read", "README" }), 0, "Pardes virtual filesystem", "fs read README");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "read", "commands" }), 0, "Newcol root -- ", "fs read commands");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "complete", "pa" }), 0, "pager\npane/\n", "fs complete pa");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "read", "index" }), 1, "that is a running session's, and none runs", "fs read index");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "write", "ctl", "Newcol" }), 1, "no session runs to write", "fs write");
+ try expectRan(try pardes(a, exe, root, &.{ "do", "Newcol" }), 1, "no session runs: start one", "do");
+ const w = try pardes(a, exe, root, &.{"words"});
+ try expectRan(w, 0, "column:\n Newcol ", "words");
+ try expectRan(try pardes(a, exe, root, &.{ "words", "nosuch" }), 1, "no group nosuch", "words nosuch");
+}
+
+fn againstSession(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var d = try process.Detached.start(gpa, exe, "cli", .{});
+ defer d.deinit();
+ const c = try Conn.dial(gpa, d.socket());
+ defer c.deinit(gpa);
+ const root = d.root();
+ const cols = std.mem.count(u8, try c.read(a, "/layout"), "\n");
+ try expectRan(try pardes(a, exe, root, &.{ "do", "Newcol", "-s", "cli" }), 0, "", "do Newcol -s cli");
+ try check(std.mem.count(u8, try c.read(a, "/layout"), "\n") == cols + 1, "do Newcol made no column: {s}", .{try c.read(a, "/layout")});
+ // The only session, unnamed.
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "read", "index" }), 0, "1 text 0 ", "fs read index");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "read", "pane/1/body", "-s", "cli" }), 0, "initial\n", "fs read body");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "write", "pane/1/ctl", "bogus" }), 1, "fs: pane/1/ctl: ", "fs write refused");
+ try expectRan(try pardes(a, exe, root, &.{ "do", "Save" }), 1, "is a pane's word: name the pane with -p N", "do Save");
+ try expectRan(try pardes(a, exe, root, &.{ "do", "Nosuch" }), 1, "no word Nosuch in this session", "do Nosuch");
+ try expectRan(try pardes(a, exe, root, &.{ "words", "column" }), 0, "Newcol", "words column");
+ try expectRan(try pardes(a, exe, root, &.{ "help", "index" }), 0, "index a line per pane", "help index");
+ try expectRan(try pardes(a, exe, root, &.{ "fs", "read", "index", "-s", "nosuch" }), 1, "no session answers at ", "-s nosuch");
+}
+
+fn completion(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var buf: [64]u8 = undefined;
+ const root = try emptyRoot(&buf);
+ defer process.removeDir(root);
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "fish" }), 0, "pardes completion -- ", "completion fish");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "bash" }), 0, "complete -o filenames -F _pardes pardes", "completion bash");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "zsh" }), 0, "compdef _pardes pardes", "completion zsh");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "csh" }), 1, "no shell csh", "completion csh");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "--", "he" }), 0, "help\tthis, a command", "complete he");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "--", "do", "Newc" }), 0, "Newcol\t", "complete do Newc");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "--", "fs", "read", "pane/" }), 0, "pane/new\n", "complete fs read pane/");
+ try expectRan(try pardes(a, exe, root, &.{ "completion", "--", "new", "--det" }), 0, "--detach\t", "complete new --det");
+}
+
+fn versionAndOld(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var buf: [64]u8 = undefined;
+ const root = try emptyRoot(&buf);
+ defer process.removeDir(root);
+ const v = try pardes(a, exe, root, &.{"version"});
+ try expectRan(v, 0, "\nsemantics ", "version");
+ try expectRan(v, 0, "9p 9P2000 msize ", "version");
+ try check(std.mem.eql(u8, v.said, (try pardes(a, exe, root, &.{"--version"})).said), "--version is not version", .{});
+ try expectRan(try pardes(a, exe, root, &.{"skill"}), 0, "pardes help PATH", "skill");
+ // The daemon is off in a case's environment: both spellings say so.
+ try expectRan(try pardes(a, exe, root, &.{"ps"}), 1, "no pardes daemon is running", "ps");
+ try expectRan(try pardes(a, exe, root, &.{"--ps"}), 1, "no pardes daemon is running", "--ps");
+ try expectRan(try pardes(a, exe, root, &.{"kill"}), 1, "kill needs a session's name", "kill");
+ try expectRan(try pardes(a, exe, root, &.{"--kill"}), 1, "--kill needs a session's name", "--kill");
+ try expectRan(try pardes(a, exe, root, &.{"--tty=x"}), 1, "--tty takes no value", "--tty=x");
+}