diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 19:02:34 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 19:02:34 -0300 |
| commit | 486f347adeed5bac6aaabe8be34e6a69bf323a62 (patch) | |
| tree | da8b333b4033889aa2fd16ab7f5a4bef35b0401d /test/process/tty_editing.zig | |
| parent | 4053e62a2aabd794db9075d93ebe57eec3f432a6 (diff) | |
| parent | 06f6c72583faf8256190a0ae195a8085e7cd7f32 (diff) | |
| download | pardes-486f347adeed5bac6aaabe8be34e6a69bf323a62.tar.gz pardes-486f347adeed5bac6aaabe8be34e6a69bf323a62.zip | |
integration: six small faults on a hang-up as a close: pardes-faults-6 (a hang-up with no daemon kills the language servers' children; the daemon's reader hands a note under a lock; a retried Edit write answered from the listener's hold; the cursor hidden when a frame has no caret; syntax-test deleted and the grammar tiers' tests skipping; the tty harness's Esc after what came before is read) and pardes-merge41, merged without a textual conflict; tui core-test 874/1031 (157 skipped), shell-test 1073/1076, term-test 17/17, both soaks diverged 0, unequal 0, unlisted 0, the window builds; the coordinator's gate in the ledger (reorg/merge42)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/process/tty_editing.zig')
| -rw-r--r-- | test/process/tty_editing.zig | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/process/tty_editing.zig b/test/process/tty_editing.zig index 63c75512..53e1da1e 100644 --- a/test/process/tty_editing.zig +++ b/test/process/tty_editing.zig @@ -27,6 +27,7 @@ pub const cases = .{ .{ "tty editing: lsp", lsp }, .{ "tty editing: lsp-client", lsp_client }, .{ "tty editing: lsp-client-edit", lsp_client_edit }, + .{ "tty editing: lsp-hangup", lsp_hangup }, .{ "tty editing: lspcomplete", lspcomplete }, .{ "tty editing: lspcompletemoved", lspcompletemoved }, .{ "tty editing: lspdebug", lspdebug }, @@ -1511,6 +1512,60 @@ fn lsp_client(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.done(); } +// A pardes with no daemon whose terminal hangs up dies by the signal, and +// no exit hook runs: its language servers' groups go with it all the same. +// The mock, busy (LSPMOCK_MODE=busy), leaves a child in its group, as zls +// in a build does, which its socket's end does not stop. +fn lsp_hangup(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var t = try Tty.init(gpa, exe, "lsp-hangup"); + defer t.deinit(); + _ = setenv("LSPMOCK_MODE", "busy", 1); + // The server's root, where it says its child's pid. + try t.file("Cargo.toml", ""); + try t.file("main.rs", "fn main() {}\n"); + try t.start(25, 100, &.{"main.rs"}); + try t.wait(8000, "fn main()"); + // A request starts the server (goto-definition). + try t.key("g"); + try t.key("d"); + var buf: [32]u8 = undefined; + const child: std.c.pid_t = for (0..1000) |_| { + const fd = std.c.open("lspmock-busy.pid", .{}); + if (fd >= 0) { + const n = std.c.read(fd, &buf, buf.len); + _ = std.c.close(fd); + if (n > 0) if (std.fmt.parseInt(std.c.pid_t, std.mem.trim(u8, buf[0..@intCast(n)], " \n"), 10)) |pid| break pid else |_| {}; + } + try t.settle(10); + } else return error.NoServerChild; + // Whatever the test's end, the child it made goes. + defer _ = std.c.kill(child, .KILL); + t.h.?.deinit(); // the terminal hangs up + t.h = null; + for (0..500) |_| { + if (!alive(child)) return; + var none: [0]std.posix.pollfd = .{}; + _ = std.posix.poll(&none, 10) catch 0; + } + return error.ServerChildLivesOn; +} + +/// Whether `pid` runs (a zombie waiting for its reaper does not). +fn alive(pid: std.c.pid_t) bool { + var path: [32]u8 = undefined; + const p = std.fmt.bufPrintSentinel(&path, "/proc/{d}/stat", .{pid}, 0) catch return false; + const fd = std.c.open(p, .{}); + if (fd < 0) return false; + defer _ = std.c.close(fd); + var stat: [256]u8 = undefined; + const n = std.c.read(fd, &stat, stat.len); + if (n <= 0) return false; + const close_paren = std.mem.lastIndexOfScalar(u8, stat[0..@intCast(n)], ')') orelse return false; + return close_paren + 2 < n and stat[close_paren + 2] != 'Z'; +} + +extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; + // The protocol client's MUTATING answers, through the @put record path: a // server TextEdit response becomes one atomic buffer edit with one undo step. // = applies the mock's formatting edit (a header line) and narrates |
