fix(qqbot): skip token cache on invalid clock · openclaw/openclaw@472606d
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
File tree
extensions/qqbot/src/engine/api
| Original file line number | Diff line number | Diff line change |
|---|
@@ -87,7 +87,7 @@ describe("QQBot token manager", () => {
|
87 | 87 | }); |
88 | 88 | }); |
89 | 89 | |
90 | | -it("does not throw while logging fetched tokens when the process clock is outside the Date range", async () => { |
| 90 | +it("does not cache fetched tokens when the process clock is outside the Date range", async () => { |
91 | 91 | const logger = { debug: vi.fn(), info: vi.fn(), error: vi.fn() }; |
92 | 92 | const dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(8_640_000_000_000_001); |
93 | 93 | mockGuardedTokenResponse('{"access_token":"token-1","expires_in":7200}', { |
@@ -102,9 +102,9 @@ describe("QQBot token manager", () => {
|
102 | 102 | dateNowSpy.mockRestore(); |
103 | 103 | } |
104 | 104 | |
105 | | -expect(manager.getStatus("app-id").expiresAt).toBe(7_200_000); |
| 105 | +expect(manager.getStatus("app-id")).toEqual({ status: "none", expiresAt: null }); |
106 | 106 | expect(logger.debug).toHaveBeenCalledWith( |
107 | | -"[qqbot:token:app-id] Cached, expires at: 1970-01-01T02:00:00.000Z", |
| 107 | +"[qqbot:token:app-id] Not cached: invalid process clock", |
108 | 108 | ); |
109 | 109 | }); |
110 | 110 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,8 +7,8 @@
|
7 | 7 | */ |
8 | 8 | |
9 | 9 | import { |
| 10 | +asDateTimestampMs, |
10 | 11 | parseStrictPositiveInteger, |
11 | | -resolveDateTimestampMs, |
12 | 12 | resolveExpiresAtMsFromDurationSeconds, |
13 | 13 | resolveTimestampMsToIsoString, |
14 | 14 | } from "openclaw/plugin-sdk/number-runtime"; |
@@ -278,7 +278,11 @@ export class TokenManager {
|
278 | 278 | throw new Error(`Failed to get access_token: ${JSON.stringify(data)}`); |
279 | 279 | } |
280 | 280 | |
281 | | -const nowMs = resolveDateTimestampMs(Date.now()); |
| 281 | +const nowMs = asDateTimestampMs(Date.now()); |
| 282 | +if (nowMs === undefined) { |
| 283 | +this.logger?.debug?.(`[qqbot:token:${appId}] Not cached: invalid process clock`); |
| 284 | +return data.access_token; |
| 285 | +} |
282 | 286 | const expiresAt = |
283 | 287 | resolveExpiresAtMsFromDurationSeconds(resolveTokenExpiresInSeconds(data.expires_in), { |
284 | 288 | nowMs, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。