

























@@ -7,6 +7,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
77import { WebSocket } from "ws";
88import { emitAgentEvent, registerAgentRunContext } from "../infra/agent-events.js";
99import { extractFirstTextBlock } from "../shared/chat-message-content.js";
10+import { captureEnv, setTestEnvValue } from "../test-utils/env.js";
1011import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js";
1112import {
1213connectOk,
@@ -1533,8 +1534,8 @@ describe("gateway server chat", () => {
15331534test("chat.history persists assistant image data URLs as managed image blocks", async () => {
15341535await withMainSessionStore(
15351536async (dir) => {
1536-const previousStateDir = process.env.OPENCLAW_STATE_DIR;
1537-process.env.OPENCLAW_STATE_DIR = dir;
1537+const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
1538+setTestEnvValue("OPENCLAW_STATE_DIR", dir);
15381539const pngB64 =
15391540"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgYAAAAAMAASsJTYQAAAAASUVORK5CYII=";
15401541dispatchInboundMessageMock.mockImplementationOnce(async (...args: unknown[]) => {
@@ -1616,11 +1617,7 @@ describe("gateway server chat", () => {
16161617expect(serializedAssistant).not.toContain("data:image/png;base64");
16171618expect(serializedAssistant).not.toContain(pngB64);
16181619} finally {
1619-if (previousStateDir == null) {
1620-delete process.env.OPENCLAW_STATE_DIR;
1621-} else {
1622-process.env.OPENCLAW_STATE_DIR = previousStateDir;
1623-}
1620+envSnapshot.restore();
16241621}
16251622},
16261623{ sessionId: "sess-managed-image-history" },
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。