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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Y
Y Combinator Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
S
SegmentFault 最新的问题
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
月光博客
月光博客
Microsoft Security Blog
Microsoft Security Blog
美团技术团队

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): cache startup bot info · openclaw/openclaw...
steipete · 2026-05-17 · via Recent Commits to openclaw:main

@@ -0,0 +1,130 @@

1+

import fs from "node:fs/promises";

2+

import os from "node:os";

3+

import path from "node:path";

4+

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

5+

import {

6+

deleteCachedTelegramBotInfo,

7+

readCachedTelegramBotInfo,

8+

resolveTelegramBotInfoCachePath,

9+

TELEGRAM_BOT_INFO_CACHE_MAX_AGE_MS,

10+

writeCachedTelegramBotInfo,

11+

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

12+

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

13+14+

const tempRoots: string[] = [];

15+16+

const botInfo: TelegramBotInfo = {

17+

id: 123456,

18+

is_bot: true,

19+

first_name: "OpenClaw",

20+

username: "openclaw_bot",

21+

can_join_groups: true,

22+

can_read_all_group_messages: false,

23+

can_manage_bots: false,

24+

supports_inline_queries: false,

25+

can_connect_to_business: false,

26+

has_main_web_app: false,

27+

has_topics_enabled: false,

28+

allows_users_to_create_topics: false,

29+

};

30+31+

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 };

35+

}

36+37+

afterEach(async () => {

38+

vi.unstubAllEnvs();

39+

await Promise.all(

40+

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

41+

);

42+

});

43+44+

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

45+

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

46+

const env = await useTempStateDir();

47+48+

await writeCachedTelegramBotInfo({

49+

accountId: "ops",

50+

botToken: "123456:secret",

51+

botInfo,

52+

env,

53+

});

54+55+

await expect(

56+

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

57+

).resolves.toMatchObject({ botInfo });

58+

});

59+60+

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

61+

const env = await useTempStateDir();

62+63+

await writeCachedTelegramBotInfo({

64+

accountId: "ops",

65+

botToken: "123456:old-secret",

66+

botInfo,

67+

env,

68+

});

69+70+

await expect(

71+

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

72+

).resolves.toBeNull();

73+

});

74+75+

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

76+

const env = await useTempStateDir();

77+78+

await writeCachedTelegramBotInfo({

79+

accountId: "ops",

80+

botToken: "123456:secret",

81+

botInfo,

82+

env,

83+

});

84+85+

await expect(

86+

readCachedTelegramBotInfo({

87+

accountId: "ops",

88+

botToken: "123456:secret",

89+

env,

90+

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

91+

}),

92+

).resolves.toBeNull();

93+

});

94+95+

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

96+

const env = await useTempStateDir();

97+98+

await writeCachedTelegramBotInfo({

99+

accountId: "ops",

100+

botToken: "123456:secret",

101+

botInfo,

102+

env,

103+

});

104+

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

105+106+

await expect(

107+

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

108+

).resolves.toBeNull();

109+

});

110+111+

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+

);

125+126+

await expect(

127+

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

128+

).resolves.toBeNull();

129+

});

130+

});