PEP-296: чужая ссылка не закрывает задачу и в запомненной приёмке, «Принять», автомерже
Some checks failed
peppa/lint lint: success за 2с
peppa/typecheck typecheck: success за 50с
peppa/build build: success за 35с
peppa/test test: failure за 1638с
peppa-ci / ci (pull_request) Failing after 29m35s

pendingAcceptTick завершал приёмку, когда taskPrNumber не узнавал ссылку
(так закрылись PEP-255 и PEP-257); mergeTaskPr возвращал «PR нет», автомерж
шёл в afterMerge. Теперь ссылка вида /pulls/<n> не из репозитория проекта —
отказ с причиной, задача остаётся на проверке. Тест на все три пути.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
peppa-bot 2026-11-25 18:41:22 +05:00
parent 23fc8e063a
commit d20bfe496e
4 changed files with 35 additions and 1 deletions

View File

@ -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;
}

View File

@ -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<MergeState>(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;

View File

@ -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);

View File

@ -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" });