mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
perf(test): stabilize e2e harness and reduce flaky gateway coverage
This commit is contained in:
@@ -337,16 +337,62 @@ const connectNode = async (
|
||||
return { client, nodeId };
|
||||
};
|
||||
|
||||
const fetchNodeList = async (
|
||||
inst: GatewayInstance,
|
||||
timeoutMs = 5_000,
|
||||
): Promise<NodeListPayload> => {
|
||||
let settled = false;
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
|
||||
return await new Promise<NodeListPayload>((resolve, reject) => {
|
||||
const finish = (err?: Error, payload?: NodeListPayload) => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
client.stop();
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(payload ?? {});
|
||||
};
|
||||
|
||||
const client = new GatewayClient({
|
||||
url: `ws://127.0.0.1:${inst.port}`,
|
||||
token: inst.gatewayToken,
|
||||
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
||||
clientDisplayName: `status-${inst.name}`,
|
||||
clientVersion: "1.0.0",
|
||||
platform: "test",
|
||||
mode: GATEWAY_CLIENT_MODES.CLI,
|
||||
onHelloOk: () => {
|
||||
void client
|
||||
.request<NodeListPayload>("node.list", {})
|
||||
.then((payload) => finish(undefined, payload))
|
||||
.catch((err) => finish(err instanceof Error ? err : new Error(String(err))));
|
||||
},
|
||||
onConnectError: (err) => finish(err),
|
||||
onClose: (code, reason) => {
|
||||
finish(new Error(`gateway closed (${code}): ${reason}`));
|
||||
},
|
||||
});
|
||||
|
||||
timer = setTimeout(() => {
|
||||
finish(new Error("timeout waiting for node.list"));
|
||||
}, timeoutMs);
|
||||
|
||||
client.start();
|
||||
});
|
||||
};
|
||||
|
||||
const waitForNodeStatus = async (inst: GatewayInstance, nodeId: string, timeoutMs = 10_000) => {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
while (Date.now() < deadline) {
|
||||
const list = (await runCliJson(
|
||||
["nodes", "status", "--json", "--url", `ws://127.0.0.1:${inst.port}`],
|
||||
{
|
||||
OPENCLAW_GATEWAY_TOKEN: inst.gatewayToken,
|
||||
OPENCLAW_GATEWAY_PASSWORD: "",
|
||||
},
|
||||
)) as NodeListPayload;
|
||||
const list = await fetchNodeList(inst);
|
||||
const match = list.nodes?.find((n) => n.nodeId === nodeId);
|
||||
if (match?.connected && match?.paired) {
|
||||
return;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { MsgContext } from "../src/auto-reply/templating.js";
|
||||
import type { OpenClawConfig } from "../src/config/config.js";
|
||||
import { applyMediaUnderstanding } from "../src/media-understanding/apply.js";
|
||||
import { clearMediaUnderstandingBinaryCacheForTests } from "../src/media-understanding/runner.js";
|
||||
|
||||
const makeTempDir = async (prefix: string) => await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
|
||||
@@ -20,11 +22,6 @@ const makeTempMedia = async (ext: string) => {
|
||||
return { dir, filePath };
|
||||
};
|
||||
|
||||
const loadApply = async () => {
|
||||
vi.resetModules();
|
||||
return await import("../src/media-understanding/apply.js");
|
||||
};
|
||||
|
||||
const envSnapshot = () => ({
|
||||
PATH: process.env.PATH,
|
||||
SHERPA_ONNX_MODEL_DIR: process.env.SHERPA_ONNX_MODEL_DIR,
|
||||
@@ -40,6 +37,10 @@ const restoreEnv = (snapshot: ReturnType<typeof envSnapshot>) => {
|
||||
describe("media understanding auto-detect (e2e)", () => {
|
||||
let tempPaths: string[] = [];
|
||||
|
||||
beforeEach(() => {
|
||||
clearMediaUnderstandingBinaryCacheForTests();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
for (const p of tempPaths) {
|
||||
await fs.rm(p, { recursive: true, force: true }).catch(() => {});
|
||||
@@ -71,7 +72,6 @@ describe("media understanding auto-detect (e2e)", () => {
|
||||
const { filePath } = await makeTempMedia(".wav");
|
||||
tempPaths.push(path.dirname(filePath));
|
||||
|
||||
const { applyMediaUnderstanding } = await loadApply();
|
||||
const ctx: MsgContext = {
|
||||
Body: "<media:audio>",
|
||||
MediaPath: filePath,
|
||||
@@ -116,7 +116,6 @@ describe("media understanding auto-detect (e2e)", () => {
|
||||
const { filePath } = await makeTempMedia(".wav");
|
||||
tempPaths.push(path.dirname(filePath));
|
||||
|
||||
const { applyMediaUnderstanding } = await loadApply();
|
||||
const ctx: MsgContext = {
|
||||
Body: "<media:audio>",
|
||||
MediaPath: filePath,
|
||||
@@ -141,7 +140,7 @@ describe("media understanding auto-detect (e2e)", () => {
|
||||
await writeExecutable(
|
||||
binDir,
|
||||
"gemini",
|
||||
`#!/usr/bin/env bash\necho '{\\"response\\":\\"gemini ok\\"' + "}'\n`,
|
||||
`#!/usr/bin/env bash\necho '{"response":"gemini ok"}'\n`,
|
||||
);
|
||||
|
||||
process.env.PATH = `${binDir}:/usr/bin:/bin`;
|
||||
@@ -149,7 +148,6 @@ describe("media understanding auto-detect (e2e)", () => {
|
||||
const { filePath } = await makeTempMedia(".png");
|
||||
tempPaths.push(path.dirname(filePath));
|
||||
|
||||
const { applyMediaUnderstanding } = await loadApply();
|
||||
const ctx: MsgContext = {
|
||||
Body: "<media:image>",
|
||||
MediaPath: filePath,
|
||||
|
||||
Reference in New Issue
Block a user