mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 05:06:55 +00:00
fix(telegram): harden persisted offset confirmation and stall recovery
Landed from #39111 by @MumuTW. Co-authored-by: MumuTW <clothl47364@gmail.com>
This commit is contained in:
@@ -78,4 +78,32 @@ describe("deleteTelegramUpdateOffset", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores invalid persisted update IDs from disk", async () => {
|
||||
await withStateDirEnv("openclaw-tg-offset-", async ({ stateDir }) => {
|
||||
const offsetPath = path.join(stateDir, "telegram", "update-offset-default.json");
|
||||
await fs.mkdir(path.dirname(offsetPath), { recursive: true });
|
||||
await fs.writeFile(
|
||||
offsetPath,
|
||||
`${JSON.stringify({ version: 2, lastUpdateId: -1, botId: "111111" }, null, 2)}\n`,
|
||||
"utf-8",
|
||||
);
|
||||
expect(await readTelegramUpdateOffset({ accountId: "default" })).toBeNull();
|
||||
|
||||
await fs.writeFile(
|
||||
offsetPath,
|
||||
`${JSON.stringify({ version: 2, lastUpdateId: Number.POSITIVE_INFINITY, botId: "111111" }, null, 2)}\n`,
|
||||
"utf-8",
|
||||
);
|
||||
expect(await readTelegramUpdateOffset({ accountId: "default" })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects writing invalid update IDs", async () => {
|
||||
await withStateDirEnv("openclaw-tg-offset-", async () => {
|
||||
await expect(
|
||||
writeTelegramUpdateOffset({ accountId: "default", updateId: -1 as number }),
|
||||
).rejects.toThrow(/non-negative safe integer/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user