Skip to content

Commit fcee268

Browse files
committed
feat(qa-lab): support scenario-defined plugin runs
1 parent ea71a59 commit fcee268

17 files changed

Lines changed: 1131 additions & 191 deletions

‎extensions/qa-lab/src/cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function registerQaLabCli(program: Command) {
166166
.option(
167167
"--provider-mode <mode>",
168168
"Provider mode: mock-openai or live-frontier (legacy live-openai still works)",
169-
"mock-openai",
169+
"live-frontier",
170170
)
171171
.option("--model <ref>", "Primary provider/model ref")
172172
.option("--alt-model <ref>", "Alternate provider/model ref")

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ export async function startQaGatewayChild(params: {
836836
thinkingDefault?: QaThinkingLevel;
837837
claudeCliAuthMode?: QaCliBackendAuthMode;
838838
controlUiEnabled?: boolean;
839+
enabledPluginIds?: string[];
839840
mutateConfig?: (cfg: OpenClawConfig) => OpenClawConfig;
840841
}) {
841842
const tempRoot = await fs.mkdtemp(
@@ -873,14 +874,17 @@ export async function startQaGatewayChild(params: {
873874
const liveProviderConfigs = await readQaLiveProviderConfigOverrides({
874875
providerIds: liveProviderIds,
875876
});
876-
const enabledPluginIds =
877+
const liveOwnerPluginIds =
877878
liveProviderIds.length > 0
878879
? await resolveQaOwnerPluginIdsForProviderIds({
879880
repoRoot: params.repoRoot,
880881
providerIds: liveProviderIds,
881882
providerConfigs: liveProviderConfigs,
882883
})
883-
: undefined;
884+
: [];
885+
const enabledPluginIds = [
886+
...new Set([...(liveOwnerPluginIds ?? []), ...(params.enabledPluginIds ?? [])]),
887+
];
884888
const buildGatewayConfig = (gatewayPort: number) =>
885889
buildQaGatewayConfig({
886890
bind: "loopback",

‎extensions/qa-lab/src/lab-server.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("qa-lab server", () => {
116116
expect(bootstrap.scenarios.length).toBeGreaterThanOrEqual(10);
117117
expect(bootstrap.scenarios.some((scenario) => scenario.id === "dm-chat-baseline")).toBe(true);
118118
expect(bootstrap.runner.status).toBe("idle");
119-
expect(bootstrap.runner.selection.providerMode).toBe("mock-openai");
119+
expect(bootstrap.runner.selection.providerMode).toBe("live-frontier");
120120
expect(bootstrap.runner.selection.scenarioIds).toHaveLength(bootstrap.scenarios.length);
121121

122122
const messageResponse = await fetch(`${lab.baseUrl}/api/inbound/message`, {

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

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,151 @@ describe("qa mock openai server", () => {
433433
"Protocol note: I checked memory and the current Project Nebula codename is ORBIT-10.",
434434
);
435435

436+
const activeMemorySearch = await fetch(`${server.baseUrl}/v1/responses`, {
437+
method: "POST",
438+
headers: {
439+
"content-type": "application/json",
440+
},
441+
body: JSON.stringify({
442+
stream: true,
443+
input: [
444+
{
445+
role: "user",
446+
content: [
447+
{
448+
type: "input_text",
449+
text: [
450+
"You are a memory search agent.",
451+
"Use only memory_search and memory_get.",
452+
"",
453+
"Conversation context:",
454+
"Latest user message:",
455+
"Silent snack recall check: what snack do I usually want for QA movie night? Reply in one short sentence.",
456+
].join("\n"),
457+
},
458+
],
459+
},
460+
],
461+
}),
462+
});
463+
expect(activeMemorySearch.status).toBe(200);
464+
expect(await activeMemorySearch.text()).toContain('"name":"memory_search"');
465+
466+
const activeMemoryGet = await fetch(`${server.baseUrl}/v1/responses`, {
467+
method: "POST",
468+
headers: {
469+
"content-type": "application/json",
470+
},
471+
body: JSON.stringify({
472+
stream: true,
473+
input: [
474+
{
475+
role: "user",
476+
content: [
477+
{
478+
type: "input_text",
479+
text: [
480+
"You are a memory search agent.",
481+
"Use only memory_search and memory_get.",
482+
"",
483+
"Conversation context:",
484+
"Latest user message:",
485+
"Silent snack recall check: what snack do I usually want for QA movie night? Reply in one short sentence.",
486+
].join("\n"),
487+
},
488+
],
489+
},
490+
{
491+
type: "function_call_output",
492+
output: JSON.stringify({
493+
results: [
494+
{
495+
path: "MEMORY.md",
496+
startLine: 1,
497+
endLine: 1,
498+
},
499+
],
500+
}),
501+
},
502+
],
503+
}),
504+
});
505+
expect(activeMemoryGet.status).toBe(200);
506+
expect(await activeMemoryGet.text()).toContain('"name":"memory_get"');
507+
508+
const activeMemorySummary = await fetch(`${server.baseUrl}/v1/responses`, {
509+
method: "POST",
510+
headers: {
511+
"content-type": "application/json",
512+
},
513+
body: JSON.stringify({
514+
stream: false,
515+
input: [
516+
{
517+
role: "user",
518+
content: [
519+
{
520+
type: "input_text",
521+
text: [
522+
"You are a memory search agent.",
523+
"Use only memory_search and memory_get.",
524+
"",
525+
"Conversation context:",
526+
"Latest user message:",
527+
"Silent snack recall check: what snack do I usually want for QA movie night? Reply in one short sentence.",
528+
].join("\n"),
529+
},
530+
],
531+
},
532+
{
533+
type: "function_call_output",
534+
output: JSON.stringify({
535+
text: "Stable QA movie night snack preference: lemon pepper wings with blue cheese.",
536+
}),
537+
},
538+
],
539+
}),
540+
});
541+
expect(activeMemorySummary.status).toBe(200);
542+
expect(JSON.stringify(await activeMemorySummary.json())).toContain(
543+
"lemon pepper wings with blue cheese",
544+
);
545+
546+
const injectedMainReply = await fetch(`${server.baseUrl}/v1/responses`, {
547+
method: "POST",
548+
headers: {
549+
"content-type": "application/json",
550+
},
551+
body: JSON.stringify({
552+
stream: false,
553+
instructions: [
554+
"System context:",
555+
"<active_memory_plugin>User usually wants lemon pepper wings with blue cheese for QA movie night.</active_memory_plugin>",
556+
].join("\n"),
557+
input: [
558+
{
559+
role: "user",
560+
content: [
561+
{
562+
type: "input_text",
563+
text: "Silent snack recall check: what snack do I usually want for QA movie night? Reply in one short sentence.",
564+
},
565+
],
566+
},
567+
],
568+
}),
569+
});
570+
expect(injectedMainReply.status).toBe(200);
571+
expect(JSON.stringify(await injectedMainReply.json())).toContain(
572+
"lemon pepper wings with blue cheese",
573+
);
574+
const lastRequest = await fetch(`${server.baseUrl}/debug/last-request`);
575+
expect(lastRequest.status).toBe(200);
576+
expect(await lastRequest.json()).toMatchObject({
577+
instructions: expect.stringContaining("<active_memory_plugin>"),
578+
allInputText: expect.stringContaining("<active_memory_plugin>"),
579+
});
580+
436581
const spawn = await fetch(`${server.baseUrl}/v1/responses`, {
437582
method: "POST",
438583
headers: {

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

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type MockOpenAiRequestSnapshot = {
2727
body: Record<string, unknown>;
2828
prompt: string;
2929
allInputText: string;
30+
instructions?: string;
3031
toolOutput: string;
3132
model: string;
3233
imageInputCount: number;
@@ -181,6 +182,23 @@ function extractAllInputTexts(input: ResponsesInputItem[]) {
181182
return texts.join("\n");
182183
}
183184

185+
function extractInstructionsText(body: Record<string, unknown>) {
186+
return typeof body.instructions === "string" ? body.instructions.trim() : "";
187+
}
188+
189+
function extractAllRequestTexts(input: ResponsesInputItem[], body: Record<string, unknown>) {
190+
const texts: string[] = [];
191+
const instructions = extractInstructionsText(body);
192+
if (instructions) {
193+
texts.push(instructions);
194+
}
195+
const inputText = extractAllInputTexts(input);
196+
if (inputText) {
197+
texts.push(inputText);
198+
}
199+
return texts.join("\n");
200+
}
201+
184202
function countImageInputs(input: ResponsesInputItem[]) {
185203
let count = 0;
186204
for (const item of input) {
@@ -320,6 +338,33 @@ function extractOrbitCode(text: string) {
320338
return /\bORBIT-\d+\b/i.exec(text)?.[0]?.toUpperCase() ?? null;
321339
}
322340

341+
function decodeXmlEntities(text: string) {
342+
return text
343+
.replaceAll("&lt;", "<")
344+
.replaceAll("&gt;", ">")
345+
.replaceAll("&amp;", "&")
346+
.replaceAll("&quot;", '"')
347+
.replaceAll("&#39;", "'");
348+
}
349+
350+
function extractActiveMemorySummary(text: string) {
351+
const match = /<active_memory_plugin>\s*([\s\S]*?)\s*<\/active_memory_plugin>/i.exec(text);
352+
return match?.[1] ? decodeXmlEntities(match[1]).trim() : null;
353+
}
354+
355+
function isActiveMemorySubagentPrompt(text: string) {
356+
return text.includes("You are a memory search agent.");
357+
}
358+
359+
function extractSnackPreference(text: string) {
360+
const normalized = text.replace(/\s+/g, " ").trim();
361+
const match =
362+
/(lemon pepper wings(?:\s+with\s+blue cheese)?|blue cheese(?:\s+with\s+lemon pepper wings)?)/i.exec(
363+
normalized,
364+
);
365+
return match?.[0]?.trim() ?? null;
366+
}
367+
323368
function extractLastCapture(text: string, pattern: RegExp) {
324369
let lastMatch: RegExpExecArray | null = null;
325370
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
@@ -355,7 +400,7 @@ function buildAssistantText(input: ResponsesInputItem[], body: Record<string, un
355400
const toolOutput = extractToolOutput(input);
356401
const toolJson = parseToolOutputJson(toolOutput);
357402
const userTexts = extractAllUserTexts(input);
358-
const allInputText = extractAllInputTexts(input);
403+
const allInputText = extractAllRequestTexts(input, body);
359404
const rememberedFact = extractRememberedFact(userTexts);
360405
const model = typeof body.model === "string" ? body.model : "";
361406
const memorySnippet =
@@ -369,6 +414,8 @@ function buildAssistantText(input: ResponsesInputItem[], body: Record<string, un
369414
const exactReplyDirective = extractExactReplyDirective(allInputText);
370415
const exactMarkerDirective = extractExactMarkerDirective(allInputText);
371416
const imageInputCount = countImageInputs(input);
417+
const activeMemorySummary = extractActiveMemorySummary(allInputText);
418+
const snackPreference = extractSnackPreference(activeMemorySummary ?? memorySnippet);
372419

373420
if (/what was the qa canary code/i.test(prompt) && rememberedFact) {
374421
return `Protocol note: the QA canary code was ${rememberedFact}.`;
@@ -400,6 +447,12 @@ function buildAssistantText(input: ResponsesInputItem[], body: Record<string, un
400447
if (/memory tools check/i.test(prompt) && orbitCode) {
401448
return `Protocol note: I checked memory and the project codename is ${orbitCode}.`;
402449
}
450+
if (/silent snack recall check/i.test(prompt) && snackPreference) {
451+
return `Protocol note: you usually want ${snackPreference} for QA movie night.`;
452+
}
453+
if (/silent snack recall check/i.test(prompt)) {
454+
return "Protocol note: I do not have enough context to say what you usually want for QA movie night.";
455+
}
403456
if (/tool continuity check/i.test(prompt) && toolOutput) {
404457
return `Protocol note: model switch handoff confirmed on ${model || "the requested model"}. QA mission from QA_KICKOFF_TASK.md still applies: understand this OpenClaw repo from source + docs before acting.`;
405458
}
@@ -531,7 +584,7 @@ async function buildResponsesPayload(body: Record<string, unknown>) {
531584
const prompt = extractLastUserText(input);
532585
const toolOutput = extractToolOutput(input);
533586
const toolJson = parseToolOutputJson(toolOutput);
534-
const allInputText = extractAllInputTexts(input);
587+
const allInputText = extractAllRequestTexts(input, body);
535588
const isGroupChat = allInputText.includes('"is_group_chat": true');
536589
const isBaselineUnmentionedChannelChatter = /\bno bot ping here\b/i.test(prompt);
537590
if (isHeartbeatPrompt(prompt)) {
@@ -591,6 +644,48 @@ async function buildResponsesPayload(body: Record<string, unknown>) {
591644
});
592645
}
593646
}
647+
if (
648+
isActiveMemorySubagentPrompt(allInputText) &&
649+
/silent snack recall check/i.test(allInputText)
650+
) {
651+
if (!toolOutput) {
652+
return buildToolCallEventsWithArgs("memory_search", {
653+
query: "QA movie night snack lemon pepper wings blue cheese",
654+
maxResults: 3,
655+
});
656+
}
657+
const results = Array.isArray(toolJson?.results)
658+
? (toolJson.results as Array<Record<string, unknown>>)
659+
: [];
660+
const first = results[0];
661+
if (
662+
typeof first?.path === "string" &&
663+
(typeof first.startLine === "number" || typeof first.endLine === "number")
664+
) {
665+
const from =
666+
typeof first.startLine === "number"
667+
? Math.max(1, first.startLine)
668+
: typeof first.endLine === "number"
669+
? Math.max(1, first.endLine)
670+
: 1;
671+
return buildToolCallEventsWithArgs("memory_get", {
672+
path: first.path,
673+
from,
674+
lines: 4,
675+
});
676+
}
677+
const memorySnippet =
678+
typeof toolJson?.text === "string"
679+
? toolJson.text
680+
: Array.isArray(toolJson?.results)
681+
? JSON.stringify(toolJson.results)
682+
: toolOutput;
683+
const snackPreference = extractSnackPreference(memorySnippet);
684+
if (snackPreference) {
685+
return buildAssistantEvents(`User usually wants ${snackPreference} for QA movie night.`);
686+
}
687+
return buildAssistantEvents("NONE");
688+
}
594689
if (/session memory ranking check/i.test(prompt)) {
595690
if (!toolOutput) {
596691
return buildToolCallEventsWithArgs("memory_search", {
@@ -798,7 +893,8 @@ export async function startQaMockOpenAiServer(params?: { host?: string; port?: n
798893
raw,
799894
body,
800895
prompt: extractLastUserText(input),
801-
allInputText: extractAllInputTexts(input),
896+
allInputText: extractAllRequestTexts(input, body),
897+
instructions: extractInstructionsText(body) || undefined,
802898
toolOutput: extractToolOutput(input),
803899
model: typeof body.model === "string" ? body.model : "",
804900
imageInputCount: countImageInputs(input),

‎extensions/qa-lab/src/multipass.runtime.test.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("qa multipass runtime", () => {
8181
expect(plan.summaryPath).toBe(path.join(outputDir, "qa-suite-summary.json"));
8282
});
8383

84-
it("renders a guest script that runs the mock qa suite with explicit scenarios", () => {
84+
it("renders a guest script that runs the live qa suite by default", () => {
8585
const plan = createQaMultipassPlan({
8686
repoRoot: process.cwd(),
8787
outputDir: path.join(process.cwd(), ".artifacts", "qa-e2e", "multipass-test"),
@@ -93,9 +93,8 @@ describe("qa multipass runtime", () => {
9393
expect(script).toContain("pnpm install --frozen-lockfile");
9494
expect(script).toContain("pnpm build");
9595
expect(script).toContain("corepack prepare '[email protected]' --activate");
96-
expect(script).toContain(
97-
"'pnpm' 'openclaw' 'qa' 'suite' '--transport' 'qa-channel' '--provider-mode' 'mock-openai'",
98-
);
96+
expect(script).toContain("'pnpm' 'openclaw' 'qa' 'suite' '--transport' 'qa-channel'");
97+
expect(script).toContain("'--provider-mode' 'live-frontier'");
9998
expect(script).toContain("'--scenario' 'channel-chat-baseline'");
10099
expect(script).toContain("'--scenario' 'thread-follow-up'");
101100
expect(script).toContain("/workspace/openclaw-host/.artifacts/qa-e2e/multipass-test");
@@ -128,9 +127,8 @@ describe("qa multipass runtime", () => {
128127
);
129128
expect(plan.forwardedEnv.OPENAI_API_KEY).toBe("test-openai-key");
130129
expect(script).toContain("OPENAI_API_KEY='test-openai-key'");
131-
expect(script).toContain(
132-
"'pnpm' 'openclaw' 'qa' 'suite' '--transport' 'qa-channel' '--provider-mode' 'live-frontier'",
133-
);
130+
expect(script).toContain("'pnpm' 'openclaw' 'qa' 'suite' '--transport' 'qa-channel'");
131+
expect(script).toContain("'--provider-mode' 'live-frontier'");
134132
});
135133

136134
it("redacts forwarded live secrets in the persisted artifact script", () => {

0 commit comments

Comments
 (0)