Merge branch 'worktree-agent-a785be85dc8fbff78'
This commit is contained in:
@@ -555,7 +555,9 @@ func (c *Chat) ActivateSkill(ctx context.Context, id, skill string) error {
|
||||
|
||||
func (c *Chat) Create(ctx context.Context, title, directory string) (protocol.ChatSession, error) {
|
||||
body := struct {
|
||||
Title string `json:"title"`
|
||||
// Omitted when blank, so OpenCode gives the session its placeholder
|
||||
// title and later names it from the conversation.
|
||||
Title string `json:"title,omitempty"`
|
||||
Location struct {
|
||||
Directory string `json:"directory"`
|
||||
} `json:"location"`
|
||||
|
||||
@@ -838,6 +838,26 @@ func TestChatCreatePostsSessionEndpoint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatCreateWithoutTitleOmitsIt pins that an unnamed chat sends no title,
|
||||
// so OpenCode keeps its placeholder and later names the session itself.
|
||||
func TestChatCreateWithoutTitleOmitsIt(t *testing.T) {
|
||||
var body string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
data, _ := io.ReadAll(r.Body)
|
||||
body = string(data)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"data":{"id":"ses_new","title":"New session - 2026-12-02T09:00:00.000Z","location":{"directory":"/work"}}}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
chat := NewChat(&Connection{Backend: "v2", URL: srv.URL})
|
||||
if _, err := chat.Create(context.Background(), "", "/work"); err != nil {
|
||||
t.Fatalf("create: %v", err)
|
||||
}
|
||||
if body != `{"location":{"directory":"/work"}}` {
|
||||
t.Fatalf("create body = %q", body)
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatCreateRejectsMalformedSession pins that a response without a valid
|
||||
// session id is an error, not a silent empty success.
|
||||
func TestChatCreateRejectsMalformedSession(t *testing.T) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// A chat created without a name records no operator title, so the list shows
|
||||
// the harness's own title for it; a named chat keeps the operator's name.
|
||||
func TestChatCreateWithoutTitleListsTheHarnessTitle(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dir := t.TempDir()
|
||||
store := newOperatorStore(t)
|
||||
broker := &fakeChat{created: protocol.ChatSession{ID: "ses_untitled"}}
|
||||
var created protocol.Message
|
||||
handleChatCreate(ctx, protocol.Message{ID: "c1", Type: protocol.ChatCreate, ChatCreate: &protocol.ChatCreateRequest{Directory: dir, OperationID: "op-untitled"}}, broker, store, func(message protocol.Message) error {
|
||||
created = message
|
||||
return nil
|
||||
})
|
||||
if created.Type != protocol.ChatCreate {
|
||||
t.Fatalf("create reply = %#v", created)
|
||||
}
|
||||
if _, title, _ := broker.createQuery(); title != "" {
|
||||
t.Fatalf("harness asked to create %q, want no title", title)
|
||||
}
|
||||
rows, err := store.OperatorSessions(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].Title != "" {
|
||||
t.Fatalf("registry rows = %+v, want one without a title", rows)
|
||||
}
|
||||
|
||||
broker.mu.Lock()
|
||||
broker.sessions = []protocol.ChatSession{{ID: "ses_untitled", Title: "Fix the flaky test"}}
|
||||
broker.mu.Unlock()
|
||||
var listed protocol.Message
|
||||
handleChatSessions(ctx, protocol.Message{ID: "list", Type: protocol.ChatSessions}, broker, nil, store, func(message protocol.Message) error {
|
||||
listed = message
|
||||
return nil
|
||||
})
|
||||
if len(listed.ChatSessions) != 1 || listed.ChatSessions[0].Title != "Fix the flaky test" {
|
||||
t.Fatalf("listed = %+v, want the harness title", listed.ChatSessions)
|
||||
}
|
||||
}
|
||||
@@ -158,9 +158,8 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
if operationID == "" {
|
||||
operationID = chatClientToken()
|
||||
}
|
||||
if title == "" {
|
||||
title = "New chat"
|
||||
}
|
||||
// A blank title records no operator title: the list then shows the
|
||||
// harness's own title for the chat (see handleChatSessions).
|
||||
resolved, err := resolveChatDirectory(directory)
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user