testsupport

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testsupport provides the chat-store fakes that more than one sibling package's TEST binary needs, plus the contract suites those packages run against both a fake and the real implementation.

Membership rule: a double belongs here only while at least two packages consume it. A double with a single consumer moves into that package's own _test.go, sized to that package's contract rather than the widest one going.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ACPSessionPreOpenContractTest added in v0.15.0

func ACPSessionPreOpenContractTest(t *testing.T, newSession func() ACPPreOpenSession)

ACPSessionPreOpenContractTest verifies what any ACP session handle must satisfy before its door succeeded, without a real kiro-cli. Run against the real Session and the fakes. It lives here so no production package imports "testing".

func ChatStoreContractTest

func ChatStoreContractTest(t *testing.T, newStore func(t *testing.T) ChatStoreContract)

ChatStoreContractTest exercises the behaviour any chat store must hold, against fakes and the real store; each behaviour is its own helper.

func MCPConfigContractTest

func MCPConfigContractTest(t *testing.T, newConfig func(t *testing.T) MCPNameSets)

MCPConfigContractTest exercises the behavioral expectations any MCP name-census implementation must meet. Run against both fakes and the real store to catch drift.

Types

type ACPPreOpenSession added in v0.15.0

type ACPPreOpenSession interface {
	NotifCh() <-chan marotte.Notification
	Open() bool
	CurrentMode() string
	Modes() []marotte.SessionMode
	Models() []marotte.SessionModel
}

ACPPreOpenSession is the subject of ACPSessionPreOpenContractTest: the session methods this suite reads.

type ChatStoreContract

type ChatStoreContract interface {
	Get(ctx context.Context, id marotte.ChatID) (*marotte.Chat, bool)
	List(ctx context.Context) []marotte.ChatHeader
	Mutate(ctx context.Context, id marotte.ChatID, mutate func(c *marotte.Chat, exists bool) bool) (string, error)
	Delete(ctx context.Context, id marotte.ChatID) (sessionChain []string, err error)
	SetDraft(ctx context.Context, id marotte.ChatID, text string) (*marotte.ComposerState, error)
}

ChatStoreContract is the subject of ChatStoreContractTest: the 5 HEADER methods this suite exercises. Log operations are the real store's alone; the fakes hold headers only. SetDraft is here for its version contract only.

type InMemoryChatStore

type InMemoryChatStore struct {
	// Bus is the fan-out lifecycle events go to; see RecordingChatStore.Bus
	// for why the type is spelled out rather than named.
	Bus interface {
		Broadcast(ctx context.Context, evt marotte.ServerEvent)
	}
	// contains filtered or unexported fields
}

InMemoryChatStore is an in-memory chat store with real Mutate/Get semantics and an optional Bus for lifecycle events.

func NewInMemoryChatStore

func NewInMemoryChatStore() *InMemoryChatStore

NewInMemoryChatStore returns a ready-to-use InMemoryChatStore.

func (*InMemoryChatStore) AwaitsRunName added in v0.16.0

AwaitsRunName answers false.

func (*InMemoryChatStore) Delete

func (s *InMemoryChatStore) Delete(_ context.Context, id marotte.ChatID) ([]string, error)

Delete removes the chat with the given id, broadcasts a chat_deleted event and answers the removed record's session chain.

func (*InMemoryChatStore) DepartedName added in v0.12.0

func (*InMemoryChatStore) DepartedName(marotte.ChatID) (string, bool)

DepartedName answers false: neither fake keeps a tombstone.

func (*InMemoryChatStore) EmptyCompactions

func (*InMemoryChatStore) EmptyCompactions(context.Context, marotte.ChatID) (int, error)

EmptyCompactions answers zero.

func (*InMemoryChatStore) Get

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) Lookup added in v0.15.0

Lookup is Get with the store's error arm; an in-memory record is never unreadable.

func (*InMemoryChatStore) Mutate

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

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

func (*InMemoryChatStore) PromptAttachmentPaths

func (*InMemoryChatStore) PromptAttachmentPaths(context.Context, marotte.ChatID, string) ([]string, error)

PromptAttachmentPaths answers no paths.

func (*InMemoryChatStore) PromptReceipt added in v0.13.0

PromptReceipt answers a prompt the log never held.

func (*InMemoryChatStore) PromptTexts

PromptTexts answers no prompts.

func (*InMemoryChatStore) ReadBound added in v0.15.0

ReadBound answers 0: this store holds no log, so no read position.

func (*InMemoryChatStore) Revert

