perf(test): speed up docker-setup and web media fallback

This commit is contained in:
Peter Steinberger
2026-02-14 20:08:00 +00:00
parent 5daaab3692
commit e9294ff925
2 changed files with 18 additions and 34 deletions

View File

@@ -88,34 +88,20 @@ describe("docker-setup.sh", () => {
it("handles env defaults, home-volume mounts, and apt build args", async () => { it("handles env defaults, home-volume mounts, and apt build args", async () => {
const sandbox = await createDockerSetupSandbox(); const sandbox = await createDockerSetupSandbox();
const defaultsResult = spawnSync("bash", [sandbox.scriptPath], { const result = spawnSync("bash", [sandbox.scriptPath], {
cwd: sandbox.rootDir,
env: createEnv(sandbox, {
OPENCLAW_DOCKER_APT_PACKAGES: undefined,
OPENCLAW_EXTRA_MOUNTS: undefined,
OPENCLAW_HOME_VOLUME: undefined,
}),
stdio: ["ignore", "ignore", "pipe"],
});
expect(defaultsResult.status).toBe(0);
const defaultsEnvFile = await readFile(join(sandbox.rootDir, ".env"), "utf8");
expect(defaultsEnvFile).toContain("OPENCLAW_DOCKER_APT_PACKAGES=");
expect(defaultsEnvFile).toContain("OPENCLAW_EXTRA_MOUNTS=");
expect(defaultsEnvFile).toContain("OPENCLAW_HOME_VOLUME=");
await writeFile(sandbox.logPath, "");
const aptAndHomeVolumeResult = spawnSync("bash", [sandbox.scriptPath], {
cwd: sandbox.rootDir, cwd: sandbox.rootDir,
env: createEnv(sandbox, { env: createEnv(sandbox, {
OPENCLAW_DOCKER_APT_PACKAGES: "ffmpeg build-essential", OPENCLAW_DOCKER_APT_PACKAGES: "ffmpeg build-essential",
OPENCLAW_EXTRA_MOUNTS: "", OPENCLAW_EXTRA_MOUNTS: undefined,
OPENCLAW_HOME_VOLUME: "openclaw-home", OPENCLAW_HOME_VOLUME: "openclaw-home",
}), }),
stdio: ["ignore", "ignore", "pipe"], stdio: ["ignore", "ignore", "pipe"],
}); });
expect(aptAndHomeVolumeResult.status).toBe(0); expect(result.status).toBe(0);
const aptEnvFile = await readFile(join(sandbox.rootDir, ".env"), "utf8"); const envFile = await readFile(join(sandbox.rootDir, ".env"), "utf8");
expect(aptEnvFile).toContain("OPENCLAW_DOCKER_APT_PACKAGES=ffmpeg build-essential"); expect(envFile).toContain("OPENCLAW_DOCKER_APT_PACKAGES=ffmpeg build-essential");
expect(envFile).toContain("OPENCLAW_EXTRA_MOUNTS=");
expect(envFile).toContain("OPENCLAW_HOME_VOLUME=openclaw-home");
const extraCompose = await readFile(join(sandbox.rootDir, "docker-compose.extra.yml"), "utf8"); const extraCompose = await readFile(join(sandbox.rootDir, "docker-compose.extra.yml"), "utf8");
expect(extraCompose).toContain("openclaw-home:/home/node"); expect(extraCompose).toContain("openclaw-home:/home/node");
expect(extraCompose).toContain("volumes:"); expect(extraCompose).toContain("volumes:");

View File

@@ -116,13 +116,13 @@ describe("web auto-reply", () => {
fetchMock.mockRestore(); fetchMock.mockRestore();
}); });
it("compresses media over 5MB and still sends it", async () => { it("sends media with a caption when delivery succeeds", async () => {
const sendMedia = vi.fn(); const sendMedia = vi.fn().mockResolvedValue(undefined);
const reply = vi.fn().mockResolvedValue(undefined); const reply = vi.fn().mockResolvedValue(undefined);
const sendComposing = vi.fn(); const sendComposing = vi.fn();
const resolver = vi.fn().mockResolvedValue({ const resolver = vi.fn().mockResolvedValue({
text: "hi", text: "hi",
mediaUrl: "https://example.com/big.png", mediaUrl: "https://example.com/img.png",
}); });
let capturedOnMessage: let capturedOnMessage:
@@ -135,23 +135,21 @@ describe("web auto-reply", () => {
return { close: vi.fn() }; return { close: vi.fn() };
}; };
const bigPng = await sharp({ const png = await sharp({
create: { create: {
width: 2000, width: 64,
height: 2000, height: 64,
channels: 3, channels: 3,
background: { r: 255, g: 0, b: 0 }, background: { r: 0, g: 0, b: 255 },
}, },
}) })
.png({ compressionLevel: 0 }) .png()
.toBuffer(); .toBuffer();
expect(bigPng.length).toBeGreaterThan(5 * 1024 * 1024);
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue({ const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue({
ok: true, ok: true,
body: true, body: true,
arrayBuffer: async () => arrayBuffer: async () => png.buffer.slice(png.byteOffset, png.byteOffset + png.byteLength),
bigPng.buffer.slice(bigPng.byteOffset, bigPng.byteOffset + bigPng.byteLength),
headers: { get: () => "image/png" }, headers: { get: () => "image/png" },
status: 200, status: 200,
} as Response); } as Response);
@@ -175,8 +173,8 @@ describe("web auto-reply", () => {
caption?: string; caption?: string;
mimetype?: string; mimetype?: string;
}; };
expect(payload.image.length).toBeLessThanOrEqual(5 * 1024 * 1024); expect(payload.caption).toBe("hi");
expect(payload.mimetype).toBe("image/jpeg"); expect(payload.image.length).toBeGreaterThan(0);
// Should not fall back to separate text reply because caption is used. // Should not fall back to separate text reply because caption is used.
expect(reply).not.toHaveBeenCalled(); expect(reply).not.toHaveBeenCalled();