Skip to content

Commit 19be0f6

Browse files
authored
fix: honor scenario drivers in generated QA commands (#131101)
* fix: honor scenario drivers in generated QA commands Carry declared driver requirements through coverage search, grouping and quoted command output. Preserve unconstrained defaults and validate generated arguments through real CLI parsing and canonical lane selection. Closes #131088. * test: capture generated QA commands through the shell
1 parent 7405257 commit 19be0f6

3 files changed

Lines changed: 158 additions & 5 deletions

File tree

‎docs/concepts/qa-e2e-automation.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,10 @@ for machine-readable output). When choosing focused proof for a touched
13241324
behavior or file path, run `pnpm openclaw qa coverage --match <query>`. The
13251325
match report searches scenario metadata, docs refs, code refs, coverage IDs,
13261326
plugins, and provider requirements, then prints matching `qa suite
1327-
--scenario ...` targets.
1327+
--scenario ...` targets. Generated commands preserve declared channel-driver
1328+
requirements and separate scenarios with different driver requirements. Without
1329+
a driver requirement, non-QA channels use `live` and `qa-channel` keeps its
1330+
default driver.
13281331

13291332
Every `qa suite` run writes top-level `qa-evidence.json`,
13301333
`qa-suite-summary.json`, and `qa-suite-report.md` artifacts for the selected
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import { execFileSync } from "node:child_process";
2+
import { expectDefined } from "@openclaw/normalization-core";
3+
import { Command } from "commander";
4+
import { describe, expect, it, vi } from "vitest";
5+
import { registerQaLabCli } from "./cli.js";
6+
import { findQaScenarioMatches, renderQaScenarioMatchesMarkdownReport } from "./coverage-report.js";
7+
import { defaultQaModelForMode, type QaProviderMode } from "./model-selection.js";
8+
import { DEFAULT_QA_LIVE_PROVIDER_MODE } from "./providers/index.js";
9+
import { readQaScenarioById, type QaSeedScenarioWithSource } from "./scenario-catalog.js";
10+
import type { QaScorecardChannelDriver } from "./scorecard-taxonomy.js";
11+
import { selectQaFlowSuiteScenarios } from "./suite-planning.js";
12+
import { makeQaSuiteTestScenario } from "./suite-test-helpers.js";
13+
14+
vi.mock("openclaw/plugin-sdk/qa-runner-runtime", () => ({
15+
listQaRunnerCliContributions: () => [],
16+
}));
17+
18+
function captureReportedArgv(command: string): string[] {
19+
// Previews use POSIX quoting; Windows test hosts need Git Bash's sh on PATH.
20+
// Capture the shell-expanded arguments without starting pnpm or a QA provider.
21+
const argv = execFileSync("sh", ["-c", `pnpm() { printf '%s\\0' pnpm "$@"; }\n${command}`], {
22+
encoding: "utf8",
23+
timeout: 5_000,
24+
}).split("\0");
25+
expect(argv.pop()).toBe("");
26+
return argv;
27+
}
28+
29+
function selectReportedCommands(scenarios: QaSeedScenarioWithSource[]) {
30+
const matches = scenarios.flatMap((scenario) => findQaScenarioMatches([scenario], scenario.id));
31+
const report = renderQaScenarioMatchesMarkdownReport({ query: "selected scenarios", matches });
32+
const commands = [...report.matchAll(/`(pnpm openclaw qa suite[^`]+)`/gu)];
33+
expect(commands.length).toBeGreaterThan(0);
34+
return commands.map(([, command]) => {
35+
const argv = captureReportedArgv(command!);
36+
expect(argv.slice(0, 4)).toEqual(["pnpm", "openclaw", "qa", "suite"]);
37+
const program = new Command();
38+
registerQaLabCli(program);
39+
const qa = expectDefined(
40+
program.commands.find((entry) => entry.name() === "qa"),
41+
"qa",
42+
);
43+
const suite = expectDefined(
44+
qa.commands.find((entry) => entry.name() === "suite"),
45+
"suite",
46+
);
47+
// Parse the real options without running the suite action or starting a provider.
48+
expect(suite.parseOptions(argv.slice(4))).toEqual({ operands: [], unknown: [] });
49+
const opts = suite.opts<{
50+
scenario: string[];
51+
channelDriver?: QaScorecardChannelDriver;
52+
channel?: string;
53+
providerMode?: QaProviderMode;
54+
}>();
55+
expect(opts.scenario.length).toBeGreaterThan(0);
56+
const providerMode = opts.providerMode ?? DEFAULT_QA_LIVE_PROVIDER_MODE;
57+
const selected = selectQaFlowSuiteScenarios({
58+
scenarios,
59+
scenarioIds: opts.scenario,
60+
channelDriver: opts.channelDriver,
61+
channel: opts.channel,
62+
providerMode,
63+
primaryModel: defaultQaModelForMode(providerMode),
64+
});
65+
expect(
66+
selected.map(({ id }) => id),
67+
command,
68+
).toEqual(opts.scenario);
69+
return {
70+
driver: opts.channelDriver ?? "qa-channel",
71+
ids: selected.map(({ id }) => id),
72+
};
73+
});
74+
}
75+
76+
describe("QA coverage command selection", () => {
77+
it.each([
78+
["telegram-assistant-transcript-role-boundary", "crabline"],
79+
["native-command-session-target", "crabline"],
80+
["matrix-room-generated-image-delivery", "live"],
81+
["remember-across-conversations", "qa-channel"],
82+
["whatsapp-access-control-group-disabled", "live"],
83+
["instruction-followthrough-repo-contract", "qa-channel"],
84+
["agent-startup-instruction-first-action", "qa-channel"],
85+
["channel-canary", "qa-channel"],
86+
])("selects exactly %s from its generated command", (id, driver) => {
87+
expect(selectReportedCommands([readQaScenarioById(id)])).toEqual([{ driver, ids: [id] }]);
88+
});
89+
90+
it("separates conflicting drivers on the same channel and groups compatible scenarios", () => {
91+
const scenarios = [
92+
...["crabline", "live"].flatMap((requiredChannelDriver) =>
93+
["first", "second"].map((suffix) =>
94+
makeQaSuiteTestScenario(`${requiredChannelDriver}-${suffix}`, {
95+
channel: "telegram",
96+
config: { requiredChannelDriver, requiredProviderMode: "mock-openai" },
97+
}),
98+
),
99+
),
100+
makeQaSuiteTestScenario("unconstrained", { channel: "telegram" }),
101+
];
102+
103+
expect(selectReportedCommands(scenarios)).toEqual([
104+
{ driver: "crabline", ids: ["crabline-first", "crabline-second"] },
105+
{ driver: "live", ids: ["live-first", "live-second"] },
106+
{ driver: "live", ids: ["unconstrained"] },
107+
]);
108+
});
109+
110+
it("preserves a driver requirement without a pinned channel", () => {
111+
const scenario = makeQaSuiteTestScenario("driver-only", {
112+
config: { requiredChannelDriver: "crabline" },
113+
});
114+
115+
expect(selectReportedCommands([scenario])).toEqual([
116+
{ driver: "crabline", ids: [scenario.id] },
117+
]);
118+
});
119+
120+
it("keeps a declared driver as one shell argument", () => {
121+
const requiredChannelDriver = "crabline' ; printf unexpected #";
122+
const scenario = makeQaSuiteTestScenario("quoted-driver", {
123+
config: { requiredChannelDriver },
124+
});
125+
const report = renderQaScenarioMatchesMarkdownReport({
126+
query: scenario.id,
127+
matches: findQaScenarioMatches([scenario], scenario.id),
128+
});
129+
const command = expectDefined(report.match(/`(pnpm openclaw qa suite[^`]+)`/u)?.[1], "command");
130+
131+
expect(captureReportedArgv(command)).toEqual([
132+
"pnpm",
133+
"openclaw",
134+
"qa",
135+
"suite",
136+
"--channel-driver",
137+
requiredChannelDriver,
138+
"--scenario",
139+
scenario.id,
140+
]);
141+
});
142+
});

‎extensions/qa-lab/src/coverage-report.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
readQaScorecardTaxonomyReport,
1414
type QaScorecardTaxonomyReport,
1515
} from "./scorecard-taxonomy.js";
16+
import { shellQuote } from "./shell-quote.js";
1617

1718
type QaCoverageScenarioSummary = {
1819
id: string;
@@ -31,6 +32,7 @@ type QaScenarioSearchMatch = QaCoverageScenarioSummary & {
3132
executionKind: QaSeedScenarioWithSource["execution"]["kind"];
3233
executionPath?: string;
3334
runtimePairLane?: string;
35+
requiredChannelDriver?: string;
3436
requiredProviderMode?: string;
3537
requiredProvider?: string;
3638
requiredModel?: string;
@@ -145,6 +147,7 @@ function summarizeScenarioSearchMatch(
145147
channels[0],
146148
...(scenario.execution.kind !== "flow" ? { executionPath: scenario.execution.path } : {}),
147149
runtimePairLane: scenario.runtimePairLane,
150+
requiredChannelDriver: stringifyConfigValue(config.requiredChannelDriver),
148151
requiredProviderMode: resolveQaScenarioRequiredProviderMode(scenario),
149152
requiredProvider: stringifyConfigValue(config.requiredProvider),
150153
requiredModel: stringifyConfigValue(config.requiredModel),
@@ -393,14 +396,18 @@ function formatOptionalScenarioMetadata(match: QaScenarioSearchMatch) {
393396

394397
function formatSuiteCommand(matches: readonly QaScenarioSearchMatch[]) {
395398
const scenarioArgs = matches.map((match) => `--scenario ${match.id}`).join(" ");
396-
const { channel, requiredProviderMode } = matches[0]!;
397-
const channelArg =
398-
channel && channel !== "qa-channel" ? ` --channel-driver live --channel ${channel}` : "";
399+
const { channel, requiredChannelDriver, requiredProviderMode } = matches[0]!;
400+
const channelArg = channel && channel !== "qa-channel" ? ` --channel ${channel}` : "";
401+
const driverArg = requiredChannelDriver
402+
? ` --channel-driver ${shellQuote(requiredChannelDriver)}`
403+
: channelArg
404+
? " --channel-driver live"
405+
: "";
399406
const providerModeArg =
400407
requiredProviderMode && requiredProviderMode !== DEFAULT_QA_LIVE_PROVIDER_MODE
401408
? ` --provider-mode ${requiredProviderMode}`
402409
: "";
403-
return `pnpm openclaw qa suite${channelArg}${providerModeArg} ${scenarioArgs}`;
410+
return `pnpm openclaw qa suite${driverArg}${channelArg}${providerModeArg} ${scenarioArgs}`;
404411
}
405412

406413
function scenarioMatchCommandGroups(matches: readonly QaScenarioSearchMatch[]) {
@@ -409,6 +416,7 @@ function scenarioMatchCommandGroups(matches: readonly QaScenarioSearchMatch[]) {
409416
const key = JSON.stringify([
410417
match.executionKind,
411418
match.channel,
419+
match.requiredChannelDriver,
412420
match.requiredProviderMode ?? DEFAULT_QA_LIVE_PROVIDER_MODE,
413421
]);
414422
const group = groups.get(key) ?? [];

0 commit comments

Comments
 (0)