Files
ratatoskr-go/internal/storage/history_test.go
Hermes 2957bf0d63
All checks were successful
build-test / build (push) Successful in 1m11s
internal/core: ядро-машина состояний (ProcessTurn поверх storage) + история задач в БД
- status = единственный источник истины (collecting/ready как фазы диалога)
- команды /start /cancel /skip /retry N /status N /continue N
- Decider интерфейс (аналитик→opencode, мок для тестов)
- task_history таблица для промпта аналитика
- allow ready→collecting (правка черновика)
2026-08-15 00:27:16 +05:00

70 lines
1.8 KiB
Go

package storage
import (
"context"
"testing"
)
func TestHistoryCRUD(t *testing.T) {
s, ctx := setupTestDB(t)
task := &Task{ChatID: "tg://hist", TaskTag: "history"}
id, _ := s.CreateTask(ctx, task)
// append
if err := s.AppendHistory(ctx, id, "user", "привет"); err != nil {
t.Fatalf("AppendHistory: %v", err)
}
if err := s.AppendHistory(ctx, id, "assistant", "здравствуй"); err != nil {
t.Fatalf("AppendHistory: %v", err)
}
if err := s.AppendHistory(ctx, id, "user", "сделай задачу"); err != nil {
t.Fatalf("AppendHistory: %v", err)
}
h, err := s.GetHistory(ctx, id)
if err != nil {
t.Fatalf("GetHistory: %v", err)
}
if len(h) != 3 {
t.Fatalf("history len = %d, want 3", len(h))
}
if h[0].Role != "user" || h[0].Content != "привет" {
t.Fatalf("h[0] = %+v", h[0])
}
if h[2].Content != "сделай задачу" {
t.Fatalf("h[2] last = %q, want 'сделай задачу'", h[2].Content)
}
// clear
if err := s.ClearHistory(ctx, id); err != nil {
t.Fatalf("ClearHistory: %v", err)
}
h, _ = s.GetHistory(ctx, id)
if len(h) != 0 {
t.Fatalf("history after clear len = %d, want 0", len(h))
}
}
func TestHistoryIsolatedPerTask(t *testing.T) {
ctx := context.Background()
s, err := Open(ctx, ":memory:")
if err != nil {
t.Fatal(err)
}
defer s.Close()
id1, _ := s.CreateTask(ctx, &Task{ChatID: "a", TaskTag: "1"})
id2, _ := s.CreateTask(ctx, &Task{ChatID: "b", TaskTag: "2"})
_ = s.AppendHistory(ctx, id1, "user", "для задачи 1")
_ = s.AppendHistory(ctx, id2, "user", "для задачи 2")
h1, _ := s.GetHistory(ctx, id1)
h2, _ := s.GetHistory(ctx, id2)
if len(h1) != 1 || h1[0].Content != "для задачи 1" {
t.Fatalf("h1 wrong: %+v", h1)
}
if len(h2) != 1 || h2[0].Content != "для задачи 2" {
t.Fatalf("h2 wrong: %+v", h2)
}
}