diff --git a/openspec/changes/pep-103-bugs-first/proposal.md b/openspec/changes/pep-103-bugs-first/proposal.md new file mode 100644 index 00000000..c3903df4 --- /dev/null +++ b/openspec/changes/pep-103-bugs-first/proposal.md @@ -0,0 +1,7 @@ +# Proposal: PEP-103 — ошибки в приоритете + +## Why +PM: исправление ошибок — в первую очередь. + +## What Changes +- `readyBacklog` (диспетчер, пуш простоя) ставит первыми стори-баги: созданные из инцидентов Bugsink (`incidents.task_id`) или в эпике «Стабильность»; дальше — порядок доски. diff --git a/openspec/changes/pep-103-bugs-first/specs/project-autonomy/spec.md b/openspec/changes/pep-103-bugs-first/specs/project-autonomy/spec.md new file mode 100644 index 00000000..70c8267b --- /dev/null +++ b/openspec/changes/pep-103-bugs-first/specs/project-autonomy/spec.md @@ -0,0 +1,8 @@ +## ADDED Requirements + +### Requirement: Баги раньше фич +Диспетчер SHALL брать из бэклога сначала стори-исправления ошибок. + +#### Scenario: В бэклоге фичи и баг +- **WHEN** выше на доске фича, ниже стори из инцидента +- **THEN** агент берёт стори из инцидента первой diff --git a/openspec/changes/pep-103-bugs-first/tasks.md b/openspec/changes/pep-103-bugs-first/tasks.md new file mode 100644 index 00000000..fdbcc861 --- /dev/null +++ b/openspec/changes/pep-103-bugs-first/tasks.md @@ -0,0 +1 @@ +- [x] 1.1 `bugTaskIds`, порядок в `readyBacklog`, тест diff --git a/packages/runner/src/autonomy.ts b/packages/runner/src/autonomy.ts index 983793fb..03642900 100644 --- a/packages/runner/src/autonomy.ts +++ b/packages/runner/src/autonomy.ts @@ -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(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> { + 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). */ diff --git a/packages/testkit/test/bugs-first.test.ts b/packages/testkit/test/bugs-first.test.ts new file mode 100644 index 00000000..41598d42 --- /dev/null +++ b/packages/testkit/test/bugs-first.test.ts @@ -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"]); + }); +});