@@ -2,6 +2,7 @@ import fs from "node:fs";
|
2 | 2 | import os from "node:os"; |
3 | 3 | import path from "node:path"; |
4 | 4 | import { afterEach, beforeEach, describe, expect, test } from "vitest"; |
| 5 | +import { captureEnv, setTestEnvValue } from "../test-utils/env.js"; |
5 | 6 | import { |
6 | 7 | readLatestRecentSessionUsageFromTranscriptAsync, |
7 | 8 | readRecentSessionMessagesWithStats, |
@@ -16,21 +17,17 @@ import {
|
16 | 17 | describe("session transcript reader facade", () => { |
17 | 18 | let tempDir: string; |
18 | 19 | let storePath: string; |
19 | | -let originalStateDir: string | undefined; |
| 20 | +let envSnapshot: ReturnType<typeof captureEnv>; |
20 | 21 | |
21 | 22 | beforeEach(() => { |
22 | | -originalStateDir = process.env.OPENCLAW_STATE_DIR; |
| 23 | +envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]); |
23 | 24 | tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-transcript-readers-")); |
24 | 25 | storePath = path.join(tempDir, "sessions.json"); |
25 | | -process.env.OPENCLAW_STATE_DIR = tempDir; |
| 26 | +setTestEnvValue("OPENCLAW_STATE_DIR", tempDir); |
26 | 27 | }); |
27 | 28 | |
28 | 29 | afterEach(() => { |
29 | | -if (originalStateDir === undefined) { |
30 | | -delete process.env.OPENCLAW_STATE_DIR; |
31 | | -} else { |
32 | | -process.env.OPENCLAW_STATE_DIR = originalStateDir; |
33 | | -} |
| 30 | +envSnapshot.restore(); |
34 | 31 | fs.rmSync(tempDir, { recursive: true, force: true }); |
35 | 32 | }); |
36 | 33 | |
|