From 2873bf6548d91d997ff436861e64405eb3bc97eb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 8 Nov 2026 20:53:32 -0300 Subject: fix: a pipe's answer past max_stdout_bytes or the job's total, or with cuts that overlap, left the text as it was and said nothing: each says so in the pane's message, the text left as it was; a test answers a two-selection pipe with an output one byte past the cap Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Pipe.zig | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Pipe.zig b/src/Pipe.zig index a02b9214..4d525f01 100644 --- a/src/Pipe.zig +++ b/src/Pipe.zig @@ -297,13 +297,18 @@ pub fn pipeResponse( const n = wait.nranges; var ops: [panes.Text.max_selections]sam.Op = undefined; var total_output: usize = 0; + // The runner refuses these first (selection_pipe's too_large); an + // answer from elsewhere past them is said, the text left as it was. + var said: [128]u8 = undefined; for (0..n) |i| { const cut = pipeCut(&wait, content, i) orelse return; const output = pipeOutput(&wait, outputs, content, i); - if (output.len > selection_pipe.max_stdout_bytes) return; - total_output = std.math.add(usize, total_output, output.len) catch return; // past any cap - if (total_output > selection_pipe.max_total_stdout_bytes) return; - if (i > 0 and cut.lo < ops[i - 1].q1) return; + if (output.len > selection_pipe.max_stdout_bytes) + return p.setMessage(wait.pane, std.fmt.bufPrint(&said, "pipe: an output of {d} bytes, past {d}: the text is left as it was", .{ output.len, selection_pipe.max_stdout_bytes }) catch unreachable); // two numbers fit 128 + total_output += output.len; // each under 1 MiB, at most max_selections of them + if (total_output > selection_pipe.max_total_stdout_bytes) + return p.setMessage(wait.pane, std.fmt.bufPrint(&said, "pipe: {d} bytes of output in all, past {d}: the text is left as it was", .{ total_output, selection_pipe.max_total_stdout_bytes }) catch unreachable); // two numbers fit 128 + if (i > 0 and cut.lo < ops[i - 1].q1) return p.setMessage(wait.pane, "pipe: the selections overlap: the text is left as it was"); ops[i] = .{ .q0 = @intCast(cut.lo), .q1 = @intCast(cut.hi), .text = output }; } const replacement = sam.apply(p.gpa, content, ops[0..n]) catch |err| return p.reportError(wait.pane, "pipe", err); @@ -456,6 +461,27 @@ test "selection pipe replaces all ranges atomically and undo restores them" { try std.testing.expectEqualSlices(u8, "aa bb cc\n", pane.file.?.content); } +test "a pipe's output past its cap leaves the text as it was, and says so" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + const pane = try p.setTestFile("aa bb cc\n"); + const ranges = [_]modal.Selection{ .{ .anchor = 0, .head = 2 }, .{ .anchor = 6, .head = 8 } }; + pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 1, true); + p.update(.{ .key = .{ .cp = '|' } }); + p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); + p.update(.{ .key = .{ .cp = Key.enter } }); + const id = nextPipeEffect(p) orelse return error.MissingPipeEffect; + const big = try gpa.alloc(u8, selection_pipe.max_stdout_bytes + 1); + defer gpa.free(big); + @memset(big, 'x'); + const outputs: []const []const u8 = &.{ "AA", big }; + p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = outputs } }); + try std.testing.expectEqualSlices(u8, "aa bb cc\n", pane.file.?.content); + try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "past") != null); +} + test "the four shell behaviours put their output where helix puts it" { const gpa = std.testing.allocator; const Case = struct { -- cgit v1.3