testing/schema_ready_fixture.ts

Gen-time helper for the /ready schema-drift probe's committed fixture.

A consumer commits an expected_schema.json (the column map a fresh full migration-chain bootstrap produces) and serves it through create_ready_route_spec. This helper keeps the regenerate-and-verify test that guards that fixture to ~10 lines: it introspects a freshly-bootstrapped DB, writes the fixture when an update flag is set, and reads it back so the caller can assert the committed copy equals a fresh bootstrap — the assertion that fails when the fixture drifts from the DDLs, so the runtime expectation can't silently fall behind.

view source

Declarations
#

3 declarations

sync_expected_schema_fixture
#

testing/schema_ready_fixture.ts view source

(options: SyncExpectedSchemaFixtureOptions): Promise<SyncExpectedSchemaFixtureResult> import {sync_expected_schema_fixture} from '@fuzdev/fuz_app/testing/schema_ready_fixture.js';

Introspect the live (bootstrapped) DB's columns, write them to the committed fixture when update, then read the committed fixture back. The caller asserts deepEqual(live, committed):

const {live, committed} = await sync_expected_schema_fixture({ db, fixture_url: new URL('../../lib/server/expected_schema.json', import.meta.url), update: process.env.UPDATE_SCHEMA_READY === '1', }); assert.deepEqual(live, committed);

When update writes the fixture it emits raw JSON.stringify (one array element per line); Prettier collapses short arrays inline, so run gro format after UPDATE_SCHEMA_READY=1 before committing or the format check will flag the regenerated file. (The content is identical either way — the regen test compares values, not formatting.)

options

returns

Promise<SyncExpectedSchemaFixtureResult>

the live column map and the committed map (post-write when update)

SyncExpectedSchemaFixtureOptions
#

testing/schema_ready_fixture.ts view source

SyncExpectedSchemaFixtureOptions import type {SyncExpectedSchemaFixtureOptions} from '@fuzdev/fuz_app/testing/schema_ready_fixture.js';

db

A bootstrapped DB — the consumer has run its full migration chain on it.

type Db

fixture_url

Committed fixture location — an import.meta.url-relative URL or a path.

type URL | string

update?

When true, overwrite the fixture with the live column map instead of just reading it. Drive from an env flag (e.g. UPDATE_SCHEMA_READY === '1').

type boolean

SyncExpectedSchemaFixtureResult
#

testing/schema_ready_fixture.ts view source

SyncExpectedSchemaFixtureResult import type {SyncExpectedSchemaFixtureResult} from '@fuzdev/fuz_app/testing/schema_ready_fixture.js';

The live column map and the committed fixture, for a deepEqual assertion.

live

Columns introspected from the live, freshly-bootstrapped DB.

type Record<string, Array<string>>

committed

The committed fixture (re-read after writing when update).

type ExpectedSchema

Depends on
#