test: stop leaking image workspace temp dirs

This commit is contained in:
Peter Steinberger
2026-03-23 01:20:18 -07:00
parent fe459c9084
commit 94f397bc5f

View File

@@ -88,8 +88,10 @@ const ONE_PIXEL_JPEG_B64 = "QUJDRA==";
async function withTempWorkspacePng(
cb: (args: { workspaceDir: string; imagePath: string }) => Promise<void>,
options?: { parentDir?: string },
) {
const workspaceParent = await fs.mkdtemp(path.join(process.cwd(), ".openclaw-workspace-image-"));
const parentDir = options?.parentDir ?? os.tmpdir();
const workspaceParent = await fs.mkdtemp(path.join(parentDir, "openclaw-workspace-image-"));
try {
const workspaceDir = path.join(workspaceParent, "workspace");
await fs.mkdir(workspaceDir, { recursive: true });
@@ -715,13 +717,13 @@ describe("image tool implicit imageModel config", () => {
});
});
it("allows workspace images via createOpenClawCodingTools default workspace root", async () => {
await withTempWorkspacePng(async ({ imagePath }) => {
it("allows workspace images via createOpenClawCodingTools when workspace root is explicit", async () => {
await withTempWorkspacePng(async ({ workspaceDir, imagePath }) => {
const fetch = stubMinimaxOkFetch();
await withTempAgentDir(async (agentDir) => {
const cfg = createMinimaxImageConfig();
const tools = createOpenClawCodingTools({ config: cfg, agentDir });
const tools = createOpenClawCodingTools({ config: cfg, agentDir, workspaceDir });
const tool = requireImageTool(tools.find((candidate) => candidate.name === "image"));
await expectImageToolExecOk(tool, imagePath);