coretest

package
v1.40.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 36 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (
	AtRcpt      = testmail.AtRcpt
	AtData      = testmail.AtData
	DefaultSeed = testmail.DefaultSeed
)

The SMTP stages SMTP.Reply answers at.

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".

View Source
const NativeChildEnv = "GODWIT_CORETEST_NATIVE"

NativeChildEnv makes the test binary a fake plugin-host (ServeNativeIfChild); a Service gets it with SetNativeHostForTest(NativeChildEnv + "=1").

Variables

View Source
var (
	ScaleSmall  = testmail.ScaleSmall
	ScaleMedium = testmail.ScaleMedium
	ScaleLarge  = testmail.ScaleLarge
)

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 running Env's time (or the current time).

func NativePluginFixture added in v1.2.0

func NativePluginFixture(t *testing.T, name, version string, describe, extra map[string]any) string

NativePluginFixture writes a native plugin source directory: a manifest (capabilities translate; a text setting endpoint with a default and a secret token) and a fake library (see plugins.FakeNativeOpener) whose describe matches the manifest unless describe is given; extra is merged into the fake library's JSON (record, initFail, echoStderr).

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 PopulateMailbox added in v1.36.0

func PopulateMailbox(tb testing.TB, im *IMAP, email string, seed int64, folders, messages int)

PopulateMailbox seeds im with extra project folders up to folders (>= 4) and messages deterministic RFC 5322 messages driven by seed.

func Registry added in v1.2.0

func Registry(updated time.Time, plugins ...map[string]any) map[string]any

Registry is a registry document updated at updated with plugins, each {"name", "title", "summary", "releases"} (see NativeRelease, ScriptRelease).

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.

func ServeNativeIfChild added in v1.2.0

func ServeNativeIfChild()

ServeNativeIfChild serves as a native plugin's process when the test binary was started as one: it never loads a library (plugins.FakeNativeOpener). A TestMain whose tests run native plugins calls it first.

Types

type AccountOption added in v1.33.0

type AccountOption func(*accountConfig)

AccountOption changes how AddAccount adds an account.

func Seeded added in v1.36.0

func Seeded(scale Scale, seed int64) AccountOption

Seeded pre-populates the account's IMAP server before AddAccount connects, so the first sync imports the messages as existing mail rather than new arrivals.

func ViaJMAP added in v1.33.0

func ViaJMAP() AccountOption

ViaJMAP adds the account over JMAP, on a fake JMAP server (Env.JMAP), with the JMAP experiment turned on. It receives and sends over JMAP, saving the sent copy on the server.

func ViaPOP3 added in v1.34.0

func ViaPOP3() AccountOption

ViaPOP3 adds the account over POP3, on a fake POP3 server (Env.POP3), with the POP3 experiment turned on. It sends through its own SMTP server, which saves no sent copy.

type Autodiscover added in v1.35.0

type Autodiscover = testmail.Autodiscover

type Call

type Call = testllm.Call

type CardDAV added in v1.36.0

type CardDAV = testmail.CardDAV

type CardDAVRequest added in v1.36.0

type CardDAVRequest = testmail.CardDAVRequest

type EWS added in v1.35.0

type EWS = testmail.EWS

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.TB, 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.TB, email string, opts ...AccountOption) 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) AdvanceClock added in v1.14.0

func (e *Env) AdvanceClock(d time.Duration)

AdvanceClock moves the Service's clock forward by d, firing the waits that come due.

func (*Env) Deliver

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

Deliver appends raw to the account's folder on its IMAP or JMAP server (a POP3 server has only INBOX) and syncs: raw is new mail. (Append to IMAP().User or deliver on JMAP() or POP3() for mail already there.)

func (*Env) EWS added in v1.35.0

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

EWS is the fake EWS server of an account added with StartEWSServers' input.

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) JMAP added in v1.33.0

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

JMAP is a ViaJMAP account's fake JMAP server.

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) LLMService added in v1.7.0

func (e *Env) LLMService(t *testing.T, name, kind string) *LLM

LLMService registers a fake model service name of kind ("openai", "openai-responses" or "anthropic") with model "m1": "<name>/m1" picks it.

func (*Env) POP3 added in v1.34.0

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

POP3 is a ViaPOP3 account's fake POP3 server.

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 sending server accepted, as sent.

func (*Env) StartCardDAV added in v1.36.0

func (e *Env) StartCardDAV(t *testing.T) *CardDAV

StartCardDAV starts a fake HTTPS CardDAV server with default Basic credentials alice / secret, trusted by both the Service's CardDAV client and image fetcher.

func (*Env) StartEWSAutodiscover added in v1.35.0

func (e *Env) StartEWSAutodiscover(t *testing.T, email string) (core.AccountInput, *EWS, *Autodiscover)

StartEWSAutodiscover starts a fake EWS server for email, as StartEWSServers does, and Autodiscover in front of it, which answers as no host until told to. The account's input has no EWS URL: the check finds it.

func (*Env) StartEWSServers added in v1.35.0

func (e *Env) StartEWSServers(t *testing.T, email string) (core.AccountInput, *EWS)

StartEWSServers starts a fake EWS server for email, not added yet, and returns the account's input, with the EWS URL typed in, and the server. Once the account is added, Deliver and EWS work for it as for AddAccount's.

func (*Env) StartJMAPServers added in v1.33.0

func (e *Env) StartJMAPServers(t *testing.T, email string) core.AccountInput

StartJMAPServers starts a fake JMAP server for email, not added yet, and returns the account's input: the session is found through /.well-known/jmap on the JMAP server's host, and mail goes out over JMAP without an SMTP server. Once the account is added, Deliver, JMAP and Sent work for it as for AddAccount's.

