Skip to content

Commit 3ac7083

Browse files
authored
improve(qa): cover vision channel offload (#118862)
* test(qa): cover vision channel offload * test(qa): harden vision channel offload coverage
1 parent 6ce6dd3 commit 3ac7083

8 files changed

Lines changed: 366 additions & 14 deletions

File tree

‎extensions/qa-lab/src/gateway-child.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,34 @@ describe("buildQaRuntimeEnv", () => {
468468
expect(env.OPENCLAW_COMPATIBILITY_HOST_VERSION).toBe("2026.4.8");
469469
});
470470

471+
it("isolates gateway children from Vitest without removing QA controls or non-test NODE_ENV", () => {
472+
const testEnv = buildQaRuntimeEnv({
473+
...createParams({
474+
NODE_ENV: "test",
475+
VITEST: "true",
476+
VITEST_POOL_ID: "base-pool",
477+
VITEST_WORKER_ID: "base-worker",
478+
}),
479+
runtimeEnvPatch: {
480+
VITEST: "patched",
481+
VITEST_POOL_ID: "patched-pool",
482+
VITEST_WORKER_ID: "patched-worker",
483+
},
484+
});
485+
486+
expect(testEnv.NODE_ENV).toBeUndefined();
487+
expect(testEnv.VITEST).toBeUndefined();
488+
expect(testEnv.VITEST_POOL_ID).toBeUndefined();
489+
expect(testEnv.VITEST_WORKER_ID).toBeUndefined();
490+
expect(testEnv.OPENCLAW_TEST_FAST).toBe("1");
491+
expect(testEnv.OPENCLAW_ALLOW_SLOW_REPLY_TESTS).toBe("1");
492+
493+
const developmentEnv = buildQaRuntimeEnv({
494+
...createParams({ NODE_ENV: "development" }),
495+
});
496+
expect(developmentEnv.NODE_ENV).toBe("development");
497+
});
498+
471499
it("maps live frontier key aliases into provider env vars", () => {
472500
const env = buildQaRuntimeEnv({
473501
...createParams({

‎extensions/qa-lab/src/gateway-child.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ function scrubQaGatewayChildSecretEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv
136136
return env;
137137
}
138138

139+
function scrubQaGatewayChildTestRunnerEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
140+
// The Gateway is a product child, not a nested Vitest worker. Leaking runner
141+
// markers makes the dist launcher select test-only startup behavior.
142+
delete env.VITEST;
143+
delete env.VITEST_POOL_ID;
144+
delete env.VITEST_WORKER_ID;
145+
if (env.NODE_ENV === "test") {
146+
delete env.NODE_ENV;
147+
}
148+
return env;
149+
}
150+
139151
function createQaGatewayEmptyTransport() {
140152
return {
141153
requiredPluginIds: [] as const,
@@ -446,7 +458,7 @@ export function buildQaRuntimeEnv(params: {
446458
normalizedEnv.OPENCLAW_BUILD_PRIVATE_QA = "1";
447459
delete normalizedEnv[QA_LIVE_ANTHROPIC_SETUP_TOKEN_ENV];
448460
delete normalizedEnv[QA_LIVE_SETUP_TOKEN_VALUE_ENV];
449-
return scrubQaGatewayChildSecretEnv(normalizedEnv);
461+
return scrubQaGatewayChildSecretEnv(scrubQaGatewayChildTestRunnerEnv(normalizedEnv));
450462
}
451463

452464
async function stageQaCodexMockModelCatalog(params: {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
extractSlackMpimRetainedBotNonce,
3939
extractAllUserTexts,
4040
extractAllRequestTexts,
41-
extractLatestImageUserTurn,
41+
extractCurrentImageRequest,
4242
parseToolOutputJson,
4343
} from "./mock-openai-input.js";
4444
import {
@@ -167,7 +167,7 @@ export function buildAssistantText(input: ResponsesInputItem[], body: Record<str
167167
const userExactMarkerDirective =
168168
promptExactMarkerDirective ?? extractExactMarkerDirective(allUserText);
169169
const exactReplyDirective = promptExactReplyDirective ?? extractExactReplyDirective(allInputText);
170-
const latestImageUserTurn = extractLatestImageUserTurn(input);
170+
const currentImageRequest = extractCurrentImageRequest(input, body);
171171
const whatsAppLocationMarker = shouldUseWhatsAppLocationMarker(prompt)
172172
? extractWhatsAppLocationMarkerDirective(allInputText)
173173
: "";
@@ -218,14 +218,14 @@ export function buildAssistantText(input: ResponsesInputItem[], body: Record<str
218218
return "HEARTBEAT_OK";
219219
}
220220
if (
221-
/roundtrip image inspection check/i.test(latestImageUserTurn.text) &&
222-
latestImageUserTurn.imageInputCount > 0
221+
/roundtrip image inspection check/i.test(currentImageRequest.text) &&
222+
currentImageRequest.imageInputCount > 0
223223
) {
224224
return "Protocol note: the generated attachment shows the same QA lighthouse scene from the previous step.";
225225
}
226226
if (
227-
/image understanding check/i.test(latestImageUserTurn.text) &&
228-
latestImageUserTurn.imageInputCount > 0
227+
/image understanding check/i.test(currentImageRequest.text) &&
228+
currentImageRequest.imageInputCount > 0
229229
) {
230230
return "Protocol note: the attached image is split horizontally, with red on top and blue on the bottom.";
231231
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export function countImageInputs(value: unknown): number {
404404
return count;
405405
}
406406

407-
export function extractLatestImageUserTurn(input: ResponsesInputItem[]) {
407+
function extractLatestImageUserTurn(input: ResponsesInputItem[]) {
408408
const latestUserIndex = findLastUserIndex(input);
409409
if (latestUserIndex < 0) {
410410
return { text: "", imageInputCount: 0 };
@@ -429,6 +429,28 @@ export function extractLatestImageUserTurn(input: ResponsesInputItem[]) {
429429
};
430430
}
431431

432+
export function extractCurrentImageRequest(
433+
input: ResponsesInputItem[],
434+
body: Record<string, unknown>,
435+
) {
436+
// Match only the current request. Historical image prompts must not override
437+
// a later non-image turn just because they remain in transcript context.
438+
const imageUserTurn = extractLatestImageUserTurn(input);
439+
if (imageUserTurn.imageInputCount === 0) {
440+
return imageUserTurn;
441+
}
442+
const developerInstructions = input
443+
.filter((item) => item.role === "developer" && Array.isArray(item.content))
444+
.map((item) => extractInputText(item.content as unknown[]))
445+
.filter(Boolean);
446+
return {
447+
text: [extractInstructionsText(body), ...developerInstructions, imageUserTurn.text]
448+
.filter(Boolean)
449+
.join("\n"),
450+
imageInputCount: imageUserTurn.imageInputCount,
451+
};
452+
}
453+
432454
export function parseToolOutputJson(toolOutput: string): Record<string, unknown> | null {
433455
if (!toolOutput.trim()) {
434456
return null;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5470,6 +5470,39 @@ Update and merge these partial structured summaries.`,
54705470
expect(requireRecord(requestLog[0], "debug request 0").imageInputCount).toBe(1);
54715471
});
54725472

5473+
it("uses current request instructions for image descriptions", async () => {
5474+
const server = await startMockServer();
5475+
5476+
const payload = (await expectNonStreamingResponsesJson(server, {
5477+
model: "mock-openai/gpt-5.6-luna",
5478+
input: [
5479+
makeDeveloperInput("Image understanding check: describe the top and bottom colors."),
5480+
{
5481+
role: "user",
5482+
content: [
5483+
{
5484+
type: "input_image",
5485+
source: {
5486+
type: "base64",
5487+
mime_type: "image/png",
5488+
data: QA_IMAGE_PNG_BASE64,
5489+
},
5490+
},
5491+
{
5492+
type: "input_text",
5493+
text: "[media attached: media://inbound/red-top-blue-bottom.png (image/png)]",
5494+
},
5495+
],
5496+
},
5497+
],
5498+
})) as {
5499+
output?: Array<{ content?: Array<{ text?: string }> }>;
5500+
};
5501+
const text = payload.output?.[0]?.content?.[0]?.text ?? "";
5502+
expect(text.toLowerCase()).toContain("red");
5503+
expect(text.toLowerCase()).toContain("blue");
5504+
});
5505+
54735506
it("recognizes OpenAI-compatible image_url parts as image inputs", async () => {
54745507
const server = await startMockServer();
54755508

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ import {
153153
buildWhatsAppGroupDispatchReply,
154154
buildWhatsAppBatchedReply,
155155
countImageInputs,
156-
extractLatestImageUserTurn,
156+
extractCurrentImageRequest,
157157
parseToolOutputJson,
158158
} from "./mock-openai-input.js";
159159
import {
@@ -713,7 +713,7 @@ async function buildResponsesPayload(
713713
const exactReplyDirective = promptExactReplyDirective ?? extractExactReplyDirective(allInputText);
714714
const exactMarkerDirective =
715715
promptExactMarkerDirective ?? extractExactMarkerDirective(allInputText);
716-
const latestImageUserTurn = extractLatestImageUserTurn(input);
716+
const currentImageRequest = extractCurrentImageRequest(input, body);
717717
const whatsAppLocationMarker = shouldUseWhatsAppLocationMarker(prompt)
718718
? extractWhatsAppLocationMarkerDirective(allInputText)
719719
: "";
@@ -1071,16 +1071,16 @@ async function buildResponsesPayload(
10711071
return buildAssistantEvents("BETA-OK");
10721072
}
10731073
if (
1074-
/roundtrip image inspection check/i.test(latestImageUserTurn.text) &&
1075-
latestImageUserTurn.imageInputCount > 0
1074+
/roundtrip image inspection check/i.test(currentImageRequest.text) &&
1075+
currentImageRequest.imageInputCount > 0
10761076
) {
10771077
return buildAssistantEvents(
10781078
"Protocol note: the generated attachment shows the same QA lighthouse scene from the previous step.",
10791079
);
10801080
}
10811081
if (
1082-
/image understanding check/i.test(latestImageUserTurn.text) &&
1083-
latestImageUserTurn.imageInputCount > 0
1082+
/image understanding check/i.test(currentImageRequest.text) &&
1083+
currentImageRequest.imageInputCount > 0
10841084
) {
10851085
return buildAssistantEvents(
10861086
"Protocol note: the attached image is split horizontally, with red on top and blue on the bottom.",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
title: QA-channel vision offload
2+
3+
scenario:
4+
id: vision-channel-offload
5+
surface: media
6+
category: media.media-understanding
7+
coverage:
8+
primary:
9+
- media.image-summary-qa-channel
10+
- media.text-only-model-media-offload
11+
objective: Verify QA-channel image ingress is summarized by a configured vision model before the text-only active model emits one visible reply.
12+
successCriteria:
13+
- QA-channel ingests an inline PNG through the real bundled channel and gateway flow.
14+
- The configured image model receives at least one image input.
15+
- The active text-only model receives zero image inputs and the provider summary in its text context.
16+
- QA-channel emits exactly one visible final outbound reply.
17+
docsRefs:
18+
- docs/channels/qa-channel.md
19+
- docs/nodes/media-understanding.md
20+
- docs/concepts/qa-e2e-automation.md
21+
codeRefs:
22+
- extensions/qa-channel/src/inbound.ts
23+
- src/auto-reply/reply/get-reply.ts
24+
- src/media-understanding/apply.ts
25+
- src/media-understanding/runner.ts
26+
- test/e2e/qa-lab/media/vision-channel-offload.e2e.test.ts
27+
execution:
28+
kind: vitest
29+
path: test/e2e/qa-lab/media/vision-channel-offload.e2e.test.ts
30+
summary: Send an image through QA-channel, prove the configured image model summarizes it, and prove the text-only active model receives only the summary before one visible reply.

0 commit comments

Comments
 (0)