mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-09 15:35:17 +00:00
refactor(agents): dedupe anthropic turn validation fixtures
This commit is contained in:
@@ -10,6 +10,28 @@ function asMessages(messages: unknown[]): AgentMessage[] {
|
||||
return messages as AgentMessage[];
|
||||
}
|
||||
|
||||
function makeDualToolUseAssistantContent() {
|
||||
return [
|
||||
{ type: "toolUse", id: "tool-1", name: "test1", input: {} },
|
||||
{ type: "toolUse", id: "tool-2", name: "test2", input: {} },
|
||||
{ type: "text", text: "Done" },
|
||||
];
|
||||
}
|
||||
|
||||
function makeDualToolAnthropicTurns(nextUserContent: unknown[]) {
|
||||
return asMessages([
|
||||
{ role: "user", content: [{ type: "text", text: "Use tools" }] },
|
||||
{
|
||||
role: "assistant",
|
||||
content: makeDualToolUseAssistantContent(),
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: nextUserContent,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
describe("validate turn edge cases", () => {
|
||||
it("returns empty array unchanged", () => {
|
||||
expect(validateGeminiTurns([])).toEqual([]);
|
||||
@@ -410,18 +432,7 @@ describe("validateAnthropicTurns strips dangling tool_use blocks", () => {
|
||||
});
|
||||
|
||||
it("should handle multiple dangling tool_use blocks", () => {
|
||||
const msgs = asMessages([
|
||||
{ role: "user", content: [{ type: "text", text: "Use tools" }] },
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolUse", id: "tool-1", name: "test1", input: {} },
|
||||
{ type: "toolUse", id: "tool-2", name: "test2", input: {} },
|
||||
{ type: "text", text: "Done" },
|
||||
],
|
||||
},
|
||||
{ role: "user", content: [{ type: "text", text: "OK" }] },
|
||||
]);
|
||||
const msgs = makeDualToolAnthropicTurns([{ type: "text", text: "OK" }]);
|
||||
|
||||
const result = validateAnthropicTurns(msgs);
|
||||
|
||||
@@ -432,27 +443,13 @@ describe("validateAnthropicTurns strips dangling tool_use blocks", () => {
|
||||
});
|
||||
|
||||
it("should handle mixed tool_use with some having matching tool_result", () => {
|
||||
const msgs = asMessages([
|
||||
{ role: "user", content: [{ type: "text", text: "Use tools" }] },
|
||||
const msgs = makeDualToolAnthropicTurns([
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolUse", id: "tool-1", name: "test1", input: {} },
|
||||
{ type: "toolUse", id: "tool-2", name: "test2", input: {} },
|
||||
{ type: "text", text: "Done" },
|
||||
],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "toolResult",
|
||||
toolUseId: "tool-1",
|
||||
content: [{ type: "text", text: "Result 1" }],
|
||||
},
|
||||
{ type: "text", text: "Thanks" },
|
||||
],
|
||||
type: "toolResult",
|
||||
toolUseId: "tool-1",
|
||||
content: [{ type: "text", text: "Result 1" }],
|
||||
},
|
||||
{ type: "text", text: "Thanks" },
|
||||
]);
|
||||
|
||||
const result = validateAnthropicTurns(msgs);
|
||||
@@ -486,25 +483,11 @@ describe("validateAnthropicTurns strips dangling tool_use blocks", () => {
|
||||
});
|
||||
|
||||
it("is replay-safe across repeated validation passes", () => {
|
||||
const msgs = asMessages([
|
||||
{ role: "user", content: [{ type: "text", text: "Use tools" }] },
|
||||
const msgs = makeDualToolAnthropicTurns([
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolUse", id: "tool-1", name: "test1", input: {} },
|
||||
{ type: "toolUse", id: "tool-2", name: "test2", input: {} },
|
||||
{ type: "text", text: "Done" },
|
||||
],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "toolResult",
|
||||
toolUseId: "tool-1",
|
||||
content: [{ type: "text", text: "Result 1" }],
|
||||
},
|
||||
],
|
||||
type: "toolResult",
|
||||
toolUseId: "tool-1",
|
||||
content: [{ type: "text", text: "Result 1" }],
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user