Documentation
¶
Index ¶
- type Harness
- func (h *Harness) AssertContains(s, substr string)
- func (h *Harness) AssertEquals(got, want string)
- func (h *Harness) AssertError(err error)
- func (h *Harness) AssertErrorContains(err error, substr string)
- func (h *Harness) AssertEventPublished(eventType string)
- func (h *Harness) AssertExecutorCalledN(n int)
- func (h *Harness) AssertFirstMessageIsSystem()
- func (h *Harness) AssertLastRequestHasNMessages(n int)
- func (h *Harness) AssertLastRequestHasTool(name string)
- func (h *Harness) AssertNoError(err error)
- func (h *Harness) AssertNoEventsPublished()
- func (h *Harness) AssertProviderCalledN(n int)
- func (h *Harness) AssertSessionID(agent *core.Agent, want string)
- func (h *Harness) AssertSessionIDNotEmpty(agent *core.Agent)
- func (h *Harness) AssertStateHasNMessages(agent *core.Agent, n int)
- func (h *Harness) AssertStateHasTokens(agent *core.Agent, want int)
- func (h *Harness) AssertSystemPromptEquals(want string)
- func (h *Harness) EventBus() *events.EventBus
- func (h *Harness) Executor() *MockExecutor
- func (h *Harness) FindEvents(eventType string) []events.UIEvent
- func (h *Harness) NewAgent() *core.Agent
- func (h *Harness) NewAgentWithOptions(opts core.Options) *core.Agent
- func (h *Harness) Provider() *MockProvider
- func (h *Harness) Reset()
- func (h *Harness) Run(query string) (string, error)
- func (h *Harness) RunWithAgent(agent *core.Agent, query string) (string, error)
- func (h *Harness) UI() *MockUI
- type MockExecutor
- func (m *MockExecutor) AddResult(msg core.Message) *MockExecutor
- func (m *MockExecutor) AddTool(tool core.Tool) *MockExecutor
- func (m *MockExecutor) AddToolResult(toolCallID, content string) *MockExecutor
- func (m *MockExecutor) CallCount() int
- func (m *MockExecutor) Execute(_ context.Context, calls []core.ToolCall) []core.Message
- func (m *MockExecutor) GetTools() []core.Tool
- func (m *MockExecutor) LastCalls() []core.ToolCall
- func (m *MockExecutor) Reset()
- func (m *MockExecutor) SetResults(results []core.Message) *MockExecutor
- func (m *MockExecutor) WithTools(tools []core.Tool) *MockExecutor
- type MockProvider
- func (m *MockProvider) AddError(err error) *MockProvider
- func (m *MockProvider) AddMalformedResponse(content string) *MockProvider
- func (m *MockProvider) AddResponse(resp *core.ChatResponse) *MockProvider
- func (m *MockProvider) AddStreamChunks(chunks ...string) *MockProvider
- func (m *MockProvider) AddTextResponse(content string) *MockProvider
- func (m *MockProvider) AddTextResponseWithFinish(content, finishReason string) *MockProvider
- func (m *MockProvider) AddToolCallResponse(content string, toolCalls ...core.ToolCall) *MockProvider
- func (m *MockProvider) BlockOnCallN(n int) chan struct{}
- func (m *MockProvider) BlockUntil() chan struct{}
- func (m *MockProvider) CallCount() int
- func (m *MockProvider) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
- func (m *MockProvider) ChatStream(ctx context.Context, req *core.ChatRequest, handler core.StreamHandler) error
- func (m *MockProvider) EstimateTokens(_ *core.ChatRequest) int
- func (m *MockProvider) Info() core.ProviderInfo
- func (m *MockProvider) LastRequest() *core.ChatRequest
- func (m *MockProvider) Reset()
- func (m *MockProvider) SetResponses(resps []*core.ChatResponse) *MockProvider
- func (m *MockProvider) WithInfo(info core.ProviderInfo) *MockProvider
- func (m *MockProvider) WithStreamDelay(delay time.Duration) *MockProvider
- func (m *MockProvider) WithStreaming() *MockProvider
- func (m *MockProvider) WithTokenEstimate(count int) *MockProvider
- type MockUI
- func (m *MockUI) Confirm(message string) (bool, error)
- func (m *MockUI) LineOutput() string
- func (m *MockUI) Output() string
- func (m *MockUI) Print(message string)
- func (m *MockUI) PrintLine(message string)
- func (m *MockUI) Prompt(message string) (string, error)
- func (m *MockUI) Reset()
- func (m *MockUI) WithConfirmResponse(resp bool) *MockUI
- func (m *MockUI) WithPromptResponse(resp string) *MockUI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Harness ¶
type Harness struct {
// contains filtered or unexported fields
}
Harness is an end-to-end test harness for the seed agent. It wires up mock Provider, ToolExecutor, UI, and EventBus so you can script full conversation flows and assert on every interface interaction.
Usage:
h := test.NewHarness()
h.Provider().AddTextResponse("Hello!")
agent := h.NewAgent()
result, err := agent.Run(ctx, "Hi")
h.AssertNoError(err)
h.AssertEquals(result, "Hello!")
func NewHarnessWithT ¶
func NewHarnessWithT(t interface {
Errorf(format string, args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
}) *Harness
NewHarnessWithT creates a harness that can call t.Fatalf directly.
func (*Harness) AssertContains ¶
AssertContains fails if s doesn't contain substr.
func (*Harness) AssertEquals ¶
AssertEquals fails if got != want.
func (*Harness) AssertError ¶
AssertError fails the test if err is nil.
func (*Harness) AssertErrorContains ¶
AssertErrorContains fails if err doesn't contain the substring.
func (*Harness) AssertEventPublished ¶
AssertEventPublished checks that an event of the given type was published.
func (*Harness) AssertExecutorCalledN ¶
AssertExecutorCalledN times.
func (*Harness) AssertFirstMessageIsSystem ¶
func (h *Harness) AssertFirstMessageIsSystem()
AssertFirstMessageIsSystem checks that the first message in the last request is a system message.
func (*Harness) AssertLastRequestHasNMessages ¶
AssertLastRequestHasNMessages checks the message count in the last provider request.
func (*Harness) AssertLastRequestHasTool ¶
AssertLastRequestHasTool checks that the last request included a tool with the given name.
func (*Harness) AssertNoError ¶
AssertNoError fails the test if err is not nil.
func (*Harness) AssertNoEventsPublished ¶
func (h *Harness) AssertNoEventsPublished()
AssertNoEventsPublished checks that no events were published.
func (*Harness) AssertProviderCalledN ¶
AssertProviderCalledN times.
func (*Harness) AssertSessionID ¶
AssertSessionID checks the session ID.
func (*Harness) AssertSessionIDNotEmpty ¶
AssertSessionIDNotEmpty checks that the session ID is non-empty.
func (*Harness) AssertStateHasNMessages ¶
AssertStateHasNMessages checks the agent state message count.
func (*Harness) AssertStateHasTokens ¶
AssertStateHasTokens checks the total token count in state.
func (*Harness) AssertSystemPromptEquals ¶
AssertSystemPromptEquals checks the system prompt content.
func (*Harness) Executor ¶
func (h *Harness) Executor() *MockExecutor
Executor returns the mock executor for configuration.
func (*Harness) FindEvents ¶
FindEvents returns all collected events of the given type.
func (*Harness) NewAgentWithOptions ¶
NewAgentWithOptions creates an agent with custom options. Provider and Executor are set from the harness; other options are from opts.
func (*Harness) Provider ¶
func (h *Harness) Provider() *MockProvider
Provider returns the mock provider for configuration.
func (*Harness) RunWithAgent ¶
RunWithAgent runs a query on the given agent.
type MockExecutor ¶
type MockExecutor struct {
// Recorded calls for assertion
Calls [][]core.ToolCall
// contains filtered or unexported fields
}
MockExecutor is a recording mock implementation of core.ToolExecutor. Configure tool results via AddResult or SetResults.
func NewMockExecutor ¶
func NewMockExecutor() *MockExecutor
NewMockExecutor creates an empty MockExecutor.
func (*MockExecutor) AddResult ¶
func (m *MockExecutor) AddResult(msg core.Message) *MockExecutor
AddResult appends a tool result message to the sequence.
func (*MockExecutor) AddTool ¶
func (m *MockExecutor) AddTool(tool core.Tool) *MockExecutor
AddTool adds a single tool.
func (*MockExecutor) AddToolResult ¶
func (m *MockExecutor) AddToolResult(toolCallID, content string) *MockExecutor
AddToolResult adds a tool result for a specific call ID.
func (*MockExecutor) CallCount ¶
func (m *MockExecutor) CallCount() int
CallCount returns the number of Execute calls made.
func (*MockExecutor) GetTools ¶
func (m *MockExecutor) GetTools() []core.Tool
GetTools implements core.ToolExecutor.
func (*MockExecutor) LastCalls ¶
func (m *MockExecutor) LastCalls() []core.ToolCall
LastCalls returns the tool calls from the last Execute call.
func (*MockExecutor) Reset ¶
func (m *MockExecutor) Reset()
Reset clears recorded calls and resets the result index.
func (*MockExecutor) SetResults ¶
func (m *MockExecutor) SetResults(results []core.Message) *MockExecutor
SetResults replaces the entire result sequence.
func (*MockExecutor) WithTools ¶
func (m *MockExecutor) WithTools(tools []core.Tool) *MockExecutor
WithTools sets the available tools.
type MockProvider ¶
type MockProvider struct {
// Recorded calls for assertion
Calls []*core.ChatRequest
// contains filtered or unexported fields
}
MockProvider is a scriptable mock implementation of core.Provider. Configure it with a sequence of responses via AddResponse or SetResponses. It records every Chat call for assertion.
func NewMockProvider ¶
func NewMockProvider() *MockProvider
NewMockProvider creates a MockProvider with default info.
func (*MockProvider) AddError ¶
func (m *MockProvider) AddError(err error) *MockProvider
AddError appends an error to the sequence. The next call to Chat will return this error.
func (*MockProvider) AddMalformedResponse ¶
func (m *MockProvider) AddMalformedResponse(content string) *MockProvider
AddMalformedResponse adds a response where tool calls are embedded in the content string rather than in the structured ToolCalls field. This simulates a malformed LLM response that the fallback parser must recover from. The content should contain tool-call-like patterns (e.g., JSON with "tool_calls", XML <function=...>, etc.) so the fallback parser detects them.
func (*MockProvider) AddResponse ¶
func (m *MockProvider) AddResponse(resp *core.ChatResponse) *MockProvider
AddResponse appends a response to the sequence. The next call to Chat will return this response.
func (*MockProvider) AddStreamChunks ¶
func (m *MockProvider) AddStreamChunks(chunks ...string) *MockProvider
AddStreamChunks configures explicit chunk sequences for streaming. Each call to ChatStream will use the next chunk sequence in order.
func (*MockProvider) AddTextResponse ¶
func (m *MockProvider) AddTextResponse(content string) *MockProvider
AddTextResponse adds a simple text response (no tool calls).
func (*MockProvider) AddTextResponseWithFinish ¶
func (m *MockProvider) AddTextResponseWithFinish(content, finishReason string) *MockProvider
AddTextResponseWithFinish adds a simple text response with a custom finish reason. Useful for testing finish-reason-specific behavior (e.g., "length", "stop", "content_filter").
func (*MockProvider) AddToolCallResponse ¶
func (m *MockProvider) AddToolCallResponse(content string, toolCalls ...core.ToolCall) *MockProvider
AddToolCallResponse adds a response that includes tool calls.
func (*MockProvider) BlockOnCallN ¶
func (m *MockProvider) BlockOnCallN(n int) chan struct{}
BlockOnCallN causes the Nth Chat call (1-indexed) to block until the returned channel is closed. This is useful for cancellation tests where you want the first N-1 calls to succeed normally.
func (*MockProvider) BlockUntil ¶
func (m *MockProvider) BlockUntil() chan struct{}
BlockUntil causes the next Chat call to block until the returned channel is closed. Use this in cancellation tests: cancel the channel to unblock the provider so the context cancellation is observed.
func (*MockProvider) CallCount ¶
func (m *MockProvider) CallCount() int
CallCount returns the number of Chat calls made.
func (*MockProvider) Chat ¶
func (m *MockProvider) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
Chat implements core.Provider.
func (*MockProvider) ChatStream ¶
func (m *MockProvider) ChatStream(ctx context.Context, req *core.ChatRequest, handler core.StreamHandler) error
ChatStream implements core.Provider. When streaming is enabled (via WithStreaming), it delivers the configured response as chunked content via the StreamHandler. Otherwise, it calls OnDone with the response directly.
func (*MockProvider) EstimateTokens ¶
func (m *MockProvider) EstimateTokens(_ *core.ChatRequest) int
EstimateTokens implements core.Provider.
func (*MockProvider) Info ¶
func (m *MockProvider) Info() core.ProviderInfo
Info implements core.Provider.
func (*MockProvider) LastRequest ¶
func (m *MockProvider) LastRequest() *core.ChatRequest
LastRequest returns the last Chat request, or nil.
func (*MockProvider) Reset ¶
func (m *MockProvider) Reset()
Reset clears all recorded calls and resets the response index.
func (*MockProvider) SetResponses ¶
func (m *MockProvider) SetResponses(resps []*core.ChatResponse) *MockProvider
SetResponses replaces the entire response sequence.
func (*MockProvider) WithInfo ¶
func (m *MockProvider) WithInfo(info core.ProviderInfo) *MockProvider
WithInfo sets the provider info.
func (*MockProvider) WithStreamDelay ¶
func (m *MockProvider) WithStreamDelay(delay time.Duration) *MockProvider
WithStreamDelay sets the delay between streaming chunks.
func (*MockProvider) WithStreaming ¶
func (m *MockProvider) WithStreaming() *MockProvider
WithStreaming enables streaming mode. When true, ChatStream will deliver the response content as chunks via the StreamHandler instead of returning it all at once. Configure chunks with AddStreamChunks or use the content from AddTextResponse / AddToolCallResponse (split into word-sized chunks).
func (*MockProvider) WithTokenEstimate ¶
func (m *MockProvider) WithTokenEstimate(count int) *MockProvider
WithTokenEstimate sets the token estimate returned by EstimateTokens.
type MockUI ¶
type MockUI struct {
// Recorded calls for assertion
Prompts []string
Confirms []string
Prints []string
PrintLines []string
// contains filtered or unexported fields
}
MockUI is a recording mock implementation of core.UI. It captures all Print/PrintLine output and can be pre-configured with prompt/confirm responses.
func (*MockUI) LineOutput ¶
LineOutput returns all PrintLine output (with newlines).
func (*MockUI) WithConfirmResponse ¶
WithConfirmResponse sets the response returned by the next Confirm call.
func (*MockUI) WithPromptResponse ¶
WithPromptResponse sets the response returned by the next Prompt call.