fix(analyst): repos как строка или массив — устойчивый парсинг вердикта
This commit is contained in:
@@ -2,6 +2,7 @@ package analyst
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -218,6 +219,27 @@ func TestAskEmptyReplyAndQuestions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDecideProposeStringRepos — модель вернула repos строкой (а не массивом):
|
||||
// парсер должен нормализовать и не падать.
|
||||
func TestDecideProposeStringRepos(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"propose\",\"title\":\"Калькулятор\",\"repos\":\"tools/calc, tools/ui\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
history := []core.Message{{Role: "user", Content: "Сделай калькулятор"}}
|
||||
dec, err := a.Decide(context.Background(), history, storage.Task{}, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Decide err: %v", err)
|
||||
}
|
||||
if dec.Phase != "propose" {
|
||||
t.Errorf("Phase = %q, want propose", dec.Phase)
|
||||
}
|
||||
if dec.Draft.Repos[0] != "tools/calc" || dec.Draft.Repos[1] != "tools/ui" {
|
||||
t.Errorf("Repos = %#v, want [tools/calc tools/ui]", dec.Draft.Repos)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFormatVerdict — человекочитаемое описание вердикта аналитика.
|
||||
func TestFormatVerdict(t *testing.T) {
|
||||
tests := []struct {
|
||||
@@ -231,7 +253,7 @@ func TestFormatVerdict(t *testing.T) {
|
||||
Phase: "propose",
|
||||
Title: "Калькулятор",
|
||||
Goal: "Сделать веб-калькулятор",
|
||||
Repos: []string{"tools/calc", "tools/ui"},
|
||||
Repos: json.RawMessage(`["tools/calc","tools/ui"]`),
|
||||
Why: "Нужен для учёта",
|
||||
AC: "Работает + - * /",
|
||||
ChatReply: "Готово!",
|
||||
|
||||
Reference in New Issue
Block a user