test(heartbeat): dedupe sandbox/session helpers and collapse ack cases

This commit is contained in:
Peter Steinberger
2026-02-22 09:20:19 +00:00
parent b4cdffc7a4
commit 4520fdda69
3 changed files with 108 additions and 120 deletions

View File

@@ -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"],
});
}