mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 08:19:31 +00:00
test: scope send state env helper
This commit is contained in:
@@ -8,6 +8,7 @@ import { jsonResult } from "../../agents/tools/common.js";
|
||||
import type { ChannelPlugin } from "../../channels/plugins/types.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
import { captureEnv, setTestEnvValue } from "../../test-utils/env.js";
|
||||
import type { GatewayRequestContext } from "./types.js";
|
||||
|
||||
type ResolveOutboundTarget = typeof import("../../infra/outbound/targets.js").resolveOutboundTarget;
|
||||
@@ -213,17 +214,13 @@ async function runMessageActionRequest(
|
||||
}
|
||||
|
||||
async function withTempOpenClawStateDir<T>(test: (stateDir: string) => Promise<T>): Promise<T> {
|
||||
const previous = process.env.OPENCLAW_STATE_DIR;
|
||||
const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
|
||||
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "gateway-send-state-"));
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
setTestEnvValue("OPENCLAW_STATE_DIR", stateDir);
|
||||
try {
|
||||
return await test(stateDir);
|
||||
} finally {
|
||||
if (previous === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_STATE_DIR = previous;
|
||||
}
|
||||
envSnapshot.restore();
|
||||
await fs.rm(stateDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user