@@ -6,6 +6,7 @@ import { beforeAll, describe, expect, it, vi } from "vitest";
66import { repairToolUseResultPairing } from "../../agents/session-transcript-repair.js" ;
77import * as transcriptEvents from "../../sessions/transcript-events.js" ;
88import type { SessionTranscriptUpdate } from "../../sessions/transcript-events.js" ;
9+ import { deleteTestEnvValue , setTestEnvValue } from "../../test-utils/env.js" ;
910import { resolveSessionTranscriptPathInDir } from "./paths.js" ;
1011import { updateSessionStoreEntry } from "./store.js" ;
1112import { useTempSessionsFixture } from "./test-helpers.js" ;
@@ -122,7 +123,7 @@ describe("appendAssistantMessageToSessionTranscript", () => {
122123 const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "transcript-config-store-" ) ) ;
123124 const previousStateDir = process . env . OPENCLAW_STATE_DIR ;
124125 try {
125- process . env . OPENCLAW_STATE_DIR = path . join ( tempDir , "default-state" ) ;
126+ setTestEnvValue ( " OPENCLAW_STATE_DIR" , path . join ( tempDir , "default-state" ) ) ;
126127 const sessionsDir = path . join ( tempDir , "configured" , "sessions" ) ;
127128 fs . mkdirSync ( sessionsDir , { recursive : true } ) ;
128129 const storePath = path . join ( sessionsDir , "sessions.json" ) ;
@@ -158,9 +159,9 @@ describe("appendAssistantMessageToSessionTranscript", () => {
158159 ) ;
159160 } finally {
160161 if ( previousStateDir === undefined ) {
161- delete process . env . OPENCLAW_STATE_DIR ;
162+ deleteTestEnvValue ( " OPENCLAW_STATE_DIR" ) ;
162163 } else {
163- process . env . OPENCLAW_STATE_DIR = previousStateDir ;
164+ setTestEnvValue ( " OPENCLAW_STATE_DIR" , previousStateDir ) ;
164165 }
165166 fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
166167 }
@@ -171,7 +172,7 @@ describe("appendAssistantMessageToSessionTranscript", () => {
171172 const previousStateDir = process . env . OPENCLAW_STATE_DIR ;
172173 const emitSpy = vi . spyOn ( transcriptEvents , "emitSessionTranscriptUpdate" ) ;
173174 try {
174- process . env . OPENCLAW_STATE_DIR = path . join ( tempDir , "default-state" ) ;
175+ setTestEnvValue ( " OPENCLAW_STATE_DIR" , path . join ( tempDir , "default-state" ) ) ;
175176 const storeTemplate = path . join ( tempDir , "agents" , "{agentId}" , "sessions" , "sessions.json" ) ;
176177 const sessionsDir = path . join ( tempDir , "agents" , "worker" , "sessions" ) ;
177178 fs . mkdirSync ( sessionsDir , { recursive : true } ) ;
@@ -219,9 +220,9 @@ describe("appendAssistantMessageToSessionTranscript", () => {
219220 } finally {
220221 emitSpy . mockRestore ( ) ;
221222 if ( previousStateDir === undefined ) {
222- delete process . env . OPENCLAW_STATE_DIR ;
223+ deleteTestEnvValue ( " OPENCLAW_STATE_DIR" ) ;
223224 } else {
224- process . env . OPENCLAW_STATE_DIR = previousStateDir ;
225+ setTestEnvValue ( " OPENCLAW_STATE_DIR" , previousStateDir ) ;
225226 }
226227 fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
227228 }
0 commit comments