mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:54:30 +00:00
test(heartbeat): dedupe sandbox/session helpers and collapse ack cases
This commit is contained in:
@@ -3,6 +3,8 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { vi } from "vitest";
|
||||
import * as replyModule from "../auto-reply/reply.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveMainSessionKey } from "../config/sessions.js";
|
||||
|
||||
export type HeartbeatSessionSeed = {
|
||||
sessionId?: string;
|
||||
@@ -33,6 +35,16 @@ export async function seedSessionStore(
|
||||
);
|
||||
}
|
||||
|
||||
export async function seedMainSessionStore(
|
||||
storePath: string,
|
||||
cfg: OpenClawConfig,
|
||||
session: HeartbeatSessionSeed,
|
||||
): Promise<string> {
|
||||
const sessionKey = resolveMainSessionKey(cfg);
|
||||
await seedSessionStore(storePath, sessionKey, session);
|
||||
return sessionKey;
|
||||
}
|
||||
|
||||
export async function withTempHeartbeatSandbox<T>(
|
||||
fn: (ctx: {
|
||||
tmpDir: string;
|
||||
@@ -67,3 +79,19 @@ export async function withTempHeartbeatSandbox<T>(
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
export async function withTempTelegramHeartbeatSandbox<T>(
|
||||
fn: (ctx: {
|
||||
tmpDir: string;
|
||||
storePath: string;
|
||||
replySpy: ReturnType<typeof vi.spyOn>;
|
||||
}) => Promise<T>,
|
||||
options?: {
|
||||
prefix?: string;
|
||||
},
|
||||
): Promise<T> {
|
||||
return withTempHeartbeatSandbox(fn, {
|
||||
prefix: options?.prefix,
|
||||
unsetEnvVars: ["TELEGRAM_BOT_TOKEN"],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user