storetest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 52 Imported by: 0

Documentation

Overview

Package storetest is the contract suite of the composite stores and the suites that need a whole composite: Run holds every backend of the metadata store (in memory, SQLite in memory and in a file, PostgreSQL) to one set of expectations, and the SQL suites check key rotation, sealed repository headers, layout fencing across a reopen, a crashed replayed write and the refusal of a legacy migration history on both SQL composites. It also gives the tests of the modules the composite SQL store's type and openers.

Role

app, test support: the composite stores' counterpart of each module's adapters/storetest. A module's tests may import test support from app and nothing else (dependency rule 1), so SQLStore, Options, SQLiteOptions, PostgresOptions, OpenSQLite and OpenPostgres are how they name and open the SQL composite. Production code never imports it. It imports the composite SQL store and its dialect packages, every module's port and adapters/storetest, the platform's store suite and SQL harness, storekit, and the roles and repository services that RepositoryHeaderEnvironmentRename drives.

Inputs

  • Run: a Factory that returns a fresh, empty composite store and registers its cleanup with the test.
  • Rotation, RepositoryHeaderEnvironmentRename and RepositoryHeadersOpen: an Opener that opens the same database on each call with the keyring it is given.
  • RemoteLayoutPersistence: an open SQL composite and a function that opens the same database again.
  • ReplayCrash and KeyedReplayCrash: a store and the environment that makes the backend's child test, which calls ReplayCrashChild or KeyedReplayCrashChild, open the same database.
  • LegacyHistoryRefused: an empty database, its dialect and a function that opens a store over it with migrations. Reset: a database and its dialect.
  • OpenSQLite and OpenPostgres: a path or a DSN and the options of the composite store and its driver.

Outputs

  • Run: a subtest per concern: the transactions, one of them across two modules' stores, and the pagination input every store builds on, each module's contract and the platform's, the layout fence that needs the platform's config store and the artifacts module's remote sources together, and the build row lock.
  • Opener, Rotation, RepositoryHeaderEnvironmentRename, RepositoryHeadersOpen, RemoteLayoutPersistence, ReplayCrash, ReplayCrashChild, KeyedReplayCrash, KeyedReplayCrashChild and LegacyHistoryRefused: failures of the calling test, each naming the expectation it breaks.
  • Reset: the database emptied, by rolling back and applying again every stream that the composite's module list registers.
  • SQLStore and Options, the composite SQL store and its options; SQLiteOptions and PostgresOptions; OpenSQLite and OpenPostgres, which open the composite as the server does.

Invariants

  • It never imports app, which imports every module, so a test of a module may import it without an import cycle unless the test's package is one that this package imports itself: a module's port, adapters and storetest, which the composites import, and the roles and repository services.
  • Each case of Run gets a store of its own from the factory, so no case sees another's rows.
  • OpenSQLite and OpenPostgres are the server's opens: the database is migrated unless Options.SkipMigrate, the pool is closed on failure, and the error texts are the server's.

