Багрепорты todo_service: проверка (CI-баг и запись без проекта приняты в approved, токены - обсуждение); масштаб лимита только при полном покрытии окна; промт khb-todo
Some checks failed
ci / test (push) Failing after 28s
ci / deploy (push) Has been skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 10:53:07 +03:00
parent 82315add2e
commit 4b89ab84be
11 changed files with 159 additions and 14 deletions

View File

@@ -122,12 +122,16 @@ d("учёт токенов в БД (временная БД)", () => {
}) as unknown as typeof fetch;
const notes: string[] = [];
const poller = new LimitsPoller(db.pool, log, async (t) => { notes.push(t); }, { intervalMs: 0, credentialsPath: cred, fetchFn });
// 4 млн «взвешенных» токенов за недельное окно при 40% -> лимит недели 10 млн
await db.pool.query("insert into agent_usage (op, input_tokens, output_tokens) values ('x', 3000000, 1000000)");
// учёт моложе недельного окна: масштаб в токенах не оцениваем (иначе занижение), проценты пишем
await poller.tick();
let g = (await db.pool.query("select * from globals")).rows[0];
expect(seen[0]).toBe("Bearer tok-test");
expect(Number(g.limit_week_used_pct)).toBe(40);
expect(g.limit_week_tokens_est).toBeNull();
// учёт покрывает окно: 4 млн «взвешенных» токенов при 40% -> лимит недели 10 млн
await db.pool.query("insert into agent_usage (ts, op, input_tokens, output_tokens) values (now() - interval '8 days', 'x', 0, 0), (now(), 'x', 3000000, 1000000)");
await poller.tick();
g = (await db.pool.query("select * from globals")).rows[0];
expect(seen[0]).toBe("Bearer tok-test");
expect(Number(g.limit_week_tokens_est)).toBeGreaterThanOrEqual(10_000_000);
expect(Number(g.limit_day_tokens_est)).toBe(Math.round(Number(g.limit_week_tokens_est) / 7));
expect(Number(g.limit_month_tokens_est)).toBe(Math.round((Number(g.limit_week_tokens_est) * 30) / 7));