From d20bfe496e99a61746a56a478606dd8c98b16bc4 Mon Sep 17 00:00:00 2001 From: peppa-bot Date: Wed, 25 Nov 2026 18:41:22 +0500 Subject: [PATCH] =?UTF-8?q?PEP-296:=20=D1=87=D1=83=D0=B6=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BA=D1=80=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D1=83=20=D0=B8=20=D0=B2=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D0=BE=D0=BC=D0=BD=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D1=91=D0=BC=D0=BA=D0=B5,=20=C2=AB=D0=9F=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=8F=D1=82=D1=8C=C2=BB,=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=B6=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pendingAcceptTick завершал приёмку, когда taskPrNumber не узнавал ссылку (так закрылись PEP-255 и PEP-257); mergeTaskPr возвращал «PR нет», автомерж шёл в afterMerge. Теперь ссылка вида /pulls/ не из репозитория проекта — отказ с причиной, задача остаётся на проверке. Тест на все три пути. Co-Authored-By: Claude Fable 5.2 --- packages/runner/src/accept-pending.ts | 4 ++- packages/runner/src/autonomy.ts | 3 +++ packages/runner/src/ci-feedback.ts | 3 +++ packages/testkit/test/foreign-pr-url.test.ts | 26 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/runner/src/accept-pending.ts b/packages/runner/src/accept-pending.ts index 5e322443..3e3e13d9 100644 --- a/packages/runner/src/accept-pending.ts +++ b/packages/runner/src/accept-pending.ts @@ -1,7 +1,7 @@ // PEP-127: «Принять» remembered over a conflict is carried through by the watchdog — the agent // rebases (flow.ts `deferAccept`), and once the story is back in review with green checks the PR // is merged and the story closed. The PM hears when it closed, or once if it could not be done. -import { alertAdmins, getReviewHold, platformDelay, setReviewHold, answerQuestion, askPm, clearPendingAccept, productLookLine, giteaForBot, listPendingAccepts, listSessions, logEvent, prGate, setPendingAccept, taskPrNumber, type GiteaClient, type PendingAccept, type TaskRef, isProjectPaused } from "@peppa/core"; +import { alertAdmins, foreignPrUrl, getReviewHold, platformDelay, setReviewHold, answerQuestion, askPm, clearPendingAccept, productLookLine, giteaForBot, listPendingAccepts, listSessions, logEvent, prGate, setPendingAccept, taskPrNumber, type GiteaClient, type PendingAccept, type TaskRef, isProjectPaused } from "@peppa/core"; import { questions, type Db } from "@peppa/db"; import { asIs, m } from "@peppa/shared/i18n"; import { and, eq, isNull } from "drizzle-orm"; @@ -45,6 +45,8 @@ async function carry(db: Db, taskId: number, state: PendingAccept, now: number, const hours = Math.round(waitMs() / 3_600_000); if (now - state.at > waitMs()) return fail(db, ref, m("агент не обновил изменения за {hours} ч", { hours }), true, log); if (!taskPrNumber(ref.project, ref.task.prUrl)) { + // PEP-296: a pull request of another repository is not «no PR» — nothing proves the result is merged. + if (foreignPrUrl(ref.project, ref.task.prUrl)) return fail(db, ref, m("ссылка на результат ведёт не в код проекта"), true, log); if (ref.task.status === "review") await finish(db, ref, log); return; } diff --git a/packages/runner/src/autonomy.ts b/packages/runner/src/autonomy.ts index d8662afa..25d15a7a 100644 --- a/packages/runner/src/autonomy.ts +++ b/packages/runner/src/autonomy.ts @@ -32,6 +32,7 @@ import { platformFailure, setSetting, taskPrNumber, + foreignPrUrl, type AutonomySettings, type GiteaClient, type Project, @@ -141,6 +142,8 @@ async function autoMergeReviews(db: Db, project: Project, a: AutonomySettings, c // PEP-197: a story the factory made itself waits for the owner unless «Принимать сами» says otherwise. if (!(await mayAutoAcceptTask(db, task))) continue; const state = (await getSetting(db, mergeKey(task.id))) ?? {}; + // PEP-296: a pull request of another repository is not «no PR»: nothing is merged, nothing is closed on it. + if (foreignPrUrl(project, task.prUrl)) continue; if (!taskPrNumber(project, task.prUrl)) { await afterMerge(db, ref, a, state, log); continue; diff --git a/packages/runner/src/ci-feedback.ts b/packages/runner/src/ci-feedback.ts index 06318aaa..802653d7 100644 --- a/packages/runner/src/ci-feedback.ts +++ b/packages/runner/src/ci-feedback.ts @@ -20,6 +20,7 @@ import { runLink, taskForCheck, taskPrNumber, + foreignPrUrl, upsertCheckRun, verifyHookSignature, type CheckReport, @@ -321,6 +322,8 @@ export async function pollChecks(db: Db, gitea: GiteaClient = giteaForBot()): Pr * Throws with the reason for the PM; a task without a PR has nothing to merge. */ export async function mergeTaskPr(ref: TaskRef, client?: GiteaClient): Promise<"merged" | "already" | "no_pr"> { + // PEP-296: a pull request of another repository is not «no PR» — accepting on it would close the story unmerged. + if (foreignPrUrl(ref.project, ref.task.prUrl)) throw new PeppaError(m("Принять не удалось: {reason}", { reason: m("ссылка на результат ведёт не в код проекта") })); if (!taskPrNumber(ref.project, ref.task.prUrl)) return "no_pr"; const gitea = client ?? giteaForBot(); const gate = await prGate(ref, gitea); diff --git a/packages/testkit/test/foreign-pr-url.test.ts b/packages/testkit/test/foreign-pr-url.test.ts index da1a154f..25c19e8a 100644 --- a/packages/testkit/test/foreign-pr-url.test.ts +++ b/packages/testkit/test/foreign-pr-url.test.ts @@ -10,6 +10,8 @@ import { join } from "node:path"; import { after, before, describe, test } from "node:test"; import { core, db, project, runner, teardown, waitFor, type TestProject } from "./helpers.ts"; import { MockGitea } from "../src/mock-gitea.ts"; +import { events } from "@peppa/db"; +import { and, eq } from "drizzle-orm"; process.env.PEPPA_SECRET = "mock-secret-for-tests"; const gitea = new MockGitea(join(mkdtempSync(join(tmpdir(), "peppa-foreign-pr-")), "gitea")); @@ -84,6 +86,30 @@ describe("PEP-296: ссылка на PR не из репозитория про assert.equal((await t.ref()).task.status, "done"); }); + test("Чужая ссылка уже записана: «Принять», запомненная приёмка и автомерж задачу не закрывают", async () => { + const t = await prTask([]); + await core.updateTask(db, await t.ref(), { prUrl: oldGit(t.pr.number) }); + const taskId = (await t.ref()).task.id; + const status = async () => (await t.ref()).task.status; + + // «Принять» by a person: refused with the reason. + await assert.rejects(runner.acceptStory(db, await t.ref(), "web"), /не в код проекта/); + assert.equal(await status(), "review"); + + // The accept remembered earlier (the way PEP-255 was closed): forgotten, the story stays. + await core.setPendingAccept(db, taskId, { at: Date.now(), via: "web", rebases: 1 }); + await tick(); + assert.equal(await status(), "review", "not «Готово» without a merge"); + assert.equal(await core.getPendingAccept(db, taskId), null); + assert.equal((await db.select().from(events).where(and(eq(events.taskId, taskId), eq(events.type, "accept_failed")))).length, 1); + + // «Сам мержит и закрывает»: the auto-merge leaves it alone as well. + await core.setAutonomy(db, t.proj.id, { level: "auto", merge: "auto", close: "after_merge" }); + await runner.autonomyTick(db, { now: new Date() }); + assert.equal(await status(), "review"); + assert.equal(t.pull().merged, false); + }); + test("Чужая ссылка на PR другой задачи — отказ, прежняя ссылка остаётся", async () => { const t = await prTask([[{ mcp: "update_task", args: { task: "1", status: "review", pr_url: oldGit(99) } }, { say: "Готово." }]]); await core.updateTask(db, await t.ref(), { status: "in_progress" });