test(heartbeat): reuse shared temp sandbox in model override suite

This commit is contained in:
Peter Steinberger
2026-02-22 09:21:14 +00:00
parent 703f7213b6
commit c0995103a5

View File

@@ -1,6 +1,3 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { telegramPlugin } from "../../extensions/telegram/src/channel.js"; import { telegramPlugin } from "../../extensions/telegram/src/channel.js";
import { setTelegramRuntime } from "../../extensions/telegram/src/runtime.js"; import { setTelegramRuntime } from "../../extensions/telegram/src/runtime.js";
@@ -13,6 +10,7 @@ import { setActivePluginRegistry } from "../plugins/runtime.js";
import { createPluginRuntime } from "../plugins/runtime/index.js"; import { createPluginRuntime } from "../plugins/runtime/index.js";
import { createTestRegistry } from "../test-utils/channel-plugins.js"; import { createTestRegistry } from "../test-utils/channel-plugins.js";
import { runHeartbeatOnce } from "./heartbeat-runner.js"; import { runHeartbeatOnce } from "./heartbeat-runner.js";
import { seedSessionStore, withTempHeartbeatSandbox } from "./heartbeat-runner.test-utils.js";
// Avoid pulling optional runtime deps during isolated runs. // Avoid pulling optional runtime deps during isolated runs.
vi.mock("jiti", () => ({ createJiti: () => () => ({}) })); vi.mock("jiti", () => ({ createJiti: () => () => ({}) }));
@@ -30,34 +28,20 @@ async function withHeartbeatFixture(
seedSession: (sessionKey: string, input: SeedSessionInput) => Promise<void>; seedSession: (sessionKey: string, input: SeedSessionInput) => Promise<void>;
}) => Promise<unknown>, }) => Promise<unknown>,
): Promise<unknown> { ): Promise<unknown> {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-hb-model-")); return withTempHeartbeatSandbox(
const storePath = path.join(tmpDir, "sessions.json"); async ({ tmpDir, storePath }) => {
const seedSession = async (sessionKey: string, input: SeedSessionInput) => { const seedSession = async (sessionKey: string, input: SeedSessionInput) => {
await fs.writeFile( await seedSessionStore(storePath, sessionKey, {
storePath, updatedAt: input.updatedAt,
JSON.stringify(
{
[sessionKey]: {
sessionId: "sid",
updatedAt: input.updatedAt ?? Date.now(),
lastChannel: input.lastChannel, lastChannel: input.lastChannel,
lastProvider: input.lastChannel,
lastTo: input.lastTo, lastTo: input.lastTo,
}, });
},
null,
2,
),
);
}; };
return run({ tmpDir, storePath, seedSession });
await fs.writeFile(path.join(tmpDir, "HEARTBEAT.md"), "- Check status\n", "utf-8"); },
{ prefix: "openclaw-hb-model-" },
try { );
return await run({ tmpDir, storePath, seedSession });
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
} }
beforeEach(() => { beforeEach(() => {