feat(analyst): этапы задачи — аналитик раскладывает на steps с критериями готовности, dev идёт по ним
This commit is contained in:
@@ -24,7 +24,7 @@ func (m *mockRunner) Run(_ context.Context, _, _, _, _ string) (*opencode.Result
|
||||
|
||||
func TestDecideAsk(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"ask\",\"chat_reply\":\"Уточню про репозиторий\",\"questions\":[\"Где лежит код?\",\"Какая цель?\"]}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestDecideAsk(t *testing.T) {
|
||||
|
||||
func TestDecidePropose(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"propose\",\"title\":\"Калькулятор\",\"goal\":\"Сделать веб-калькулятор\",\"repo\":\"tools/calc\",\"why\":\"Нужен для учёта\",\"ac\":\"Работает + - * /\",\"chat_reply\":\"Готово!\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestDecidePropose(t *testing.T) {
|
||||
|
||||
func TestDecideAbort(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"abort\",\"chat_reply\":\"Это не про код.\",\"abort_reason\":\"Тема не подходит opencode\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestDecideAbort(t *testing.T) {
|
||||
func TestDecideReady(t *testing.T) {
|
||||
// ready с пустыми изменёнными полями — ВАЛИДНО (черновик готов как есть)
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"ready\",\"chat_reply\":\"Черновик готов, запускаю.\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -147,7 +147,7 @@ func TestEmptyHistory(t *testing.T) {
|
||||
|
||||
func TestForceEmptyHistory(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"ask\",\"chat_reply\":\"Опишите задачу.\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestForceEmptyHistory(t *testing.T) {
|
||||
|
||||
func TestInvalidPhase(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"unknown\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -188,7 +188,7 @@ func TestNonZeroExit(t *testing.T) {
|
||||
func TestProposeEmptyFields(t *testing.T) {
|
||||
// propose без изменённых полей — A3
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"propose\",\"chat_reply\":\"ok\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -205,7 +205,7 @@ func TestProposeEmptyFields(t *testing.T) {
|
||||
func TestAskEmptyReplyAndQuestions(t *testing.T) {
|
||||
// ask без chat_reply и questions — A3
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"ask\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -223,7 +223,7 @@ func TestAskEmptyReplyAndQuestions(t *testing.T) {
|
||||
// парсер должен нормализовать и не падать.
|
||||
func TestDecideProposeStringRepos(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"propose\",\"title\":\"Калькулятор\",\"repos\":\"tools/calc, tools/ui\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
@@ -240,6 +240,52 @@ func TestDecideProposeStringRepos(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDecideProposeSteps — аналитик разложил задачу на этапы с критериями.
|
||||
func TestDecideProposeSteps(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"propose\",\"title\":\"Калькулятор\",\"steps\":[{\"title\":\"Модель\",\"ac\":\"операции + - * /\"},{\"title\":\"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 len(dec.Draft.Steps) != 2 {
|
||||
t.Fatalf("len(Steps) = %d, want 2", len(dec.Draft.Steps))
|
||||
}
|
||||
if dec.Draft.Steps[0].Title != "Модель" || dec.Draft.Steps[0].AC != "операции + - * /" {
|
||||
t.Errorf("Steps[0] = %q/%q, want Модель/операции + - * /", dec.Draft.Steps[0].Title, dec.Draft.Steps[0].AC)
|
||||
}
|
||||
if dec.Draft.Steps[1].Title != "UI" || dec.Draft.Steps[1].AC != "" {
|
||||
t.Errorf("Steps[1] = %q/%q, want UI/(пусто)", dec.Draft.Steps[1].Title, dec.Draft.Steps[1].AC)
|
||||
}
|
||||
}
|
||||
|
||||
// TestProposeOnlyStepsValid — propose меняет только steps → валидно.
|
||||
func TestProposeOnlyStepsValid(t *testing.T) {
|
||||
a := &Analyst{Runner: &mockRunner{result: &opencode.Result{
|
||||
RC: 0,
|
||||
Stdout: `{"type":"text","part":{"text":"{\"phase\":\"propose\",\"steps\":[{\"title\":\"Шаг 1\"}],\"chat_reply\":\"Разбил на этапы\"}"}}`,
|
||||
}}, Worktree: "/tmp"}
|
||||
|
||||
history := []core.Message{{Role: "user", Content: "test"}}
|
||||
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 len(dec.Draft.Steps) != 1 {
|
||||
t.Fatalf("len(Steps) = %d, want 1", len(dec.Draft.Steps))
|
||||
}
|
||||
}
|
||||
|
||||
// TestFormatVerdict — человекочитаемое описание вердикта аналитика.
|
||||
func TestFormatVerdict(t *testing.T) {
|
||||
tests := []struct {
|
||||
@@ -301,4 +347,4 @@ func TestFormatVerdict(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user