mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:28:27 +00:00
test(perf): cache media fixtures and trim timeout waits
This commit is contained in:
@@ -1523,7 +1523,7 @@ describe("Cron issue regressions", () => {
|
|||||||
|
|
||||||
// Keep this short for suite speed while still separating expected timeout
|
// Keep this short for suite speed while still separating expected timeout
|
||||||
// from the 1/3-regression timeout.
|
// from the 1/3-regression timeout.
|
||||||
const timeoutSeconds = 0.12;
|
const timeoutSeconds = 0.06;
|
||||||
const cronJob = createIsolatedRegressionJob({
|
const cronJob = createIsolatedRegressionJob({
|
||||||
id: "timeout-fraction-29774",
|
id: "timeout-fraction-29774",
|
||||||
name: "timeout fraction regression",
|
name: "timeout fraction regression",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import crypto from "node:crypto";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
@@ -36,6 +37,8 @@ let applyMediaUnderstanding: typeof import("./apply.js").applyMediaUnderstanding
|
|||||||
const TEMP_MEDIA_PREFIX = "openclaw-media-";
|
const TEMP_MEDIA_PREFIX = "openclaw-media-";
|
||||||
let suiteTempMediaRootDir = "";
|
let suiteTempMediaRootDir = "";
|
||||||
let tempMediaDirCounter = 0;
|
let tempMediaDirCounter = 0;
|
||||||
|
let sharedTempMediaCacheDir = "";
|
||||||
|
const tempMediaFileCache = new Map<string, string>();
|
||||||
|
|
||||||
async function createTempMediaDir() {
|
async function createTempMediaDir() {
|
||||||
if (!suiteTempMediaRootDir) {
|
if (!suiteTempMediaRootDir) {
|
||||||
@@ -47,6 +50,13 @@ async function createTempMediaDir() {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getSharedTempMediaCacheDir() {
|
||||||
|
if (!sharedTempMediaCacheDir) {
|
||||||
|
sharedTempMediaCacheDir = await createTempMediaDir();
|
||||||
|
}
|
||||||
|
return sharedTempMediaCacheDir;
|
||||||
|
}
|
||||||
|
|
||||||
function createGroqAudioConfig(): OpenClawConfig {
|
function createGroqAudioConfig(): OpenClawConfig {
|
||||||
return {
|
return {
|
||||||
tools: {
|
tools: {
|
||||||
@@ -111,9 +121,20 @@ function createMediaDisabledConfigWithAllowedMimes(allowedMimes: string[]): Open
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createTempMediaFile(params: { fileName: string; content: Buffer | string }) {
|
async function createTempMediaFile(params: { fileName: string; content: Buffer | string }) {
|
||||||
const dir = await createTempMediaDir();
|
const normalizedContent =
|
||||||
const mediaPath = path.join(dir, params.fileName);
|
typeof params.content === "string" ? Buffer.from(params.content) : params.content;
|
||||||
|
const contentHash = crypto.createHash("sha1").update(normalizedContent).digest("hex");
|
||||||
|
const cacheKey = `${params.fileName}:${contentHash}`;
|
||||||
|
const cachedPath = tempMediaFileCache.get(cacheKey);
|
||||||
|
if (cachedPath) {
|
||||||
|
return cachedPath;
|
||||||
|
}
|
||||||
|
const cacheRootDir = await getSharedTempMediaCacheDir();
|
||||||
|
const cacheDir = path.join(cacheRootDir, contentHash);
|
||||||
|
await fs.mkdir(cacheDir, { recursive: true });
|
||||||
|
const mediaPath = path.join(cacheDir, params.fileName);
|
||||||
await fs.writeFile(mediaPath, params.content);
|
await fs.writeFile(mediaPath, params.content);
|
||||||
|
tempMediaFileCache.set(cacheKey, mediaPath);
|
||||||
return mediaPath;
|
return mediaPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,6 +255,8 @@ describe("applyMediaUnderstanding", () => {
|
|||||||
}
|
}
|
||||||
await fs.rm(suiteTempMediaRootDir, { recursive: true, force: true });
|
await fs.rm(suiteTempMediaRootDir, { recursive: true, force: true });
|
||||||
suiteTempMediaRootDir = "";
|
suiteTempMediaRootDir = "";
|
||||||
|
sharedTempMediaCacheDir = "";
|
||||||
|
tempMediaFileCache.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets Transcript and replaces Body when audio transcription succeeds", async () => {
|
it("sets Transcript and replaces Body when audio transcription succeeds", async () => {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ describe("runCommandWithTimeout", () => {
|
|||||||
'process.stdout.write((process.env.OPENCLAW_BASE_ENV ?? "") + "|" + (process.env.OPENCLAW_TEST_ENV ?? ""))',
|
'process.stdout.write((process.env.OPENCLAW_BASE_ENV ?? "") + "|" + (process.env.OPENCLAW_TEST_ENV ?? ""))',
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
timeoutMs: 5_000,
|
timeoutMs: 1_000,
|
||||||
env: { OPENCLAW_TEST_ENV: "ok" },
|
env: { OPENCLAW_TEST_ENV: "ok" },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -82,7 +82,7 @@ describe("runCommandWithTimeout", () => {
|
|||||||
[process.execPath, "-e", "setTimeout(() => {}, 60)"],
|
[process.execPath, "-e", "setTimeout(() => {}, 60)"],
|
||||||
{
|
{
|
||||||
timeoutMs: 500,
|
timeoutMs: 500,
|
||||||
noOutputTimeoutMs: 20,
|
noOutputTimeoutMs: 12,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user