refactor(test): share temp workspace helper for skill download suites

This commit is contained in:
Peter Steinberger
2026-02-21 18:51:40 +00:00
parent a814cce359
commit 61817c90e7
3 changed files with 27 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
export function setTempStateDir(workspaceDir: string): string {
@@ -7,6 +8,18 @@ export function setTempStateDir(workspaceDir: string): string {
return stateDir;
}
export async function withTempWorkspace(
run: (params: { workspaceDir: string; stateDir: string }) => Promise<void>,
) {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skills-install-"));
try {
const stateDir = setTempStateDir(workspaceDir);
await run({ workspaceDir, stateDir });
} finally {
await fs.rm(workspaceDir, { recursive: true, force: true }).catch(() => undefined);
}
}
export async function writeDownloadSkill(params: {
workspaceDir: string;
name: string;