packagecompat

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package packagecompat compares a route's legacy kernel handler with its package-native implementation on identical seeded data. Extraction PRs use it to prove that a native route answers byte-compatibly (after v2compat.NormalizeForCompare) before its mode moves past shadow.

Every run seeds two independent databases: the legacy handler reads the kernel's global database, the native handler gets its own connection. They are SQLite files by default; with ANIX_TEST_POSTGRES_DSN set, RunRead and RunWrite also run on two PostgreSQL schemas. Each case starts from empty databases with the route's Models migrated; the cases a test runs share the migrated databases, emptied between cases (shared.go).

Index

Constants

View Source
const PostgresDSNEnvironment = "ANIX_TEST_POSTGRES_DSN"

PostgresDSNEnvironment enables the PostgreSQL runs.

Variables

This section is empty.

Functions

func CompareAnswers

func CompareAnswers(legacy, native Result) error

CompareAnswers reports how two answers differ: status code, or body after v2compat.NormalizeForCompare. A sealed handle in the native answer matches the secret the legacy answer shows there, as in the router's shadow comparison (v2compat.EqualForCompare).

func KernelSettings

func KernelSettings(t testing.TB, db *gorm.DB, grants SettingsGrants) kernelsettingsv1.KernelSettingsClient

KernelSettings serves the kernel's KernelSettings (internal/kernelsettings) on db in process over gRPC, to grants' host, and returns a client for it, as the package host gets one over its bridge connection.

func RunRead

func RunRead(t *testing.T, route Route, c Case)

RunRead runs c against both implementations and requires equal status codes and normalized bodies.

func RunWrite

func RunWrite(t *testing.T, route Route, c Case)

RunWrite is RunRead plus an equal Snapshot of each database afterwards.

Types

type Case

type Case struct {
	Name string
	// Path is the concrete request path, with query string if any.
	Path      string
	Body      []byte
	Principal pluginhostsdk.Principal
	// Seed writes the same data into each database.
	Seed func(t testing.TB, db *gorm.DB)
	// Snapshot returns the database state RunWrite compares after the
	// request; any JSON-encodable value.
	Snapshot func(t testing.TB, db *gorm.DB) any
	// Mask lists dotted JSON paths (for example "data.token") whose values
	// differ by design, such as tokens and secrets: they must exist on both
	// sides and are replaced before comparing.
	Mask []string
	// Headers lists response headers both sides must send.
	Headers []string
	// RequestHeaders are sent with the request: the legacy handler reads
	// them from it, the native one from the metadata the kernel forwards.
	RequestHeaders map[string]string
	// Host is the request's Host (default example.com) and TLS whether it
	// arrived over TLS: the legacy handler reads them from the request, the
	// native one from the request scheme and host the kernel sends.
	Host string
	TLS  bool
	// Warmup bodies are sent, in order, before the compared request.
	Warmup [][]byte
}

Case is one request.

type Result

type Result struct {
	StatusCode int
	Body       []byte
	Header     http.Header
	State      any
}

Result is one side's answer.

type Route

type Route struct {
	// Method and Pattern are the gin registration, for example GET and
	// "/api/v2/user/knowledge/:id".
	Method  string
	Pattern string
	RouteID string
	// Legacy is the kernel's gin handler. It reads database.GetDB().
	Legacy gin.HandlerFunc
	// Native builds the package implementation on a database connection.
	Native func(db *gorm.DB) pluginhostsdk.NativeHandler
	// Models are migrated into both databases before Seed runs.
	Models []any
}

Route is one v2 route with both implementations.

type SettingsGrants

type SettingsGrants struct {
	Host         packagebridge.HostIdentity
	Capabilities []string
}

SettingsGrants authorizes the capabilities a package's signed release declares, for that package's host only.

func (SettingsGrants) AuthorizeCapability

func (g SettingsGrants) AuthorizeCapability(_ context.Context, host packagebridge.HostIdentity, capability string) error

AuthorizeCapability implements kernelsettings.Authorizer.

Jump to

Keyboard shortcuts

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