|
1 | 1 | import fs from "node:fs/promises"; |
| 2 | +import os from "node:os"; |
2 | 3 | import path from "node:path"; |
3 | 4 | import { |
4 | 5 | clearRuntimeConfigSnapshot, |
@@ -10,11 +11,38 @@ import {
|
10 | 11 | updateSessionStore, |
11 | 12 | } from "openclaw/plugin-sdk/config-runtime"; |
12 | 13 | import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; |
13 | | -import { createSuiteTempRootTracker } from "../../../src/test-helpers/temp-dir.js"; |
14 | 14 | import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js"; |
15 | 15 | |
16 | 16 | const TELEGRAM_DIRECT_KEY = "agent:main:telegram:direct:7463849194"; |
17 | 17 | |
| 18 | +function createSuiteTempRootTracker(params: { prefix: string }) { |
| 19 | +let root: string | undefined; |
| 20 | +const children: string[] = []; |
| 21 | +return { |
| 22 | +async setup() { |
| 23 | +root = await fs.mkdtemp(path.join(os.tmpdir(), params.prefix)); |
| 24 | +}, |
| 25 | +async make(name: string) { |
| 26 | +if (!root) { |
| 27 | +throw new Error("temp root not initialized"); |
| 28 | +} |
| 29 | +const child = path.join(root, name); |
| 30 | +await fs.mkdir(child, { recursive: true }); |
| 31 | +children.push(child); |
| 32 | +return child; |
| 33 | +}, |
| 34 | +async cleanup() { |
| 35 | +await Promise.all( |
| 36 | +children.splice(0).map((child) => fs.rm(child, { force: true, recursive: true })), |
| 37 | +); |
| 38 | +if (root) { |
| 39 | +await fs.rm(root, { force: true, recursive: true }); |
| 40 | +root = undefined; |
| 41 | +} |
| 42 | +}, |
| 43 | +}; |
| 44 | +} |
| 45 | + |
18 | 46 | describe("Telegram direct session recreation after delete", () => { |
19 | 47 | const suiteRootTracker = createSuiteTempRootTracker({ |
20 | 48 | prefix: "openclaw-telegram-context-recreate-", |
|