mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 01:03:29 +00:00
refactor(test): share temp workspace helper for skill download suites
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user