test(agents): dedupe agent and cron test scaffolds

This commit is contained in:
Peter Steinberger
2026-03-02 06:40:42 +00:00
parent 281494ae52
commit 7e29d604ba
38 changed files with 3114 additions and 4486 deletions

View File

@@ -7,92 +7,66 @@ import {
import { sanitizeSessionHistory } from "./pi-embedded-runner/google.js";
describe("sanitizeSessionHistory openai tool id preservation", () => {
it("strips fc ids when replayable reasoning metadata is missing", async () => {
const sessionEntries = [
const makeSessionManager = () =>
makeInMemorySessionManager([
makeModelSnapshotEntry({
provider: "openai",
modelApi: "openai-responses",
modelId: "gpt-5.2-codex",
}),
];
const sessionManager = makeInMemorySessionManager(sessionEntries);
]);
const messages: AgentMessage[] = [
{
role: "assistant",
content: [{ type: "toolCall", id: "call_123|fc_123", name: "noop", arguments: {} }],
} as unknown as AgentMessage,
{
role: "toolResult",
toolCallId: "call_123|fc_123",
toolName: "noop",
content: [{ type: "text", text: "ok" }],
isError: false,
} as unknown as AgentMessage,
];
const makeMessages = (withReasoning: boolean): AgentMessage[] => [
{
role: "assistant",
content: [
...(withReasoning
? [
{
type: "thinking",
thinking: "internal reasoning",
thinkingSignature: JSON.stringify({ id: "rs_123", type: "reasoning" }),
},
]
: []),
{ type: "toolCall", id: "call_123|fc_123", name: "noop", arguments: {} },
],
} as unknown as AgentMessage,
{
role: "toolResult",
toolCallId: "call_123|fc_123",
toolName: "noop",
content: [{ type: "text", text: "ok" }],
isError: false,
} as unknown as AgentMessage,
];
it.each([
{
name: "strips fc ids when replayable reasoning metadata is missing",
withReasoning: false,
expectedToolId: "call_123",
},
{
name: "keeps canonical call_id|fc_id pairings when replayable reasoning is present",
withReasoning: true,
expectedToolId: "call_123|fc_123",
},
])("$name", async ({ withReasoning, expectedToolId }) => {
const result = await sanitizeSessionHistory({
messages,
messages: makeMessages(withReasoning),
modelApi: "openai-responses",
provider: "openai",
modelId: "gpt-5.2-codex",
sessionManager,
sessionManager: makeSessionManager(),
sessionId: "test-session",
});
const assistant = result[0] as { content?: Array<{ type?: string; id?: string }> };
const toolCall = assistant.content?.find((block) => block.type === "toolCall");
expect(toolCall?.id).toBe("call_123");
expect(toolCall?.id).toBe(expectedToolId);
const toolResult = result[1] as { toolCallId?: string };
expect(toolResult.toolCallId).toBe("call_123");
});
it("keeps canonical call_id|fc_id pairings when replayable reasoning is present", async () => {
const sessionEntries = [
makeModelSnapshotEntry({
provider: "openai",
modelApi: "openai-responses",
modelId: "gpt-5.2-codex",
}),
];
const sessionManager = makeInMemorySessionManager(sessionEntries);
const messages: AgentMessage[] = [
{
role: "assistant",
content: [
{
type: "thinking",
thinking: "internal reasoning",
thinkingSignature: JSON.stringify({ id: "rs_123", type: "reasoning" }),
},
{ type: "toolCall", id: "call_123|fc_123", name: "noop", arguments: {} },
],
} as unknown as AgentMessage,
{
role: "toolResult",
toolCallId: "call_123|fc_123",
toolName: "noop",
content: [{ type: "text", text: "ok" }],
isError: false,
} as unknown as AgentMessage,
];
const result = await sanitizeSessionHistory({
messages,
modelApi: "openai-responses",
provider: "openai",
modelId: "gpt-5.2-codex",
sessionManager,
sessionId: "test-session",
});
const assistant = result[0] as { content?: Array<{ type?: string; id?: string }> };
const toolCall = assistant.content?.find((block) => block.type === "toolCall");
expect(toolCall?.id).toBe("call_123|fc_123");
const toolResult = result[1] as { toolCallId?: string };
expect(toolResult.toolCallId).toBe("call_123|fc_123");
expect(toolResult.toolCallId).toBe(expectedToolId);
});
});