mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: capture usage format env setup
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
setGatewayModelPricingForTest,
|
||||
} from "../gateway/model-pricing-cache-state.js";
|
||||
import * as manifestModelIdNormalization from "../plugins/manifest-model-id-normalization.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import {
|
||||
resetUsageFormatCachesForTest,
|
||||
estimateUsageCost,
|
||||
@@ -42,12 +43,12 @@ function requireTieredPricing(
|
||||
}
|
||||
|
||||
describe("usage-format", () => {
|
||||
const originalAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
||||
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
let envSnapshot: ReturnType<typeof captureEnv> | undefined;
|
||||
let agentDir: string;
|
||||
let stateDir: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
envSnapshot = captureEnv(["OPENCLAW_AGENT_DIR", "OPENCLAW_STATE_DIR"]);
|
||||
stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-usage-format-"));
|
||||
agentDir = path.join(stateDir, "agents", "main", "agent");
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
@@ -58,16 +59,8 @@ describe("usage-format", () => {
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (originalAgentDir === undefined) {
|
||||
delete process.env.OPENCLAW_AGENT_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_AGENT_DIR = originalAgentDir;
|
||||
}
|
||||
if (originalStateDir === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_STATE_DIR = originalStateDir;
|
||||
}
|
||||
envSnapshot?.restore();
|
||||
envSnapshot = undefined;
|
||||
resetUsageFormatCachesForTest();
|
||||
resetGatewayModelPricingCacheForTest();
|
||||
await fs.rm(stateDir, { recursive: true, force: true });
|
||||
|
||||
Reference in New Issue
Block a user