summaryrefslogtreecommitdiff
path: root/test/lspmock.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 19:02:34 -0300
committerGabriel Schneider <[email protected]>2026-11-20 19:02:34 -0300
commit486f347adeed5bac6aaabe8be34e6a69bf323a62 (patch)
treeda8b333b4033889aa2fd16ab7f5a4bef35b0401d /test/lspmock.zig
parent4053e62a2aabd794db9075d93ebe57eec3f432a6 (diff)
parent06f6c72583faf8256190a0ae195a8085e7cd7f32 (diff)
downloadpardes-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/lspmock.zig')
-rw-r--r--test/lspmock.zig26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/lspmock.zig b/test/lspmock.zig
index 001c3488..8b5c73a8 100644
--- a/test/lspmock.zig
+++ b/test/lspmock.zig
@@ -15,12 +15,17 @@
//! mute handshake, then never answer another request (timeout path)
//! die exit right after the handshake (dead-server path)
//! utf16 refuse the utf-8 negotiation (column-conversion path)
+//! busy at the handshake, leave a child running in the server's
+//! group, as a build a server started does; its pid said in
+//! `lspmock-busy.pid` in the server's directory (its root)
const std = @import("std");
const libc = std.c;
extern "c" fn getenv(name: [*:0]const u8) ?[*:0]const u8;
+extern "c" fn fork() libc.pid_t;
+extern "c" fn pause() c_int;
-var mode: enum { normal, mute, die, utf16 } = .normal;
+var mode: enum { normal, mute, die, utf16, busy } = .normal;
/// stdout, written with plain libc write(2): the transport is a socketpair
/// and the frames are small, so partial writes are retried and nothing else
@@ -118,6 +123,7 @@ pub fn main(init: std.process.Init) !void {
if (std.mem.eql(u8, s, "mute")) mode = .mute;
if (std.mem.eql(u8, s, "die")) mode = .die;
if (std.mem.eql(u8, s, "utf16")) mode = .utf16;
+ if (std.mem.eql(u8, s, "busy")) mode = .busy;
}
const gpa = std.heap.page_allocator;
@@ -164,6 +170,23 @@ pub fn main(init: std.process.Init) !void {
}
}
+/// A child that runs on in this server's group, its socket closed, and
+/// says its pid.
+fn leaveChild() void {
+ const pid = fork();
+ if (pid != 0) return;
+ _ = libc.close(0);
+ _ = libc.close(1);
+ var buf: [16]u8 = undefined;
+ const said = std.fmt.bufPrint(&buf, "{d}\n", .{libc.getpid()}) catch unreachable;
+ const fd = libc.open("lspmock-busy.pid", .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o600));
+ if (fd >= 0) {
+ _ = libc.write(fd, said.ptr, said.len);
+ _ = libc.close(fd);
+ }
+ while (true) _ = pause();
+}
+
fn handle(a: std.mem.Allocator, raw: []const u8) void {
const v = std.json.parseFromSliceLeaky(std.json.Value, a, raw, .{}) catch return;
const method = str(get(v, "method")) orelse "";
@@ -195,6 +218,7 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void {
}
if (std.mem.eql(u8, method, "initialized")) {
if (mode == .die) std.process.exit(0);
+ if (mode == .busy) leaveChild();
// the progress trio, so the status pipeline has something to narrate
notify(a, "$/progress", "{{\"token\":\"t1\",\"value\":{{\"kind\":\"begin\",\"title\":\"mocking\"}}}}", .{});
notify(a, "$/progress", "{{\"token\":\"t1\",\"value\":{{\"kind\":\"report\",\"percentage\":50,\"message\":\"halfway\"}}}}", .{});