testsupport

package
v0.2.49 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: GPL-2.0, GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testsupport provides shared test fakes for interfaces defined in the api package. These are intended for use across multiple test packages to avoid duplicating interface implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ACPBridgeContractTest

func ACPBridgeContractTest(t *testing.T, b api.ACPBridge)

ACPBridgeContractTest verifies that an api.ACPBridge implementation satisfies the basic contract: Start/Stop don't panic, NotifCh is non-nil or nil consistently, and Stop is idempotent.

func ChatStoreContractTest

func ChatStoreContractTest(t *testing.T, newStore func(t *testing.T) api.ChatStore)

ChatStoreContractTest exercises the behavioral expectations of any api.ChatStore implementation. Run against both fakes and real implementations to catch drift. Each behavior lives in its own helper so the suite stays flat; this is the dispatcher.

func MCPConfigContractTest

func MCPConfigContractTest(t *testing.T, newConfig func(t *testing.T) api.MCPConfig)

MCPConfigContractTest exercises the behavioral expectations of any api.MCPConfig implementation. Run against both fakes and real implementations to catch drift.

Types

type CaptureBroadcaster

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

CaptureBroadcaster is a thread-safe event capture implementing api.Broadcaster.

func (*CaptureBroadcaster) Broadcast

func (c *CaptureBroadcaster) Broadcast(_ context.Context, e api.ServerEvent)

Broadcast captures the event.

func (*CaptureBroadcaster) Reset

func (c *CaptureBroadcaster) Reset()

Reset clears all captured events.

func (*CaptureBroadcaster) Snapshot

func (c *CaptureBroadcaster) Snapshot() []api.ServerEvent

Snapshot returns a copy of all captured events.

type InMemoryChatStore

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

InMemoryChatStore is a functional in-memory api.ChatStore with broadcast support. Suitable for integration-style tests that need real Mutate/Get semantics without filesystem I/O.

func NewInMemoryChatStore

func NewInMemoryChatStore() *InMemoryChatStore

NewInMemoryChatStore returns a ready-to-use InMemoryChatStore.

func (*InMemoryChatStore) AppendMessage

func (s *InMemoryChatStore) AppendMessage(_ context.Context, chatID api.ChatID, msg *api.Message) error

AppendMessage appends a message to the stored chat and broadcasts message_appended.

func (*InMemoryChatStore) Archive

func (s *InMemoryChatStore) Archive(_ context.Context, id api.ChatID) error

Archive removes the chat; delegates to Delete for test simplicity.

func (*InMemoryChatStore) BuildHistory

func (s *InMemoryChatStore) BuildHistory(_ context.Context, id api.ChatID) string

BuildHistory returns the plain-text transcript for the chat with the given id.

func (*InMemoryChatStore) ChildrenOf

func (s *InMemoryChatStore) ChildrenOf(_ context.Context, parentID api.ChatID) []api.ChatID

ChildrenOf returns the IDs of chats whose ParentChatID equals parentID.

func (*InMemoryChatStore) Delete

func (s *InMemoryChatStore) Delete(_ context.Context, id api.ChatID) error

Delete removes the chat with the given id and broadcasts a chat_deleted event.

func (*InMemoryChatStore) DeleteArchived

func (s *InMemoryChatStore) DeleteArchived(_ context.Context, _ api.ChatID) error

DeleteArchived is a no-op; implements api.ChatStore.

func (*InMemoryChatStore) DeleteFamily added in v0.2.8

func (s *InMemoryChatStore) DeleteFamily(ctx context.Context, parentID api.ChatID, prepare func(api.ChatID)) ([]api.ChatID, error)

DeleteFamily removes children first, then the parent, mirroring the real store's ordering contract; implements api.ChatStore.

func (*InMemoryChatStore) Get

func (s *InMemoryChatStore) Get(_ context.Context, id api.ChatID) (*api.Chat, bool)

Get returns a copy of the stored chat for id, or (nil, false) if not found.

func (*InMemoryChatStore) List

List returns headers for all stored chats.

func (*InMemoryChatStore) ListArchived

func (s *InMemoryChatStore) ListArchived(_ context.Context) []api.ChatHeader

ListArchived returns nil; implements api.ChatStore.

func (*InMemoryChatStore) LoadArchived

