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

memorytest

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	SessionUserID     = "00000000-0000-7000-8000-000000000001"
	ProfileUserID     = "00000000-0000-7000-8000-000000000002"
	NonexistentUserID = "00000000-0000-7000-8000-000000000999"
)

Fixed valid-uuid ids the suite operates on (user_id columns are PostgreSQL uuid). A Provider backed by a real database must seed auth_user rows for SessionUserID and ProfileUserID before RunConformance; NonexistentUserID is deliberately never seeded, so lookups against it return empty, not an error.

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 string, agentID string, text string) ([]memory.ConstraintEntry, error)

AddConstraint implements memory.ConstraintStore.

func (*Fake) AddFact added in v0.60.0

func (f *Fake) AddFact(userID string, agentID string, fact memory.Fact)

AddFact is a test helper to populate active facts.

func (*Fake) AddProfileEntry added in v0.42.0

func (f *Fake) AddProfileEntry(userID, agentID string, entry memory.ProfileEntry)

AddProfileEntry is a test helper to populate profile entries.

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 string, 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) FailRotation added in v0.61.0

func (f *Fake) FailRotation(err error)

FailRotation makes the next RotateInfo calls fail with err, so callers can prove a rotation failure leaves the predecessor untouched.

func (*Fake) GetAgentSoul

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

GetAgentSoul implements memory.ProfileStore.

func (*Fake) GetAgentSoulAt

func (f *Fake) GetAgentSoulAt(_ context.Context, userID string, 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 string, agentID string) ([]memory.ConstraintEntry, error)

GetConstraints implements memory.ConstraintStore.

func (*Fake) GetConstraintsAt

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

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

func (*Fake) GetGroupMemory added in v0.42.0

func (f *Fake) GetGroupMemory(_ context.Context, groupID string) (string, error)

GetGroupMemory implements memory.GroupMemoryStore.

func (*Fake) GetOrCreateSessionSnapshot

func (f *Fake) GetOrCreateSessionSnapshot(_ context.Context, sessionID string, userID string, 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 string, agentID string) (string, error)

GetProfile implements memory.ProfileStore.

func (*Fake) GetProfileAt

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

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

func (*Fake) GetProfileEntries added in v0.42.0

func (f *Fake) GetProfileEntries(_ context.Context, userID string, agentID string) ([]memory.ProfileEntry, error)

GetProfileEntries implements memory.ProfileEntryStore.

func (*Fake) ListActiveFacts added in v0.60.0

func (f *Fake) ListActiveFacts(_ context.Context, userID string, agentID string, subject memory.FactSubject) ([]memory.Fact, error)

ListActiveFacts implements memory.FactStore.

func (*Fake) ListActiveFactsAt added in v0.60.0

func (f *Fake) ListActiveFactsAt(_ context.Context, userID string, agentID string, subject memory.FactSubject, _ int64) ([]memory.Fact, error)

ListActiveFactsAt implements memory.VersionedFactStore. The fake ignores version and returns the current facts, which is sufficient for prompt unit tests that only need the interface shape.

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) MarkSessionTurnCompleted added in v0.63.0

func (f *Fake) MarkSessionTurnCompleted(_ context.Context, session memory.Session, result memory.SessionTurnResult) (bool, error)

MarkSessionTurnCompleted implements memory.SessionActivityStore.

func (*Fake) MarkSessionTurnStarted added in v0.63.0

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

MarkSessionTurnStarted implements memory.SessionActivityStore.

func (*Fake) MarkSessionViewed added in v0.63.0

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

MarkSessionViewed implements memory.SessionActivityStore.

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 string, 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) ReadChangelogPage added in v0.60.0

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

ReadChangelogPage implements stable keyset pagination for server tests.

func (*Fake) RemoveConstraint

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

RemoveConstraint implements memory.ConstraintStore.

func (*Fake) RotateInfo added in v0.61.0

func (f *Fake) RotateInfo(_ context.Context, expectedSessionID string, successor memory.SessionInfo) error

RotateInfo implements memory.SessionManager. The mutex stands in for the real provider's transaction: the archive and the successor become visible together.

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 string, agentID string, content string) error

SetAgentSoul implements memory.ProfileStore.

func (*Fake) SetGroupMemory added in v0.42.0

func (f *Fake) SetGroupMemory(groupID, content string)

SetGroupMemory is a test helper to populate group memory.

func (*Fake) SetProfile

func (f *Fake) SetProfile(_ context.Context, userID string, 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) TouchActiveInfo added in v0.61.0

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

TouchActiveInfo implements memory.SessionManager. The mutex stands in for the real provider's single guarded UPDATE: an archived (or missing) row is never written and never resurrected.

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