test(telegram): use platform temp path in bot harness · openclaw/openclaw@16d137d
vincentkoc
·
2026-05-26
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -import { readdirSync, rmSync } from "node:fs"; |
| 1 | +import { existsSync, readdirSync, rmSync } from "node:fs"; |
2 | 2 | import path from "node:path"; |
3 | 3 | import { buildChannelInboundEventContext } from "openclaw/plugin-sdk/channel-inbound"; |
4 | 4 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
@@ -34,9 +34,18 @@ type ReplyPayloadLike = {
|
34 | 34 | replyToId?: string; |
35 | 35 | }; |
36 | 36 | |
37 | | -const { sessionStorePath } = vi.hoisted(() => ({ |
38 | | -sessionStorePath: `/tmp/openclaw-telegram-${process.pid}-${process.env.VITEST_POOL_ID ?? "0"}.json`, |
39 | | -})); |
| 37 | +const { sessionStorePath } = vi.hoisted(() => { |
| 38 | +const tempRoot = |
| 39 | +process.platform === "win32" |
| 40 | + ? (process.env.TEMP ?? process.env.TMP ?? "C:\\Windows\\Temp") |
| 41 | + : (process.env.TMPDIR ?? "/tmp"); |
| 42 | +const separator = process.platform === "win32" ? "\\" : "/"; |
| 43 | +return { |
| 44 | +sessionStorePath: `${tempRoot.replace(/[\\/]+$/u, "")}${separator}openclaw-telegram-${ |
| 45 | + process.pid |
| 46 | + }-${process.env.VITEST_POOL_ID ?? "0"}.json`, |
| 47 | +}; |
| 48 | +}); |
40 | 49 | |
41 | 50 | const { loadWebMedia } = vi.hoisted((): { loadWebMedia: AnyMock } => ({ |
42 | 51 | loadWebMedia: vi.fn(), |
@@ -480,6 +489,9 @@ export function makeForumGroupMessageCtx(params?: {
|
480 | 489 | |
481 | 490 | function clearTelegramDispatchDedupeFilesForTest(): void { |
482 | 491 | const dir = path.dirname(sessionStorePath); |
| 492 | +if (!existsSync(dir)) { |
| 493 | +return; |
| 494 | +} |
483 | 495 | const prefix = `${path.basename(sessionStorePath)}.telegram-message-dispatch-`; |
484 | 496 | for (const entry of readdirSync(dir)) { |
485 | 497 | if (entry.startsWith(prefix)) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。