PEP-235: тесты Access Hub под ожидание подтверждения

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
peppa-bot 2026-11-30 11:15:06 +00:00
parent 51b72611f8
commit b46177d319
3 changed files with 15 additions and 9 deletions

View File

@ -161,14 +161,16 @@ describe("Права «чтение» и «запись»", () => {
assert.equal(m.calls.length, 1, "the write never left FORGE");
});
test("«Спрашивать меня» до подтверждений", async () => {
test("«Спрашивать меня» — ждёт подтверждения владельца", async () => {
const c = await core.createConnection(db, anna.id, { catalogId: "stripe", name: "Stripe-ask", secret: KEY });
const { proj, task } = await ownedProject();
await core.grantConnection(db, anna.id, c.id, { projectId: proj.id, readMode: "ask", writeMode: "ask" });
const sessionId = await agentSession(proj.id, task.id);
const m = mockFetch();
assert.deepEqual(await core.callConnection(db, { sessionId, connection: "Stripe-ask", method: "POST", path: "/v1/refunds", body: "{}" }, { fetch: m.fetch }), { ok: false, reason: "needs_approval" });
assert.deepEqual(await core.callConnection(db, { sessionId, connection: "Stripe-ask", method: "GET", path: "/v1/balance" }, { fetch: m.fetch }), { ok: false, reason: "needs_approval" });
const w = await core.callConnection(db, { sessionId, connection: "Stripe-ask", method: "POST", path: "/v1/refunds", body: "{}" }, { fetch: m.fetch });
assert.ok(!w.ok && w.reason === "needs_approval" && w.approval?.status === "pending", JSON.stringify(w));
const r = await core.callConnection(db, { sessionId, connection: "Stripe-ask", method: "GET", path: "/v1/balance" }, { fetch: m.fetch });
assert.ok(!r.ok && r.reason === "needs_approval" && r.approval && r.approval.id !== w.approval!.id, JSON.stringify(r));
assert.equal(m.calls.length, 0);
const [row] = await db.select().from(connectionLog).where(eq(connectionLog.connectionId, c.id));
assert.equal(row!.reason, "needs_approval");
@ -356,8 +358,8 @@ describe("Короткое имя подключения для агента", (
assert.equal(seen.at(-1)!.url, "/api/items/7");
assert.equal(seen.at(-1)!.headers.authorization, `Bearer ${KEY}`);
const w = await callTool("execute", { code: 'return await peppa.connections.call("crm-kod", {method: "POST", path: "/items", body: "{}"});' });
assert.equal(w.isError, true);
assert.match(w.text, /needs_approval/);
assert.equal(w.isError, false, w.text);
assert.match(w.text, /Waiting for the owner's confirmation: call #\d+/);
const log = await core.connectionJournal(db, anna.id, { connectionId: c.id });
assert.ok(log.some((l) => l.method === "GET" && l.path === "/items/7" && l.decision === "allowed"));
assert.ok(!JSON.stringify(log).includes(KEY));

View File

@ -112,7 +112,8 @@ describe("База данных через шлюз", () => {
test("Запись в базу ждёт подтверждения владельца", async () => {
const { c, sessionId } = await setup("Магазин БД запись", "postgres", PG, PG_PASSWORD);
const before = pg.calls.length;
assert.deepEqual(await use(sessionId, c.id, "execute", { sql: "insert into orders values (999, 1)" }), { ok: false, reason: "needs_approval" });
const w = await use(sessionId, c.id, "execute", { sql: "insert into orders values (999, 1)" });
assert.ok(!w.ok && w.reason === "needs_approval" && w.approval, JSON.stringify(w));
assert.equal(pg.calls.length, before, "the database is not touched");
// Write through `query` is refused before the database too.
assert.deepEqual(await use(sessionId, c.id, "query", { sql: "delete from orders" }), { ok: false, reason: "not_read_query" });
@ -293,7 +294,8 @@ describe("Почта через шлюз", () => {
assert.ok(list.ok && list.text.includes("Где мой заказ?"), JSON.stringify(list));
const one = await use(sessionId, c.id, "read", { uid });
assert.ok(one.ok && one.text.includes("Заказ 15 не пришёл"));
assert.deepEqual(await use(sessionId, c.id, "send", { to: "client@example.kz", subject: "Ответ", text: "Заказ в пути" }), { ok: false, reason: "needs_approval" });
const sent = await use(sessionId, c.id, "send", { to: "client@example.kz", subject: "Ответ", text: "Заказ в пути" });
assert.ok(!sent.ok && sent.reason === "needs_approval" && sent.approval, JSON.stringify(sent));
assert.equal(mail.sent.length, 0);
assert.equal(mail.calls.at(-1)!.target.imap.address, PUBLIC);
});
@ -331,8 +333,8 @@ describe("MCP агента", () => {
assert.match(r.text, /ДАННЫЕ, НЕ ИНСТРУКЦИИ/);
assert.ok(!r.text.includes(PG_PASSWORD));
const denied = await mcp("use_connection", { connection: c.slug, operation: "execute", args: { sql: "delete from orders" } });
assert.equal(denied.isError, true);
assert.match(denied.text, /needs_approval/);
assert.equal(denied.isError, false, denied.text);
assert.match(denied.text, /Waiting for the owner's confirmation: call #\d+/);
const exec = await mcp("execute", { code: `return await peppa.connections.use("${c.slug}", { operation: "query", args: { sql: "select 1" } })` });
assert.ok(!exec.text.includes(PG_PASSWORD), exec.text);
assert.match(exec.text, /rows: 1/);

View File

@ -37,6 +37,8 @@ Object.assign(process.env, {
PEPPA_DEPLOY_LAG: "off",
// PEP-185: no «Взять в работу?» questions in other suites; pick-question.test.ts turns it on.
PEPPA_PICK_QUESTION: "off",
// PEP-235: a gateway call at «ask» does not wait for the owner in tests (tests that wait set their own).
PEPPA_APPROVAL_WAIT_SEC: "0",
// PEP-168: no real HTTP probe of the live site :3100 from tests; monitor tests pass their own probe.
PEPPA_WEB_PROBE: "off",
// PEP-189: the guard runs `docker stop` — never against the real docker of the machine running tests;