test: share qa temp dir harness

This commit is contained in:
Peter Steinberger
2026-04-20 20:54:36 +01:00
parent f5305afcfb
commit f587887122
5 changed files with 32 additions and 44 deletions

View File

@@ -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 () => {

View File

@@ -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(() => {

View File

@@ -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();

View File

@@ -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(() => {

View 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;
},
};
}