func (s *InMemoryChatStore) LoadArchived(_ context.Context, _ api.ChatID) (*api.Chat, error)

LoadArchived returns (nil, nil); implements api.ChatStore.

func (*InMemoryChatStore) Mutate

func (s *InMemoryChatStore) Mutate(_ context.Context, id api.ChatID, mutate func(*api.Chat, bool) bool) error

Mutate applies the mutate function to the chat with the given id, creating it if needed.

func (*InMemoryChatStore) PromoteRewind added in v0.2.8

func (s *InMemoryChatStore) PromoteRewind(ctx context.Context, childID api.ChatID) (api.ChatID, error)

PromoteRewind clears the rewind linkage under one Mutate, mirroring the real store's contract; implements api.ChatStore.

func (*InMemoryChatStore) RegisterRoutes

func (s *InMemoryChatStore) RegisterRoutes(_ *http.ServeMux)

RegisterRoutes is a no-op; implements api.ChatStore.

func (*InMemoryChatStore) RestoreArchived

func (s *InMemoryChatStore) RestoreArchived(_ context.Context, _ api.ChatID) error

RestoreArchived is a no-op; implements api.ChatStore.

func (*InMemoryChatStore) SetBroadcaster

func (s *InMemoryChatStore) SetBroadcaster(b api.Broadcaster)

SetBroadcaster sets the broadcaster used to fan out chat lifecycle events.

func (*InMemoryChatStore) UpdateArchivedSummary

func (s *InMemoryChatStore) UpdateArchivedSummary(_ context.Context, _ api.ChatID, _ string) error

UpdateArchivedSummary is a no-op; implements api.ChatStore.

func (*InMemoryChatStore) UpdateMessage

func (s *InMemoryChatStore) UpdateMessage(_ context.Context, chatID api.ChatID, msgID string, mutate func(*api.Message)) error

UpdateMessage applies mutate to the message identified by msgID within the stored chat.

type NopACPBridge

type NopACPBridge struct{}

NopACPBridge is a minimal no-op implementation of api.ACPBridge for benchmarks and tests that need a bridge but don't care about its behavior. All methods return zero values.

func (*NopACPBridge) Call

Call is a no-op; implements api.ACPBridge.

func (*NopACPBridge) CurrentMode

func (*NopACPBridge) CurrentMode() string

CurrentMode returns an empty mode string; implements api.ACPBridge.

func (*NopACPBridge) ModelID

func (*NopACPBridge) ModelID() api.ModelID

ModelID returns an empty model ID; implements api.ACPBridge.

func (*NopACPBridge) Models

func (*NopACPBridge) Models() []api.SessionModel

Models returns nil; implements api.ACPBridge.

func (*NopACPBridge) Modes

func (*NopACPBridge) Modes() []api.SessionMode

Modes returns nil; implements api.ACPBridge.

func (*NopACPBridge) NotifCh

func (*NopACPBridge) NotifCh() <-chan *api.RPCResponse

NotifCh returns nil; implements api.ACPBridge.

func (*NopACPBridge) Notify

Notify is a no-op; implements api.ACPBridge.

func (*NopACPBridge) Respond

Respond is a no-op; implements api.ACPBridge.

func (*NopACPBridge) SessionID

func (*NopACPBridge) SessionID() api.SessionID

SessionID returns an empty session ID; implements api.ACPBridge.

func (*NopACPBridge) SetModel

func (*NopACPBridge) SetModel(context.Context, string) error

SetModel is a no-op; implements api.ACPBridge.

func (*NopACPBridge) Start

Start is a no-op; implements api.ACPBridge.

func (*NopACPBridge) Stop

func (*NopACPBridge) Stop()

Stop is a no-op; implements api.ACPBridge.

type NopBroadcaster

type NopBroadcaster struct{}

NopBroadcaster is a zero-alloc no-op satisfying api.Broadcaster.

func (NopBroadcaster) Broadcast

func (NopBroadcaster) Broadcast(_ context.Context, _ api.ServerEvent)

Broadcast is a no-op.

type NopChatStore

type NopChatStore struct{}

NopChatStore is a no-op api.ChatStore implementation for benchmarks. Every method returns zero/nil.

func (NopChatStore) AppendMessage

func (NopChatStore) AppendMessage(context.Context, api.ChatID, *api.Message) error

