Skip to content

Commit d916272

Browse files
authored
fix(qa-lab): release Mantis credentials when cleanup fails (#128315)
1 parent 19cbcee commit d916272

7 files changed

Lines changed: 359 additions & 365 deletions

‎extensions/qa-lab/src/mantis/crabbox-runtime.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Qa Lab tests cover Crabbox runtime behavior.
22
import { describe, expect, it } from "vitest";
3-
import { type CommandRunner, defaultCommandRunner, sshCommand } from "./crabbox-runtime.js";
3+
import {
4+
type CommandRunner,
5+
copyCrabboxArtifacts,
6+
defaultCommandRunner,
7+
} from "./crabbox-runtime.js";
48

59
describe("Crabbox command runner", () => {
610
it("preserves UTF-8 split across child-process pipe chunks", async () => {
@@ -54,7 +58,7 @@ describe("Crabbox command runner", () => {
5458
}
5559
return { stderr: "", stdout: "" };
5660
};
57-
const transport = await sshCommand({
61+
await copyCrabboxArtifacts({
5862
cwd: "/repo",
5963
env: {},
6064
inspect: {
@@ -63,21 +67,23 @@ describe("Crabbox command runner", () => {
6367
sshKey: "/tmp/key",
6468
sshUser: "proof",
6569
},
70+
outputDir: "/output",
71+
remoteOutputDir: "/remote",
6672
runner,
6773
});
6874

69-
await runner("rsync", ["-e", transport.sshArgs], {});
70-
7175
const expectedProbes = ports.length === 1 ? [] : ports;
7276
expect(calls.filter((call) => call.command === "ssh").map((call) => call.args[3])).toEqual(
7377
expectedProbes,
7478
);
7579
expect(calls.filter((call) => call.command === "ssh").map((call) => call.args[12])).toEqual(
7680
expectedProbes.map(() => `proof@${host}`),
7781
);
78-
expect(transport.host).toBe(host);
7982
expect(calls.filter((call) => call.command === "rsync")).toEqual([
80-
{ args: ["-e", expect.stringContaining(`-p ${ports.at(-1)}`)], command: "rsync" },
83+
{
84+
args: expect.arrayContaining([expect.stringContaining(`-p ${ports.at(-1)}`)]),
85+
command: "rsync",
86+
},
8187
]);
8288
});
8389

@@ -92,7 +98,7 @@ describe("Crabbox command runner", () => {
9298
};
9399

94100
await expect(
95-
sshCommand({
101+
copyCrabboxArtifacts({
96102
cwd: "/repo",
97103
env: {},
98104
inspect: {
@@ -102,6 +108,8 @@ describe("Crabbox command runner", () => {
102108
sshPort: "2222",
103109
sshUser: "proof",
104110
},
111+
outputDir: "/output",
112+
remoteOutputDir: "/remote",
105113
runner,
106114
}),
107115
).rejects.toThrow("Permission denied");

‎extensions/qa-lab/src/mantis/crabbox-runtime.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function sshCommandForPort(inspect: CrabboxInspect, sshPort: string) {
223223
};
224224
}
225225

226-
export async function sshCommand(params: {
226+
async function sshCommand(params: {
227227
cwd: string;
228228
env: NodeJS.ProcessEnv;
229229
inspect: CrabboxInspect;
@@ -256,3 +256,30 @@ export async function sshCommand(params: {
256256
}
257257
throw lastError;
258258
}
259+
260+
export async function copyCrabboxArtifacts(params: {
261+
cwd: string;
262+
env: NodeJS.ProcessEnv;
263+
exclude?: readonly string[];
264+
inspect: CrabboxInspect;
265+
outputDir: string;
266+
remoteOutputDir: string;
267+
runner: CommandRunner;
268+
}) {
269+
const { host, sshArgs, sshUser } = await sshCommand(params);
270+
const excludeArgs = params.exclude?.flatMap((pattern) => ["--exclude", pattern]) ?? [];
271+
await runCommand({
272+
command: "rsync",
273+
args: [
274+
"-az",
275+
"-e",
276+
sshArgs,
277+
...excludeArgs,
278+
`${sshUser}@${host}:${params.remoteOutputDir}/`,
279+
`${params.outputDir}/`,
280+
],
281+
cwd: params.cwd,
282+
env: params.env,
283+
runner: params.runner,
284+
});
285+
}

‎extensions/qa-lab/src/mantis/desktop-browser-smoke.runtime.ts‎

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { pathExists } from "openclaw/plugin-sdk/security-runtime";
77
import { ensureRepoBoundDirectory, resolveRepoRelativeOutputDir } from "../cli-paths.js";
88
import { isTruthyOptIn, trimToValue } from "../mantis-options.runtime.js";
99
import {
10+
copyCrabboxArtifacts,
1011
type CommandRunner,
11-
type CrabboxInspect,
1212
defaultCommandRunner,
1313
inspectCrabbox,
1414
resolveCrabboxBin,
1515
runCommand,
1616
shellQuote,
17-
sshCommand,
1817
stopCrabbox,
1918
warmupCrabbox,
2019
} from "./crabbox-runtime.js";
@@ -282,32 +281,6 @@ function renderReport(summary: MantisDesktopBrowserSmokeSummary) {
282281
return `${lines.join("\n")}\n`;
283282
}
284283

285-
async function copyRemoteArtifacts(params: {
286-
cwd: string;
287-
env: NodeJS.ProcessEnv;
288-
inspect: CrabboxInspect;
289-
outputDir: string;
290-
remoteOutputDir: string;
291-
runner: CommandRunner;
292-
}) {
293-
const { host, sshArgs, sshUser } = await sshCommand(params);
294-
await runCommand({
295-
command: "rsync",
296-
args: [
297-
"-az",
298-
"-e",
299-
sshArgs,
300-
"--exclude",
301-
"chrome-profile/**",
302-
`${sshUser}@${host}:${params.remoteOutputDir}/`,
303-
`${params.outputDir}/`,
304-
],
305-
cwd: params.cwd,
306-
env: params.env,
307-
runner: params.runner,
308-
});
309-
}
310-
311284
export async function runMantisDesktopBrowserSmoke(
312285
opts: MantisDesktopBrowserSmokeOptions = {},
313286
): Promise<MantisDesktopBrowserSmokeResult> {
@@ -419,9 +392,10 @@ export async function runMantisDesktopBrowserSmoke(
419392
runner,
420393
stdio: "inherit",
421394
});
422-
await copyRemoteArtifacts({
395+
await copyCrabboxArtifacts({
423396
cwd: repoRoot,
424397
env,
398+
exclude: ["chrome-profile/**"],
425399
inspect: inspected,
426400
outputDir,
427401
remoteOutputDir,

0 commit comments

Comments
 (0)