MCP: автоочистка журнала acc_mcp_log (оставляем последние 100000 записей)
Some checks failed
ci / test (push) Failing after 39s
ci / deploy (push) Has been skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 11:41:17 +03:00
parent de20e0400f
commit 5b2470a369
2 changed files with 21 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ import { exportJWK, generateKeyPair, SignJWT, createLocalJWKSet } from "jose";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { createTestDb, testDatabaseUrl, type TestDb } from "khb_common";
import { keycloakVerifier } from "./mcp-auth.js";
import { ReviewTools, registerMcp, type McpDeps } from "./mcp.js";
import { ReviewTools, pruneMcpLog, registerMcp, type McpDeps } from "./mcp.js";
const url = testDatabaseUrl();
const d = url ? describe : describe.skip;
@@ -358,6 +358,15 @@ d("MCP бухгалтерии (временная БД)", () => {
expect((await db.pool.query("select sum(bad_calls)::int as b from acc_mcp_error_rate")).rows[0].b).toBe(2);
});
it("автоочистка журнала: остаются последние N записей", async () => {
await db.pool.query("delete from acc_mcp_log");
await db.pool.query("insert into acc_mcp_log (method, ok) select 'tools/call', true from generate_series(1, 25)");
expect(await pruneMcpLog(db.pool, 10)).toBe(15);
const { rows } = await db.pool.query("select count(*)::int as n, min(id)::int as lo, max(id)::int as hi from acc_mcp_log");
expect(rows[0].n).toBe(10);
expect(rows[0].hi - rows[0].lo).toBe(9);
});
it("JWT Keycloak: person по основной и дополнительной почте; чужой email - 403; плохие токены - 401", async () => {
await addInvoice();
const call = { name: "acc_review_list", arguments: {} };