AppendMessage is a no-op; implements api.ChatStore.

func (NopChatStore) Archive

Archive is a no-op; implements api.ChatStore.

func (NopChatStore) BuildHistory

func (NopChatStore) BuildHistory(context.Context, api.ChatID) string

BuildHistory returns an empty string; implements api.ChatStore.

func (NopChatStore) ChildrenOf

func (NopChatStore) ChildrenOf(context.Context, api.ChatID) []api.ChatID

ChildrenOf returns nil; implements api.ChatStore.

func (NopChatStore) Delete

Delete is a no-op; implements api.ChatStore.

func (NopChatStore) DeleteArchived

func (NopChatStore) DeleteArchived(context.Context, api.ChatID) error

DeleteArchived is a no-op; implements api.ChatStore.

func (NopChatStore) DeleteFamily added in v0.2.8

func (NopChatStore) DeleteFamily(context.Context, api.ChatID, func(api.ChatID)) ([]api.ChatID, error)

DeleteFamily is a no-op; implements api.ChatStore.

func (NopChatStore) Get

Get returns (nil, false); implements api.ChatStore.

func (NopChatStore) List

List returns nil; implements api.ChatStore.

func (NopChatStore) ListArchived

func (NopChatStore) ListArchived(context.Context) []api.ChatHeader

ListArchived returns nil; implements api.ChatStore.

func (NopChatStore) LoadArchived

func (NopChatStore) LoadArchived(context.Context, api.ChatID) (*api.Chat, error)

LoadArchived returns (nil, nil); implements api.ChatStore.

func (NopChatStore) Mutate

Mutate is a no-op; implements api.ChatStore.

func (NopChatStore) PromoteRewind added in v0.2.8

func (NopChatStore) PromoteRewind(context.Context, api.ChatID) (api.ChatID, error)

PromoteRewind returns ErrChatNotFound; implements api.ChatStore.

func (NopChatStore) RegisterRoutes

func (NopChatStore) RegisterRoutes(*http.ServeMux)

RegisterRoutes is a no-op; implements api.ChatStore.

func (NopChatStore) RestoreArchived

func (NopChatStore) RestoreArchived(context.Context, api.ChatID) error

RestoreArchived is a no-op; implements api.ChatStore.

func (NopChatStore) SetBroadcaster

func (NopChatStore) SetBroadcaster(api.Broadcaster)

SetBroadcaster is a no-op; implements api.ChatStore.

func (NopChatStore) UpdateArchivedSummary

func (NopChatStore) UpdateArchivedSummary(context.Context, api.ChatID, string) error

UpdateArchivedSummary is a no-op; implements api.ChatStore.

func (NopChatStore) UpdateMessage

func (NopChatStore) UpdateMessage(context.Context, api.ChatID, string, func(*api.Message)) error

UpdateMessage is a no-op; implements api.ChatStore.

type NopMCPRecorder

type NopMCPRecorder struct{}

NopMCPRecorder is a no-op implementation of translate.MCPRecorder for tests and benchmarks. The compile-time assertion lives in mcprecorder_test.go to avoid a circular import (translate imports testsupport in its test files).

func (*NopMCPRecorder) RecordConnected

RecordConnected is a no-op; implements translate.MCPRecorder.

func (*NopMCPRecorder) RecordInitFailure

func (*NopMCPRecorder) RecordInitFailure(context.Context, string, string)

RecordInitFailure is a no-op; implements translate.MCPRecorder.

func (*NopMCPRecorder) RecordOAuth

func (*NopMCPRecorder) RecordOAuth(context.Context, string, string)

RecordOAuth is a no-op; implements translate.MCPRecorder.

func (*NopMCPRecorder) SetKnownTools

func (*NopMCPRecorder) SetKnownTools(context.Context, string, []string)

SetKnownTools is a no-op; implements translate.MCPRecorder.

func (*NopMCPRecorder) SignalReady

func (*NopMCPRecorder) SignalReady()

SignalReady is a no-op; implements translate.MCPRecorder.

type RecordingChatStore

type RecordingChatStore struct {
	Bus   api.Broadcaster
	Chats map[api.ChatID]*api.Chat
	// contains filtered or unexported fields
}

