test: scope send state env helper · openclaw/openclaw@6834a2d
shakkernerd
·
2026-06-23
·
via Recent Commits to openclaw:main
File tree
src/gateway/server-methods
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ import { jsonResult } from "../../agents/tools/common.js";
|
8 | 8 | import type { ChannelPlugin } from "../../channels/plugins/types.js"; |
9 | 9 | import { setActivePluginRegistry } from "../../plugins/runtime.js"; |
10 | 10 | import { createTestRegistry } from "../../test-utils/channel-plugins.js"; |
| 11 | +import { captureEnv, setTestEnvValue } from "../../test-utils/env.js"; |
11 | 12 | import type { GatewayRequestContext } from "./types.js"; |
12 | 13 | |
13 | 14 | type ResolveOutboundTarget = typeof import("../../infra/outbound/targets.js").resolveOutboundTarget; |
@@ -213,17 +214,13 @@ async function runMessageActionRequest(
|
213 | 214 | } |
214 | 215 | |
215 | 216 | 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"]); |
217 | 218 | 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); |
219 | 220 | try { |
220 | 221 | return await test(stateDir); |
221 | 222 | } 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(); |
227 | 224 | await fs.rm(stateDir, { recursive: true, force: true }); |
228 | 225 | } |
229 | 226 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。