mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-19 12:41:35 +00:00
normalizeAgentEventType checked the `phase:"end" || status==="completed"` branch before the `failed/blocked` branch, but terminal tool/item events are emitted with phase:"end" AND the real status, so failed and blocked tools were normalized to tool.call.completed and the tool.call.failed branch was dead for the item stream. SDK consumers filtering on tool.call.failed never saw tool failures (they looked like successes). Reorder so failed/blocked is classified before end/completed. Co-authored-by: ly-wang19 <ly-wang19@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { normalizeGatewayEvent } from "./normalize.js";
|
|
|
|
// Terminal tool/item events are emitted with phase:"end" plus the real status
|
|
// (running|completed|failed|blocked), so failed/blocked must not collapse to completed.
|
|
function agentItemEvent(data: Record<string, unknown>) {
|
|
return { event: "agent", payload: { runId: "r1", stream: "item", data } };
|
|
}
|
|
|
|
describe("normalizeGatewayEvent terminal tool item status", () => {
|
|
it("classifies a failed terminal tool item as tool.call.failed", () => {
|
|
expect(normalizeGatewayEvent(agentItemEvent({ phase: "end", status: "failed" })).type).toBe(
|
|
"tool.call.failed",
|
|
);
|
|
});
|
|
|
|
it("classifies a blocked terminal tool item as tool.call.failed", () => {
|
|
expect(normalizeGatewayEvent(agentItemEvent({ phase: "end", status: "blocked" })).type).toBe(
|
|
"tool.call.failed",
|
|
);
|
|
});
|
|
|
|
it("still classifies a completed terminal tool item as tool.call.completed", () => {
|
|
expect(normalizeGatewayEvent(agentItemEvent({ phase: "end", status: "completed" })).type).toBe(
|
|
"tool.call.completed",
|
|
);
|
|
});
|
|
|
|
it("still classifies a phase:end tool item without status as tool.call.completed", () => {
|
|
expect(normalizeGatewayEvent(agentItemEvent({ phase: "end" })).type).toBe(
|
|
"tool.call.completed",
|
|
);
|
|
});
|
|
});
|