PEP-270: задачи агентов — предложения, не больше 5 в сутки на проект #255

Merged
peppa-bot merged 6 commits from task/pep-270 into main 2026-11-25 15:25:55 +00:00
2 changed files with 15 additions and 4 deletions
Showing only changes of commit c7c11a4120 - Show all commits

View File

@ -292,8 +292,12 @@ describe("ready-for-review only when mergeable", () => {
t.green(t.push());
t.pull().mergeable = true;
await t.toReview();
await cardTick();
const fresh = await cards(t.proj.id);
// The watchdog ticks until the card goes: on a loaded CI runner one Gitea answer may come too late for the first tick.
const fresh = await waitFor("a new message", async () => {
await cardTick();
const c = await cards(t.proj.id);
return c.length ? c : null;
});
assert.equal(fresh.length, 1, "a new message");
assert.notEqual(fresh[0]!.id, q!.id);
await t.stopAll();

View File

@ -6,7 +6,7 @@ import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { after, before, describe, test } from "node:test";
import { core, db, project, runner, setDefaultOwner, teardown } from "./helpers.ts";
import { core, db, project, runner, setDefaultOwner, teardown, waitFor } from "./helpers.ts";
import { MockGitea } from "../src/mock-gitea.ts";
import { questions, releases, tasks, telegramOutbox, users } from "@peppa/db";
import { eq, sql } from "drizzle-orm";
@ -132,7 +132,14 @@ describe("Сводка готовых в Telegram", () => {
const { proj, refs } = await inReview(5);
const t0 = Date.now();
for (const ref of refs) await core.sendReviewCard(db, ref, { text: `${ref.key} готова` }, null, null as never).catch(() => null);
const cards = (await db.select().from(questions).where(eq(questions.projectId, proj.id))).filter((q) => q.msgType === "done");
// A slow Gitea answer (a loaded CI runner) holds a card back; the watchdog's ticks send it, as live.
const done = async () => (await db.select().from(questions).where(eq(questions.projectId, proj.id))).filter((q) => q.msgType === "done");
const cards = await waitFor("five cards", async () => {
const c = await done();
if (c.length >= 5) return c;
await runner.reviewCardTick(db);
return null;
});
assert.equal(cards.length, 5);
for (const q of cards) assert.equal(await core.acceptDigestHold(db, q, new Date(t0 + 60_000)), "wait", "within the pause");
for (const q of cards) assert.equal(await core.acceptDigestHold(db, q, new Date(t0 + 400_000)), "held", "more than two within an hour");