mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:51:25 +00:00
refactor(test): dedupe env setup across suites
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user