func (*InMemoryChatStore) Revert(_ context.Context, id marotte.ChatID, turn, _ string) (record *marotte.Entry, minted []*marotte.Entry, err error)

Revert refuses: an empty log holds no turn to revert to.

func (*InMemoryChatStore) RewindTarget

RewindTarget answers no prompt.

func (*InMemoryChatStore) SetAttachments

func (s *InMemoryChatStore) SetAttachments(_ context.Context, id marotte.ChatID, paths []string) (*marotte.ComposerState, error)

SetAttachments stores the paths staged beside the draft under the same contract: no UpdatedAt, no broadcast, no-op on an absent chat.

func (*InMemoryChatStore) SetDraft

SetDraft stores the chat's draft without touching UpdatedAt and without broadcasting (see (*chat.Store).SetDraft). A no-op on an absent chat; reports the state that landed, or nil.

func (*InMemoryChatStore) TurnCount

func (s *InMemoryChatStore) TurnCount(ctx context.Context, id marotte.ChatID) (uint64, bool)

TurnCount is the header's turn_count, as the real store reads it.

func (*InMemoryChatStore) UnsettledWorkflowMessages added in v0.15.0

func (*InMemoryChatStore) UnsettledWorkflowMessages(context.Context, marotte.ChatID) ([]marotte.WorkflowMessage, error)

UnsettledWorkflowMessages answers none.

func (*InMemoryChatStore) WakeCauses added in v0.16.0

WakeCauses answers none.

type MCPNameSets

type MCPNameSets interface {
	EnabledNames(ctx context.Context) map[string]struct{}
	ConfiguredNames(ctx context.Context) map[string]struct{}
}

MCPNameSets is the UNION of what the MCP name-census consumers declare; a consumer growing a set must add it here, or the suite goes silent on it.

type RecordingChatStore

type RecordingChatStore struct {
	// Bus is the fan-out lifecycle events go to: the union of internal/chat's and
	// internal/forges' 1-method broadcasters.
	Bus interface {
		Broadcast(ctx context.Context, evt marotte.ServerEvent)
	}
	Chats map[marotte.ChatID]*marotte.Chat

	// Gets counts Get calls, for a test whose subject is how OFTEN the store is read.
	Gets atomic.Int64
	// contains filtered or unexported fields
}

RecordingChatStore is an in-memory chat store that keeps 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) AwaitsRunName added in v0.16.0

AwaitsRunName answers false.

func (*RecordingChatStore) ChatVersion

func (s *RecordingChatStore) ChatVersion(id marotte.ChatID) string

ChatVersion is the `chat` version the last write to id minted, "" before any write. A test that needs to know which version a frame SHOULD carry reads it here rather than re-deriving the fake's counter.

func (*RecordingChatStore) Delete

Delete removes the chat with the given id, broadcasts a chat_deleted event and answers the removed record's session chain.

func (*RecordingChatStore) DepartedName added in v0.12.0

func (*RecordingChatStore) DepartedName(marotte.ChatID) (string, bool)

DepartedName answers false: neither fake keeps a tombstone.

func (*RecordingChatStore) EmptyCompactions

func (*RecordingChatStore) EmptyCompactions(context.Context, marotte.ChatID) (int, error)

EmptyCompactions answers zero.

func (*RecordingChatStore) Exists

func (s *RecordingChatStore) Exists(id marotte.ChatID) bool

Exists reports whether the fake holds id.

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) Mutate

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

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

func (*RecordingChatStore) PromptTexts

PromptTexts answers no prompts.

func (*RecordingChatStore) SetAttachments

func (s *RecordingChatStore) SetAttachments(_ context.Context, id marotte.ChatID, paths []string) (*marotte.ComposerState, error)

SetAttachments stores the chat's staged attachment paths under the same contract SetDraft holds: no UpdatedAt, no broadcast, no-op on an absent chat.

func (*RecordingChatStore) SetDraft

SetDraft stores the chat's draft without touching UpdatedAt and without broadcasting, as (*chat.Store).SetDraft does. A no-op on an absent chat; it reports the state that landed, nil for nothing.

func (*RecordingChatStore) UnsettledWorkflowMessages added in v0.15.0

func (*RecordingChatStore) UnsettledWorkflowMessages(context.Context, marotte.ChatID) ([]marotte.WorkflowMessage, error)

UnsettledWorkflowMessages answers none.

func (*RecordingChatStore) WakeCauses added in v0.16.0

WakeCauses answers none.

Jump to

Keyboard shortcuts

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