Free the right pane for the lead once its inbox empties or task merges
This commit is contained in:
@@ -3,6 +3,7 @@ package agents
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -10,59 +11,90 @@ import (
|
||||
"g.fc.run/misc/byre/internal/store"
|
||||
)
|
||||
|
||||
func TestTaskCreatedSignalText(t *testing.T) {
|
||||
func TestPaneFreed(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) })
|
||||
st, err := store.Open(filepath.Join(t.TempDir(), "byre.db"), func(api.Event) {})
|
||||
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")
|
||||
_, err = st.EnsureUser(ctx, "alice", "Alice")
|
||||
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})
|
||||
err = st.CreateProject(ctx, api.Project{Id: "p1", Name: "demo", RepoPath: "/nonexistent", DefaultBranch: "main", Remote: "none", CreatedBy: "alice", 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)
|
||||
for _, id := range []string{"t1", "t2"} {
|
||||
err = st.CreateTask(ctx, api.Task{Id: id, ProjectId: "p1", Title: "Fix " + id, Branch: id, WorktreePath: "/nonexistent", BaseRef: "x", Status: api.TaskStatusActive, CreatedBy: "alice", CreatedAt: now}, "alice")
|
||||
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)
|
||||
}
|
||||
err = st.CreateSession(ctx, api.AgentSession{Id: "s1", TaskId: "t1", Vendor: api.Claude, VendorSessionId: "s1", State: api.AgentSessionStateIdle, Role: api.Implementer, CreatedBy: "alice", CreatedAt: now}, "p1")
|
||||
if err != nil {
|
||||
t.Fatalf("create session: %v", err)
|
||||
}
|
||||
if len(created) != 2 {
|
||||
t.Fatalf("task.created events %+v", created)
|
||||
err = st.CreateInboxItem(ctx, api.InboxItem{
|
||||
Id: "r1", ProjectId: "p1", TaskId: "t1", AgentSessionId: "s1", ThreadId: "r1",
|
||||
Kind: api.Report, Priority: api.Fyi, Payload: map[string]any{"text": "done"},
|
||||
State: api.Open, CreatedAt: now, Responses: []api.InboxResponse{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("file report: %v", err)
|
||||
}
|
||||
|
||||
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)
|
||||
t1, t2, p1 := "t1", "t2", "p1"
|
||||
focus := func(tab api.TaskTab) {
|
||||
t.Helper()
|
||||
err := st.SetFocus(ctx, "alice", api.Focus{TaskId: &t1, ProjectId: &p1, Tabs: []api.TaskTab{tab}, Tab: tab}, "alice")
|
||||
if err != nil {
|
||||
t.Fatalf("signal text: %v", err)
|
||||
t.Fatalf("set focus: %v", err)
|
||||
}
|
||||
if got != want[i] {
|
||||
t.Fatalf("signal text\n got %q\nwant %q", got, want[i])
|
||||
}
|
||||
freed := func(kind, taskID string) string {
|
||||
t.Helper()
|
||||
text, err := m.freedText(ctx, "alice", api.Event{Kind: kind, TaskId: &taskID})
|
||||
if err != nil {
|
||||
t.Fatalf("freed text: %v", err)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
focus(api.TabInbox)
|
||||
if text := freed("inbox.updated", t1); text != "" {
|
||||
t.Fatalf("freed with an item still open: %q", text)
|
||||
}
|
||||
|
||||
err = st.WithdrawItem(ctx, "r1")
|
||||
if err != nil {
|
||||
t.Fatalf("withdraw: %v", err)
|
||||
}
|
||||
text := freed("inbox.updated", t1)
|
||||
if !strings.HasPrefix(text, "Your right pane is free: ") || !strings.HasSuffix(text, "task t1] has nothing left in its inbox.") {
|
||||
t.Fatalf("emptied inbox: %q", text)
|
||||
}
|
||||
if text := freed("inbox.updated", t2); text != "" {
|
||||
t.Fatalf("freed by another task: %q", text)
|
||||
}
|
||||
|
||||
focus(api.TabTranscript)
|
||||
if text := freed("inbox.updated", t1); text != "" {
|
||||
t.Fatalf("freed on the transcript tab: %q", text)
|
||||
}
|
||||
|
||||
_, err = st.MergeTask(ctx, "t1", "abc", "origin/main", "alice")
|
||||
if err != nil {
|
||||
t.Fatalf("merge: %v", err)
|
||||
}
|
||||
if text := freed("task.merged", t1); !strings.HasSuffix(text, "task t1] is merged.") {
|
||||
t.Fatalf("merged: %q", text)
|
||||
}
|
||||
if text := freed("inbox.updated", t1); text != "" {
|
||||
t.Fatalf("inbox.updated on a merged task: %q", text)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user