mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 23:44:33 +00:00
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");
|
.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: {
|
async function runAbortedOpenAIResponsesStream(params: {
|
||||||
messages: Array<
|
messages: Array<
|
||||||
AssistantMessage | ToolResultMessage | { role: "user"; content: string; timestamp: number }
|
AssistantMessage | ToolResultMessage | { role: "user"; content: string; timestamp: number }
|
||||||
@@ -70,31 +107,10 @@ async function runAbortedOpenAIResponsesStream(params: {
|
|||||||
|
|
||||||
describe("openai-responses reasoning replay", () => {
|
describe("openai-responses reasoning replay", () => {
|
||||||
it("replays reasoning for tool-call-only turns (OpenAI requires it)", async () => {
|
it("replays reasoning for tool-call-only turns (OpenAI requires it)", async () => {
|
||||||
const assistantToolOnly: AssistantMessage = {
|
const assistantToolOnly = buildAssistantMessage({
|
||||||
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 },
|
|
||||||
},
|
|
||||||
stopReason: "toolUse",
|
stopReason: "toolUse",
|
||||||
timestamp: Date.now(),
|
|
||||||
content: [
|
content: [
|
||||||
{
|
buildReasoningPart(),
|
||||||
type: "thinking",
|
|
||||||
thinking: "internal",
|
|
||||||
thinkingSignature: JSON.stringify({
|
|
||||||
type: "reasoning",
|
|
||||||
id: "rs_test",
|
|
||||||
summary: [],
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
type: "toolCall",
|
type: "toolCall",
|
||||||
id: "call_123|fc_123",
|
id: "call_123|fc_123",
|
||||||
@@ -102,7 +118,7 @@ describe("openai-responses reasoning replay", () => {
|
|||||||
arguments: {},
|
arguments: {},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
});
|
||||||
|
|
||||||
const toolResult: ToolResultMessage = {
|
const toolResult: ToolResultMessage = {
|
||||||
role: "toolResult",
|
role: "toolResult",
|
||||||
@@ -152,34 +168,10 @@ describe("openai-responses reasoning replay", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("still replays reasoning when paired with an assistant message", async () => {
|
it("still replays reasoning when paired with an assistant message", async () => {
|
||||||
const assistantWithText: AssistantMessage = {
|
const assistantWithText = buildAssistantMessage({
|
||||||
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 },
|
|
||||||
},
|
|
||||||
stopReason: "stop",
|
stopReason: "stop",
|
||||||
timestamp: Date.now(),
|
content: [buildReasoningPart(), { type: "text", text: "hello", textSignature: "msg_test" }],
|
||||||
content: [
|
});
|
||||||
{
|
|
||||||
type: "thinking",
|
|
||||||
thinking: "internal",
|
|
||||||
thinkingSignature: JSON.stringify({
|
|
||||||
type: "reasoning",
|
|
||||||
id: "rs_test",
|
|
||||||
summary: [],
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{ type: "text", text: "hello", textSignature: "msg_test" },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const { types } = await runAbortedOpenAIResponsesStream({
|
const { types } = await runAbortedOpenAIResponsesStream({
|
||||||
messages: [
|
messages: [
|
||||||
|
|||||||
Reference in New Issue
Block a user