References

  • Decision 0015: docs/research/decisions/0015-testing-and-acceptance.md (one contract suite for every backend).
  • Decision 0017: docs/research/decisions/0017-sealed-columns-and-master-key.md (key rotation and sealed columns).
  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Persistence"; "Dependency rules", rule 1; "Names the migration introduces").
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, line 847 (each module's store contract suite in its adapters/storetest).
  • Plan: docs/implementation/plan.md#p2-stores and #p9d-modular-monolith-migration, epic STO (https://github.com/weaveplatform/artifactweave/issues/939).
  • https://github.com/weaveplatform/artifactweave/issues/1098

Status

Implemented P2: the contract suite and key rotation (pull request 3). Later phases added the layout persistence suite (pull request 646), the repository header suites (pull request 656), the replay crash (pull request 905) and the legacy history refusal (pull request 1165). Moved here in P9d: each module's part of the contract moved to its adapters/storetest (issues 1056 to 1062), and issue 1098 merged the composite contract, the composite SQL suites and the openers here. P9d's final qualification added the transaction across two modules' stores, which epic STO (issue 939) asks for.

Testing

It has no tests of its own: app/adapters/inmem runs Run on the in-memory composite, and app/adapters/sql/sqlite and app/adapters/sql/postgres run Run and every SQL suite on theirs. Its remaining branches are t.Fatal paths taken only when a backend breaks the contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyedReplayCrash

func KeyedReplayCrash(t *testing.T, s platstoretest.Store, env []string)

KeyedReplayCrash is ReplayCrash through the replay that keyed operations share (idempotency.Replay), as the router runs a keyed request: the child is killed inside the effect, after its mutation and before the claim, the effect and the receipt commit, and a retry with the same key must run the effect anew and pass its reload. The child is each backend's TestAccKeyedReplayCrashHelper, which calls KeyedReplayCrashChild.

func KeyedReplayCrashChild

func KeyedReplayCrashChild(t *testing.T, s platstoretest.Store)

KeyedReplayCrashChild is called only by each backend's subprocess test helper for KeyedReplayCrash.

func LegacyHistoryRefused

func LegacyHistoryRefused(t *testing.T, db *sql.DB, d dialect.Dialect, open func() error)

LegacyHistoryRefused writes a history table that predates the per-module streams, with one row, into the empty database db, and checks that open, which opens a store over the same database with migrations, and the migrator's Migrate, Rollback and Version all fail with ErrLegacyHistory, which wraps ErrMigration. Afterwards the database must hold that table alone, with its columns and its row unchanged: the refusal writes nothing.

func RemoteLayoutPersistence

func RemoteLayoutPersistence(t *testing.T, s *appsql.Store, reopen func() *appsql.Store)

RemoteLayoutPersistence checks that a layout edit fences the remote source of a repository that uses the layout, and that the layout and the new source generation survive reopening the backend together.

func ReplayCrash

func ReplayCrash(t *testing.T, s platstoretest.Store, env []string)

ReplayCrash kills a separate process after its transactional mutation but before its receipt commits. Both the effect and receipt must roll back. It uses only s's settings and replay stores, so it takes the platform's Store.

func ReplayCrashChild

func ReplayCrashChild(t *testing.T, s platstoretest.Store)

ReplayCrashChild is called only by each backend's subprocess test helper.

func RepositoryHeaderEnvironmentRename

func RepositoryHeaderEnvironmentRename(t *testing.T, open Opener)

RepositoryHeaderEnvironmentRename checks that renaming an environment, which lists and rewrites whole repository configurations through the roles service, keeps a sensitive header's value and keeps it sealed.

func RepositoryHeadersOpen

func RepositoryHeadersOpen(t *testing.T, open Opener)

RepositoryHeadersOpen writes a repository whose document still holds its sensitive header values, with no secret rows and header_secrets_version 0, and reopens the store: the metadata store's open runs the artifacts module's AfterMigrate among every module's hooks, which converts the row, and the metadata store's Reseal, over every module's sealed columns, then finds nothing to change.

func Reset

func Reset(t *testing.T, db *sql.DB, d dialect.Dialect)

Reset rolls the stream of every module that appsql.Modules registers back and applies them all again, leaving an empty schema. Running it before each contract test also exercises every down migration on every run.

func Rotation

func Rotation(t *testing.T, open Opener)

Rotation is decision 0017's rotation test over a populated store: every sealed column gets a value under version 1, Reseal under versions 1 and 2 moves all of them to version 2, a second run changes nothing, and a store holding only version 2 reads every value back.

func Run

func Run(t *testing.T, newStore Factory)

Run executes the full contract, one subtest per concern, each on its own store.

Types

type Factory

type Factory func(t *testing.T) Store

Factory returns a fresh, empty store and registers its cleanup with t.

type Opener

type Opener func(t *testing.T, keys *crypt.Keyring) *appsql.Store

Opener opens the same database each call with the given keyring (nil for none).

type Options

type Options = appsql.Options

Options configures the composite store's open: whether it migrates, and the keyring that seals secret columns.

type PostgresOptions

type PostgresOptions = postgres.Options

PostgresOptions configures OpenPostgres: the composite store's Options and the PostgreSQL driver's pool settings.

type SQLStore

type SQLStore = appsql.Store

SQLStore is the composite SQL store: every module's SQL store over one unit of work, as the server opens it. A module's tests may import only test support from app, never the composite's own packages, so they name the composite, and open it with OpenSQLite and OpenPostgres, through this package.

func OpenPostgres

func OpenPostgres(ctx context.Context, dsn string, o PostgresOptions) (*SQLStore, error)

OpenPostgres opens the composite store on the PostgreSQL database that dsn names, exactly as the server's PostgreSQL open does: the database is migrated unless o.SkipMigrate, the pool is closed on failure, and the errors are the server's.

func OpenSQLite

func OpenSQLite(ctx context.Context, path string, o SQLiteOptions) (*SQLStore, error)

OpenSQLite opens the composite store on the SQLite database at path, creating it if needed, exactly as the server's SQLite open does: the database is migrated unless o.SkipMigrate, the pool is closed on failure, and the errors are the server's.

type SQLiteOptions

type SQLiteOptions = sqlite.Options

SQLiteOptions configures OpenSQLite: the composite store's Options and the SQLite driver's busy timeout.

type Store

Store is what the composite contract runs on: the platform's store and each module's port store, which together are every accessor of the composite stores, over the unit of work they share. Both composites are one; a store that leaves out an accessor any module's port declares is not.

Jump to

Keyboard shortcuts

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