Skip to content

Commit 887b6d4

Browse files
committed
test(qa): recognize internal image completions
1 parent 5e1e70e commit 887b6d4

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎extensions/qa-lab/src/providers/mock-openai/mock-openai-assistant-text.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export function buildAssistantText(
6868
scenarioState: MockScenarioState,
6969
) {
7070
const prompt = extractLastUserText(input);
71-
const completedImageMediaPath = readCompletedImageGenerationMediaPath(prompt);
71+
const latestRawUserText = extractAllUserTexts(input).at(-1) ?? "";
72+
const completedImageMediaPath = readCompletedImageGenerationMediaPath(latestRawUserText);
7273
if (completedImageMediaPath) {
7374
return `Protocol note: generated the QA lighthouse image successfully.\nMEDIA:${completedImageMediaPath}`;
7475
}

‎extensions/qa-lab/src/providers/mock-openai/server.test.ts‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,20 +4176,46 @@ describe("qa mock openai server", () => {
41764176

41774177
it("completes an image without replaying a tool unavailable to the completion turn", async () => {
41784178
const server = await startMockServer();
4179+
const prompt = "Image generation check: generate a QA lighthouse image.";
4180+
const imagePlan = await expectResponsesJson<unknown>(server, {
4181+
stream: false,
4182+
tools: [IMAGE_GENERATE_TOOL],
4183+
input: [makeUserInput(prompt)],
4184+
});
4185+
const imageCall = outputToolCall(imagePlan, "image_generate");
4186+
const callId = outputToolCallId(imageCall, "call_mock_image_generate_unavailable");
4187+
const completionEvent = [
4188+
"<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>",
4189+
"OpenClaw runtime context (internal):",
4190+
"",
4191+
"[Internal task completion event]",
4192+
"source: image_generation",
4193+
"task: A QA lighthouse on a dark sea with a tiny protocol droid silhouette.",
4194+
"status: completed successfully",
4195+
"Generated media:",
4196+
"MEDIA:/tmp/qa-lighthouse.png",
4197+
"<<<END_OPENCLAW_INTERNAL_CONTEXT>>>",
4198+
].join("\n");
41794199
const completion = await expectResponsesJson<unknown>(server, {
41804200
stream: false,
41814201
tools: [MESSAGE_TOOL],
41824202
input: [
4183-
makeUserInput("Image generation check: generate a QA lighthouse image."),
4184-
makeUserInput(
4185-
[
4186-
"[Internal task completion event]",
4187-
"source: image_generation",
4188-
"status: completed successfully",
4189-
"Generated media:",
4190-
"MEDIA:/tmp/qa-lighthouse.png",
4191-
].join("\n"),
4192-
),
4203+
makeUserInput(prompt),
4204+
{
4205+
type: "function_call",
4206+
name: "image_generate",
4207+
call_id: callId,
4208+
arguments: String(imageCall.arguments),
4209+
},
4210+
{
4211+
type: "function_call_output",
4212+
call_id: callId,
4213+
output: JSON.stringify({
4214+
content: [{ type: "text", text: "Background image generation started." }],
4215+
details: { async: true, status: "started" },
4216+
}),
4217+
},
4218+
makeUserInput(completionEvent),
41934219
],
41944220
});
41954221

0 commit comments

Comments
 (0)