diff --git a/packages/testkit/test/reviewer.test.ts b/packages/testkit/test/reviewer.test.ts index eb7a50d6..0bcde9e4 100644 --- a/packages/testkit/test/reviewer.test.ts +++ b/packages/testkit/test/reviewer.test.ts @@ -84,6 +84,12 @@ async function reviewTask(turns: Action[][], settings?: Parameters (await core.messageDetails(db, [q.id])).get(q.id) ?? ""; +/** The details are written right after the message (by the agent's MCP process): wait for them, then check. */ +const cardDetailsMatch = async (q: { id: number }, re: RegExp) => { + let last = ""; + await waitFor("card details", async () => re.test((last = stripAsIs(await cardDetails(q)))), 10000).catch(() => {}); + assert.match(last, re); +}; const readyQuestions = async (t: ReviewTask) => (await core.pendingQuestions(db, t.proj.id)).filter((q) => q.kind === "attention" && q.text.includes("готова к ревью")); const stopAll = async (t: ReviewTask) => { for (const s of await core.listSessions(db, { active: true, taskId: (await t.ref()).task.id })) await runner.stopSession(db, s.id); @@ -122,7 +128,7 @@ describe("Агент-ревьюер до ревью PM", () => { return qs.length ? qs : null; }); assert.equal((await t.ref()).task.status, "review"); - assert.match(stripAsIs(await cardDetails(q!)), /Ревьюер: ок — деление и ошибка на ноль сделаны, тесты есть/); + await cardDetailsMatch(q!, /Ревьюер: ок — деление и ошибка на ноль сделаны, тесты есть/); assert.ok(await runner.isReviewQuestion(db, q!), "«Принять» works on it"); // Exactly one ready-for-review, whichever finished first (the agent's turn or the reviewer). await new Promise((r) => setTimeout(r, 1500)); @@ -148,7 +154,7 @@ describe("Агент-ревьюер до ревью PM", () => { return qs.length ? qs : null; }); assert.equal((await t.ref()).task.status, "review"); - assert.match(await cardDetails(q!), /лимит итераций исчерпан[\s\S]*src\/divide\.ts — замечание 2/); + await cardDetailsMatch(q!, /лимит итераций исчерпан[\s\S]*src\/divide\.ts — замечание 2/); assert.equal(calls().length, 0, "the reviewer was not called again"); await stopAll(t); }); @@ -162,7 +168,7 @@ describe("Агент-ревьюер до ревью PM", () => { return qs.length ? qs : null; }); assert.equal((await t.ref()).task.status, "review"); - assert.match(await cardDetails(q!), /Ревьюер не отработал: ревьюер завершился с кодом 1/); + await cardDetailsMatch(q!, /Ревьюер не отработал: ревьюер завершился с кодом 1/); assert.equal((await core.latestReview(db, (await t.ref()).task.id))?.state, "error"); await stopAll(t); }); @@ -204,7 +210,7 @@ describe("reviewer details", () => { assert.equal(done.error, "ревьюер ответил не по формату"); // No runner: the PM gets "ready for review" directly. assert.equal((await t.ref()).task.status, "review"); - assert.match(await cardDetails((await readyQuestions(t))[0]!), /Ревьюер не отработал: ревьюер ответил не по формату/); + await cardDetailsMatch((await readyQuestions(t))[0]!, /Ревьюер не отработал: ревьюер ответил не по формату/); // Approved head → asking again goes straight to review with the note. await core.updateTask(db, await t.ref(), { status: "in_progress" });