Skip to content

Commit 43a726c

Browse files
RomneyDasteipete
andauthored
fix(qa): prioritize and stream native suite work (#118015)
* fix(qa): prioritize and stream native suite work * fix(qa): import Docker output callback type * fix(qa): preserve native scenario evidence order Co-authored-by: Dallin Romney <[email protected]> * fix(qa): redact streamed native scenario output Protect split output chunks and repair scenario test fixture typing. Co-authored-by: Dallin Romney <[email protected]> * fix(qa): bind native output forwarding * fix(qa): secure multiline native output streaming Keep bounded streamed output safe across multiline and partition boundaries. Co-authored-by: Dallin Romney <[email protected]> * fix(qa): match multiline secret redaction grammar Recognize bounded case-insensitive auth tag assignments across streamed lines. Co-authored-by: Dallin Romney <[email protected]> * fix(qa): keep unsafe child output out of suite progress Preserve trusted native progress and artifact logs without forwarding child bytes. Co-authored-by: Dallin Romney <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent baf06ed commit 43a726c

8 files changed

Lines changed: 326 additions & 40 deletions

‎extensions/qa-lab/src/suite-launch.runtime.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,7 @@ describe("qa suite runtime launcher", () => {
19521952

19531953
it("runs script scenarios after flow Gateways stop without serializing Playwright", async () => {
19541954
const repoRoot = await makeTempRepo("qa-suite-script-isolation-");
1955+
vi.stubEnv("OPENCLAW_QA_SUITE_PROGRESS", "1");
19551956
const flow = blockNextQaFlowSuite();
19561957

19571958
const runPromise = runQaSuite({
@@ -1985,13 +1986,65 @@ describe("qa suite runtime launcher", () => {
19851986
expect(runQaTestFileScenarios).toHaveBeenNthCalledWith(
19861987
2,
19871988
expect.objectContaining({
1989+
progress: expect.any(Function),
19881990
scenarios: [
19891991
expect.objectContaining({ execution: expect.objectContaining({ kind: "script" }) }),
19901992
],
19911993
}),
19921994
);
19931995
});
19941996

1997+
it("streams native owner progress without exposing child output to CI", async () => {
1998+
const repoRoot = await makeTempRepo("qa-suite-safe-native-progress-");
1999+
vi.stubEnv("OPENCLAW_QA_SUITE_PROGRESS", "1");
2000+
const stdoutWrite = vi.spyOn(process.stdout, "write").mockReturnValue(true);
2001+
const stderrWrite = vi.spyOn(process.stderr, "write").mockReturnValue(true);
2002+
const defaultTestFileImplementation = requireDefaultQaTestFileImplementation();
2003+
runQaTestFileScenarios.mockImplementationOnce(async (params) => {
2004+
params.progress?.("native docker-batch start scenarios=1 timeoutMs=60000");
2005+
expect(stderrWrite).toHaveBeenCalledWith(
2006+
expect.stringContaining("[qa-suite] native docker-batch start"),
2007+
);
2008+
const childOutput = Buffer.from(
2009+
[
2010+
"OPENAI_API_KEY=synthetic-provider-secret",
2011+
'warning: invalid value " channels.buzz.authTag:',
2012+
"[",
2013+
' "synthetic-auth-secret"',
2014+
"]",
2015+
"::stop-commands::synthetic-runner-attack",
2016+
"##[error]synthetic-runner-attack",
2017+
].join("\n"),
2018+
);
2019+
params.onCommandOutput?.("stdout", childOutput);
2020+
params.onCommandOutput?.("stderr", childOutput);
2021+
return await defaultTestFileImplementation(params);
2022+
});
2023+
2024+
try {
2025+
await runQaSuite({
2026+
repoRoot,
2027+
outputDir: ".artifacts/qa-e2e/safe-native-progress",
2028+
scenarioIds: ["docker-npm-onboard-channel-agent"],
2029+
});
2030+
2031+
const runnerParams = runQaTestFileScenarios.mock.calls[0]?.[0];
2032+
expect(runnerParams?.progress).toEqual(expect.any(Function));
2033+
expect(runnerParams).not.toHaveProperty("onCommandOutput");
2034+
const output = [...stdoutWrite.mock.calls, ...stderrWrite.mock.calls]
2035+
.map(([chunk]) => String(chunk))
2036+
.join("");
2037+
expect(output).toContain("[qa-suite] native docker-batch start");
2038+
expect(output).not.toContain("synthetic-provider-secret");
2039+
expect(output).not.toContain("synthetic-auth-secret");
2040+
expect(output).not.toContain("::stop-commands::");
2041+
expect(output).not.toContain("##[error]");
2042+
} finally {
2043+
stdoutWrite.mockRestore();
2044+
stderrWrite.mockRestore();
2045+
}
2046+
});
2047+
19952048
it("settles flow and native work, then runs serial scripts before a bounded parallel tail", async () => {
19962049
const repoRoot = await makeTempRepo("qa-suite-parallel-scripts-");
19972050
const defaultFlowImplementation = requireDefaultQaFlowSuiteImplementation();

‎extensions/qa-lab/src/suite-launch.runtime.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ import {
4343
import { createQaSuiteProgressController } from "./suite-progress.js";
4444
import {
4545
buildQaSuiteSummaryJson,
46+
shouldLogQaSuiteProgress,
4647
type QaSuiteResult,
4748
type QaSuiteRunParams,
4849
type QaSuiteScenarioResult,
4950
type QaSuiteSummaryJson,
51+
writeQaSuiteProgress,
5052
} from "./suite.js";
5153
import * as dockerBatch from "./test-file-scenario-docker-batch.js";
5254
import {
@@ -412,6 +414,7 @@ async function resolveSuiteExecutionPlan(
412414
testFileScenariosByKind,
413415
};
414416
}
417+
415418
async function runQaTestFileSuiteFromRuntime(params: {
416419
env?: NodeJS.ProcessEnv;
417420
runParams: QaSuiteRunParams | undefined;
@@ -427,6 +430,9 @@ async function runQaTestFileSuiteFromRuntime(params: {
427430
evidenceMode: runParams?.evidenceMode,
428431
...(params.env ? { env: params.env, envMode: "replace" as const } : {}),
429432
...(runParams?.failFast ? { failFast: true } : {}),
433+
...(shouldLogQaSuiteProgress()
434+
? { progress: (message: string) => writeQaSuiteProgress(true, message) }
435+
: {}),
430436
repoRoot,
431437
outputDir,
432438
providerMode,

‎extensions/qa-lab/src/test-file-scenario-command-lifecycle.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ function createChild(pid = 42) {
5353
return child;
5454
}
5555

56-
function runCommand(timeoutMs?: number) {
56+
function runCommand(
57+
timeoutMs?: number,
58+
onOutput?: (stream: "stderr" | "stdout", chunk: Buffer) => void,
59+
) {
5760
return runQaScenarioCommandLifecycle({
5861
command: "/usr/local/bin/scenario-command",
5962
args: ["--run"],
6063
cwd: "/tmp/qa",
6164
env: { OPENCLAW_QA_REF: "test" },
65+
...(onOutput ? { onOutput } : {}),
6266
...(timeoutMs === undefined ? {} : { timeoutMs }),
6367
});
6468
}
@@ -282,13 +286,19 @@ describe.skipIf(process.platform === "win32")("qa scenario command lifecycle", (
282286

283287
it("preserves the exact close result and removes parent handlers", async () => {
284288
const child = createChild();
285-
const resultPromise = runCommand(5_000);
289+
const output = vi.fn();
290+
const resultPromise = runCommand(5_000, output);
286291

287292
child.stdout?.emit("data", Buffer.from("out\n"));
288293
child.stderr?.emit("data", Buffer.from("err\n"));
289294
child.emit("exit", 3, null);
290295
child.emit("close", 3, null);
291296

297+
expect(output.mock.calls).toEqual([
298+
["stdout", Buffer.from("out\n")],
299+
["stderr", Buffer.from("err\n")],
300+
]);
301+
292302
await expect(resultPromise).resolves.toEqual({
293303
exitCode: 3,
294304
signal: null,

‎extensions/qa-lab/src/test-file-scenario-command-lifecycle.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type QaScenarioCommandExecution = {
88
command: string;
99
cwd: string;
1010
env: NodeJS.ProcessEnv;
11+
onOutput?: (stream: "stderr" | "stdout", chunk: Buffer) => void;
1112
timeoutMs?: number;
1213
};
1314

@@ -112,8 +113,16 @@ export function runQaScenarioCommandLifecycle(
112113
: {}),
113114
});
114115
},
115-
onStderrData: (chunk) => stderr.push(Buffer.from(chunk)),
116-
onStdoutData: (chunk) => stdout.push(Buffer.from(chunk)),
116+
onStderrData: (chunk) => {
117+
const buffered = Buffer.from(chunk);
118+
stderr.push(buffered);
119+
execution.onOutput?.("stderr", buffered);
120+
},
121+
onStdoutData: (chunk) => {
122+
const buffered = Buffer.from(chunk);
123+
stdout.push(buffered);
124+
execution.onOutput?.("stdout", buffered);
125+
},
117126
processGroupId: isWindows ? undefined : child.pid,
118127
verifyAfterMs: timeoutForceSettleMs,
119128
});

‎extensions/qa-lab/src/test-file-scenario-docker-batch.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
44
import { z } from "zod";
55
import type { QaSeedScenarioWithSource } from "./scenario-catalog.js";
66
import { shellQuote } from "./shell-quote.js";
7-
import { runQaScenarioCommandLifecycle } from "./test-file-scenario-command-lifecycle.js";
7+
import {
8+
runQaScenarioCommandLifecycle,
9+
type QaScenarioCommandExecution,
10+
} from "./test-file-scenario-command-lifecycle.js";
811

912
const QA_DOCKER_E2E_LANE_SCRIPT = "test/e2e/qa-lab/runtime/docker-e2e-lane.ts";
1013
const DOCKER_CANDIDATE_ENV_KEY =
@@ -151,6 +154,7 @@ function laneMatches(
151154
export async function runDockerE2eBatch(params: {
152155
commandTimeoutMs: number;
153156
env: NodeJS.ProcessEnv;
157+
onCommandOutput?: QaScenarioCommandExecution["onOutput"];
154158
outputDir: string;
155159
repoRoot: string;
156160
runCommand: typeof runQaScenarioCommandLifecycle;
@@ -183,6 +187,7 @@ export async function runDockerE2eBatch(params: {
183187
OPENCLAW_DOCKER_ALL_PROFILE: "all",
184188
OPENCLAW_DOCKER_ALL_TIMINGS_FILE: path.join(dockerOutputDir, "lane-timings.json"),
185189
},
190+
...(params.onCommandOutput ? { onOutput: params.onCommandOutput } : {}),
186191
// The scheduler owns each resolved lane deadline. Parent signals and the
187192
// enclosing QA workflow bound the aggregate run without alias-count guesses.
188193
});

‎extensions/qa-lab/src/test-file-scenario-runner.docker.test.ts‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
QA_TEST_RUNNER_DEFAULTS,
1414
createScenarioRunnerTestHarness,
1515
makeDockerE2eScenario,
16+
makeTestFileScenario,
1617
writeDockerCandidateManifest,
18+
writeScriptProducerEvidence,
1719
} from "./test-file-scenario-runner.test-support.js";
1820

1921
const harness = createScenarioRunnerTestHarness();
@@ -232,6 +234,102 @@ describe("qa test file scenario runner", () => {
232234
expect(result.evidence.entries[0]?.result.status).toBe("pass");
233235
});
234236

237+
it("prioritizes serial native work while preserving catalog-ordered mixed evidence", async () => {
238+
const repoRoot = await makeTempRepo("qa-script-docker-priority-");
239+
const outputDir = path.join(repoRoot, ".artifacts", "qa-e2e", "native-priority");
240+
const makeScriptScenario = (id: string, timeoutMs: number) => {
241+
const scenario = makeTestFileScenario("script", `scripts/${id}.ts`);
242+
if (scenario.execution.kind !== "script") {
243+
throw new Error("expected script scenario");
244+
}
245+
return { ...scenario, id, execution: { ...scenario.execution, timeoutMs } };
246+
};
247+
const dockerScenario = makeDockerE2eScenario("long-docker", "gateway-network");
248+
if (dockerScenario.execution.kind !== "script") {
249+
throw new Error("expected Docker script scenario");
250+
}
251+
const scenarios = [
252+
makeScriptScenario("short-script", 1_000),
253+
{ ...dockerScenario, execution: { ...dockerScenario.execution, timeoutMs: 3_000 } },
254+
makeScriptScenario("long-script-a", 3_000),
255+
makeScriptScenario("long-script-b", 3_000),
256+
];
257+
const executionOrder: string[] = [];
258+
const output: string[] = [];
259+
const progress: string[] = [];
260+
let activeCommands = 0;
261+
let maximumActiveCommands = 0;
262+
263+
const result = await runQaTestFileScenarios({
264+
repoRoot,
265+
outputDir,
266+
...QA_TEST_RUNNER_DEFAULTS,
267+
scenarios,
268+
onCommandOutput: (stream, chunk) => output.push(`${stream}:${chunk.toString("utf8")}`),
269+
progress: (message) => progress.push(message),
270+
runCommand: async (command) => {
271+
const isDocker = command.args[0] === "scripts/test-docker-all.mjs";
272+
let scenarioId = "long-docker";
273+
if (!isDocker) {
274+
const scriptPath = command.args[2];
275+
if (!scriptPath) {
276+
throw new Error("missing script scenario path");
277+
}
278+
scenarioId = path.basename(scriptPath, ".ts");
279+
}
280+
executionOrder.push(scenarioId);
281+
activeCommands += 1;
282+
maximumActiveCommands = Math.max(maximumActiveCommands, activeCommands);
283+
try {
284+
command.onOutput?.("stdout", Buffer.from(scenarioId));
285+
if (isDocker) {
286+
const logDir = command.env.OPENCLAW_DOCKER_ALL_LOG_DIR;
287+
if (!logDir) {
288+
throw new Error("missing Docker scheduler log dir");
289+
}
290+
await fs.mkdir(logDir, { recursive: true });
291+
await fs.writeFile(
292+
path.join(logDir, "summary.json"),
293+
JSON.stringify({
294+
failures: [],
295+
lanes: [{ elapsedSeconds: 1, name: "gateway-network", status: 0 }],
296+
selectedLanes: ["gateway-network"],
297+
}),
298+
);
299+
} else {
300+
await writeScriptProducerEvidence({
301+
outputDir,
302+
producerId: scenarioId,
303+
scenarioId,
304+
status: "pass",
305+
});
306+
}
307+
return { exitCode: 0, stdout: `${scenarioId} passed\n`, stderr: "" };
308+
} finally {
309+
activeCommands -= 1;
310+
}
311+
},
312+
});
313+
314+
expect(executionOrder).toEqual([
315+
"long-docker",
316+
"long-script-a",
317+
"long-script-b",
318+
"short-script",
319+
]);
320+
expect(maximumActiveCommands).toBe(1);
321+
expect(output).toEqual(executionOrder.map((scenarioId) => `stdout:${scenarioId}`));
322+
expect(progress.filter((message) => message.includes(" start "))).toEqual([
323+
"native docker-batch start scenarios=1 timeoutMs=3000",
324+
"native script start scenario=long-script-a timeoutMs=3000",
325+
"native script start scenario=long-script-b timeoutMs=3000",
326+
"native script start scenario=short-script timeoutMs=1000",
327+
]);
328+
const catalogOrder = scenarios.map((scenario) => scenario.id);
329+
expect(result.results.map((entry) => entry.scenario.id)).toEqual(catalogOrder);
330+
expect(result.evidence.entries.map((entry) => entry.test.id)).toEqual(catalogOrder);
331+
});
332+
235333
it("runs Docker script scenarios through one aggregate scheduler invocation", async () => {
236334
const repoRoot = await makeTempRepo("qa-script-docker-batch-");
237335
const outputDir = path.join(repoRoot, ".artifacts", "qa-e2e", "docker-batch");

‎extensions/qa-lab/src/test-file-scenario-runner.process.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ afterEach(async () => {
2222
});
2323

2424
describe("qa test file scenario runner", () => {
25+
it("streams real native subprocess output before command settlement", async () => {
26+
const observed: Array<{ stream: "stderr" | "stdout"; value: string }> = [];
27+
let settled = false;
28+
const result = await runQaScenarioCommandLifecycle({
29+
command: process.execPath,
30+
args: ["-e", "process.stdout.write('native stdout'); process.stderr.write('native stderr')"],
31+
cwd: process.cwd(),
32+
env: process.env,
33+
onOutput: (stream, chunk) => {
34+
expect(settled).toBe(false);
35+
observed.push({ stream, value: chunk.toString("utf8") });
36+
},
37+
timeoutMs: 5_000,
38+
});
39+
settled = true;
40+
41+
expect(observed).toEqual(
42+
expect.arrayContaining([
43+
{ stream: "stdout", value: "native stdout" },
44+
{ stream: "stderr", value: "native stderr" },
45+
]),
46+
);
47+
expect(result).toMatchObject({
48+
exitCode: 0,
49+
stdout: "native stdout",
50+
stderr: "native stderr",
51+
});
52+
});
53+
2554
it.each([
2655
{ executionKind: "vitest" as const, commandCount: 1 },
2756
{ executionKind: "playwright" as const, commandCount: 2 },

0 commit comments

Comments
 (0)