Documentation
¶
Overview ¶
Package stack runs the whole Web UI for integration tests, the way the program does: a real PostgreSQL (see pgenv), the scripted ADK agent behind a switch that can make it vanish, and the application served by the production server type, so that starting and shutting down are tested too.
Tests talk to it over HTTP with a Client. They can also look into the database through Pool, and at what the agent saw through Model.
It needs Docker (for PostgreSQL).
Index ¶
- Constants
- func Attr(n *html.Node, key string) string
- func Doc(t testing.TB, markup string) *html.Node
- func Find(n *html.Node, match func(*html.Node) bool) *html.Node
- func FindAll(n *html.Node, match func(*html.Node) bool) []*html.Node
- func TestID(id string) func(*html.Node) bool
- func Text(n *html.Node) string
- type Agent
- type Client
- func (c *Client) Cookie(name string) string
- func (c *Client) Do(method, path string, form url.Values, headers ...string) *Response
- func (c *Client) Get(path string, headers ...string) *Response
- func (c *Client) LatestReply(conv string) string
- func (c *Client) Messages(conv string) []Message
- func (c *Client) OpenStream(ctx context.Context, conv, reply string) *Stream
- func (c *Client) Post(path string, form url.Values, headers ...string) *Response
- func (c *Client) Raw(conv, reply string) *Response
- func (c *Client) Regenerate(conv, reply string) *Response
- func (c *Client) Send(conv, content string) (reply string)
- func (c *Client) SignIn(email, password string) *Client
- func (c *Client) Start(content string) (conv, reply string)
- func (c *Client) Stop(conv, reply string) *Response
- type Event
- type Message
- type Option
- type Response
- type Stack
- type Stream
Constants ¶
const ( Email = "owner@example.com" Password = "a-long-enough-password" )
The first user of every stack.
Variables ¶
This section is empty.
Functions ¶
func FindAll ¶
FindAll returns every node under n (n included) that match accepts, in document order.
Types ¶
type Agent ¶
Agent is the scripted agent behind a switch. While it is down, a request is dropped without an answer, as when the process is gone.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Web UI the way a browser does: it keeps cookies, and it does not follow redirects, so that tests see them.
func NewClient ¶
NewClient returns a client of the Web UI at base, such as http://127.0.0.1:8300.
func (*Client) Do ¶
Do sends a request. form, when not nil, is the urlencoded body. headers are pairs of a name and a value.
func (*Client) LatestReply ¶
LatestReply is the id of the last message of a conversation.
func (*Client) OpenStream ¶
OpenStream asks for a reply's event stream, as the browser's EventSource does. The stream is closed when the test ends or ctx is done.
func (*Client) Regenerate ¶
Regenerate presses Regenerate (or Retry) on a reply. A new reply takes its place; the answer is its wrapper.
func (*Client) Send ¶
Send adds a message to a conversation the way the composer does (htmx), and returns the id of the reply being written.
type Event ¶
type Event struct {
// Name is the event's name, "message" when it has none.
Name string
Data string
// At is when the last line of the event arrived.
At time.Time
}
Event is one server-sent event.
type Message ¶
type Message struct {
ID string
Role string // "user" or "assistant"
Status string
// Text is what the reader sees in the message body.
Text string
// Node is the whole article, for anything else a test wants to look at.
Node *html.Node
}
Message is a message as a page shows it.
type Option ¶
type Option func(*settings)
Option customizes a Stack.
func WithAgentServer ¶
func WithAgentServer(opts ...testagent.HandlerOption) Option
WithAgentServer sets how the scripted agent's server behaves, such as how long it lets one reply stream.
func WithExternalAgent ¶
WithExternalAgent uses a real agent (its ADK REST base URL, such as http://localhost:9093/api, and its application name) instead of the scripted one. Agent and Model are then nil.
func WithLogs ¶
WithLogs sends the application's log to w, as the program's own logger would write it, at the debug level so that nothing is held back. Read w once the stack is shut down; until then the server may be writing to it.
func WithSetting ¶
WithSetting sets a configuration key, as if it were in .env.
type Stack ¶
type Stack struct {
// URL is where a browser reaches it, such as http://127.0.0.1:41233.
URL string
// Config is what the application was built from.
Config config.Config
// Agent is the scripted agent behind the Web UI. It can be taken down.
Agent *Agent
// Model is the model the agent runs, for assertions on what it saw.
Model *testagent.Model
// Pool reads the database the Web UI writes.
Pool *pgxpool.Pool
// contains filtered or unexported fields
}
Stack is a running Web UI.
func (*Stack) AddUser ¶
AddUser creates another user, the way an operator would with SQL: the Web UI has no sign-up, and the first user comes from the settings.
func (*Stack) Shutdown ¶
Shutdown does what SIGTERM does to the program: it ends the replies being written, lets requests finish, and returns how long that took. Calling it again returns the same answer. It is also called when the test ends.
func (*Stack) SignedInAs ¶
SignedInAs returns a client signed in as the user.
type Stream ¶
type Stream struct {
Status int
Header http.Header
// Retry is the last retry: value the server sent, 0 if none.
Retry time.Duration
// contains filtered or unexported fields
}
Stream is an open event stream, read one event at a time.