test(utils): share temp-dir helper across cli and web tests

This commit is contained in:
Peter Steinberger
2026-02-21 23:26:41 +00:00
parent 23e07bc49c
commit 4f7032fbd9
3 changed files with 14 additions and 20 deletions

View File

@@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import { saveSessionStore } from "../../config/sessions.js";
import { withTempDir } from "../../test-utils/temp-dir.js";
import {
debugMention,
isBotMentionedFromTargets,
@@ -29,15 +29,6 @@ const makeMsg = (overrides: Partial<WebInboundMsg>): WebInboundMsg =>
...overrides,
}) as WebInboundMsg;
async function withTempDir<T>(prefix: string, run: (dir: string) => Promise<T>): Promise<T> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
try {
return await run(dir);
} finally {
await fs.rm(dir, { recursive: true, force: true });
}
}
describe("isBotMentionedFromTargets", () => {
const mentionCfg = { mentionRegexes: [/\bopenclaw\b/i] };