coretest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package coretest is a real core.Service for tests outside core: a mocked keychain, fake IMAP / SMTP servers per account, a fake model service, a fake MCP server and fixture plugins, all on this machine.

Index

Constants

View Source
const EgressHost = "egress.godwit.test"

EgressHost is the host fixture plugins fetch from, as http://egress.godwit.test:80/ (the port written out, as declared); it reaches the Env's local server, whose every answer is "pong".

Variables

This section is empty.

Functions

func MCPCommand

func MCPCommand(t *testing.T) (cmd string, args []string, env map[string]string)

MCPCommand is a stdio MCP server command: the test binary itself, whose TestMain must call ServeMCPIfChild.

func Msg

func Msg(from, to, subject, body string, opts ...MsgOption) []byte

Msg builds a raw message. Without MessageID it gets a random one; without Date, the current time.

func PluginFixture

func PluginFixture(t *testing.T, name string) string

PluginFixture copies the fixture plugin name into a temporary directory and returns it. Fixtures are looked up in core/coretest/testdata, core/plugins/testdata and core/testdata, in that order.

func ServeMCPIfChild

func ServeMCPIfChild()

ServeMCPIfChild, called first in TestMain, turns a test binary started by MCPCommand into a stdio MCP server with one read-only tool, lookup, and exits when the client goes away. Otherwise it returns at once.

Types

type Call

type Call = testllm.Call

type Env

type Env struct {
	Svc     *core.Service
	DataDir string
	// contains filtered or unexported fields
}

Env is a running Service with the fake servers behind it.

func New

func New(t *testing.T, opts ...Option) *Env

New starts a Service in a temporary directory, closed when the test ends.

func (*Env) AddAccount

func (e *Env) AddAccount(t *testing.T, email string) core.Account

AddAccount adds email with its own fake IMAP and SMTP servers (the SMTP one files sent mail into the IMAP Sent folder). The first account is the default.

func (*Env) Deliver

func (e *Env) Deliver(t *testing.T, accountID int64, folder string, raw []byte)

Deliver appends raw to the account's folder on its IMAP server and syncs.

func (*Env) EgressHits

func (e *Env) EgressHits() int

EgressHits is how many requests reached EgressHost.

func (*Env) Endpoints

func (e *Env) Endpoints(accountID int64) (imapHost string, imapPort int, smtpHost string, smtpPort int)

Endpoints are the account's servers, as a manual server form takes them.

func (*Env) IMAP

func (e *Env) IMAP(accountID int64) *IMAP

IMAP is the account's fake IMAP server, for fault injection.

func (*Env) InstallPlugin

func (e *Env) InstallPlugin(t *testing.T, name string)

InstallPlugin installs the fixture plugin name, grants its permissions and enables it.

func (*Env) LLM

func (e *Env) LLM(t *testing.T) *LLM

LLM registers a fake model service "test" with model "m1" and makes "test/m1" the default model.

func (*Env) SMTP

func (e *Env) SMTP(accountID int64) *SMTP

SMTP is the account's fake SMTP server, for fault injection.

func (*Env) Sent

func (e *Env) Sent(accountID int64) [][]byte

Sent is every message the account's SMTP server accepted, as sent.

func (*Env) StartServers

func (e *Env) StartServers(t *testing.T) (imapHost string, imapPort int, smtpHost string, smtpPort int, user, password string)

StartServers starts fake IMAP and SMTP servers for an account not added yet, as the onboarding form takes them, with the user and password they accept. Once an account is added with them, Deliver, IMAP, SMTP and Sent work for it as for AddAccount's.

type IMAP

type IMAP = testmail.IMAP

type LLM

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

LLM is a fake OpenAI-compatible model service.

func (*LLM) Release

func (l *LLM) Release()

Release lets hanging turns finish.

func (*LLM) RequestLog

func (l *LLM) RequestLog() []Request

RequestLog returns every chat request the service got, raw.

func (*LLM) Requests

func (l *LLM) Requests() int

Requests is how many chat requests the service got.

func (*LLM) Script

func (l *LLM) Script(turns ...Turn)

Script appends model turns; once they run out every request gets "ok".

type MsgOption

type MsgOption func(*msgConfig)

func Attachment

func Attachment(name, ctype string, data []byte) MsgOption

func Date

func Date(d time.Time) MsgOption

func HTML

func HTML(html string) MsgOption

HTML adds an HTML alternative to the text body.

func InReplyTo

func InReplyTo(id string) MsgOption

func MessageID

func MessageID(id string) MsgOption

type Option

type Option func(*config)

func WithoutAutoSync

func WithoutAutoSync() Option

WithoutAutoSync starts no background sync; Deliver still syncs.

type Request

type Request = testllm.Request

type SMTP

type SMTP = testmail.Inbox

type Turn

type Turn = testllm.Turn

Jump to

Keyboard shortcuts

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