mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:20:43 +00:00
test: share qa temp dir harness
This commit is contained in:
@@ -1,20 +1,12 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { seedQaAgentWorkspace } from "./qa-agent-workspace.js";
|
||||
import { createTempDirHarness } from "./temp-dir.test-helper.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
const { cleanup, makeTempDir } = createTempDirHarness();
|
||||
|
||||
async function makeTempDir(prefix: string) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("seedQaAgentWorkspace", () => {
|
||||
it("creates a repo symlink when a repo root is provided", async () => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -20,18 +19,11 @@ import {
|
||||
extractMediaPathFromText,
|
||||
resolveGeneratedImagePath,
|
||||
} from "./suite-runtime-agent-media.js";
|
||||
import { createTempDirHarness } from "./temp-dir.test-helper.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
const { cleanup, makeTempDir } = createTempDirHarness();
|
||||
|
||||
async function makeTempDir(prefix: string) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("qa suite runtime agent media helpers", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -8,18 +7,11 @@ import {
|
||||
readRawQaSessionStore,
|
||||
readSkillStatus,
|
||||
} from "./suite-runtime-agent-session.js";
|
||||
import { createTempDirHarness } from "./temp-dir.test-helper.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
const { cleanup, makeTempDir } = createTempDirHarness();
|
||||
|
||||
async function makeTempDir(prefix: string) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("qa suite runtime agent session helpers", () => {
|
||||
const gatewayCall = vi.fn();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -49,18 +48,11 @@ import {
|
||||
handleQaAction,
|
||||
writeWorkspaceSkill,
|
||||
} from "./suite-runtime-agent-tools.js";
|
||||
import { createTempDirHarness } from "./temp-dir.test-helper.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
const { cleanup, makeTempDir } = createTempDirHarness();
|
||||
|
||||
async function makeTempDir(prefix: string) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("qa suite runtime agent tools helpers", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
20
extensions/qa-lab/src/temp-dir.test-helper.ts
Normal file
20
extensions/qa-lab/src/temp-dir.test-helper.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
export function createTempDirHarness() {
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
return {
|
||||
async cleanup() {
|
||||
await Promise.all(
|
||||
tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })),
|
||||
);
|
||||
},
|
||||
async makeTempDir(prefix: string) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user