test: wrap install download state fixture

This commit is contained in:
Shakker
2026-06-06 22:02:39 +01:00
parent a33077d9c6
commit 133585d97f
2 changed files with 19 additions and 15 deletions

View File

@@ -1,11 +1,11 @@
// Install download tests cover downloading skill archives before extraction.
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { Readable } from "node:stream";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawTestState } from "../../test-utils/openclaw-test-state.js";
import { resolveSkillToolsRootDir } from "../runtime/tools-dir.js";
import { setTempStateDir } from "../test-support/install-download-test-utils.js";
import { createInstallDownloadTestState } from "../test-support/install-download-test-utils.js";
import {
fetchWithSsrFGuardMock,
hasBinaryMock,
@@ -144,16 +144,16 @@ function mockTarExtractionFlow(params: {
}
let workspaceDir = "";
let testState: OpenClawTestState | undefined;
beforeAll(async () => {
workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skills-install-"));
setTempStateDir(workspaceDir);
testState = await createInstallDownloadTestState();
workspaceDir = testState.workspaceDir;
});
afterAll(async () => {
if (workspaceDir) {
await fs.rm(workspaceDir, { recursive: true, force: true }).catch(() => undefined);
workspaceDir = "";
}
await testState?.cleanup();
testState = undefined;
workspaceDir = "";
});
beforeEach(() => {

View File

@@ -1,9 +1,13 @@
// Install download test utilities provide fake download responses and paths.
import path from "node:path";
// Install download test utilities provide isolated state and workspace paths.
import {
createOpenClawTestState,
type OpenClawTestState,
} from "../../test-utils/openclaw-test-state.js";
/** Points OpenClaw state at a workspace-local temp dir for install tests. */
export function setTempStateDir(workspaceDir: string): string {
const stateDir = path.join(workspaceDir, "state");
process.env.OPENCLAW_STATE_DIR = stateDir;
return stateDir;
/** Creates isolated OpenClaw state for install download tests. */
export async function createInstallDownloadTestState(): Promise<OpenClawTestState> {
return await createOpenClawTestState({
layout: "state-only",
prefix: "openclaw-skills-install-",
});
}