mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 09:02:02 +03:00
perf(test): stabilize e2e harness and reduce flaky gateway coverage
This commit is contained in:
@@ -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