MCP: короткий id во всех инструментах, журнал вызовов acc_mcp_log и представление acc_mcp_error_rate, расширены instructions
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:36:17 +03:00
parent 6c061929a1
commit de20e0400f
4 changed files with 111 additions and 17 deletions

View File

@@ -231,6 +231,14 @@ d("MCP бухгалтерии (временная БД)", () => {
expect(res.results[2].error).toContain("cfo");
});
it("одиночные инструменты принимают короткий id из таблицы", async () => {
const t = await addCat("s1");
await call(accountant, "acc_review_handoff", { id: t.slice(0, 8), role: "cfo", comment: "c" });
expect((await db.pool.query("select assignee_role from acc_manual_review where id = $1", [t])).rows[0].assignee_role).toBe("cfo");
await call(accountant, "acc_review_snooze", { id: t.slice(0, 8), until: "2026-12-01" }).catch(() => undefined);
expect(await errOf(call(accountant, "acc_review_done", { id: "zz" }))).toContain("8 символов");
});
it("update в пакете меняет поля, как отдельный вызов", async () => {
const t = await addCat("u1");
const res = (await call(accountant, "acc_review_batch", { actions: [{ id: t, action: "update", fields: { confidence: 55 } }] })) as { ok_count: number };
@@ -338,6 +346,18 @@ d("MCP бухгалтерии (временная БД)", () => {
expect((await db.pool.query("select assignee_role from acc_manual_review where id = $1", [c])).rows[0].assignee_role).toBe("cfo");
});
it("журнал MCP: успешные и неудачные вызовы, пакет с частичной ошибкой, представление доли ошибок", async () => {
await db.pool.query("delete from acc_mcp_log");
await post(bearer(TOKEN_A), rpc("tools/call", { name: "acc_review_list", arguments: {} }));
await post(bearer(TOKEN_A), rpc("tools/call", { name: "acc_review_done", arguments: { id: "zz" } }));
await post(bearer(TOKEN_A), rpc("tools/call", { name: "acc_review_batch", arguments: { actions: [{ id: "00000000", action: "done" }] } }));
const { rows } = await db.pool.query("select tool, ok, error_kind, items_total, items_failed from acc_mcp_log where method = 'tools/call' order by id");
expect(rows[0]).toMatchObject({ tool: "acc_review_list", ok: true, error_kind: null });
expect(rows[1]).toMatchObject({ tool: "acc_review_done", ok: false, error_kind: "invalid_args" });
expect(rows[2]).toMatchObject({ tool: "acc_review_batch", ok: true, error_kind: "partial", items_total: 1, items_failed: 1 });
expect((await db.pool.query("select sum(bad_calls)::int as b from acc_mcp_error_rate")).rows[0].b).toBe(2);
});
it("JWT Keycloak: person по основной и дополнительной почте; чужой email - 403; плохие токены - 401", async () => {
await addInvoice();
const call = { name: "acc_review_list", arguments: {} };