61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/opencode"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
func TestChatRejectsUnsupportedAttachmentsBeforeStorageOrQueue(t *testing.T) {
|
|
broker := newChannelChat() // deliberately has no file capability
|
|
manager := &chatManager{opencode: broker, cache: map[string]string{}}
|
|
dir := filepath.Join(t.TempDir(), "uploads")
|
|
t.Setenv("PIPELINES_CHAT_ATTACHMENT_DIR", dir)
|
|
var reply protocol.Message
|
|
handleChatPrompt(context.Background(), protocol.Message{ID: "p", ChatPrompt: &protocol.ChatPromptRequest{SessionID: "ses_1", Text: "hello", Attachments: []protocol.ChatAttachment{{Name: "x", Data: "eA=="}}}}, manager, newChatHub(), nil, "client", func(msg protocol.Message) error { reply = msg; return nil })
|
|
if reply.Type != protocol.Error || reply.Error != errChatAttachmentsUnsupported.Error() {
|
|
t.Fatalf("reply = %+v", reply)
|
|
}
|
|
if broker.promptCount() != 0 {
|
|
t.Fatal("unsupported prompt reached harness")
|
|
}
|
|
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
|
t.Fatal("unsupported upload wrote storage", err)
|
|
}
|
|
if err := manager.PromptWithMessageIDFiles(context.Background(), "ses_1", "hello", "", []opencode.PromptFile{{URI: "file:///x"}}); !errors.Is(err, errChatAttachmentsUnsupported) {
|
|
t.Fatalf("silent fallback: %v", err)
|
|
}
|
|
}
|
|
|
|
type failingChatInstructions struct{ *fakeChat }
|
|
|
|
func (f failingChatInstructions) SetInstruction(context.Context, string, string, any) error {
|
|
return errors.New("instruction service unavailable")
|
|
}
|
|
|
|
func TestChatCreateReportsInstructionCapabilities(t *testing.T) {
|
|
for _, status := range []string{"applied", "failed", "unsupported"} {
|
|
t.Run(status, func(t *testing.T) {
|
|
fake := scriptedChat()
|
|
fake.created = protocol.ChatSession{ID: "ses_new"}
|
|
var broker chatBroker = fake
|
|
if status == "failed" {
|
|
broker = failingChatInstructions{fake}
|
|
}
|
|
if status == "unsupported" {
|
|
broker = newChannelChat()
|
|
}
|
|
var reply protocol.Message
|
|
handleChatCreate(context.Background(), protocol.Message{ID: "create", ChatCreate: &protocol.ChatCreateRequest{Directory: t.TempDir(), Instructions: "be careful"}}, broker, newOperatorStore(t), func(msg protocol.Message) error { reply = msg; return nil })
|
|
if reply.ChatSession == nil || reply.ChatSession.InstructionStatus != status {
|
|
t.Fatalf("reply = %+v", reply)
|
|
}
|
|
})
|
|
}
|
|
}
|