-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhooks.test.ts
More file actions
51 lines (43 loc) · 1.89 KB
/
Copy pathhooks.test.ts
File metadata and controls
51 lines (43 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { describe, expect, test } from "bun:test";
import type { ReactorEmittedEvent } from "@intx/inference";
import { createTurnContextCollector, HOOK_PAYLOAD_TOOL_RESULT_CHARS } from "./hooks.js";
function event(type: string, data: unknown): ReactorEmittedEvent {
return { type, seq: 1, data } as ReactorEmittedEvent;
}
function observeOneTurnWithToolResult(
collector: ReturnType<typeof createTurnContextCollector>,
toolResultContent: string,
): void {
collector.observe(event("inference.done", {
turn: {
role: "assistant",
content: [{ type: "tool_call", id: "call-1", name: "run_shell", arguments: {} }],
model: "test",
timestamp: 0,
},
usage: { input: 1, output: 1, cacheRead: 0, cacheWrite: 0, thinking: 0 },
source: { provider: "test", model: "test" },
}));
collector.observe(event("tool.done", {
result: { callId: "call-1", content: toolResultContent },
}));
}
describe("createTurnContextCollector tool result truncation", () => {
test("retains oversized tool result content within the hook-payload budget", () => {
const collector = createTurnContextCollector(() => {});
const hugeOutput = "x".repeat(HOOK_PAYLOAD_TOOL_RESULT_CHARS * 4);
observeOneTurnWithToolResult(collector, hugeOutput);
const [turn] = collector.getTurns();
const content = turn?.toolResults[0]?.content;
expect(typeof content).toBe("string");
expect((content as string).length).toBeLessThan(hugeOutput.length);
expect((content as string).length).toBeLessThanOrEqual(HOOK_PAYLOAD_TOOL_RESULT_CHARS + 64);
});
test("leaves tool result content under the budget untouched", () => {
const collector = createTurnContextCollector(() => {});
const smallOutput = "exit code 0";
observeOneTurnWithToolResult(collector, smallOutput);
const [turn] = collector.getTurns();
expect(turn?.toolResults[0]?.content).toBe(smallOutput);
});
});