testharness

package
v0.1.16-preview.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLIPath

func CLIPath() string

CLIPath returns the path to the Copilot CLI, discovering it once and caching.

func GetFinalAssistantMessage

func GetFinalAssistantMessage(session *copilot.Session, timeout time.Duration) (*copilot.SessionEvent, error)

GetFinalAssistantMessage waits for and returns the final assistant message from a session turn.

func GetNextEventOfType added in v0.1.15

func GetNextEventOfType(session *copilot.Session, eventType copilot.SessionEventType, timeout time.Duration) (*copilot.SessionEvent, error)

GetNextEventOfType waits for and returns the next event of the specified type from a session.

Types

type CapiProxy

type CapiProxy struct {
	// contains filtered or unexported fields
}

CapiProxy manages a child process that acts as a replaying proxy to AI endpoints. It spawns the shared test harness server from test/harness/server.ts.

func NewCapiProxy

func NewCapiProxy() *CapiProxy

NewCapiProxy creates a new proxy instance.

func (*CapiProxy) Configure

func (p *CapiProxy) Configure(filePath, workDir string) error

Configure sends configuration to the proxy.

func (*CapiProxy) GetExchanges

func (p *CapiProxy) GetExchanges() ([]ParsedHttpExchange, error)

GetExchanges retrieves the captured HTTP exchanges from the proxy.

func (*CapiProxy) Start

func (p *CapiProxy) Start() (string, error)

Start launches the proxy server and returns its URL.

func (*CapiProxy) Stop

func (p *CapiProxy) Stop() error

Stop gracefully shuts down the proxy server.

func (*CapiProxy) StopWithOptions

func (p *CapiProxy) StopWithOptions(skipWritingCache bool) error

StopWithOptions gracefully shuts down the proxy server. If skipWritingCache is true, the proxy won't write captured exchanges to disk.

func (*CapiProxy) URL

func (p *CapiProxy) URL() string

URL returns the proxy URL, or empty if not started.

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Index        int                   `json:"index"`
	Message      ChatCompletionMessage `json:"message"`
	FinishReason string                `json:"finish_reason"`
}

ChatCompletionChoice represents a choice in the response.

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role       string     `json:"role"`
	Content    string     `json:"content,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
}

ChatCompletionMessage represents a message in the chat completion request.

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model    string                  `json:"model"`
	Messages []ChatCompletionMessage `json:"messages"`
	Tools    []ChatCompletionTool    `json:"tools,omitempty"`
}

ChatCompletionRequest represents an OpenAI chat completion request.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID      string                 `json:"id"`
	Model   string                 `json:"model"`
	Choices []ChatCompletionChoice `json:"choices"`
}

ChatCompletionResponse represents an OpenAI chat completion response.

type ChatCompletionTool

type ChatCompletionTool struct {
	Type     string                     `json:"type"`
	Function ChatCompletionToolFunction `json:"function"`
}

ChatCompletionTool represents a tool in the chat completion request.

type ChatCompletionToolFunction

type ChatCompletionToolFunction struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

ChatCompletionToolFunction represents a function tool.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

FunctionCall represents the function details in a tool call.

type Message

type Message = ChatCompletionMessage

Message is an alias for ChatCompletionMessage for test convenience.

type ParsedHttpExchange

type ParsedHttpExchange struct {
	Request  ChatCompletionRequest   `json:"request"`
	Response *ChatCompletionResponse `json:"response,omitempty"`
}

ParsedHttpExchange represents a captured HTTP exchange.

type TestContext

type TestContext struct {
	CLIPath  string
	HomeDir  string
	WorkDir  string
	ProxyURL string
	// contains filtered or unexported fields
}

TestContext holds shared resources for E2E tests.

func NewTestContext

func NewTestContext(t *testing.T) *TestContext

NewTestContext creates a new test context with isolated directories and a replaying proxy.

func (*TestContext) Close

func (c *TestContext) Close(testFailed bool)

Close cleans up the test context resources.

func (*TestContext) ConfigureForTest

func (c *TestContext) ConfigureForTest(t *testing.T)

ConfigureForTest configures the proxy for a specific subtest. Call this at the start of each t.Run subtest.

func (*TestContext) Env

func (c *TestContext) Env() []string

Env returns environment variables configured for isolated testing.

func (*TestContext) GetExchanges

func (c *TestContext) GetExchanges() ([]ParsedHttpExchange, error)

GetExchanges retrieves the captured HTTP exchanges from the proxy.

func (*TestContext) NewClient

func (c *TestContext) NewClient() *copilot.Client

NewClient creates a CopilotClient configured for this test context.

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function FunctionCall `json:"function"`
}

ToolCall represents a tool call in an assistant message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL