feat: воркер берёт задачи только после одобрения (approved)
Исправляет баг: воркер захватывал задачу на выполнение по статусу ready ещё до «создавай» (consent был заглушкой). Теперь: - новый статус approved: «создавай» → ready→approved; - воркер (pollAndDispatch + runTask) берёт ТОЛЬКО approved, ready = черновик готов, ждёт одобрения; - правка/текст в approved запрещены (финальное одобрение); - e2e-тест TestE2EWorkerDoesNotTakeUnconfirmed: в ready воркер задачу не трогает, запускает только после «создавай» → success; - обновлены все затронутые тесты (models/core/worker) и retry-фикстуры.
This commit is contained in:
@@ -52,7 +52,7 @@ func (c *Core) ProcessTurn(ctx context.Context, taskID int64, text string) (Resu
|
||||
return Result{}, err
|
||||
}
|
||||
|
||||
// 2. согласие в фазе ready → создание
|
||||
// 2. согласие в фазе ready → одобрение
|
||||
if task.Status == storage.StatusReady {
|
||||
if isConsent(text) {
|
||||
return c.handleConsent(ctx, task)
|
||||
@@ -61,6 +61,17 @@ func (c *Core) ProcessTurn(ctx context.Context, taskID int64, text string) (Resu
|
||||
return c.handleEdit(ctx, task, text)
|
||||
}
|
||||
|
||||
// 2b. approved — финальное одобрение, правка запрещена.
|
||||
// Воркер уже взял/заберёт задачу; текст не меняет статус.
|
||||
if task.Status == storage.StatusApproved {
|
||||
return Result{
|
||||
Reply: "Задача уже одобрена и передана на выполнение. Следите за статусом: /status " + itoa(task.ID),
|
||||
Action: "send",
|
||||
TaskID: task.ID,
|
||||
Status: task.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 3. обычный ход: накопление + аналитик
|
||||
return c.handleTurn(ctx, task, text)
|
||||
}
|
||||
@@ -271,14 +282,15 @@ func (c *Core) notFoundReply(ctx context.Context, id int64, err error) (Result,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// handleConsent создаёт задачу (статус ready → ...). Пока — подтверждение готовности.
|
||||
// handleConsent одобряет задачу: ready → approved (финальное одобрение,
|
||||
// после которого воркер забирает задачу на выполнение).
|
||||
func (c *Core) handleConsent(ctx context.Context, task *storage.Task) (Result, error) {
|
||||
task.Status = storage.StatusReady
|
||||
task.Status = storage.StatusApproved
|
||||
if err := c.Store.UpdateTask(ctx, task); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
return Result{
|
||||
Reply: "✅ Задача #" + itoa(task.ID) + " готова к запуску.",
|
||||
Reply: "✅ Задача #" + itoa(task.ID) + " одобрена. Запускаю выполнение.",
|
||||
Action: "created:" + itoa(task.ID),
|
||||
TaskID: task.ID,
|
||||
Status: task.Status,
|
||||
|
||||
@@ -160,6 +160,10 @@ func TestConsentInReady(t *testing.T) {
|
||||
if res.Action != "created:"+itoa(id) {
|
||||
t.Fatalf("action = %q, want created:%d", res.Action, id)
|
||||
}
|
||||
task, _ := store.GetTask(ctx, id)
|
||||
if task.Status != storage.StatusApproved {
|
||||
t.Fatalf("status после создавай = %s, want approved", task.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditInReadyGoesCollecting(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user