test(agents): cover openai responses phase replay

This commit is contained in:
Peter Steinberger
2026-03-11 20:10:18 +00:00
parent 9c81c31232
commit 9329a0ab24

View File

@@ -30,6 +30,13 @@ function extractInputTypes(input: unknown[]) {
.filter((t): t is string => typeof t === "string"); .filter((t): t is string => typeof t === "string");
} }
function extractInputMessages(input: unknown[]) {
return input.filter(
(item): item is Record<string, unknown> =>
!!item && typeof item === "object" && (item as Record<string, unknown>).type === "message",
);
}
const ZERO_USAGE = { const ZERO_USAGE = {
input: 0, input: 0,
output: 0, output: 0,
@@ -184,4 +191,36 @@ describe("openai-responses reasoning replay", () => {
expect(types).toContain("reasoning"); expect(types).toContain("reasoning");
expect(types).toContain("message"); expect(types).toContain("message");
}); });
it.each(["commentary", "final_answer"] as const)(
"replays assistant message phase metadata for %s",
async (phase) => {
const assistantWithText = buildAssistantMessage({
stopReason: "stop",
content: [
buildReasoningPart(),
{
type: "text",
text: "hello",
textSignature: JSON.stringify({ v: 1, id: `msg_${phase}`, phase }),
},
],
});
const { input, types } = await runAbortedOpenAIResponsesStream({
messages: [
{ role: "user", content: "Hi", timestamp: Date.now() },
assistantWithText,
{ role: "user", content: "Ok", timestamp: Date.now() },
],
});
expect(types).toContain("message");
const replayedMessage = extractInputMessages(input).find(
(item) => item.id === `msg_${phase}`,
);
expect(replayedMessage?.phase).toBe(phase);
},
);
}); });