























@@ -21,12 +21,14 @@ import {
2121} from "../plugins/runtime.js";
2222import { extractFirstTextBlock } from "../shared/chat-message-content.js";
2323import { createTestRegistry } from "../test-utils/channel-plugins.js";
24+import { deleteTestEnvValue, setTestEnvValue } from "../test-utils/env.js";
2425import { sleep } from "../utils.js";
2526import type { GatewayClient } from "./client.js";
2627import {
2728connectTestGatewayClient,
2829getFreeGatewayPort,
2930} from "./gateway-cli-backend.live-helpers.js";
31+import { restoreLiveEnv, snapshotLiveEnv, type LiveEnvSnapshot } from "./live-env-test-helpers.js";
3032import { startGatewayServer } from "./server.js";
31333234const LIVE = isLiveTestEnabled();
@@ -172,14 +174,6 @@ async function waitForOutboundText(params: {
172174);
173175}
174176175-function restoreEnvVar(name: string, value: string | undefined): void {
176-if (value === undefined) {
177-delete process.env[name];
178-return;
179-}
180-process.env[name] = value;
181-}
182-183177async function waitForAgentRunOk(
184178client: GatewayClient,
185179runId: string,
@@ -400,17 +394,7 @@ describeLive("gateway live (native Codex conversation binding)", () => {
400394it(
401395"binds a Slack DM to Codex app-server, updates controls, and forwards image media paths",
402396async () => {
403-const previous = {
404-codexHome: process.env.CODEX_HOME,
405-configPath: process.env.OPENCLAW_CONFIG_PATH,
406-gatewayToken: process.env.OPENCLAW_GATEWAY_TOKEN,
407-home: process.env.HOME,
408-skipCanvas: process.env.OPENCLAW_SKIP_CANVAS_HOST,
409-skipChannels: process.env.OPENCLAW_SKIP_CHANNELS,
410-skipCron: process.env.OPENCLAW_SKIP_CRON,
411-skipGmail: process.env.OPENCLAW_SKIP_GMAIL_WATCHER,
412-stateDir: process.env.OPENCLAW_STATE_DIR,
413-};
397+const previous: LiveEnvSnapshot = snapshotLiveEnv(["CODEX_HOME", "HOME"]);
414398const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-live-codex-bind-"));
415399const tempHome = path.join(tempRoot, "home");
416400const stateDir = path.join(tempRoot, "state");
@@ -453,20 +437,20 @@ describeLive("gateway live (native Codex conversation binding)", () => {
453437clearPluginLoaderCache();
454438resetPluginRuntimeStateForTest();
455439const codexHome =
456-previous.codexHome || (previous.home ? path.join(previous.home, ".codex") : "");
440+previous.CODEX_HOME || (previous.HOME ? path.join(previous.HOME, ".codex") : "");
457441if (codexHome) {
458-process.env.CODEX_HOME = codexHome;
442+setTestEnvValue("CODEX_HOME", codexHome);
459443} else {
460-delete process.env.CODEX_HOME;
444+deleteTestEnvValue("CODEX_HOME");
461445}
462-process.env.HOME = tempHome;
463-process.env.OPENCLAW_CONFIG_PATH = configPath;
464-process.env.OPENCLAW_GATEWAY_TOKEN = token;
465-process.env.OPENCLAW_SKIP_CANVAS_HOST = "1";
466-process.env.OPENCLAW_SKIP_CHANNELS = "1";
467-process.env.OPENCLAW_SKIP_CRON = "1";
468-process.env.OPENCLAW_SKIP_GMAIL_WATCHER = "1";
469-process.env.OPENCLAW_STATE_DIR = stateDir;
446+setTestEnvValue("HOME", tempHome);
447+setTestEnvValue("OPENCLAW_CONFIG_PATH", configPath);
448+setTestEnvValue("OPENCLAW_GATEWAY_TOKEN", token);
449+setTestEnvValue("OPENCLAW_SKIP_CANVAS_HOST", "1");
450+setTestEnvValue("OPENCLAW_SKIP_CHANNELS", "1");
451+setTestEnvValue("OPENCLAW_SKIP_CRON", "1");
452+setTestEnvValue("OPENCLAW_SKIP_GMAIL_WATCHER", "1");
453+setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
470454let server: Awaited<ReturnType<typeof startGatewayServer>> | undefined;
471455let client: Awaited<ReturnType<typeof connectTestGatewayClient>> | undefined;
472456let pinnedChannelRegistry:
@@ -631,15 +615,7 @@ describeLive("gateway live (native Codex conversation binding)", () => {
631615}
632616} finally {
633617await fs.rm(tempRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
634-restoreEnvVar("CODEX_HOME", previous.codexHome);
635-restoreEnvVar("OPENCLAW_CONFIG_PATH", previous.configPath);
636-restoreEnvVar("OPENCLAW_GATEWAY_TOKEN", previous.gatewayToken);
637-restoreEnvVar("HOME", previous.home);
638-restoreEnvVar("OPENCLAW_SKIP_CANVAS_HOST", previous.skipCanvas);
639-restoreEnvVar("OPENCLAW_SKIP_CHANNELS", previous.skipChannels);
640-restoreEnvVar("OPENCLAW_SKIP_CRON", previous.skipCron);
641-restoreEnvVar("OPENCLAW_SKIP_GMAIL_WATCHER", previous.skipGmail);
642-restoreEnvVar("OPENCLAW_STATE_DIR", previous.stateDir);
618+restoreLiveEnv(previous);
643619}
644620}
645621},
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。