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
- Variables
- func AsWritten(value any) any
- func Cases(family string) []string
- func CheckContractVersion(lock any) (string, error)
- func Difference(expected, actual any, path string, options Options) string
- func EmbeddingWriteOf(value any) ae.EmbeddingWrite
- func EvidenceOf(value any) ae.Evidence
- func HoldoutStepOf(record *ae.Object) (ae.Scope, ae.HoldoutAssignment, error)
- func LessonsDifference(c *LessonsCase, page ae.LessonsPage) string
- func LessonsPageJSON(page ae.LessonsPage) *ae.Object
- func MustReadJSON(path string) any
- func ParseTimestamptz(text string) (ae.Instant, error)
- func ReadJSON(path string) (any, error)
- func RunFinalizeCase(input any) (ae.FinalizedExperience, *ae.Object, error)
- func ScopeOf(value any) ae.Scope
- func SearchOutcome(result ae.VectorSearchResult) *ae.Object
- func VectorQueryOf(value any) ae.VectorQuery
- func WriteOutcome(result ae.EmbeddingWriteResult) *ae.Object
- type InjectionRow
- type LessonsCase
- type Options
Constants ¶
const LessonsFamily = "lessons-view"
LessonsFamily is the lessons-view fixture family's directory name.
Variables ¶
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.
var ErrUnsupportedContractVersion = errors.New("unsupported contract version")
ErrUnsupportedContractVersion is a lock naming a contract version this package does not support.
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.
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 ¶
AsWritten is a value as this package writes it, read back: what is compared is what the package would write.
func CheckContractVersion ¶
CheckContractVersion is the lock's contract version, when this package supports it; a clear failure otherwise.
func Difference ¶
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 ¶
EvidenceOf reads one piece of a fixture's evidence.
func HoldoutStepOf ¶
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 ¶
MustReadJSON is ReadJSON, panicking on failure: for fixtures, which are known to exist.
func ParseTimestamptz ¶
ParseTimestamptz reads PostgreSQL's text form of a timestamptz ("2026-03-02 08:00:00.123456+00").
func ReadJSON ¶
ReadJSON reads a JSON file, keeping every number exactly as written and every object's member order.
func RunFinalizeCase ¶
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 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.
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.