mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: contain sessions tool state env
This commit is contained in:
@@ -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", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user