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

contracttest

package
v0.1.0-preview.17 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package contracttest is shared by the conformance tests and the PostgreSQL tests: where the contract is, how a fixture runs, and how two JSON values are compared.

Index

Constants

View Source
const LessonsFamily = "lessons-view"

LessonsFamily is the lessons-view fixture family's directory name.

Variables

View Source
var (
	Contract   = filepath.Join(Repository, "contract")
	Fixtures   = filepath.Join(Contract, "fixtures")
	Schema     = filepath.Join(Contract, "schema", "experience-record.v1.json")
	Migrations = filepath.Join(Repository, "src", "AgentExperience.Storage.Postgres", "Migrations")
	// VectorMigrations are the vectors package's migrations (contract 1.6), which need the pgvector extension.
	VectorMigrations = filepath.Join(Repository, "src", "AgentExperience.Storage.Postgres.Vectors", "Migrations")
)

Paths into the repository.

View Source
var ErrUnsupportedContractVersion = errors.New("unsupported contract version")

ErrUnsupportedContractVersion is a lock naming a contract version this package does not support.

View Source
var InjectionColumns = []string{"experience_id", "tenant_id", "application_id", "project_id", "team_id", "agent_id",
	"user_id", "last_injected_at", "injection_count"}

InjectionColumns are agent_experience.experience_injections' columns, in the order a seed row holds them.

View Source
var Repository = func() string {
	_, file, _, ok := runtime.Caller(0)
	if !ok {
		panic("contracttest: cannot locate the repository")
	}
	return filepath.Clean(filepath.Join(filepath.Dir(file), "..", "..", ".."))
}()

Repository is the repository's root directory.

Functions

func AsWritten

func AsWritten(value any) any

AsWritten is a value as this package writes it, read back: what is compared is what the package would write.

func Cases

func Cases(family string) []string

Cases are every case directory of a fixture family, by name.

func CheckContractVersion

func CheckContractVersion(lock any) (string, error)

CheckContractVersion is the lock's contract version, when this package supports it; a clear failure otherwise.

func Difference

func Difference(expected, actual any, path string, options Options) string

Difference is the first difference between two JSON values (as ae.DecodeJSON reads them), compared by value; "" when they are equal. Member order is ignored.

func EmbeddingWriteOf

func EmbeddingWriteOf(value any) ae.EmbeddingWrite

EmbeddingWriteOf reads a write step of the embedding-write and vector-search fixtures.

func EvidenceOf

func EvidenceOf(value any) ae.Evidence

EvidenceOf reads one piece of a fixture's evidence.

func HoldoutStepOf

func HoldoutStepOf(record *ae.Object) (ae.Scope, ae.HoldoutAssignment, error)

HoldoutStepOf reads a holdout-record "record" step (or an eraseDuringRecord step's "record"): the scope, which is also the caller's bounds, and the assignment.

func LessonsDifference

func LessonsDifference(c *LessonsCase, page ae.LessonsPage) string

LessonsDifference is the first difference between a case's expected page and the page the port answered; "" when they are equal. Instants compare as instants, a confidence exactly, a block text byte for byte.

func LessonsPageJSON

func LessonsPageJSON(page ae.LessonsPage) *ae.Object

LessonsPageJSON is a page in the fixtures' form.

func MustReadJSON

func MustReadJSON(path string) any

MustReadJSON is ReadJSON, panicking on failure: for fixtures, which are known to exist.

func ParseTimestamptz

func ParseTimestamptz(text string) (ae.Instant, error)

ParseTimestamptz reads PostgreSQL's text form of a timestamptz ("2026-03-02 08:00:00.123456+00").

func ReadJSON

func ReadJSON(path string) (any, error)

ReadJSON reads a JSON file, keeping every number exactly as written and every object's member order.

func RunFinalizeCase

func RunFinalizeCase(input any) (ae.FinalizedExperience, *ae.Object, error)

RunFinalizeCase runs a finalize case's input.json through capture and finalization. It returns the result and what capture answered, in expected-capture.json's form.

func ScopeOf

func ScopeOf(value any) ae.Scope

ScopeOf reads a fixture's scope ({"tenantId", "applicationId", ...}).

func SearchOutcome

func SearchOutcome(result ae.VectorSearchResult) *ae.Object

SearchOutcome is a search's result in the fixtures' form: the outcome, and the rows with each distance (null for NaN) and relevance.

func VectorQueryOf

func VectorQueryOf(value any) ae.VectorQuery

VectorQueryOf reads a search step of the vector-search fixtures.

func WriteOutcome

func WriteOutcome(result ae.EmbeddingWriteResult) *ae.Object

WriteOutcome is a write's result in the fixtures' form: {"outcome": ...} and, for Stale, "currentRevision".

Types

type InjectionRow

type InjectionRow struct {
	Raw            *ae.Object
	ExperienceID   ae.UUID
	Scope          ae.Scope
	LastInjectedAt ae.Instant
	InjectionCount int64
}

InjectionRow is one row of a lessons-view seed's injections: Raw is the row as written (every column in PostgreSQL's text form, for inserting it as the schema's owner), the rest is the same row read.

type LessonsCase

type LessonsCase struct {
	Name       string
	Records    []ae.ExperienceRecord
	Injections []InjectionRow
	// Scope is the scope listed and also the caller's bounds.
	Scope             ae.Scope
	Statuses          []ae.ExperienceStatus
	Limit             int
	IncludeIneligible bool
	Now               ae.Instant
	Expected          *ae.Object
}

LessonsCase is one lessons-view case: seed.json, query.json and expected.json.

func LoadLessonsCase

func LoadLessonsCase(name string) (*LessonsCase, error)

LoadLessonsCase reads a lessons-view case.

func (*LessonsCase) Query

func (c *LessonsCase) Query() ae.LessonQuery

Query is the case's query.

type Options

type Options struct {
	// Tolerance is the largest difference two numbers may have; 0 compares them exactly.
	Tolerance float64
	// IgnoreKind compares numbers by value only. By default an integer literal (no fraction, no exponent) never
	// equals a number written with a fraction or an exponent, so a double is never written as an integer or the
	// other way round. PostgreSQL's jsonb rewrites numbers in its own form (1E2 as 100), so a value read back from
	// it is compared by value only.
	IgnoreKind bool
}

Options change how Difference compares numbers.

Jump to

Keyboard shortcuts

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