






















@@ -6,6 +6,7 @@ import path from "node:path";
66import { pathToFileURL } from "node:url";
77import { describe, expect, it, vi } from "vitest";
88import { resolvePreferredOpenClawTmpDir } from "../../../infra/tmp-openclaw-dir.js";
9+import { captureEnv, setTestEnvValue } from "../../../test-utils/env.js";
910import { createHostSandboxFsBridge } from "../../test-helpers/host-sandbox-fs-bridge.js";
1011import { createUnsafeMountedSandbox } from "../../test-helpers/unsafe-mounted-sandbox.js";
1112import {
@@ -420,7 +421,8 @@ describe("loadImageFromRef", () => {
420421await fs.mkdir(workspaceDir, { recursive: true });
421422await fs.mkdir(inboundDir, { recursive: true });
422423await fs.writeFile(path.join(inboundDir, mediaId), Buffer.from(TINY_PNG_BASE64, "base64"));
423-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
424+const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
425+setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
424426425427try {
426428const image = await loadImageFromRef(
@@ -437,7 +439,7 @@ describe("loadImageFromRef", () => {
437439expect(image?.mimeType).toBe("image/png");
438440expect(image?.data).toBe(TINY_PNG_BASE64);
439441} finally {
440-vi.unstubAllEnvs();
442+envSnapshot.restore();
441443await fs.rm(stateDir, { recursive: true, force: true });
442444}
443445});
@@ -670,7 +672,8 @@ describe("detectAndLoadPromptImages", () => {
670672const imagePath = path.join(inboundDir, "signal-replay.png");
671673const pngB64 = TINY_PNG_BASE64;
672674await fs.writeFile(imagePath, Buffer.from(pngB64, "base64"));
673-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
675+const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
676+setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
674677675678try {
676679const result = await detectAndLoadPromptImages({
@@ -685,7 +688,7 @@ describe("detectAndLoadPromptImages", () => {
685688expect(result.skippedCount).toBe(0);
686689expect(result.images).toHaveLength(1);
687690} finally {
688-vi.unstubAllEnvs();
691+envSnapshot.restore();
689692await fs.rm(stateDir, { recursive: true, force: true });
690693}
691694});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。