Merge pull request 'PEP-103: исправление ошибок в приоритете у агентов' (#94) from task/pep-103 into main

This commit is contained in:
peppa-bot 2026-11-15 14:59:57 +05:00
commit 0d269114f2
5 changed files with 62 additions and 3 deletions

View File

@ -0,0 +1,7 @@
# Proposal: PEP-103 — ошибки в приоритете
## Why
PM: исправление ошибок — в первую очередь.
## What Changes
- `readyBacklog` (диспетчер, пуш простоя) ставит первыми стори-баги: созданные из инцидентов Bugsink (`incidents.task_id`) или в эпике «Стабильность»; дальше — порядок доски.

View File

@ -0,0 +1,8 @@
## ADDED Requirements
### Requirement: Баги раньше фич
Диспетчер SHALL брать из бэклога сначала стори-исправления ошибок.
#### Scenario: В бэклоге фичи и баг
- **WHEN** выше на доске фича, ниже стори из инцидента
- **THEN** агент берёт стори из инцидента первой

View File

@ -0,0 +1 @@
- [x] 1.1 `bugTaskIds`, порядок в `readyBacklog`, тест

View File

@ -34,9 +34,9 @@ import {
projectAgentWarning,
intakePendingTasks,
} from "@peppa/core";
import { questions, type Db } from "@peppa/db";
import { goals, incidents, questions, tasks, type Db } from "@peppa/db";
import { formatTaskKey } from "@peppa/shared";
import { and, eq, isNull } from "drizzle-orm";
import { and, eq, isNotNull, isNull } from "drizzle-orm";
import { acceptTask, moveTask } from "./flow.ts";
import { autoMergeTask } from "./ci-feedback.ts";
import { onAnswer, resolveTaskById, sendToSession } from "./sessions.ts";
@ -291,7 +291,21 @@ export async function readyBacklog<T extends Task = Task & { key: string }>(db:
const blocked = await blockedTaskIds(db, projectId);
// PEP-84: stories «продакт» and «аналитик» have not finished with stay out of the dispatcher's reach.
const refining = await intakePendingTasks(db, projectId);
return list.filter((t) => !blocked.has(t.id) && !refining.has(t.id));
const ready = list.filter((t) => !blocked.has(t.id) && !refining.has(t.id));
// PEP-103: fixing errors comes first — bug stories, then the rest, each in board order.
const bugs = await bugTaskIds(db, projectId);
return [...ready.filter((t) => bugs.has(t.id)), ...ready.filter((t) => !bugs.has(t.id))];
}
/** Bug stories of a project: made from a production error (PEP-58) or in the «Стабильность» epic. */
export async function bugTaskIds(db: Db, projectId: number): Promise<Set<number>> {
const fromIncidents = await db.select({ id: incidents.taskId }).from(incidents).where(and(eq(incidents.projectId, projectId), isNotNull(incidents.taskId)));
const inStability = await db
.select({ id: tasks.id })
.from(tasks)
.innerJoin(goals, eq(goals.id, tasks.goalId))
.where(and(eq(tasks.projectId, projectId), eq(goals.title, "Стабильность")));
return new Set([...fromIncidents.map((r) => r.id!), ...inStability.map((r) => r.id)]);
}
/** Sessions that hold a WIP slot: their story is being worked on (not in review). */

View File

@ -0,0 +1,29 @@
// PEP-103: the dispatcher takes bug stories first — from production errors or the «Стабильность» epic.
import assert from "node:assert/strict";
import { after, describe, test } from "node:test";
import { sql } from "drizzle-orm";
import { core, db, runner, teardown } from "./helpers.ts";
after(teardown);
describe("PEP-103: bugs first", () => {
test("bug stories come before features, each in board order", async () => {
const p = await core.createProject(db, { slug: "mock-bugs", key: "MBUG", name: "Bugs", giteaOwner: "x", workspacePath: "/tmp/mock-bugs" });
const feature1 = await core.createTask(db, { projectId: p.id, title: "Фича 1" });
const feature2 = await core.createTask(db, { projectId: p.id, title: "Фича 2" });
const stability = await core.createGoal(db, p.id, "Стабильность");
const epicBug = await core.createTask(db, { projectId: p.id, title: "Падает оплата", goalId: stability.id });
const incidentBug = await core.createTask(db, { projectId: p.id, title: "TypeError на главной" });
db.run(sql`insert into incidents (project_id, source, bugsink_issue_id, title, status, task_id, events, first_seen, last_seen, created_at, updated_at) values (${p.id}, 'api', 'mock-issue-1', 'TypeError', 'open', ${incidentBug.task.id}, 1, 0, 0, 0, 0)`);
const order = (await runner.readyBacklog(db, p.id)).map((t) => t.title);
assert.deepEqual(order, ["Падает оплата", "TypeError на главной", "Фича 1", "Фича 2"]);
assert.ok(feature1 && feature2);
});
test("no bugs — the board order is kept", async () => {
const p = await core.createProject(db, { slug: "mock-nobugs", key: "MNOB", name: "No bugs", giteaOwner: "x", workspacePath: "/tmp/mock-nobugs" });
await core.createTask(db, { projectId: p.id, title: "A" });
await core.createTask(db, { projectId: p.id, title: "B" });
assert.deepEqual((await runner.readyBacklog(db, p.id)).map((t) => t.title), ["A", "B"]);
});
});