Files
jules/engine/prompt/prompt_test.go
T

194 lines
4.1 KiB
Go

package prompt
import (
"testing"
"time"
"github.com/d1nch8g/jules/database"
"github.com/d1nch8g/jules/engine/user"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestBuild(t *testing.T) {
tests := []struct {
name string
user *user.User
source string
content string
errs []error
contains []string
excludes []string
}{
{
name: "full user context with message",
user: &user.User{
User: &database.User{
Language: "en",
Timezone: "Europe/Moscow",
PreferredChat: "telegram",
BindCode: uuid.New(),
ContactCode: uuid.New(),
},
Chats: []database.Chat{
{Platform: "telegram"},
{Platform: "whatsapp"},
},
Facts: []database.Fact{
{Value: "fact1"},
{Value: "fact2"},
},
Contacts: []database.Contact{
{Name: "Mom"},
{Name: "Brother"},
},
IncomingNotifications: []database.Notification{
{ID: uuid.New(), ScheduledAt: time.Now(), Content: "incoming1"},
},
OutgoingNotifications: []database.Notification{
{ID: uuid.New(), ScheduledAt: time.Now(), Content: "outgoing1"},
},
RecentActions: []database.Action{
{ExecutedAt: time.Now(), Payload: []byte(`{"type":"reply"}`)},
},
},
source: "telegram",
content: "Hello, Jules!",
contains: []string{
"YOU ARE JULES",
"Language: en",
"Time:",
"Monday",
"Timezone: Europe/Moscow",
"User chat (selected): telegram",
"Bind code:",
"Contact code:",
"Connected chats:",
"telegram",
"whatsapp",
"Facts:",
"fact1",
"fact2",
"Contacts:",
"Mom",
"Brother",
"Incoming notifications:",
"incoming1",
"Outgoing notifications:",
"outgoing1",
"Recent actions:",
`{"type":"reply"}`,
"Next 7 days:",
"Monday:",
"Tuesday:",
"Wednesday:",
"Thursday:",
"Friday:",
"Saturday:",
"Sunday:",
"Message platform: telegram",
"Message contents: Hello, Jules!",
},
},
{
name: "notification source",
user: &user.User{
User: &database.User{
Language: "ru",
Timezone: "UTC",
PreferredChat: "telegram",
BindCode: uuid.New(),
ContactCode: uuid.New(),
},
},
source: database.DatabaseSource,
content: "Пора позвонить маме",
contains: []string{
"Language: ru",
"Process user notification: Пора позвонить маме",
},
excludes: []string{
"Message platform:",
"Message contents:",
},
},
{
name: "empty data sections not rendered",
user: &user.User{
User: &database.User{
Language: "ru",
Timezone: "UTC",
PreferredChat: "telegram",
BindCode: uuid.New(),
ContactCode: uuid.New(),
},
},
source: "telegram",
content: "Привет",
excludes: []string{
"Connected chats:",
"Facts:",
"Contacts:",
"Incoming notifications:",
"Outgoing notifications:",
"Recent actions:",
},
},
{
name: "execution errors rendered",
user: &user.User{
User: &database.User{
Language: "en",
Timezone: "UTC",
PreferredChat: "telegram",
BindCode: uuid.New(),
ContactCode: uuid.New(),
},
},
source: "telegram",
content: "test",
errs: []error{assert.AnError},
contains: []string{
"Execution errors:",
assert.AnError.Error(),
"Try to fix the error yourself",
},
},
{
name: "invalid timezone falls back to UTC",
user: &user.User{
User: &database.User{
Language: "en",
Timezone: "Mars/City",
PreferredChat: "telegram",
BindCode: uuid.New(),
ContactCode: uuid.New(),
},
},
source: "telegram",
content: "test",
contains: []string{
"Time:",
"Next 7 days:",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var err error
if len(tt.errs) > 0 {
err = tt.errs[0]
}
result := Build(tt.user, tt.source, tt.content, err)
for _, s := range tt.contains {
assert.Contains(t, result, s)
}
for _, s := range tt.excludes {
assert.NotContains(t, result, s)
}
})
}
}