



























@@ -2,12 +2,14 @@
22import fs from "node:fs/promises";
33import os from "node:os";
44import path from "node:path";
5-import { beforeEach, describe, expect, it, vi } from "vitest";
5+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6+import { captureEnv, setTestEnvValue } from "../../test-utils/env.js";
67import { getReplyPayloadMetadata, setReplyPayloadMetadata } from "../reply-payload.js";
7889const ensureSandboxWorkspaceForSession = vi.hoisted(() => vi.fn());
910const resolveOutboundAttachmentFromUrl = vi.hoisted(() => vi.fn());
1011const resolveAgentScopedOutboundMediaAccess = vi.hoisted(() => vi.fn());
12+const stateDirEnvSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
11131214vi.mock("../../agents/sandbox.js", () => ({
1315 ensureSandboxWorkspaceForSession,
@@ -86,7 +88,10 @@ describe("createReplyMediaPathNormalizer", () => {
8688localRoots: workspaceDir ? [workspaceDir] : undefined,
8789readFile: async () => Buffer.from("image"),
8890}));
89-vi.unstubAllEnvs();
91+});
92+93+afterEach(() => {
94+stateDirEnvSnapshot.restore();
9095});
91969297it("stages workspace-relative media through shared outbound attachment loading", async () => {
@@ -355,7 +360,7 @@ describe("createReplyMediaPathNormalizer", () => {
355360});
356361357362it("keeps managed generated media under the shared media root", async () => {
358-vi.stubEnv("OPENCLAW_STATE_DIR", "/Users/peter/.openclaw");
363+setTestEnvValue("OPENCLAW_STATE_DIR", "/Users/peter/.openclaw");
359364const normalize = createReplyMediaPathNormalizer({
360365cfg: {},
361366sessionKey: "session-key",
@@ -377,7 +382,7 @@ describe("createReplyMediaPathNormalizer", () => {
377382workspaceDir: "/tmp/sandboxes/session-1",
378383containerWorkdir: "/workspace",
379384});
380-vi.stubEnv("OPENCLAW_STATE_DIR", "/Users/peter/.openclaw");
385+setTestEnvValue("OPENCLAW_STATE_DIR", "/Users/peter/.openclaw");
381386const normalize = createReplyMediaPathNormalizer({
382387cfg: {},
383388sessionKey: "session-key",
@@ -406,7 +411,7 @@ describe("createReplyMediaPathNormalizer", () => {
406411await fs.mkdir(path.dirname(symlinkPath), { recursive: true });
407412await fs.writeFile(outsideFile, "secret", "utf8");
408413await fs.symlink(outsideFile, symlinkPath);
409-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
414+setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
410415const normalize = createReplyMediaPathNormalizer({
411416cfg: {},
412417sessionKey: "session-key",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。