From b46177d3190f80a464950e39243e0e7eacb0b7d1 Mon Sep 17 00:00:00 2001 From: peppa-bot Date: Mon, 30 Nov 2026 11:15:06 +0000 Subject: [PATCH] =?UTF-8?q?PEP-235:=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20Acc?= =?UTF-8?q?ess=20Hub=20=D0=BF=D0=BE=D0=B4=20=D0=BE=D0=B6=D0=B8=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D1=82=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- packages/testkit/test/access-hub-catalog.test.ts | 12 +++++++----- packages/testkit/test/access-hub-protocols.test.ts | 10 ++++++---- packages/testkit/test/helpers.ts | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/testkit/test/access-hub-catalog.test.ts b/packages/testkit/test/access-hub-catalog.test.ts index 19de94e8..7c4e8a1d 100644 --- a/packages/testkit/test/access-hub-catalog.test.ts +++ b/packages/testkit/test/access-hub-catalog.test.ts @@ -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)); diff --git a/packages/testkit/test/access-hub-protocols.test.ts b/packages/testkit/test/access-hub-protocols.test.ts index 7d64c4c7..e6b34627 100644 --- a/packages/testkit/test/access-hub-protocols.test.ts +++ b/packages/testkit/test/access-hub-protocols.test.ts @@ -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/); diff --git a/packages/testkit/test/helpers.ts b/packages/testkit/test/helpers.ts index 65b9607a..2f745696 100644 --- a/packages/testkit/test/helpers.ts +++ b/packages/testkit/test/helpers.ts @@ -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;