refactor(test): dedupe env setup across suites

This commit is contained in:
Peter Steinberger
2026-02-21 13:12:53 +00:00
parent f903603722
commit 7724abeee0
5 changed files with 43 additions and 122 deletions

View File

@@ -4,6 +4,7 @@ import path from "node:path";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ChannelPlugin } from "../channels/plugins/types.js";
import type { OpenClawConfig } from "../config/config.js";
import { withEnvAsync } from "../test-utils/env.js";
import { collectPluginsCodeSafetyFindings } from "./audit-extra.js";
import type { SecurityAuditOptions, SecurityAuditReport } from "./audit.js";
import { runSecurityAudit } from "./audit.js";
@@ -102,19 +103,9 @@ describe("security audit", () => {
};
const withStateDir = async (label: string, fn: (tmp: string) => Promise<void>) => {
const prevStateDir = process.env.OPENCLAW_STATE_DIR;
const tmp = await makeTmpDir(label);
process.env.OPENCLAW_STATE_DIR = tmp;
await fs.mkdir(path.join(tmp, "credentials"), { recursive: true, mode: 0o700 });
try {
await fn(tmp);
} finally {
if (prevStateDir == null) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = prevStateDir;
}
}
await withEnvAsync({ OPENCLAW_STATE_DIR: tmp }, async () => await fn(tmp));
};
beforeAll(async () => {