@fuzdev/fuz_app 0.133.0 → 0.134.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db/CLAUDE.md +10 -7
- package/dist/db/create_db.d.ts +8 -6
- package/dist/db/create_db.d.ts.map +1 -1
- package/dist/db/create_db.js +11 -10
- package/dist/db/db.d.ts +9 -7
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +5 -4
- package/dist/db/db_pglet.d.ts +43 -0
- package/dist/db/db_pglet.d.ts.map +1 -0
- package/dist/db/db_pglet.js +55 -0
- package/dist/testing/CLAUDE.md +17 -18
- package/dist/testing/app_server.d.ts +5 -5
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +21 -20
- package/dist/testing/cross_backend/default_backend_configs.d.ts +5 -5
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +1 -1
- package/dist/testing/cross_backend/in_process_setup.d.ts +2 -2
- package/dist/testing/cross_backend/in_process_setup.js +3 -3
- package/dist/testing/cross_backend/test_cell_gated_create_authorize.js +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +2 -2
- package/dist/testing/cross_backend/testing_reset_actions.js +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +2 -2
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/db.d.ts +49 -60
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +104 -101
- package/dist/testing/rate_limiting.d.ts +2 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +2 -2
- package/dist/testing/sse_round_trip.d.ts +1 -1
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/stubs.js +1 -1
- package/package.json +6 -1
|
@@ -16,7 +16,7 @@ import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
|
16
16
|
import { default_audit_factory } from '../server/app_backend.js';
|
|
17
17
|
import { create_app_server } from '../server/app_server.js';
|
|
18
18
|
import { generate_daemon_token, DAEMON_TOKEN_HEADER } from '../auth/daemon_token.js';
|
|
19
|
-
import {
|
|
19
|
+
import { create_default_db_factory } from './db.js';
|
|
20
20
|
import { token_scope_full } from '../auth/token_scope.js';
|
|
21
21
|
/**
|
|
22
22
|
* Fast password stub for tests that don't exercise login/password flows.
|
|
@@ -31,21 +31,22 @@ export const stub_password_deps = {
|
|
|
31
31
|
};
|
|
32
32
|
/** 64-hex-char test cookie secret — deterministic, never used in production. */
|
|
33
33
|
export const TEST_COOKIE_SECRET = 'a'.repeat(64);
|
|
34
|
-
// Module-level
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
34
|
+
// Module-level default factory (pglet-wasm unless `set_default_db_factory` installed
|
|
35
|
+
// another) for create_test_app_server when no db is provided. Shares the WASM instance
|
|
36
|
+
// cache from `testing/db.ts`, avoiding redundant cold starts within one loaded copy of
|
|
37
|
+
// that module. Schema is reset on each create() call.
|
|
38
|
+
const fallback_db_factory = create_default_db_factory(async (db) => {
|
|
38
39
|
await run_migrations(db, [auth_migration_ns]);
|
|
39
40
|
});
|
|
40
|
-
// Auto-created
|
|
41
|
+
// Auto-created default factories keyed by extra-namespace identity. Suites
|
|
41
42
|
// whose backend needs tables beyond auth (e.g. the cell layer) share one
|
|
42
43
|
// factory per distinct namespace set — and the worker-cached WASM instance —
|
|
43
44
|
// rather than each hand-building its own. The cell parity suite is the first
|
|
44
45
|
// user.
|
|
45
46
|
const fallback_factories_by_namespaces = new Map();
|
|
46
47
|
/**
|
|
47
|
-
* Resolve the no-`db`
|
|
48
|
-
* namespaces. Empty / omitted → the shared auth-only `
|
|
48
|
+
* Resolve the no-`db` default factory for the requested extra migration
|
|
49
|
+
* namespaces. Empty / omitted → the shared auth-only `fallback_db_factory`;
|
|
49
50
|
* otherwise a memoized factory whose `init` runs
|
|
50
51
|
* `[auth_migration_ns, ...migration_namespaces]` on each reset. The
|
|
51
52
|
* reset-on-`create` gives the same fresh-db-per-test isolation as the
|
|
@@ -54,12 +55,12 @@ const fallback_factories_by_namespaces = new Map();
|
|
|
54
55
|
*/
|
|
55
56
|
const resolve_fallback_factory = (migration_namespaces) => {
|
|
56
57
|
if (!migration_namespaces || migration_namespaces.length === 0) {
|
|
57
|
-
return
|
|
58
|
+
return fallback_db_factory;
|
|
58
59
|
}
|
|
59
60
|
const key = migration_namespaces.map((ns) => ns.namespace).join(',');
|
|
60
61
|
let factory = fallback_factories_by_namespaces.get(key);
|
|
61
62
|
if (!factory) {
|
|
62
|
-
factory =
|
|
63
|
+
factory = create_default_db_factory(async (db) => {
|
|
63
64
|
await run_migrations(db, [auth_migration_ns, ...migration_namespaces]);
|
|
64
65
|
});
|
|
65
66
|
fallback_factories_by_namespaces.set(key, factory);
|
|
@@ -176,7 +177,7 @@ const default_test_fs_stubs = {
|
|
|
176
177
|
* resets it to false before this runs).
|
|
177
178
|
*/
|
|
178
179
|
const _build_test_backend = async (options) => {
|
|
179
|
-
const { db: existing_db, db_type = '
|
|
180
|
+
const { db: existing_db, db_type = 'pglet-memory', password = stub_password_deps, audit_factory = default_audit_factory, fs_stubs = default_test_fs_stubs, migration_namespaces } = options;
|
|
180
181
|
if (existing_db && migration_namespaces && migration_namespaces.length > 0) {
|
|
181
182
|
throw new Error('test app setup: pass either `db` (caller owns migrations) or `migration_namespaces` ' +
|
|
182
183
|
'(harness migrates), not both');
|
|
@@ -188,14 +189,14 @@ const _build_test_backend = async (options) => {
|
|
|
188
189
|
let db;
|
|
189
190
|
let db_name;
|
|
190
191
|
if (existing_db) {
|
|
191
|
-
// Reset singleton config row from a previous test (harmless on fresh
|
|
192
|
+
// Reset singleton config row from a previous test (harmless on a fresh database).
|
|
192
193
|
await existing_db.query('UPDATE app_settings SET open_signup = false, updated_at = NULL, updated_by = NULL WHERE open_signup = true OR updated_at IS NOT NULL');
|
|
193
194
|
db = existing_db;
|
|
194
195
|
db_name = 'test';
|
|
195
196
|
}
|
|
196
197
|
else {
|
|
197
|
-
// In-memory
|
|
198
|
-
// instead of creating a new
|
|
198
|
+
// In-memory default driver via cached factory — reuses the WASM instance from
|
|
199
|
+
// `testing/db.ts` instead of creating a new instance each time. Schema is reset and migrations re-run
|
|
199
200
|
// on each call, but the expensive WASM cold start only happens once per loaded
|
|
200
201
|
// copy of `testing/db.ts` — under the `db` project's `isolate: false` +
|
|
201
202
|
// `fileParallelism: false` that is once for the whole run.
|
|
@@ -205,11 +206,11 @@ const _build_test_backend = async (options) => {
|
|
|
205
206
|
}
|
|
206
207
|
const backend = {
|
|
207
208
|
// a supplied `db` reports the caller's `db_type`; the auto-created one names
|
|
208
|
-
//
|
|
209
|
-
// (`
|
|
209
|
+
// pglet unconditionally — a run that installs another default factory
|
|
210
|
+
// (`set_default_db_factory`) before this module loads gets that driver
|
|
210
211
|
// here, and no caller reads this field to pick behavior: it is reported,
|
|
211
212
|
// not dispatched on
|
|
212
|
-
db_type: existing_db ? db_type : '
|
|
213
|
+
db_type: existing_db ? db_type : 'pglet-memory',
|
|
213
214
|
db_name,
|
|
214
215
|
// the factory's init ran the migrations, for a supplied `db` and the auto-created one alike
|
|
215
216
|
migration_results: [],
|
|
@@ -230,7 +231,7 @@ const _build_test_backend = async (options) => {
|
|
|
230
231
|
* Create an app server with a bootstrapped account for testing.
|
|
231
232
|
*
|
|
232
233
|
* Sets up:
|
|
233
|
-
* - Auth tables (via cached
|
|
234
|
+
* - Auth tables (via the cached default factory, or reuses existing `db`)
|
|
234
235
|
* - A keeper account with hashed password
|
|
235
236
|
* - Role role_grants for each role in `options.roles`
|
|
236
237
|
* - An API token for Bearer auth
|
|
@@ -310,7 +311,7 @@ const create_bearer_headers_builder = (api_token) => (extra) => ({
|
|
|
310
311
|
*
|
|
311
312
|
* A fresh Hono app is created each call — middleware closures bind to the
|
|
312
313
|
* server's deps (db, keyring), so reuse across servers is unsafe.
|
|
313
|
-
* The expensive resource (
|
|
314
|
+
* The expensive resource (the WASM database) is cached separately in `testing/db.ts`.
|
|
314
315
|
*
|
|
315
316
|
* @param options - test app configuration
|
|
316
317
|
* @returns a `TestApp` ready for HTTP testing
|
|
@@ -408,7 +409,7 @@ export const create_test_app_for_bootstrap = async (options) => {
|
|
|
408
409
|
const { session_options, bootstrap, bootstrap_token } = options;
|
|
409
410
|
// Caller-supplied DB may carry lock state from a prior test — reset to false
|
|
410
411
|
// before `_build_test_backend` runs (which doesn't touch the lock itself).
|
|
411
|
-
//
|
|
412
|
+
// A fresh database already starts at false (factory init).
|
|
412
413
|
if (options.db) {
|
|
413
414
|
await options.db.query('UPDATE bootstrap_lock SET bootstrapped = false WHERE bootstrapped = true');
|
|
414
415
|
}
|
|
@@ -11,11 +11,11 @@ import '../assert_dev_env.js';
|
|
|
11
11
|
*
|
|
12
12
|
* Defaults baked in by family:
|
|
13
13
|
*
|
|
14
|
-
* - **TS** — `'memory://'`
|
|
14
|
+
* - **TS** — `'memory://'` (in-memory pglet), 30s startup window. Its shape notes
|
|
15
15
|
* (`ts_default_shape_notes`) record `trusted_proxy: false` /
|
|
16
16
|
* `login_rate_limit: false` — the TS canonical path leaves those limiters
|
|
17
17
|
* null in test mode.
|
|
18
|
-
* - **Rust** — caller-supplied real Postgres URL (
|
|
18
|
+
* - **Rust** — caller-supplied real Postgres URL (an in-process WASM database isn't reachable
|
|
19
19
|
* from `tokio-postgres`), 120s startup window (cargo first-build cost), the
|
|
20
20
|
* `FUZ_TESTING_RESET_DB_ON_STARTUP=true` self-wipe gate, and shape notes
|
|
21
21
|
* (`rust_default_shape_notes`) recording `trusted_proxy: true` +
|
|
@@ -82,7 +82,7 @@ export interface MakeDefaultTsBackendConfigOptions {
|
|
|
82
82
|
readonly port: number;
|
|
83
83
|
/** argv passed to the spawn (first entry is the binary). */
|
|
84
84
|
readonly start_command: ReadonlyArray<string>;
|
|
85
|
-
/** Defaults to `'memory://'` (in-memory
|
|
85
|
+
/** Defaults to `'memory://'` (in-memory pglet). */
|
|
86
86
|
readonly database_url?: string;
|
|
87
87
|
/** Merged on top of the generic env baseline; later keys win. */
|
|
88
88
|
readonly extra_env?: Readonly<Record<string, string>>;
|
|
@@ -109,7 +109,7 @@ export interface MakeDefaultTsBackendConfigOptions {
|
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* Shared builder for TS-family backends (Deno + Node). Owns the common
|
|
112
|
-
* env baseline (NODE_ENV, HOST, PORT, in-memory
|
|
112
|
+
* env baseline (NODE_ENV, HOST, PORT, in-memory pglet, cookie keys,
|
|
113
113
|
* bootstrap token path) so per-backend factories only declare what
|
|
114
114
|
* genuinely differs.
|
|
115
115
|
*/
|
|
@@ -122,7 +122,7 @@ export interface MakeDefaultRustBackendConfigOptions {
|
|
|
122
122
|
/** argv passed to the spawn (first entry is the binary). */
|
|
123
123
|
readonly start_command: ReadonlyArray<string>;
|
|
124
124
|
/**
|
|
125
|
-
* Required — Rust needs real Postgres (
|
|
125
|
+
* Required — Rust needs real Postgres (an in-process WASM database isn't reachable from
|
|
126
126
|
* `tokio-postgres`). Consumers typically supply
|
|
127
127
|
* `'postgres://localhost/{repo}_test_{name}'`.
|
|
128
128
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default_backend_configs.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/default_backend_configs.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAA4B,KAAK,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAYhG,2CAA2C;AAC3C,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAC5C,QAAQ,CAAC,8BAA8B,CAAC,EAAE,MAAM,CAAC;CACjD;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GACjC,SAAS,yBAAyB,KAChC,MAAM,CAAC,MAAM,EAAE,MAAM,CAKtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,mBAsCpC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,mBAgCtC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,iBAInC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBAIrC,CAAC;AAeH,MAAM,WAAW,iCAAiC;IACjD,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9C,
|
|
1
|
+
{"version":3,"file":"default_backend_configs.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/default_backend_configs.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAA4B,KAAK,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAYhG,2CAA2C;AAC3C,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAC5C,QAAQ,CAAC,8BAA8B,CAAC,EAAE,MAAM,CA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CAAmC;IACnD,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAC5C,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAClC,sEAAsE;IACtE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC/D;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,mCAAmC,KACvC,aA4CF,CAAC"}
|
|
@@ -131,7 +131,7 @@ const build_default_bootstrap = (paths, overrides) => ({
|
|
|
131
131
|
});
|
|
132
132
|
/**
|
|
133
133
|
* Shared builder for TS-family backends (Deno + Node). Owns the common
|
|
134
|
-
* env baseline (NODE_ENV, HOST, PORT, in-memory
|
|
134
|
+
* env baseline (NODE_ENV, HOST, PORT, in-memory pglet, cookie keys,
|
|
135
135
|
* bootstrap token path) so per-backend factories only declare what
|
|
136
136
|
* genuinely differs.
|
|
137
137
|
*/
|
|
@@ -44,8 +44,8 @@ export interface InProcessSetupOptions extends CreateTestAppOptions {
|
|
|
44
44
|
* `_testing_reset` cradle so suite bodies read
|
|
45
45
|
* `fixture.extra_accounts[username]` uniformly regardless of transport.
|
|
46
46
|
*
|
|
47
|
-
* The describe-level `auth_integration_truncate_tables` /
|
|
48
|
-
* cache lifecycle stays in `
|
|
47
|
+
* The describe-level `auth_integration_truncate_tables` / WASM database
|
|
48
|
+
* cache lifecycle stays in `create_default_db_factory` / `create_describe_db`
|
|
49
49
|
* (`testing/db.ts`) — `default_in_process_setup` doesn't manage db state
|
|
50
50
|
* beyond what `create_test_app` already does.
|
|
51
51
|
*/
|
|
@@ -32,14 +32,14 @@ const in_process_fetch_transport = (app) => {
|
|
|
32
32
|
* `_testing_reset` cradle so suite bodies read
|
|
33
33
|
* `fixture.extra_accounts[username]` uniformly regardless of transport.
|
|
34
34
|
*
|
|
35
|
-
* The describe-level `auth_integration_truncate_tables` /
|
|
36
|
-
* cache lifecycle stays in `
|
|
35
|
+
* The describe-level `auth_integration_truncate_tables` / WASM database
|
|
36
|
+
* cache lifecycle stays in `create_default_db_factory` / `create_describe_db`
|
|
37
37
|
* (`testing/db.ts`) — `default_in_process_setup` doesn't manage db state
|
|
38
38
|
* beyond what `create_test_app` already does.
|
|
39
39
|
*/
|
|
40
40
|
export const default_in_process_setup = (options) => async () => {
|
|
41
41
|
// Per-test fresh db. When `options.migration_namespaces` is set,
|
|
42
|
-
// `create_test_app` provisions an auth+extras
|
|
42
|
+
// `create_test_app` provisions an auth+extras database (e.g. the cell
|
|
43
43
|
// layer); otherwise the auth-only default. Either way the factory
|
|
44
44
|
// resets + re-migrates on each `create`, so the per-test keeper
|
|
45
45
|
// bootstrap below lands on a clean DB.
|
|
@@ -18,7 +18,7 @@ import '../assert_dev_env.js';
|
|
|
18
18
|
* admits with the entry's `moderation_required` folded into the verdict. The
|
|
19
19
|
* root's `data` arrives in `input.root_data` (the handler read it in-tx), so
|
|
20
20
|
* the predicate is **pure** — no DB read of its own (which also dodges the
|
|
21
|
-
* single-connection
|
|
21
|
+
* single-connection in-memory deadlock a separate handle would hit — pglet, PGlite).
|
|
22
22
|
*
|
|
23
23
|
* @module
|
|
24
24
|
*/
|
|
@@ -482,8 +482,8 @@ export interface CreateTestingActionsOptions {
|
|
|
482
482
|
* Consumer-supplied callback invoked after the auth-table reset, passed
|
|
483
483
|
* the same transactional `Db` the auth wipes ran on. DB-domain consumers
|
|
484
484
|
* (e.g. fuz_forge truncating its cell / fact / file tables) MUST use this
|
|
485
|
-
* `db` rather than a separately-pooled connection — under
|
|
486
|
-
* connection a second connection deadlocks against this still-open
|
|
485
|
+
* `db` rather than a separately-pooled connection — under the in-memory
|
|
486
|
+
* drivers' single connection (pglet, PGlite) a second connection deadlocks against this still-open
|
|
487
487
|
* transaction. `testing_zzz_server` clears in-memory workspace registry +
|
|
488
488
|
* terminals + scoped-FS scratch (ignores `db`); `testing_spine_stub` has
|
|
489
489
|
* no domain layer and omits the option. Runs inside the same RPC dispatch
|
|
@@ -527,7 +527,7 @@ export const create_testing_actions = (deps, options) => {
|
|
|
527
527
|
// fuz_forge cell/fact/file truncation, or no-op for spine_stub).
|
|
528
528
|
// Pass the transactional `ctx.db` so DB-domain truncation runs
|
|
529
529
|
// on the same connection — a separate pool connection deadlocks
|
|
530
|
-
// against this open transaction under
|
|
530
|
+
// against this open transaction under the in-memory drivers.
|
|
531
531
|
if (reset_state)
|
|
532
532
|
await reset_state(ctx.db);
|
|
533
533
|
return { ...keeper, extra_accounts: extras, extra_actors };
|
|
@@ -7,7 +7,7 @@ import '../assert_dev_env.js';
|
|
|
7
7
|
* these spawn fuz_app's own TS impl over real HTTP with no domain layer, so
|
|
8
8
|
* the `cross_backend_ts_node` / `cross_backend_ts_deno` / `cross_backend_ts_bun`
|
|
9
9
|
* self-test projects verify fuz_app's wire path in its own repo across all
|
|
10
|
-
* three JS runtimes. All run against in-memory
|
|
10
|
+
* three JS runtimes. All run against in-memory pglet (`memory://`) — no
|
|
11
11
|
* external Postgres, unlike the Rust path.
|
|
12
12
|
*
|
|
13
13
|
* The binary writes its daemon token to `{FUZ_TESTING_TS_SPINE_DIR}/run/daemon_token`;
|
|
@@ -32,7 +32,7 @@ export declare const TS_SPINE_BUN_ENTRY = "src/test/cross_backend/testing_spine_
|
|
|
32
32
|
export interface TsSpineBackendConfigOptions {
|
|
33
33
|
/** Listening port. Defaults per runtime (`1178` Node, `1179` Deno, `1180` Bun). */
|
|
34
34
|
readonly port?: number;
|
|
35
|
-
/** Database URL. Default `'memory://'` (in-memory
|
|
35
|
+
/** Database URL. Default `'memory://'` (in-memory pglet). */
|
|
36
36
|
readonly database_url?: string;
|
|
37
37
|
/**
|
|
38
38
|
* Enable the per-IP + per-account login rate limiters on the spawned binary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts_spine_backend_config.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/ts_spine_backend_config.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAsDzD,6FAA6F;AAC7F,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,iDAAiD;AACjD,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,gDAAgD;AAChD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAE9C,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,wDAAwD,CAAC;AAEzF,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,wDAAwD,CAAC;AAEzF,wDAAwD;AACxD,eAAO,MAAM,kBAAkB,uDAAuD,CAAC;AAEvF,MAAM,WAAW,2BAA2B;IAC3C,mFAAmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,
|
|
1
|
+
{"version":3,"file":"ts_spine_backend_config.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/ts_spine_backend_config.ts"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I detection — `CI=true` is set automatically by GitHub Actions, GitLab CI, etc.
|
|
5
|
-
*/
|
|
6
|
-
export declare const IS_CI: boolean;
|
|
7
3
|
/**
|
|
8
4
|
* Factory interface for creating test database instances.
|
|
9
5
|
*/
|
|
@@ -15,75 +11,83 @@ export interface DbFactory {
|
|
|
15
11
|
skip_reason?: string;
|
|
16
12
|
}
|
|
17
13
|
/**
|
|
18
|
-
* Reset a test database to a clean
|
|
14
|
+
* Reset a test database to a clean slate by dropping and recreating the `public` schema.
|
|
19
15
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
16
|
+
* `DROP SCHEMA public CASCADE; CREATE SCHEMA public` in plain SQL, so it resets
|
|
17
|
+
* every driver: the in-memory factories call it on each `create()`, and it is
|
|
18
|
+
* recommended at the start of `init_schema` callbacks for `create_pg_factory`,
|
|
19
|
+
* whose persistent databases accumulate stale DDL across fuz_app versions.
|
|
20
|
+
* Drift-proof — it wipes every table, type, and sequence regardless of
|
|
21
|
+
* namespace, so it needs no upkeep when the schema gains a table. The database
|
|
22
|
+
* instance remains usable after reset.
|
|
23
23
|
*
|
|
24
24
|
* @mutates db - drops the `public` schema and recreates it; all rows in all
|
|
25
25
|
* tables are gone after this returns.
|
|
26
26
|
*/
|
|
27
|
-
export declare const
|
|
27
|
+
export declare const reset_public_schema: (db: Db) => Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
* Builds a `DbFactory` from a schema initializer —
|
|
29
|
+
* Builds a `DbFactory` from a schema initializer — the shape of every factory builder here.
|
|
30
30
|
*/
|
|
31
31
|
export type DbFactoryBuilder = (init_schema: (db: Db) => Promise<void>) => DbFactory;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Create a PGlite (in-memory) database factory for tests.
|
|
34
|
+
*
|
|
35
|
+
* Always enabled — needs the optional `@electric-sql/pglite` peer installed.
|
|
36
|
+
* Shares one PGlite WASM instance across the PGlite factories this module
|
|
37
|
+
* builds; each `create()` resets the schema via `DROP SCHEMA public CASCADE`
|
|
38
|
+
* instead of paying the cold start again.
|
|
39
|
+
*
|
|
40
|
+
* @param init_schema - callback to initialize the database schema
|
|
34
41
|
*/
|
|
35
|
-
export
|
|
36
|
-
/**
|
|
37
|
-
* Whether an installed substitute (`set_substitute_db_factory`) may stand in
|
|
38
|
-
* for the PGlite factory at this call site. Defaults to `true`; pass `false`
|
|
39
|
-
* where PGlite itself is the subject under test.
|
|
40
|
-
*/
|
|
41
|
-
substitutable?: boolean;
|
|
42
|
-
}
|
|
42
|
+
export declare const create_pglite_factory: DbFactoryBuilder;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* Create a pglet-wasm (in-memory) database factory for tests.
|
|
45
|
+
*
|
|
46
|
+
* Always enabled — needs the optional `@fuzdev/pglet-wasm` peer installed.
|
|
47
|
+
* Shares one pglet instance across the pglet-wasm factories this module
|
|
48
|
+
* builds, created with fuz_app's value coercion (`PGLET_COERCION`); each
|
|
49
|
+
* `create()` resets the schema via `DROP SCHEMA public CASCADE`.
|
|
46
50
|
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
* @param init_schema - callback to initialize the database schema
|
|
52
|
+
*/
|
|
53
|
+
export declare const create_pglet_wasm_factory: DbFactoryBuilder;
|
|
54
|
+
/**
|
|
55
|
+
* Install the builder `create_default_db_factory` uses, so suites written
|
|
56
|
+
* against the default run against another driver without being edited —
|
|
57
|
+
* `create_pglite_factory` to run them on PGlite. Pass `null` to restore
|
|
58
|
+
* pglet-wasm.
|
|
50
59
|
*
|
|
51
60
|
* The slot is read when a factory is built, not when it creates a database,
|
|
52
|
-
* so install before the first `
|
|
61
|
+
* so install before the first `create_default_db_factory` call — a vitest
|
|
53
62
|
* `setupFiles` entry, which runs ahead of every test file's imports, is the
|
|
54
63
|
* shape fuz_app's own `db` project uses. A factory built earlier (including
|
|
55
64
|
* the module-level fallback in `testing/app_server.ts`) keeps the driver it
|
|
56
65
|
* was built with, and uninstalling does not revert it.
|
|
57
66
|
*
|
|
58
|
-
* @param create_factory - the builder to install, or `null` to
|
|
67
|
+
* @param create_factory - the builder to install, or `null` to restore the default
|
|
68
|
+
* @returns the builder this replaced (`null` for pglet-wasm), so a caller can put it back
|
|
59
69
|
*/
|
|
60
|
-
export declare const
|
|
70
|
+
export declare const set_default_db_factory: (create_factory: DbFactoryBuilder | null) => DbFactoryBuilder | null;
|
|
61
71
|
/**
|
|
62
|
-
* Create
|
|
63
|
-
*
|
|
64
|
-
* Always enabled — no external dependencies required.
|
|
65
|
-
* Shares a single PGlite WASM instance across the PGlite factories this module builds.
|
|
66
|
-
* Subsequent `create()` calls reset the schema via `DROP SCHEMA public CASCADE`
|
|
67
|
-
* instead of paying the WASM cold-start cost again.
|
|
72
|
+
* Create the default in-memory database factory for tests: pglet-wasm, or the
|
|
73
|
+
* builder `set_default_db_factory` installed.
|
|
68
74
|
*
|
|
69
|
-
*
|
|
70
|
-
* `
|
|
75
|
+
* The factory fuz_app's own test helpers fall back to when a suite passes none
|
|
76
|
+
* (`create_test_app_server`, `describe_rate_limiting_tests`,
|
|
77
|
+
* `describe_sse_route_tests`). Call `create_pglite_factory` or
|
|
78
|
+
* `create_pglet_wasm_factory` directly to pin a driver.
|
|
71
79
|
*
|
|
72
80
|
* @param init_schema - callback to initialize the database schema
|
|
73
|
-
* @param options - `substitutable: false` pins this call site to PGlite
|
|
74
81
|
*/
|
|
75
|
-
export declare const
|
|
82
|
+
export declare const create_default_db_factory: DbFactoryBuilder;
|
|
76
83
|
/**
|
|
77
84
|
* Create a pg (PostgreSQL) database factory for tests.
|
|
78
85
|
*
|
|
79
|
-
* Skipped when `test_url` is not provided.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* For full clean-slate behavior (recommended), call `drop_auth_schema(db)`
|
|
85
|
-
* at the start of `init_schema` before running migrations. This handles
|
|
86
|
-
* upstream schema changes that go beyond adding new tables/columns.
|
|
86
|
+
* Skipped when `test_url` is not provided. Each `create()` opens a pool,
|
|
87
|
+
* resets the `public` schema (`reset_public_schema`) and runs `init_schema` —
|
|
88
|
+
* the lifecycle every factory here shares, so a persistent test database never
|
|
89
|
+
* carries stale DDL or tracker rows from an earlier run or another suite's
|
|
90
|
+
* schema. Point `test_url` at a database used only for tests.
|
|
87
91
|
*
|
|
88
92
|
* @param init_schema - callback to initialize the database schema
|
|
89
93
|
* @param test_url - PostgreSQL connection URL (e.g. from `TEST_DATABASE_URL`)
|
|
@@ -107,21 +111,6 @@ export declare const auth_truncate_tables: string[];
|
|
|
107
111
|
* touch audit logging don't need to truncate it.
|
|
108
112
|
*/
|
|
109
113
|
export declare const auth_integration_truncate_tables: string[];
|
|
110
|
-
/**
|
|
111
|
-
* Reset the entire `public` schema for a clean slate before re-migration.
|
|
112
|
-
*
|
|
113
|
-
* Recommended at the start of `init_schema` callbacks for `create_pg_factory`.
|
|
114
|
-
* Persistent test databases accumulate stale DDL across fuz_app versions;
|
|
115
|
-
* `DROP SCHEMA public CASCADE; CREATE SCHEMA public` wipes every table, type,
|
|
116
|
-
* and sequence regardless of namespace, so migrations always run against a
|
|
117
|
-
* truly empty database. Drift-proof — unlike a hand-maintained drop list it
|
|
118
|
-
* needs no upkeep when the schema gains a table. Despite the historical name,
|
|
119
|
-
* this resets the whole schema, not just auth tables (the only documented use
|
|
120
|
-
* is clean-slate re-migration, which always wanted a full reset).
|
|
121
|
-
*
|
|
122
|
-
* @mutates db - drops and recreates the `public` schema; all tables gone.
|
|
123
|
-
*/
|
|
124
|
-
export declare const drop_auth_schema: (db: Db) => Promise<void>;
|
|
125
114
|
/**
|
|
126
115
|
* Create a `describe_db` function bound to specific factories and truncate tables.
|
|
127
116
|
*
|
package/dist/testing/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/db.ts"],"names":[],"mappings":"AAAA,O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