mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: snapshot diagnostic state env
This commit is contained in:
@@ -4,6 +4,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { saveCronStore } from "../cron/store.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import {
|
||||
formatCronSessionDiagnosticFields,
|
||||
formatStoppedCronSessionDiagnosticFields,
|
||||
@@ -13,7 +14,7 @@ import {
|
||||
} from "./diagnostic-session-context.js";
|
||||
|
||||
let tempDir: string | undefined;
|
||||
let previousStateDir: string | undefined;
|
||||
let envSnapshot: ReturnType<typeof captureEnv> | undefined;
|
||||
|
||||
function writeJsonl(filePath: string, rows: unknown[]) {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
@@ -22,17 +23,14 @@ function writeJsonl(filePath: string, rows: unknown[]) {
|
||||
|
||||
describe("diagnostic session context", () => {
|
||||
beforeEach(() => {
|
||||
previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-diagnostic-session-"));
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (previousStateDir === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_STATE_DIR = previousStateDir;
|
||||
}
|
||||
envSnapshot?.restore();
|
||||
envSnapshot = undefined;
|
||||
if (tempDir) {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user