test: contain sessions tool state env

This commit is contained in:
Shakker
2026-06-05 16:58:37 +01:00
parent 415272d17e
commit b19904931e

View File

@@ -6,6 +6,7 @@ import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coerci
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ChannelMessagingAdapter } from "../../channels/plugins/types.js"; import type { ChannelMessagingAdapter } from "../../channels/plugins/types.js";
import { createTestRegistry } from "../../test-utils/channel-plugins.js"; import { createTestRegistry } from "../../test-utils/channel-plugins.js";
import { withEnvAsync } from "../../test-utils/env.js";
import { extractAssistantText, sanitizeTextContent } from "./sessions-helpers.js"; import { extractAssistantText, sanitizeTextContent } from "./sessions-helpers.js";
const callGatewayMock = vi.fn(); const callGatewayMock = vi.fn();
@@ -228,12 +229,7 @@ async function withStubbedStateDir<T>(
run: (stateDir: string) => Promise<T>, run: (stateDir: string) => Promise<T>,
): Promise<T> { ): Promise<T> {
const stateDir = path.join(os.tmpdir(), name); const stateDir = path.join(os.tmpdir(), name);
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir); return await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => await run(stateDir));
try {
return await run(stateDir);
} finally {
vi.unstubAllEnvs();
}
} }
describe("sanitizeTextContent", () => { describe("sanitizeTextContent", () => {