mirror of https://github.com/openclaw/openclaw.git
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveCronPayloadOutcome } from "./isolated-agent/helpers.js";
|
|
|
|
describe("resolveCronPayloadOutcome", () => {
|
|
it("uses the last non-empty non-error payload as summary and output", () => {
|
|
const result = resolveCronPayloadOutcome({
|
|
payloads: [{ text: "first" }, { text: " " }, { text: " last " }],
|
|
});
|
|
|
|
expect(result.summary).toBe("last");
|
|
expect(result.outputText).toBe("last");
|
|
expect(result.hasFatalErrorPayload).toBe(false);
|
|
});
|
|
|
|
it("returns a fatal error from the last error payload when no success follows", () => {
|
|
const result = resolveCronPayloadOutcome({
|
|
payloads: [
|
|
{
|
|
text: "⚠️ 🛠️ Exec failed: /bin/bash: line 1: python: command not found",
|
|
isError: true,
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(result.hasFatalErrorPayload).toBe(true);
|
|
expect(result.embeddedRunError).toContain("command not found");
|
|
expect(result.summary).toContain("Exec failed");
|
|
});
|
|
|
|
it("treats transient error payloads as non-fatal when a later success exists", () => {
|
|
const result = resolveCronPayloadOutcome({
|
|
payloads: [
|
|
{ text: "⚠️ ✍️ Write: failed", isError: true },
|
|
{ text: "Write completed successfully.", isError: false },
|
|
],
|
|
});
|
|
|
|
expect(result.hasFatalErrorPayload).toBe(false);
|
|
expect(result.summary).toBe("Write completed successfully.");
|
|
});
|
|
|
|
it("keeps error payloads fatal when the run also reported a run-level error", () => {
|
|
const result = resolveCronPayloadOutcome({
|
|
payloads: [
|
|
{ text: "Model context overflow", isError: true },
|
|
{ text: "Partial assistant text before error" },
|
|
],
|
|
runLevelError: { kind: "context_overflow", message: "exceeded context window" },
|
|
});
|
|
|
|
expect(result.hasFatalErrorPayload).toBe(true);
|
|
expect(result.embeddedRunError).toContain("Model context overflow");
|
|
});
|
|
|
|
it("truncates long summaries", () => {
|
|
const result = resolveCronPayloadOutcome({
|
|
payloads: [{ text: "a".repeat(2001) }],
|
|
});
|
|
|
|
expect(String(result.summary ?? "")).toMatch(/…$/);
|
|
});
|
|
});
|