Help us shape the future of Go! Take the 2026 Go Developer Survey

memorytest

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 11 Imported by: 0

Documentation

Overview

Package memorytest provides test doubles and conformance testing for memory.Provider implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunConformance

func RunConformance(t *testing.T, provider memory.Provider)

RunConformance runs the standard conformance suite against any Provider. It tests: Bootstrap idempotency, Append ordering, Assemble budget/freshTail, Stats accuracy, and any optional capabilities detected via type assertion.

Types

type Fake

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

Fake is an in-memory Provider that implements all optional capability interfaces. Use it in unit tests to avoid database setup.

func New

func New() *Fake

New creates a new Fake provider ready for use.

func (*Fake) AddConstraint

func (f *Fake) AddConstraint(_ context.Context, userID int64, agentID string, text string) ([]memory.ConstraintEntry, error)

AddConstraint implements memory.ConstraintStore.

func (*Fake) AddSummary

func (f *Fake) AddSummary(s FakeSummary)

AddSummary adds a fake summary for testing Explorer capability.

func (*Fake) AdvanceSessionSnapshot

func (f *Fake) AdvanceSessionSnapshot(_ context.Context, sessionID string, userID int64, agentID string) error

AdvanceSessionSnapshot implements memory.SessionSnapshotStore. Updates the snapshot version to match the number of changelog entries.

func (*Fake) Append

func (f *Fake) Append(_ context.Context, session memory.Session, msgs ...ai.Message) error

Append implements memory.Provider.

func (*Fake) Assemble

func (f *Fake) Assemble(_ context.Context, session memory.Session, budget, freshTail int) ([]ai.Message, error)

Assemble implements memory.Provider.

func (*Fake) Bootstrap

func (f *Fake) Bootstrap(_ context.Context, session memory.Session) error

Bootstrap implements memory.Provider.

func (*Fake) BuildReviewContext

func (f *Fake) BuildReviewContext(_ context.Context, session memory.Session, since time.Time) (string, error)

BuildReviewContext implements memory.Reviewer.

func (*Fake) Changelog

func (f *Fake) Changelog() []memory.ChangeEntry

Changelog returns all recorded changelog entries (in insertion order) for test assertions.

func (*Fake) Close

func (f *Fake) Close() error

Close implements memory.Provider.

func (*Fake) Compact

Compact implements memory.Compactor.

func (*Fake) Describe

func (f *Fake) Describe(_ context.Context, summaryID string) (*memory.DescribeResult, error)

Describe implements memory.Explorer.

func (*Fake) Expand

func (f *Fake) Expand(_ context.Context, summaryID string, _ int) (*memory.ExpandResult, error)

Expand implements memory.Explorer.

func (*Fake) GetAgentSoul

func (f *Fake) GetAgentSoul(_ context.Context, userID int64, agentID string) (string, error)

GetAgentSoul implements memory.ProfileStore.

func (*Fake) GetAgentSoulAt

func (f *Fake) GetAgentSoulAt(_ context.Context, userID int64, agentID string, _ int64) (string, error)

GetAgentSoulAt implements memory.VersionedProfileStore. The fake ignores version and returns the current soul (sufficient for tests).

func (*Fake) GetConstraints

func (f *Fake) GetConstraints(_ context.Context, userID int64, agentID string) ([]memory.ConstraintEntry, error)

GetConstraints implements memory.ConstraintStore.

func (*Fake) GetConstraintsAt

func (f *Fake) GetConstraintsAt(_ context.Context, userID int64, agentID string, _ int64) ([]memory.ConstraintEntry, error)

GetConstraintsAt implements memory.VersionedConstraintStore. The fake ignores version and returns the current constraints (sufficient for tests).

func (*Fake) GetOrCreateSessionSnapshot

func (f *Fake) GetOrCreateSessionSnapshot(_ context.Context, sessionID string, userID int64, agentID string) (memory.SessionSnapshot, error)

GetOrCreateSessionSnapshot implements memory.SessionSnapshotStore. Creates with version 0 when not found (sufficient for tests).

func (*Fake) GetProfile

func (f *Fake) GetProfile(_ context.Context, userID int64, agentID string) (string, error)

GetProfile implements memory.ProfileStore.

func (*Fake) GetProfileAt

func (f *Fake) GetProfileAt(_ context.Context, userID int64, agentID string, _ int64) (string, error)

GetProfileAt implements memory.VersionedProfileStore. The fake ignores version and returns the current profile (sufficient for tests).

func (*Fake) ListInfo

func (f *Fake) ListInfo(_ context.Context, opts memory.ListOptions) ([]memory.SessionInfo, error)

ListInfo implements memory.SessionManager.

func (*Fake) LoadHistory

func (f *Fake) LoadHistory(_ context.Context, sessionID string) ([]ai.Message, error)

LoadHistory implements memory.SessionManager.

func (*Fake) LoadInfo

func (f *Fake) LoadInfo(_ context.Context, sessionID string) (memory.SessionInfo, error)

LoadInfo implements memory.SessionManager.

func (*Fake) Name

func (f *Fake) Name() string

Name implements memory.Provider.

func (*Fake) NeedsCompaction

func (f *Fake) NeedsCompaction(_ context.Context, session memory.Session, threshold float64) bool

NeedsCompaction implements memory.Compactor.

func (*Fake) ReadChangelog

func (f *Fake) ReadChangelog(_ context.Context, userID int64, agentID string, scope string, limit int) ([]memory.ChangeEntry, error)

ReadChangelog implements memory.ChangelogReader. Returns up to limit entries for the given scope in reverse-insertion order.

func (*Fake) RemoveConstraint

func (f *Fake) RemoveConstraint(_ context.Context, userID int64, agentID string, id string) ([]memory.ConstraintEntry, error)

RemoveConstraint implements memory.ConstraintStore.

func (*Fake) SaveInfo

func (f *Fake) SaveInfo(_ context.Context, info memory.SessionInfo) error

SaveInfo implements memory.SessionManager.

func (*Fake) Search

func (f *Fake) Search(_ context.Context, session memory.Session, query memory.SearchQuery) ([]memory.SearchResult, error)

Search implements memory.Searcher.

func (*Fake) SetAgentSoul

func (f *Fake) SetAgentSoul(_ context.Context, userID int64, agentID string, content string) error

SetAgentSoul implements memory.ProfileStore.

func (*Fake) SetProfile

func (f *Fake) SetProfile(_ context.Context, userID int64, agentID string, content string) error

SetProfile implements memory.ProfileStore.

func (*Fake) Snapshots

func (f *Fake) Snapshots() map[string]memory.SessionSnapshot

Snapshots returns all stored snapshots for test assertions.

func (*Fake) Stats

func (f *Fake) Stats(_ context.Context, session memory.Session) (memory.SessionStats, error)

Stats implements memory.Provider.

func (*Fake) WriteChangelog

func (f *Fake) WriteChangelog(_ context.Context, entry memory.ChangeEntry) error

WriteChangelog implements memory.ChangelogWriter.

type FakeSummary

type FakeSummary struct {
	ID              string
	Kind            string // "leaf" or "condensed"
	Depth           int
	Content         string
	EarliestAt      *time.Time
	LatestAt        *time.Time
	DescendantCount int
	ParentIDs       []string
	ChildIDs        []string
	// For leaf: source messages. For condensed: child summaries.
	SourceMessages []memory.ExpandMessage
	ChildSummaries []memory.ExpandChild
}

FakeSummary holds summary data for the Explorer capability.

Jump to

Keyboard shortcuts

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