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
- func MCPCommand(t *testing.T) (cmd string, args []string, env map[string]string)
- func Msg(from, to, subject, body string, opts ...MsgOption) []byte
- func NativePluginFixture(t *testing.T, name, version string, describe, extra map[string]any) string
- func PluginFixture(t *testing.T, name string) string
- func Registry(updated time.Time, plugins ...map[string]any) map[string]any
- func ServeMCPIfChild()
- func ServeNativeIfChild()
- type Call
- type Env
- func (e *Env) AddAccount(t *testing.T, email string) core.Account
- func (e *Env) Deliver(t *testing.T, accountID int64, folder string, raw []byte)
- func (e *Env) EgressHits() int
- func (e *Env) Endpoints(accountID int64) (imapHost string, imapPort int, smtpHost string, smtpPort int)
- func (e *Env) IMAP(accountID int64) *IMAP
- func (e *Env) InstallPlugin(t *testing.T, name string)
- func (e *Env) LLM(t *testing.T) *LLM
- func (e *Env) SMTP(accountID int64) *SMTP
- func (e *Env) Sent(accountID int64) [][]byte
- func (e *Env) StartServers(t *testing.T) (imapHost string, imapPort int, smtpHost string, smtpPort int, ...)
- type IMAP
- type LLM
- type MsgOption
- type Option
- type RegistryServer
- func (r *RegistryServer) NativeRelease(t *testing.T, name, version string, extra map[string]any) map[string]any
- func (r *RegistryServer) Publish(t *testing.T, reg map[string]any)
- func (r *RegistryServer) ScriptRelease(name, version, perms, code string) map[string]any
- func (r *RegistryServer) Serve(path string, body []byte)
- func (r *RegistryServer) Tamper(fn func([]byte) []byte)
- func (r *RegistryServer) URL(path string) string
- type Request
- type SMTP
- type Turn
Constants ¶
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".
const NativeChildEnv = "GODWIT_CORETEST_NATIVE"
NativeChildEnv makes the test binary a fake plugin-host (ServeNativeIfChild); a Service gets it with SetNativeHostForTest(NativeChildEnv + "=1").
Variables ¶
This section is empty.
Functions ¶
func MCPCommand ¶
MCPCommand is a stdio MCP server command: the test binary itself, whose TestMain must call ServeMCPIfChild.
func Msg ¶
Msg builds a raw message. Without MessageID it gets a random one; without Date, the current time.
func NativePluginFixture ¶ added in v1.2.0
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 ¶
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 Registry ¶ added in v1.2.0
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 Env ¶
Env is a running Service with the fake servers behind it.
func (*Env) AddAccount ¶
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) EgressHits ¶
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) InstallPlugin ¶
InstallPlugin installs the fixture plugin name, grants its permissions and enables it.
func (*Env) LLM ¶
LLM registers a fake model service "test" with model "m1" and makes "test/m1" the default model.
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 LLM ¶
type LLM struct {
// contains filtered or unexported fields
}
LLM is a fake OpenAI-compatible model service.
func (*LLM) RequestLog ¶
RequestLog returns every chat request the service got, raw.
type Option ¶
type Option func(*config)
func WithRegistry ¶ added in v1.2.0
func WithRegistry(src *core.RegistrySource) Option
WithRegistry gives the Service a plugin registry, as from NewRegistryServer.
func WithoutAutoSync ¶
func WithoutAutoSync() Option
WithoutAutoSync starts no background sync; Deliver still syncs.
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) 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.