feat: custom tool renderers
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { readStoredToolError, serializeToolError } from "../utils/tool-errors";
|
||||
|
||||
const validationError = "Invalid input for tool search: Type validation failed: Value: {\"query\":123}.\nError message: [{\"code\":\"custom\"}]";
|
||||
|
||||
test("tool Error instances persist their message, not an empty JSON object", () => {
|
||||
expect(serializeToolError(new Error(validationError))).toBe(validationError);
|
||||
expect(serializeToolError(validationError)).toBe(validationError);
|
||||
expect(serializeToolError({ reason: "invalid input" })).toBe('{"reason":"invalid input"}');
|
||||
});
|
||||
|
||||
test("text validation errors remain text on history replay", () => {
|
||||
expect(readStoredToolError({ type: "text", value: validationError })).toEqual({
|
||||
type: "error-text",
|
||||
value: validationError,
|
||||
});
|
||||
});
|
||||
|
||||
test("legacy mislabeled JSON errors cannot break subsequent prompts", () => {
|
||||
expect(readStoredToolError({ type: "json", value: validationError })).toEqual({
|
||||
type: "error-text",
|
||||
value: validationError,
|
||||
});
|
||||
});
|
||||
|
||||
test("preserves actual JSON errors and handles missing errors", () => {
|
||||
expect(readStoredToolError({ type: "json", value: '{"reason":"bad input"}' })).toEqual({
|
||||
type: "error-json",
|
||||
value: { reason: "bad input" },
|
||||
});
|
||||
expect(readStoredToolError(null).type).toBe("error-text");
|
||||
expect(readStoredToolError(undefined).type).toBe("error-text");
|
||||
});
|
||||
Reference in New Issue
Block a user