exttesting

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package exttesting provides in-process test utilities for Productize extension authors.

TestHarness simulates the host side of the extension subprocess protocol, letting authors exercise their extension logic without a running Productize instance. MockTransport provides connected in-memory transport pairs for unit tests that operate at the message level.

Quick start

harness := exttesting.NewTestHarness(exttesting.HarnessOptions{
	GrantedCapabilities: []extension.Capability{extension.CapabilityRunMutate},
})
ext := extension.New("my-ext", "0.1.0").
	OnRunPostShutdown(func(
		ctx context.Context,
		hook extension.HookContext,
		payload extension.RunPostShutdownPayload,
	) error {
		return nil
	})
errCh := harness.Run(context.Background(), ext)
resp, _ := harness.Initialize(ctx, extension.InitializeRequestIdentity{
	Name: "my-ext", Version: "0.1.0", Source: "workspace",
})
_ = harness.Shutdown(ctx, extension.ShutdownRequest{Reason: "test"})
<-errCh

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockTransportPair

func NewMockTransportPair() (*MockTransport, *MockTransport)

NewMockTransportPair creates a connected in-memory transport pair.

func NewMockTransportPairWithBuffer

func NewMockTransportPairWithBuffer(buffer int) (*MockTransport, *MockTransport)

NewMockTransportPairWithBuffer creates a connected in-memory transport pair with the provided per-link buffer.

func SortedHostCalls

func SortedHostCalls(calls []HostCall) []string

SortedHostCalls returns the recorded Host API methods in lexical order.

Types

type HarnessOptions

type HarnessOptions struct {
	ProtocolVersion           string
	SupportedProtocolVersions []string
	ProductizeVersion         string
	Source                    string
	GrantedCapabilities       []extension.Capability
	Runtime                   extension.InitializeRuntime
}

HarnessOptions configures the host-side initialize request defaults.

type HostCall

type HostCall struct {
	Method string
	Params json.RawMessage
}

HostCall records one Host API request emitted by the extension.

type HostHandler

type HostHandler func(context.Context, json.RawMessage) (any, error)

HostHandler serves one Host API method inside the test harness.

type MockTransport

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

MockTransport is an in-memory message transport used by SDK tests.

func (*MockTransport) Close

func (m *MockTransport) Close() error

Close closes this transport endpoint.

func (*MockTransport) ReadMessage

func (m *MockTransport) ReadMessage() (extension.Message, error)

ReadMessage reads one queued message.

func (*MockTransport) Receive

func (m *MockTransport) Receive(ctx context.Context) (extension.Message, error)

Receive reads one queued message with context cancellation.

func (*MockTransport) Send

func (m *MockTransport) Send(ctx context.Context, message extension.Message) error

Send enqueues one message with context cancellation.

func (*MockTransport) WriteMessage

func (m *MockTransport) WriteMessage(message extension.Message) error

WriteMessage enqueues one message for the peer transport.

type TestHarness

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

TestHarness simulates the Productize host for in-process SDK tests.

func NewTestHarness

func NewTestHarness(options HarnessOptions) *TestHarness

NewTestHarness constructs a new in-process host harness.

func (*TestHarness) DispatchHook

func (h *TestHarness) DispatchHook(
	ctx context.Context,
	invocationID string,
	hook extension.HookInfo,
	payload any,
) (*extension.ExecuteHookResponse, error)

DispatchHook issues one execute_hook request against the running extension.

func (*TestHarness) HandleHostMethod

func (h *TestHarness) HandleHostMethod(method string, handler HostHandler)

HandleHostMethod registers a Host API method handler.

func (*TestHarness) HealthCheck

HealthCheck issues one health_check request against the running extension.

func (*TestHarness) HostCalls

func (h *TestHarness) HostCalls() []HostCall

HostCalls returns the Host API calls emitted by the extension so far.

func (*TestHarness) Initialize

Initialize performs the host-initiated initialize handshake.

func (*TestHarness) Run

func (h *TestHarness) Run(ctx context.Context, ext *extension.Extension) <-chan error

Run starts the extension against the harness transport.

func (*TestHarness) SendEvent

func (h *TestHarness) SendEvent(ctx context.Context, event events.Event) error

SendEvent issues one on_event request against the running extension.

func (*TestHarness) Shutdown

Shutdown issues one shutdown request against the running extension.

func (*TestHarness) Transport

func (h *TestHarness) Transport() extension.Transport

Transport returns the extension-side transport to pass into the SDK.

Jump to

Keyboard shortcuts

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