fix: bound preview query context
This commit is contained in:
6 files changed
+139
-5
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { customWidgetPreviewQueryOutputMaxCharacters, toAssistantToolOutput } from "./assistant-tool-output";
|
||||
|
||||
describe("assistant tool output", () => {
|
||||
test("preserves tool output within the configured context budget", () => {
|
||||
expect(toAssistantToolOutput({ ok: true, data: [{ id: 1 }] }, { maxCharacters: 8_000 })).toEqual({
|
||||
ok: true,
|
||||
data: [{ id: 1 }],
|
||||
});
|
||||
});
|
||||
|
||||
test("returns a bounded preview for oversized tool output", () => {
|
||||
const output = toAssistantToolOutput(
|
||||
{ ok: true, status: 200, data: Array.from({ length: 1_000 }, (_, index) => ({ index, value: "x".repeat(100) })) },
|
||||
{ maxCharacters: customWidgetPreviewQueryOutputMaxCharacters },
|
||||
);
|
||||
const serialized = JSON.stringify(output);
|
||||
|
||||
expect(output).toEqual(
|
||||
expect.objectContaining({
|
||||
truncated: true,
|
||||
originalCharacters: expect.any(Number),
|
||||
preview: expect.stringContaining('"status":200'),
|
||||
}),
|
||||
);
|
||||
expect(serialized.length).toBeLessThanOrEqual(customWidgetPreviewQueryOutputMaxCharacters);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user