mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-11 05:11:49 +01:00
test: cover heartbeat run summary projections
(cherry picked from commit d6c3a86b2221adf3ce406622b85cfd5e7f284201)
This commit is contained in:
1 parent
10ade0582b
commit
d976fd8944
1 file changed
+83
@@ -0,0 +1,83 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
summarizeHeartbeatRunContextSnapshot,
|
||||
summarizeHeartbeatRunListResultJson,
|
||||
} from "../services/heartbeat.js";
|
||||
|
||||
describe("summarizeHeartbeatRunContextSnapshot", () => {
|
||||
it("keeps only the small retry/linking fields needed by the client", () => {
|
||||
const summarized = summarizeHeartbeatRunContextSnapshot({
|
||||
issueId: "issue-1",
|
||||
taskId: "task-1",
|
||||
taskKey: "PAP-1",
|
||||
commentId: "comment-1",
|
||||
wakeCommentId: "comment-2",
|
||||
wakeReason: "retry_failed_run",
|
||||
wakeSource: "on_demand",
|
||||
wakeTriggerDetail: "manual",
|
||||
paperclipWake: {
|
||||
comments: [
|
||||
{
|
||||
body: "x".repeat(50_000),
|
||||
},
|
||||
],
|
||||
},
|
||||
executionStage: {
|
||||
summary: "large nested object that should not be sent back in run lists",
|
||||
},
|
||||
});
|
||||
|
||||
expect(summarized).toEqual({
|
||||
issueId: "issue-1",
|
||||
taskId: "task-1",
|
||||
taskKey: "PAP-1",
|
||||
commentId: "comment-1",
|
||||
wakeCommentId: "comment-2",
|
||||
wakeReason: "retry_failed_run",
|
||||
wakeSource: "on_demand",
|
||||
wakeTriggerDetail: "manual",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when no allowed fields are present", () => {
|
||||
expect(
|
||||
summarizeHeartbeatRunContextSnapshot({
|
||||
paperclipWake: { comments: [{ body: "hello" }] },
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("summarizeHeartbeatRunListResultJson", () => {
|
||||
it("keeps only summary fields and parses numeric cost aliases", () => {
|
||||
expect(
|
||||
summarizeHeartbeatRunListResultJson({
|
||||
summary: "Completed the task",
|
||||
result: "Updated three files",
|
||||
message: "",
|
||||
error: null,
|
||||
totalCostUsd: "1.25",
|
||||
costUsd: "0.75",
|
||||
costUsdCamel: "0.5",
|
||||
}),
|
||||
).toEqual({
|
||||
summary: "Completed the task",
|
||||
result: "Updated three files",
|
||||
total_cost_usd: 1.25,
|
||||
cost_usd: 0.75,
|
||||
costUsd: 0.5,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when projected fields are empty", () => {
|
||||
expect(
|
||||
summarizeHeartbeatRunListResultJson({
|
||||
summary: "",
|
||||
result: null,
|
||||
message: undefined,
|
||||
error: " ",
|
||||
totalCostUsd: "abc",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user