func (*Env) StartPOP3Servers added in v1.34.0

func (e *Env) StartPOP3Servers(t *testing.T, email string) core.AccountInput

StartPOP3Servers starts a fake POP3 server and an SMTP server for email, not added yet, and returns the account's input. Once the account is added, Deliver (to INBOX), POP3, SMTP and Sent work for it as for AddAccount's.

func (*Env) StartServers

func (e *Env) StartServers(t testing.TB) (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 JMAP added in v1.33.0

type JMAP = testmail.JMAP

type LLM

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

LLM is a fake OpenAI-compatible model service.

func (*LLM) Rearm added in v1.37.0

func (l *LLM) Rearm()

Rearm makes turns hang again after a Release: a test that releases one run can hold the next.

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 Header(line string) MsgOption

Header adds a header line, as "List-Id: <news.example>".

func InReplyTo

func InReplyTo(id string) MsgOption

func Inline added in v1.36.0

func Inline(cid, ctype string, data []byte) MsgOption

func MessageID

func MessageID(id string) MsgOption

type Option

type Option func(*config)

func WithConfirmWindow added in v1.13.0

func WithConfirmWindow() Option

WithConfirmWindow is the GUI's Service: a ui client is connected for the whole test (core.WithUISession), so a window can confirm godwit mcp's sends. Without it 每次确认 refuses them, as headless with no notification.

func WithMCPSendNotify added in v1.36.0

func WithMCPSendNotify() Option

WithMCPSendNotify is the backend's Service: with no ui client connected, a 每次确认 request posts a notification (core.Options.NotifyMCPSend) and waits.

func WithRecognitionModelSources added in v1.21.0

func WithRecognitionModelSources(urls ...string) Option

WithRecognitionModelSources has the Service download 识别模型's files from urls (core.Options.RecognitionModelSources), as httptest servers'.

func WithRecognizer added in v1.21.0

func WithRecognizer(r mask.Recognizer) Option

WithRecognizer reads for 识别模型 with r (core.Options.Recognizer).

func WithRegistry added in v1.2.0

func WithRegistry(src *core.RegistrySource) Option

WithRegistry gives the Service a plugin registry, as from NewRegistryServer.

func WithSystemTranslator added in v1.9.0

func WithSystemTranslator(t core.SystemTranslator) Option

WithSystemTranslator gives the Service the system's translation.

func WithUnsubscribeClient added in v1.14.0

func WithUnsubscribeClient(c *http.Client) Option

WithUnsubscribeClient sends one-click unsubscribes with c, as one reaching an httptest server.

func WithoutAutoSync

func WithoutAutoSync() Option

WithoutAutoSync starts no background sync; Deliver still syncs.

func WithoutIdle added in v1.36.0

func WithoutIdle() Option

WithoutIdle gives every account an IMAP server without IDLE: the worker polls instead.

func WithoutUIDPlus added in v1.33.0

func WithoutUIDPlus() Option

WithoutUIDPlus gives every account an IMAP server without UIDPLUS: it cannot delete permanently.

type POP3 added in v1.34.0

type POP3 = testmail.POP3

type RegistryServer added in v1.2.0

type RegistryServer struct {
	Src *core.RegistrySource
	// contains filtered or unexported fields
}

RegistryServer is a plugin registry over https with its own signing key.

func NewRegistryServer added in v1.2.0

func NewRegistryServer(t *testing.T) *RegistryServer

NewRegistryServer starts an empty registry; Publish puts one up.

func (*RegistryServer) Intercept added in v1.7.0

func (r *RegistryServer) Intercept(fn func(w http.ResponseWriter, req *http.Request, body []byte) bool)

Intercept lets fn answer a request first (body is what the path serves, nil if none); returning false serves it as usual. nil removes it.

func (*RegistryServer) NativeModelsRelease added in v1.7.0

func (r *RegistryServer) NativeModelsRelease(t *testing.T, name, version, record string, models []any) map[string]any

NativeModelsRelease is a registry release of a native plugin offering models (the fake library's "models" list), recording each models.* request to record + "." + method.

func (*RegistryServer) NativeRelease added in v1.2.0

func (r *RegistryServer) NativeRelease(t *testing.T, name, version string, extra map[string]any) map[string]any

NativeRelease is a registry release of the NativePluginFixture plugin name at version for this platform, its library served from r.

func (*RegistryServer) Publish added in v1.2.0

func (r *RegistryServer) Publish(t *testing.T, reg map[string]any)

Publish signs and serves reg as /registry.json with /registry.json.sig.

func (*RegistryServer) ScriptRelease added in v1.2.0

func (r *RegistryServer) ScriptRelease(name, version, perms, code string) map[string]any

ScriptRelease is a registry release of a one-file script plugin.

func (*RegistryServer) Serve added in v1.2.0

func (r *RegistryServer) Serve(path string, body []byte)

Serve puts body at path (an artifact), or removes it when body is nil.

func (*RegistryServer) Tamper added in v1.2.0

func (r *RegistryServer) Tamper(fn func([]byte) []byte)

Tamper changes the published registry without signing it again.

func (*RegistryServer) URL added in v1.2.0

func (r *RegistryServer) URL(path string) string

URL is the server's address for path.

type Request

type Request = testllm.Request

type SMTP

type SMTP = testmail.Inbox

type Scale added in v1.36.0

type Scale = testmail.Scale

type Turn

type Turn = testllm.Turn

Jump to

Keyboard shortcuts

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