RecordingChatStore is an in-memory api.ChatStore that stores chats in a map and fires broadcasts via an attached Broadcaster. Suitable for integration-style tests that need a ChatStore that actually stores things.

func NewRecordingChatStore

func NewRecordingChatStore() *RecordingChatStore

NewRecordingChatStore returns a ready-to-use RecordingChatStore.

func (*RecordingChatStore) AppendMessage

func (s *RecordingChatStore) AppendMessage(_ context.Context, chatID api.ChatID, msg *api.Message) error

AppendMessage appends a message to the stored chat and broadcasts message_appended.

func (*RecordingChatStore) Archive

func (s *RecordingChatStore) Archive(_ context.Context, id api.ChatID) error

Archive removes the chat; delegates to Delete for test simplicity.

func (*RecordingChatStore) BuildHistory

func (s *RecordingChatStore) BuildHistory(_ context.Context, id api.ChatID) string

BuildHistory returns the plain-text transcript for the chat with the given id.

func (*RecordingChatStore) ChildrenOf

func (s *RecordingChatStore) ChildrenOf(_ context.Context, parentID api.ChatID) []api.ChatID

ChildrenOf returns the IDs of chats whose ParentChatID equals parentID.

func (*RecordingChatStore) Delete

func (s *RecordingChatStore) Delete(_ context.Context, id api.ChatID) error

Delete removes the chat with the given id and broadcasts a chat_deleted event.

func (*RecordingChatStore) DeleteArchived

func (s *RecordingChatStore) DeleteArchived(_ context.Context, _ api.ChatID) error

DeleteArchived is a no-op; implements api.ChatStore.

func (*RecordingChatStore) DeleteFamily added in v0.2.8

func (s *RecordingChatStore) DeleteFamily(ctx context.Context, parentID api.ChatID, prepare func(api.ChatID)) ([]api.ChatID, error)

DeleteFamily removes children first, then the parent, mirroring the real store's ordering contract; implements api.ChatStore.

func (*RecordingChatStore) Get

Get returns a copy of the stored chat for id, or (nil, false) if not found.

func (*RecordingChatStore) List

List returns headers for all stored chats.

func (*RecordingChatStore) ListArchived

func (s *RecordingChatStore) ListArchived(_ context.Context) []api.ChatHeader

ListArchived returns nil; implements api.ChatStore.

func (*RecordingChatStore) LoadArchived

func (s *RecordingChatStore) LoadArchived(_ context.Context, _ api.ChatID) (*api.Chat, error)

LoadArchived returns (nil, nil); implements api.ChatStore.

func (*RecordingChatStore) Mutate

func (s *RecordingChatStore) Mutate(_ context.Context, id api.ChatID, mutate func(*api.Chat, bool) bool) error

Mutate applies the mutate function to the chat with the given id, creating it if needed.

func (*RecordingChatStore) PromoteRewind added in v0.2.8

func (s *RecordingChatStore) PromoteRewind(ctx context.Context, childID api.ChatID) (api.ChatID, error)

PromoteRewind clears the rewind linkage under one Mutate, mirroring the real store's contract; implements api.ChatStore.

func (*RecordingChatStore) RegisterRoutes

func (s *RecordingChatStore) RegisterRoutes(_ *http.ServeMux)

RegisterRoutes is a no-op; implements api.ChatStore.

func (*RecordingChatStore) RestoreArchived

func (s *RecordingChatStore) RestoreArchived(_ context.Context, _ api.ChatID) error

RestoreArchived is a no-op; implements api.ChatStore.

func (*RecordingChatStore) SetBroadcaster

func (s *RecordingChatStore) SetBroadcaster(b api.Broadcaster)

SetBroadcaster sets the broadcaster used to fan out chat lifecycle events.

func (*RecordingChatStore) UpdateArchivedSummary

func (s *RecordingChatStore) UpdateArchivedSummary(_ context.Context, _ api.ChatID, _ string) error

UpdateArchivedSummary is a no-op; implements api.ChatStore.

func (*RecordingChatStore) UpdateMessage

func (s *RecordingChatStore) UpdateMessage(_ context.Context, chatID api.ChatID, msgID string, mutate func(*api.Message)) error

UpdateMessage applies mutate to the message identified by msgID within the stored chat.

Jump to

Keyboard shortcuts

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