mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-26 09:29:32 +00:00
test: wrap install download state fixture
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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-",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user