From 0401762144db99c78caff39160dffa19ae445c78 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 19:00:25 +0000 Subject: [PATCH] refactor(test): dedupe temp root setup in identity avatar e2e --- src/agents/identity-avatar.e2e.test.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/agents/identity-avatar.e2e.test.ts b/src/agents/identity-avatar.e2e.test.ts index 2e06c545f..fcfbf6ff4 100644 --- a/src/agents/identity-avatar.e2e.test.ts +++ b/src/agents/identity-avatar.e2e.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { resolveAgentAvatar } from "./identity-avatar.js"; @@ -24,9 +24,25 @@ async function expectLocalAvatarPath( } } +const tempRoots: string[] = []; + +async function createTempAvatarRoot() { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-avatar-")); + tempRoots.push(root); + return root; +} + +afterEach(async () => { + await Promise.all( + tempRoots + .splice(0, tempRoots.length) + .map((root) => fs.rm(root, { recursive: true, force: true })), + ); +}); + describe("resolveAgentAvatar", () => { it("resolves local avatar from config when inside workspace", async () => { - const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-avatar-")); + const root = await createTempAvatarRoot(); const workspace = path.join(root, "work"); const avatarPath = path.join(workspace, "avatars", "main.png"); await writeFile(avatarPath); @@ -47,7 +63,7 @@ describe("resolveAgentAvatar", () => { }); it("rejects avatars outside the workspace", async () => { - const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-avatar-")); + const root = await createTempAvatarRoot(); const workspace = path.join(root, "work"); await fs.mkdir(workspace, { recursive: true }); const outsidePath = path.join(root, "outside.png"); @@ -73,7 +89,7 @@ describe("resolveAgentAvatar", () => { }); it("falls back to IDENTITY.md when config has no avatar", async () => { - const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-avatar-")); + const root = await createTempAvatarRoot(); const workspace = path.join(root, "work"); const avatarPath = path.join(workspace, "avatars", "fallback.png"); await writeFile(avatarPath); @@ -94,7 +110,7 @@ describe("resolveAgentAvatar", () => { }); it("returns missing for non-existent local avatar files", async () => { - const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-avatar-")); + const root = await createTempAvatarRoot(); const workspace = path.join(root, "work"); await fs.mkdir(workspace, { recursive: true });