storetest

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package storetest contains provider-independent contract tests for vector-store implementations and their filter visitors.

Run verifies the exact capability set and validation boundary of a store. VisitorConformance exercises the common filter AST shapes, while VisitorLifecycle verifies that a visitor can be safely reused.

Each vendor wires the suite up in a single test file:

func TestVisitor_Conformance(t *testing.T) {
    storetest.VisitorConformance(t, func(src string) error {
        expr, err := filter.Parse(src)
        if err != nil {
            return err
        }
        compiler := newVisitor(myFieldSchema)
        return expr.Accept(compiler)
    })
}

Output equivalence (the actual emitted SQL / filter struct) is NOT covered by the suite — backends emit heterogeneous output types and the vendor's own tests still own that responsibility. The suite only guarantees "every valid AST shape visits without error; every well-known invalid AST shape produces an error".

Field identifiers

Every success case uses a disjoint field name per filter-value type so schema-required backends (redis, elasticsearch, opensearch, …) can declare each identifier with one fixed type:

author           — string-comparable
year             — number-comparable
published        — bool-comparable
n, a, b, c, d    — number-comparable (used in ordering / AND / OR)
tags             — string-list (IN)
years            — number-list (IN)
flags            — bool-list (IN)
title            — string-pattern (LIKE)
metadata['author'], metadata['a']['b'] — keyed access

Capability gaps

A backend that genuinely doesn't support a shape (redis can't IN on numeric fields, for example) declares that case via Options.Unsupported. Each entry documents a real vendor capability gap; use sparingly.

Example
package main

import (
	"fmt"

	"github.com/Tangerg/scope/core/vectorstore/storetest"
)

func main() {
	capabilities := storetest.Capabilities{Indexer: true, Searcher: true}
	fmt.Println(capabilities.Indexer, capabilities.Searcher)
}
Output:
true true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, store any, expected Capabilities)

Run verifies the backend's exact capability set and the common operations that must complete before external I/O. Pass a non-nil zero-value *Store; the calls below must not reach provider dependencies.

func VisitorConformance

func VisitorConformance(t *testing.T, build BuildFn, options ...Options)

VisitorConformance runs the standard expression-coverage suite against a vendor's visitor.

The case lists below are the union of what every backend's filter language must accept (success cases) and the known-rejected shapes every backend must error on (failure cases). Adding a new shape here exercises it across ALL vendors that opt into the suite — the single best lever for "no more silent visitor regressions on the 27th provider".

func VisitorLifecycle

func VisitorLifecycle(t *testing.T, factory func() Compiler)

VisitorLifecycle verifies that a compiler resets before every visit and remains reusable after rejecting a malformed predicate.

Types

type BuildFn

type BuildFn func(source string) error

BuildFn parses a filter expression source and feeds it through the vendor's visitor. It returns nil on success, an error on failure. Implementations are responsible for assembling the AST (typically via filter.Parse) and driving the vendor visitor.

type Capabilities

type Capabilities struct {
	Indexer       bool
	Searcher      bool
	HybridSearch  bool
	IDDeleter     bool
	FilterDeleter bool
}

Capabilities is the exact interface and search-semantics set a backend promises. A false interface flag forbids accidental implementation; a false HybridSearch flag requires rejection before external I/O.

type Compiler

type Compiler struct {
	Visit    func(filter.Predicate) error
	Snapshot func() any
}

Compiler exposes the lifecycle surface shared by provider filter compilers. Snapshot must return a value suitable for reflect.DeepEqual.

type Options

type Options struct {
	// Unsupported lists cases the vendor cannot represent exactly. The suite
	// verifies that each one returns an error; capability gaps must never turn
	// into silent approximations or unexecuted tests.
	Unsupported []string
}

Options tunes the conformance suite for vendors with genuine capability gaps.

Jump to

Keyboard shortcuts

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