test(agents): dedupe openai reasoning replay fixtures
This commit is contained in:
@@ -30,6 +30,43 @@ function extractInputTypes(input: unknown[]) {
|
||||
.filter((t): t is string => typeof t === "string");
|
||||
}
|
||||
|
||||
const ZERO_USAGE = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
} as const;
|
||||
|
||||
function buildReasoningPart(id = "rs_test") {
|
||||
return {
|
||||
type: "thinking" as const,
|
||||
thinking: "internal",
|
||||
thinkingSignature: JSON.stringify({
|
||||
type: "reasoning",
|
||||
id,
|
||||
summary: [],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function buildAssistantMessage(params: {
|
||||
stopReason: AssistantMessage["stopReason"];
|
||||
content: AssistantMessage["content"];
|
||||
}): AssistantMessage {
|
||||
return {
|
||||
role: "assistant",
|
||||
api: "openai-responses",
|
||||
provider: "openai",
|
||||
model: "gpt-5.2",
|
||||
usage: ZERO_USAGE,
|
||||
stopReason: params.stopReason,
|
||||
timestamp: Date.now(),
|
||||
content: params.content,
|
||||
};
|
||||
}
|
||||
|
||||
async function runAbortedOpenAIResponsesStream(params: {
|
||||
messages: Array<
|
||||
AssistantMessage | ToolResultMessage | { role: "user"; content: string; timestamp: number }
|
||||
@@ -70,31 +107,10 @@ async function runAbortedOpenAIResponsesStream(params: {
|
||||
|
||||
describe("openai-responses reasoning replay", () => {
|
||||
it("replays reasoning for tool-call-only turns (OpenAI requires it)", async () => {
|
||||
const assistantToolOnly: AssistantMessage = {
|
||||
role: "assistant",
|
||||
api: "openai-responses",
|
||||
provider: "openai",
|
||||
model: "gpt-5.2",
|
||||
usage: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
},
|
||||
const assistantToolOnly = buildAssistantMessage({
|
||||
stopReason: "toolUse",
|
||||
timestamp: Date.now(),
|
||||
content: [
|
||||
{
|
||||
type: "thinking",
|
||||
thinking: "internal",
|
||||
thinkingSignature: JSON.stringify({
|
||||
type: "reasoning",
|
||||
id: "rs_test",
|
||||
summary: [],
|
||||
}),
|
||||
},
|
||||
buildReasoningPart(),
|
||||
{
|
||||
type: "toolCall",
|
||||
id: "call_123|fc_123",
|
||||
@@ -102,7 +118,7 @@ describe("openai-responses reasoning replay", () => {
|
||||
arguments: {},
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
const toolResult: ToolResultMessage = {
|
||||
role: "toolResult",
|
||||
@@ -152,34 +168,10 @@ describe("openai-responses reasoning replay", () => {
|
||||
});
|
||||
|
||||
it("still replays reasoning when paired with an assistant message", async () => {
|
||||
const assistantWithText: AssistantMessage = {
|
||||
role: "assistant",
|
||||
api: "openai-responses",
|
||||
provider: "openai",
|
||||
model: "gpt-5.2",
|
||||
usage: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
},
|
||||
const assistantWithText = buildAssistantMessage({
|
||||
stopReason: "stop",
|
||||
timestamp: Date.now(),
|
||||
content: [
|
||||
{
|
||||
type: "thinking",
|
||||
thinking: "internal",
|
||||
thinkingSignature: JSON.stringify({
|
||||
type: "reasoning",
|
||||
id: "rs_test",
|
||||
summary: [],
|
||||
}),
|
||||
},
|
||||
{ type: "text", text: "hello", textSignature: "msg_test" },
|
||||
],
|
||||
};
|
||||
content: [buildReasoningPart(), { type: "text", text: "hello", textSignature: "msg_test" }],
|
||||
});
|
||||
|
||||
const { types } = await runAbortedOpenAIResponsesStream({
|
||||
messages: [
|
||||
|
||||
Reference in New Issue
Block a user