Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Move the ACP citation test out of acp_stream.zig (600-line cap)

justrachcec14f74d494
diff --git a/src/acp_citations.zig b/src/acp_citations.zig
index 40f2bd1b..86aca7b6 100644
--- a/src/acp_citations.zig
+++ b/src/acp_citations.zig
@@ -177,3 +177,32 @@ test "whole strips replayed history without session state" {
defer cleaned.deinit();
try std.testing.expectEqualStrings("History line", cleaned.text);
}
+
+test "translateEvent: a citation marker split across text events never reaches the client" {
+ defer endTurn("sess-9");
+ var buf: [2048]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&buf);
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const a = arena_state.allocator();
+ var id_buf: [64]u8 = @splat(0);
+ var next: u32 = 0;
+ for ([_][]const u8{
+ "{\"type\":\"reasoning\",\"text\":\"checked \\ue200cite\\ue202turn1search0\\ue201\"}",
+ "{\"type\":\"text\",\"text\":\"Rotate them. \\ue200cite\\ue202tur\"}",
+ "{\"type\":\"text\",\"text\":\"n3search0\\ue201\"}",
+ "{\"type\":\"text\",\"text\":\" Done.\"}",
+ }) |line| {
+ const ev = try std.json.parseFromSliceLeaky(std.json.Value, a, line, .{});
+ _ = try @import("acp_stream.zig").translateEvent(&w, "sess-9", ev, &id_buf, &next);
+ }
+ const out = w.buffered();
+ try std.testing.expect(std.mem.indexOf(u8, out, "\u{E200}") == null and std.mem.indexOf(u8, out, "\u{E201}") == null);
+ try std.testing.expect(std.mem.indexOf(u8, out, "turn3search0") == null and std.mem.indexOf(u8, out, "search0") == null);
+ try std.testing.expect(std.mem.indexOf(u8, out, "cite") == null);
+ try std.testing.expect(std.mem.indexOf(u8, out, "Rotate them. ") != null and std.mem.indexOf(u8, out, " Done.") != null);
+ try std.testing.expect(std.mem.indexOf(u8, out, "checked ") != null);
+ // The all-marker delta sends nothing: two message chunks, one thought.
+ try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, out, "agent_message_chunk"));
+ try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, out, "agent_thought_chunk"));
+}
diff --git a/src/acp_stream.zig b/src/acp_stream.zig
index e02135ef..f8cd09bf 100644
--- a/src/acp_stream.zig
+++ b/src/acp_stream.zig
@@ -454,35 +454,6 @@ test "translateEvent: reasoning and text become chunks" {
try testing.expect(std.mem.indexOf(u8, w.buffered(), "agent_message_chunk") != null);
}
-test "translateEvent: a citation marker split across text events never reaches the client" {
- defer @import("acp_citations.zig").endTurn("sess-9");
- var buf: [2048]u8 = undefined;
- var w: Io.Writer = .fixed(&buf);
- var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
- defer arena_state.deinit();
- const a = arena_state.allocator();
- var id_buf: [64]u8 = @splat(0);
- var next: u32 = 0;
- for ([_][]const u8{
- "{\"type\":\"reasoning\",\"text\":\"checked \\ue200cite\\ue202turn1search0\\ue201\"}",
- "{\"type\":\"text\",\"text\":\"Rotate them. \\ue200cite\\ue202tur\"}",
- "{\"type\":\"text\",\"text\":\"n3search0\\ue201\"}",
- "{\"type\":\"text\",\"text\":\" Done.\"}",
- }) |line| {
- const ev = try std.json.parseFromSliceLeaky(Value, a, line, .{});
- _ = try translateEvent(&w, "sess-9", ev, &id_buf, &next);
- }
- const out = w.buffered();
- try testing.expect(std.mem.indexOf(u8, out, "\u{E200}") == null and std.mem.indexOf(u8, out, "\u{E201}") == null);
- try testing.expect(std.mem.indexOf(u8, out, "turn3search0") == null and std.mem.indexOf(u8, out, "search0") == null);
- try testing.expect(std.mem.indexOf(u8, out, "cite") == null);
- try testing.expect(std.mem.indexOf(u8, out, "Rotate them. ") != null and std.mem.indexOf(u8, out, " Done.") != null);
- try testing.expect(std.mem.indexOf(u8, out, "checked ") != null);
- // The all-marker delta sends nothing: two message chunks, one thought.
- try testing.expectEqual(@as(usize, 2), std.mem.count(u8, out, "agent_message_chunk"));
- try testing.expectEqual(@as(usize, 1), std.mem.count(u8, out, "agent_thought_chunk"));
-}
-
test "translateEvent: a transient-retry text event is an agent_message_chunk" {
var buf: [1024]u8 = undefined;
var w: Io.Writer = .fixed(&buf);