Агенты: обновление токена для замера лимитов (п.77), повтор открытых вопросов и закрытие своих дублей todo (п.78); багрепорт employee_reports уточнён правилом владельца
All checks were successful
ci / test (push) Successful in 32s
ci / deploy (push) Successful in 2m26s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 20:05:07 +03:00
parent f9b249b446
commit f1d8809e1d
11 changed files with 124 additions and 7 deletions

View File

@@ -167,4 +167,26 @@ d("учёт токенов в БД (временная БД)", () => {
const poller = new LimitsPoller(db.pool, log, async () => undefined, { intervalMs: 0, credentialsPath: cred, fetchFn });
expect(await poller.tick()).toBeNull();
});
it("устаревший токен (401): один раз обновляем токен и повторяем замер; повторно - не чаще кулдауна", async () => {
const dir = mkdtempSync(join(tmpdir(), "llmtest-cred-"));
const cred = join(dir, ".credentials.json");
writeFileSync(cred, JSON.stringify({ claudeAiOauth: { accessToken: "old" } }));
let refreshed = 0;
const fetchFn = (async (_u: string, init: { headers: Record<string, string> }) => {
if (init.headers.authorization === "Bearer old") return { ok: false, status: 401, json: async () => ({}) };
return { ok: true, status: 200, json: async () => ({ five_hour: { utilization: 1, resets_at: new Date(Date.now() + 3600_000).toISOString() }, seven_day: { utilization: 2, resets_at: new Date(Date.now() + 86400_000).toISOString() } }) };
}) as unknown as typeof fetch;
const refreshToken = async () => {
refreshed++;
writeFileSync(cred, JSON.stringify({ claudeAiOauth: { accessToken: "new" } })); // как делает сам claude
};
const poller = new LimitsPoller(db.pool, log, async () => undefined, { intervalMs: 0, credentialsPath: cred, fetchFn, refreshToken });
expect((await poller.tick())?.weekPct).toBe(2);
expect(refreshed).toBe(1);
// токен снова «устарел»: в пределах кулдауна второй раз не обновляем
writeFileSync(cred, JSON.stringify({ claudeAiOauth: { accessToken: "old" } }));
expect(await poller.tick()).toBeNull();
expect(refreshed).toBe(1);
});
});