惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(telegram): store bot info cache in plugin state · ope...
obviyus · 2026-05-24 · via Recent Commits to openclaw:main

@@ -1,18 +1,13 @@

1-

import fs from "node:fs/promises";

2-

import os from "node:os";

3-

import path from "node:path";

41

import { afterEach, describe, expect, it, vi } from "vitest";

52

import {

63

deleteCachedTelegramBotInfo,

74

readCachedTelegramBotInfo,

8-

resolveTelegramBotInfoCachePath,

5+

setTelegramBotInfoCacheStoreForTest,

96

TELEGRAM_BOT_INFO_CACHE_MAX_AGE_MS,

107

writeCachedTelegramBotInfo,

118

} from "./bot-info-cache.js";

129

import type { TelegramBotInfo } from "./bot-info.js";

131014-

const tempRoots: string[] = [];

15-1611

const botInfo: TelegramBotInfo = {

1712

id: 123456,

1813

is_bot: true,

@@ -28,103 +23,104 @@ const botInfo: TelegramBotInfo = {

2823

allows_users_to_create_topics: false,

2924

};

302531-

async function useTempStateDir(): Promise<NodeJS.ProcessEnv> {

32-

const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-tg-bot-info-"));

33-

tempRoots.push(stateDir);

34-

return { ...process.env, OPENCLAW_STATE_DIR: stateDir };

26+

type BotInfoCacheValue = {

27+

tokenFingerprint: string;

28+

fetchedAt: string;

29+

botInfo: TelegramBotInfo;

30+

};

31+32+

function useMemoryStore() {

33+

const entries = new Map<string, BotInfoCacheValue>();

34+

setTelegramBotInfoCacheStoreForTest({

35+

async register(key, value) {

36+

entries.set(key, value);

37+

},

38+

async lookup(key) {

39+

return entries.get(key);

40+

},

41+

async delete(key) {

42+

return entries.delete(key);

43+

},

44+

});

45+

return entries;

3546

}

364737-

afterEach(async () => {

48+

afterEach(() => {

3849

vi.unstubAllEnvs();

39-

await Promise.all(

40-

tempRoots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })),

41-

);

50+

setTelegramBotInfoCacheStoreForTest(undefined);

4251

});

43524453

describe("Telegram bot info cache", () => {

4554

it("reads botInfo for the same account and bot token", async () => {

46-

const env = await useTempStateDir();

55+

useMemoryStore();

47564857

await writeCachedTelegramBotInfo({

4958

accountId: "ops",

5059

botToken: "123456:secret",

5160

botInfo,

52-

env,

5361

});

54625563

await expect(

56-

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:secret", env }),

64+

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:secret" }),

5765

).resolves.toMatchObject({ botInfo });

5866

});

59676068

it("ignores botInfo written for a different token fingerprint", async () => {

61-

const env = await useTempStateDir();

69+

useMemoryStore();

62706371

await writeCachedTelegramBotInfo({

6472

accountId: "ops",

6573

botToken: "123456:old-secret",

6674

botInfo,

67-

env,

6875

});

69767077

await expect(

71-

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:new-secret", env }),

78+

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:new-secret" }),

7279

).resolves.toBeNull();

7380

});

74817582

it("treats stale botInfo as a cache miss", async () => {

76-

const env = await useTempStateDir();

83+

useMemoryStore();

77847885

await writeCachedTelegramBotInfo({

7986

accountId: "ops",

8087

botToken: "123456:secret",

8188

botInfo,

82-

env,

8389

});

84908591

await expect(

8692

readCachedTelegramBotInfo({

8793

accountId: "ops",

8894

botToken: "123456:secret",

89-

env,

9095

now: new Date(Date.now() + TELEGRAM_BOT_INFO_CACHE_MAX_AGE_MS + 1),

9196

}),

9297

).resolves.toBeNull();

9398

});

949995100

it("deletes cached botInfo for an account", async () => {

96-

const env = await useTempStateDir();

101+

useMemoryStore();

9710298103

await writeCachedTelegramBotInfo({

99104

accountId: "ops",

100105

botToken: "123456:secret",

101106

botInfo,

102-

env,

103107

});

104-

await deleteCachedTelegramBotInfo({ accountId: "ops", env });

108+

await deleteCachedTelegramBotInfo({ accountId: "ops" });

105109106110

await expect(

107-

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:secret", env }),

111+

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:secret" }),

108112

).resolves.toBeNull();

109113

});

110114111-

it("treats malformed persisted botInfo as a cache miss", async () => {

112-

const env = await useTempStateDir();

113-

const filePath = resolveTelegramBotInfoCachePath("ops", env);

114-

await fs.mkdir(path.dirname(filePath), { recursive: true });

115-

await fs.writeFile(

116-

filePath,

117-

JSON.stringify({

118-

version: 1,

119-

tokenFingerprint: "not-the-token",

120-

fetchedAt: new Date().toISOString(),

121-

botInfo: { id: 123456, is_bot: true },

122-

}),

123-

"utf8",

124-

);

115+

it("uses normalized account ids as store keys", async () => {

116+

const entries = useMemoryStore();

125117126-

await expect(

127-

readCachedTelegramBotInfo({ accountId: "ops", botToken: "123456:secret", env }),

128-

).resolves.toBeNull();

118+

await writeCachedTelegramBotInfo({

119+

accountId: "ops team",

120+

botToken: "123456:secret",

121+

botInfo,

122+

});

123+124+

expect(entries.has("ops_team")).toBe(true);

129125

});

130126

});