Skip to content

Commit 6834a2d

Browse files
committed
test: scope send state env helper
1 parent 5225126 commit 6834a2d

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/gateway/server-methods/send.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { jsonResult } from "../../agents/tools/common.js";
88
import type { ChannelPlugin } from "../../channels/plugins/types.js";
99
import { setActivePluginRegistry } from "../../plugins/runtime.js";
1010
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
11+
import { captureEnv, setTestEnvValue } from "../../test-utils/env.js";
1112
import type { GatewayRequestContext } from "./types.js";
1213

1314
type ResolveOutboundTarget = typeof import("../../infra/outbound/targets.js").resolveOutboundTarget;
@@ -213,17 +214,13 @@ async function runMessageActionRequest(
213214
}
214215

215216
async function withTempOpenClawStateDir<T>(test: (stateDir: string) => Promise<T>): Promise<T> {
216-
const previous = process.env.OPENCLAW_STATE_DIR;
217+
const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
217218
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "gateway-send-state-"));
218-
process.env.OPENCLAW_STATE_DIR = stateDir;
219+
setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
219220
try {
220221
return await test(stateDir);
221222
} finally {
222-
if (previous === undefined) {
223-
delete process.env.OPENCLAW_STATE_DIR;
224-
} else {
225-
process.env.OPENCLAW_STATE_DIR = previous;
226-
}
223+
envSnapshot.restore();
227224
await fs.rm(stateDir, { recursive: true, force: true });
228225
}
229226
}

0 commit comments

Comments
 (0)