test: reuse update method env wrapper · openclaw/openclaw@ae81aa0
shakkernerd
·
2026-06-21
·
via Recent Commits to openclaw:main
File tree
src/gateway/server-methods
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import type { ConfigFileSnapshot, OpenClawConfig } from "../../config/types.open
|
5 | 5 | import type { RestartSentinelPayload } from "../../infra/restart-sentinel.js"; |
6 | 6 | import type { RespawnSupervisor } from "../../infra/supervisor-markers.js"; |
7 | 7 | import type { UpdateInstallSurface, UpdateRunResult } from "../../infra/update-runner.js"; |
| 8 | +import { withEnvAsync } from "../../test-utils/env.js"; |
8 | 9 | |
9 | 10 | // Capture the sentinel payload written during update.run |
10 | 11 | let capturedPayload: RestartSentinelPayload | undefined; |
@@ -273,27 +274,7 @@ async function withProcessEnv<T>(
|
273 | 274 | updates: Record<string, string | undefined>, |
274 | 275 | run: () => Promise<T>, |
275 | 276 | ): Promise<T> { |
276 | | -const previous = new Map<string, string | undefined>(); |
277 | | -for (const key of Object.keys(updates)) { |
278 | | -previous.set(key, process.env[key]); |
279 | | -const value = updates[key]; |
280 | | -if (value === undefined) { |
281 | | -delete process.env[key]; |
282 | | -} else { |
283 | | -process.env[key] = value; |
284 | | -} |
285 | | -} |
286 | | -try { |
287 | | -return await run(); |
288 | | -} finally { |
289 | | -for (const [key, value] of previous) { |
290 | | -if (value === undefined) { |
291 | | -delete process.env[key]; |
292 | | -} else { |
293 | | -process.env[key] = value; |
294 | | -} |
295 | | -} |
296 | | -} |
| 277 | +return await withEnvAsync(updates, run); |
297 | 278 | } |
298 | 279 | |
299 | 280 | function mockGlobalInstallSurface() { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。