refactor(test): centralize temp workspace env handling for skill install tests

This commit is contained in:
Peter Steinberger
2026-02-21 18:52:38 +00:00
parent 61817c90e7
commit 603e28648b
2 changed files with 8 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { captureEnv } from "../test-utils/env.js";
export function setTempStateDir(workspaceDir: string): string {
const stateDir = path.join(workspaceDir, "state");
@@ -11,11 +12,13 @@ export function setTempStateDir(workspaceDir: string): string {
export async function withTempWorkspace(
run: (params: { workspaceDir: string; stateDir: string }) => Promise<void>,
) {
const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skills-install-"));
try {
const stateDir = setTempStateDir(workspaceDir);
await run({ workspaceDir, stateDir });
} finally {
envSnapshot.restore();
await fs.rm(workspaceDir, { recursive: true, force: true }).catch(() => undefined);
}
}