test: exercise managed model dialogs and intermediate chat steps in Chrome
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type browserModelFixture struct{ *fakeChat }
|
||||
|
||||
func (b browserModelFixture) Models(ctx context.Context, id string) ([]protocol.ChatModel, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-time.After(250 * time.Millisecond):
|
||||
}
|
||||
return b.fakeChat.Models(ctx, id)
|
||||
}
|
||||
|
||||
func TestChatBrowserLifecycleAndModelDialog(t *testing.T) {
|
||||
if os.Getenv("PIPELINES_BROWSER_TEST") != "1" {
|
||||
t.Skip("set PIPELINES_BROWSER_TEST=1 for the scratch Chrome check")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "scratch.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
directory := t.TempDir()
|
||||
session := protocol.ChatSession{ID: "ses_browser", Title: "Scratch chat", Model: "model-a", Directory: directory}
|
||||
if err := store.RecordOperatorSession(ctx, session.ID, directory, session.Title, protocol.ChatSessionTagOperator); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fake := scriptedChat()
|
||||
fake.block = true
|
||||
fake.sessions = []protocol.ChatSession{session}
|
||||
fake.models = []protocol.ChatModel{{ID: "model-a", Provider: "fixture", Name: "Model Alpha"}, {ID: "model-b", Provider: "fixture", Name: "Model Beta"}}
|
||||
fake.messages = []protocol.ChatMessage{
|
||||
{ID: "msg_user", Role: protocol.ChatRoleUser, Parts: []protocol.ChatPart{{Type: "text", Text: "Scratch prompt"}}},
|
||||
{ID: "msg_answer", Role: protocol.ChatRoleAssistant, Parts: []protocol.ChatPart{{Type: "reasoning", Text: "Controlled reasoning evidence"}, {Type: "text", Text: "Controlled answer"}}},
|
||||
}
|
||||
handler := HandlerWithOptions(ctx, Options{Chat: browserModelFixture{fake}}, store)
|
||||
defer func() { cancel(); WaitRuns(handler) }()
|
||||
srv := httptest.NewServer(handler)
|
||||
defer srv.Close()
|
||||
cmd := exec.CommandContext(ctx, "node", "../../web/test/chat-hardening-probe.mjs", strings.TrimPrefix(srv.URL, "http://"), session.ID)
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("chat browser regression: %v\n%s", err, output)
|
||||
} else {
|
||||
t.Log(string(output))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user