Signal the lead when a task is created, except tasks it created

This commit is contained in:
Ian Gulliver
2026-10-15 10:12:44 -07:00
parent fdd005b591
commit 184bfe429e
15 changed files with 112 additions and 29 deletions
+68
View File
@@ -0,0 +1,68 @@
package agents
import (
"context"
"path/filepath"
"testing"
"time"
"g.fc.run/misc/byre/internal/api"
"g.fc.run/misc/byre/internal/store"
)
func TestTaskCreatedSignalText(t *testing.T) {
ctx := context.Background()
events := []api.Event{}
st, err := store.Open(filepath.Join(t.TempDir(), "byre.db"), func(ev api.Event) { events = append(events, ev) })
if err != nil {
t.Fatalf("open store: %v", err)
}
t.Cleanup(func() { st.Close() })
now := time.Now().UTC()
_, err = st.EnsureUser(ctx, "ian@fc.run", "Ian")
if err != nil {
t.Fatalf("ensure user: %v", err)
}
err = st.CreateProject(ctx, api.Project{Id: "p1", Name: "byre", RepoPath: "/nonexistent", DefaultBranch: "main", Remote: "none", CreatedBy: "ian@fc.run", CreatedAt: now})
if err != nil {
t.Fatalf("create project: %v", err)
}
item := "Question answers given while the agent is working get lost"
tasks := []api.Task{
{Id: "a5ad5dbb72eb", ProjectId: "p1", Title: item, Branch: "byre/a5ad5dbb72eb", WorktreePath: "/nonexistent", BaseRef: "x", Status: api.TaskStatusActive, CreatedBy: "ian@fc.run", CreatedAt: now, TodoItem: &item},
{Id: "b6be6ecc83fc", ProjectId: "p1", Title: "Fix the thing", Branch: "byre/b6be6ecc83fc", WorktreePath: "/nonexistent", BaseRef: "x", Status: api.TaskStatusActive, CreatedBy: "ian@fc.run", CreatedAt: now},
}
for _, task := range tasks {
err = st.CreateTask(ctx, task, task.CreatedBy)
if err != nil {
t.Fatalf("create task: %v", err)
}
}
created := []api.Event{}
for _, ev := range events {
if ev.Kind == "task.created" {
created = append(created, ev)
}
}
if len(created) != 2 {
t.Fatalf("task.created events %+v", created)
}
m := New(st, DefaultLimits, t.TempDir(), t.TempDir())
want := []string{
`[byre ▸ Question answers given while the agent is working get lost, task a5ad5dbb72eb] was created by ian@fc.run from TODO item "Question answers given while the agent is working get lost".`,
`[byre ▸ Fix the thing, task b6be6ecc83fc] was created by ian@fc.run.`,
}
for i, ev := range created {
got, err := m.signalText(ctx, ev)
if err != nil {
t.Fatalf("signal text: %v", err)
}
if got != want[i] {
t.Fatalf("signal text\n got %q\nwant %q", got, want[i])
}
}
}