@fuzdev/fuz_app 0.185.0 → 0.186.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/actions/CLAUDE.md +14 -2
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +36 -5
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -1
- package/dist/auth/CLAUDE.md +11 -5
- package/dist/auth/account_queries.d.ts +53 -40
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +57 -50
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +59 -25
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +26 -9
- package/dist/auth/audit_emitter.js +2 -2
- package/dist/auth/audit_log_queries.d.ts +11 -3
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +4 -4
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts.map +1 -1
- package/dist/auth/auth_ddl.js +4 -0
- package/dist/auth/cleanup.js +1 -1
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +35 -0
- package/dist/auth/role_grant_offer_queries.d.ts +13 -13
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +12 -13
- package/dist/auth/role_grant_queries.d.ts +16 -9
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +16 -9
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +15 -0
- package/dist/auth/session_queries.d.ts +24 -0
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -0
- package/dist/db/CLAUDE.md +3 -3
- package/dist/db/cell_ddl.d.ts +8 -3
- package/dist/db/cell_ddl.d.ts.map +1 -1
- package/dist/db/cell_ddl.js +10 -5
- package/dist/http/body_limit.d.ts +4 -4
- package/dist/http/body_limit.js +4 -4
- package/dist/testing/CLAUDE.md +126 -27
- package/dist/testing/app_server.d.ts +5 -7
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +5 -7
- package/dist/testing/auth_apps.d.ts +3 -1
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +22 -5
- package/dist/testing/cross_backend/backend_config.d.ts +8 -0
- package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/backend_log.d.ts +71 -0
- package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_log.js +134 -0
- package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
- package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_swap.js +431 -0
- package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
- package/dist/testing/cross_backend/bootstrap_backend.js +4 -4
- package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +4 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_principal.js +27 -10
- package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +50 -15
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +52 -30
- package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +36 -8
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
- package/dist/testing/cross_backend/setup.d.ts +44 -43
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +64 -62
- package/dist/testing/cross_backend/spawn_backend.d.ts +7 -3
- package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
- package/dist/testing/cross_backend/spawn_backend.js +86 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +1 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +4 -2
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +4 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +7 -6
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +10 -8
- package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_bun.js +7 -31
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +4 -3
- package/dist/testing/data_exposure.d.ts +4 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +93 -25
- package/dist/testing/db_invariants.d.ts +5 -5
- package/dist/testing/db_invariants.js +5 -5
- package/dist/testing/logged_errors.d.ts +61 -0
- package/dist/testing/logged_errors.d.ts.map +1 -0
- package/dist/testing/logged_errors.js +285 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
- package/dist/testing/middleware_gate_probes.js +15 -8
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +41 -16
- package/dist/testing/stubs.d.ts +5 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +6 -3
- package/dist/testing/test_app.d.ts +40 -11
- package/dist/testing/test_app.d.ts.map +1 -1
- package/dist/testing/test_app.js +66 -9
- package/dist/testing/transports/fetch_transport.d.ts +10 -0
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +13 -0
- package/package.json +4 -3
|
@@ -101,9 +101,9 @@ export declare const to_test_account: (seeded: {
|
|
|
101
101
|
* Transport-agnostic: in-process and cross-process producers return the
|
|
102
102
|
* same shape. Behaviors that once needed raw backend access (keyring for
|
|
103
103
|
* forging cookies) are reached through wire-shaped seams instead —
|
|
104
|
-
* `mint_expired_session()`
|
|
105
|
-
* cross-process and
|
|
106
|
-
* the transport.
|
|
104
|
+
* `mint_expired_session()` expires a session over the
|
|
105
|
+
* `_testing_shorten_credential_expiry` channel cross-process and with its
|
|
106
|
+
* statement in-process, so suite bodies never branch on the transport.
|
|
107
107
|
*
|
|
108
108
|
* **Keeper ≠ admin.** `fixture.account` / `fixture.actor` refer to the
|
|
109
109
|
* **fresh keeper** seeded per test. The keeper account holds
|
|
@@ -194,15 +194,16 @@ export interface TestFixture {
|
|
|
194
194
|
readonly name: string;
|
|
195
195
|
}>;
|
|
196
196
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* (`
|
|
202
|
-
*
|
|
203
|
-
* `
|
|
204
|
-
*
|
|
205
|
-
*
|
|
197
|
+
* Return the ready-to-send `Cookie` header value (`name=value`) of a
|
|
198
|
+
* session that authenticated and whose row is now past its `expires_at`:
|
|
199
|
+
* the signed cookie still verifies, so resolution clears the cookie gate
|
|
200
|
+
* (`parse_session_from_cookies`) and is refused at the authoritative
|
|
201
|
+
* DB-row gate (`query_session_get_valid` — `WHERE expires_at > NOW()`).
|
|
202
|
+
* Backs the `expired_session` conformance principal. The shape of
|
|
203
|
+
* `mint_expired_token`: a fresh account (`create_account`, so the keeper's
|
|
204
|
+
* own credentials live on) whose session is proven live, then expired as a
|
|
205
|
+
* real one is — `_testing_shorten_credential_expiry` and a wait
|
|
206
|
+
* cross-process, its statement and a backdate in-process.
|
|
206
207
|
*/
|
|
207
208
|
readonly mint_expired_session: () => Promise<string>;
|
|
208
209
|
/**
|
|
@@ -231,14 +232,16 @@ export interface TestFixture {
|
|
|
231
232
|
* `expires_at`. Backs the `expired_token` conformance principal. Both
|
|
232
233
|
* fixtures mint an account (`create_account`, so the keeper's own
|
|
233
234
|
* credentials live on), prove its eternal token authenticates, then pull
|
|
234
|
-
* the account's credential expiries in to `
|
|
235
|
+
* the account's credential expiries in to `EXPIRED_CREDENTIAL_SHORTEN_SECONDS`
|
|
235
236
|
* from now with the statement behind `_testing_shorten_credential_expiry`
|
|
236
|
-
* (`query_shorten_credential_expiry`),
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
237
|
+
* (`query_shorten_credential_expiry`), so the row expires as a real one
|
|
238
|
+
* does: `expires_at` after `created_at`, then passed. Cross-process the
|
|
239
|
+
* statement runs through the backdoor, which the backend must mount, and
|
|
240
|
+
* the fixture waits `EXPIRED_CREDENTIAL_WAIT_MS`. In-process it runs directly
|
|
241
|
+
* and, holding the database, moves the account's credential rows back by
|
|
242
|
+
* that wait instead — every timestamp of each row, so `expires_at` stays
|
|
243
|
+
* after `created_at`, a row a lifetime writes. `mint_expired_session` is
|
|
244
|
+
* the same mint over the account's session.
|
|
242
245
|
*/
|
|
243
246
|
readonly mint_expired_token: () => Promise<string>;
|
|
244
247
|
/**
|
|
@@ -329,7 +332,6 @@ export interface RpcPathCapabilityGatedCrossSuiteOptions extends RpcPathCrossSui
|
|
|
329
332
|
* keeper_transport,
|
|
330
333
|
* keeper_daemon_transport: create_fetch_transport({
|
|
331
334
|
* base_url: config.base_url,
|
|
332
|
-
* initial_cookies: keeper.cookies,
|
|
333
335
|
* origin: null,
|
|
334
336
|
* }),
|
|
335
337
|
* keeper_account: keeper.account,
|
|
@@ -348,9 +350,10 @@ export interface BootstrappedBackendHandle extends BackendHandle {
|
|
|
348
350
|
/** Transport carrying the keeper session cookie + cookie jar. */
|
|
349
351
|
readonly keeper_transport: FetchTransport;
|
|
350
352
|
/**
|
|
351
|
-
* Daemon-token transport for the keeper —
|
|
352
|
-
*
|
|
353
|
-
*
|
|
353
|
+
* Daemon-token transport for the keeper — no cookie jar, so a daemon-token
|
|
354
|
+
* call carries that credential alone (a cookie beside it would authenticate
|
|
355
|
+
* as the keeper's session if the token failed), and `origin: null` so it
|
|
356
|
+
* sends no `Origin` header. The daemon-token middleware discards the credential in a
|
|
354
357
|
* browser context (any `Origin` / `Referer`), so the `_testing_*`
|
|
355
358
|
* daemon-token calls (`_testing_reset` / `_testing_schema_snapshot` /
|
|
356
359
|
* `_testing_action_manifest` / `_testing_mint_session`) must route
|
|
@@ -542,29 +545,25 @@ export declare const capture_action_manifest: (handle: ReconstructedBootstrapped
|
|
|
542
545
|
*/
|
|
543
546
|
export declare const capture_migration_tracker: (handle: ReconstructedBootstrappedBackendHandle) => Promise<MigrationTracker>;
|
|
544
547
|
/**
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* comfortably past `NOW()` for the DB-row expiry gate without depending on
|
|
548
|
-
* clock precision.
|
|
549
|
-
*/
|
|
550
|
-
export declare const EXPIRED_SESSION_OFFSET_SECONDS = -60;
|
|
551
|
-
/**
|
|
552
|
-
* The seconds `mint_expired_token` pulls a token's expiry in to — over
|
|
548
|
+
* The seconds `mint_expired_token` and `mint_expired_session` pull a
|
|
549
|
+
* credential's expiry in to — over
|
|
553
550
|
* `_testing_shorten_credential_expiry` cross-process, with its statement
|
|
554
551
|
* in-process — the backdoor's floor
|
|
555
552
|
* (`TESTING_SHORTEN_CREDENTIAL_EXPIRY_MIN_SECONDS`, which this module does not
|
|
556
553
|
* import: its module carries the in-process backend), so the wait is as short
|
|
557
554
|
* as the backdoor allows; a floor raised past it fails the call loud.
|
|
558
555
|
*/
|
|
559
|
-
export declare const
|
|
556
|
+
export declare const EXPIRED_CREDENTIAL_SHORTEN_SECONDS = 1;
|
|
560
557
|
/**
|
|
561
|
-
* How long `mint_expired_token`
|
|
562
|
-
*
|
|
558
|
+
* How long the cross-process `mint_expired_token` and `mint_expired_session`
|
|
559
|
+
* wait after the shorten answers: the row's `expires_at` is
|
|
560
|
+
* `EXPIRED_CREDENTIAL_SHORTEN_SECONDS` past the
|
|
563
561
|
* database's `NOW()` of a statement that ran before the answer, so once this
|
|
564
562
|
* much has passed on the same clock the row is expired when the token is sent.
|
|
565
|
-
* The margin covers the timer firing early by its rounding.
|
|
563
|
+
* The margin covers the timer firing early by its rounding. The in-process
|
|
564
|
+
* fixture moves the rows back by it rather than waiting.
|
|
566
565
|
*/
|
|
567
|
-
export declare const
|
|
566
|
+
export declare const EXPIRED_CREDENTIAL_WAIT_MS: number;
|
|
568
567
|
/** What `assert_credential_authenticates` sends and expects. */
|
|
569
568
|
export interface AssertCredentialAuthenticatesOptions {
|
|
570
569
|
/**
|
|
@@ -572,7 +571,7 @@ export interface AssertCredentialAuthenticatesOptions {
|
|
|
572
571
|
* otherwise, since a cookie it carried would answer for the credential.
|
|
573
572
|
*/
|
|
574
573
|
readonly transport: FetchTransport;
|
|
575
|
-
/** The RPC endpoint `account_verify` is mounted on. */
|
|
574
|
+
/** The RPC endpoint `account_verify` (`account_verify_action_spec`) is mounted on. */
|
|
576
575
|
readonly rpc_path: string;
|
|
577
576
|
/** The credential, alone: a `cookie`, an `authorization`, or a daemon token. */
|
|
578
577
|
readonly headers: Readonly<Record<string, string>>;
|
|
@@ -582,12 +581,14 @@ export interface AssertCredentialAuthenticatesOptions {
|
|
|
582
581
|
readonly accessor: string;
|
|
583
582
|
}
|
|
584
583
|
/**
|
|
585
|
-
* Prove a credential authenticates — `account_verify` answers 200
|
|
586
|
-
* expected account — before a fixture
|
|
587
|
-
*
|
|
588
|
-
* a `mint_revoked_*` that minted nothing
|
|
589
|
-
*
|
|
590
|
-
*
|
|
584
|
+
* Prove a credential authenticates — `account_verify` answers 200 naming the
|
|
585
|
+
* expected account — before a fixture relies on it. A refusal reaches the same
|
|
586
|
+
* answer whether the credential was killed, never worked, or belongs to
|
|
587
|
+
* another account, so without this a `mint_revoked_*` that minted nothing, an
|
|
588
|
+
* expiry over a token that never worked, or a `scoped_token` minted on the
|
|
589
|
+
* wrong account would pass every row its principal backs; with it, the
|
|
590
|
+
* principal's refusal can only come from the state the fixture put it in (the
|
|
591
|
+
* revocation, the expiry, the scope).
|
|
591
592
|
*
|
|
592
593
|
* @param options - the transport, endpoint, credential and expected account
|
|
593
594
|
* @throws Error naming the accessor when the credential does not answer as the account
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/setup.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAQN,KAAK,KAAK,EACV,KAAK,SAAS,EACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAuB,IAAI,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/setup.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAQN,KAAK,KAAK,EACV,KAAK,SAAS,EACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAuB,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAMvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAChF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;;;GAsBG;AACH,eAAO,MAAM,2BAA2B,GACvC,QAAQ,sCAAsC,EAC9C,UAAU,wBAAwB,KAChC,SAwRF,CAAC"}
|
|
@@ -24,6 +24,7 @@ import '../assert_dev_env.js';
|
|
|
24
24
|
import { array, boolean, literal, number, parse, string, strip_object } from '@fuzdev/fuz_schema/schema.ts';
|
|
25
25
|
import { USERNAME_LENGTH_MAX, Uuid } from '../../primitive_schemas.js';
|
|
26
26
|
import { format_issues } from '../../schema_issues.js';
|
|
27
|
+
import { account_verify_action_spec } from '../../auth/account_action_specs.js';
|
|
27
28
|
import { DAEMON_TOKEN_HEADER } from '../../auth/daemon_token.js';
|
|
28
29
|
import { DEFAULT_TEST_PASSWORD } from '../test_credentials.js';
|
|
29
30
|
import { create_fetch_transport } from '../transports/fetch_transport.js';
|
|
@@ -89,13 +90,13 @@ export const reconstruct_bootstrapped_handle = (serialized) => ({
|
|
|
89
90
|
base_url: serialized.config.base_url,
|
|
90
91
|
initial_cookies: serialized.keeper_cookies
|
|
91
92
|
}),
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
93
|
+
// Cookie-free and Origin-free, so a daemon-token call carries that
|
|
94
|
+
// credential alone and the daemon-token middleware doesn't discard it as
|
|
95
|
+
// browser-context — used by the `_testing_*` daemon-token calls
|
|
96
|
+
// (`_testing_reset` / `_testing_schema_snapshot` /
|
|
95
97
|
// `_testing_action_manifest` / `_testing_mint_session`).
|
|
96
98
|
keeper_daemon_transport: create_fetch_transport({
|
|
97
99
|
base_url: serialized.config.base_url,
|
|
98
|
-
initial_cookies: serialized.keeper_cookies,
|
|
99
100
|
origin: null
|
|
100
101
|
})
|
|
101
102
|
});
|
|
@@ -251,40 +252,36 @@ export const capture_action_manifest = async (handle) => capture_via_daemon(hand
|
|
|
251
252
|
*/
|
|
252
253
|
export const capture_migration_tracker = async (handle) => capture_via_daemon(handle, '_testing_migration_tracker', MigrationTracker);
|
|
253
254
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* comfortably past `NOW()` for the DB-row expiry gate without depending on
|
|
257
|
-
* clock precision.
|
|
258
|
-
*/
|
|
259
|
-
export const EXPIRED_SESSION_OFFSET_SECONDS = -60;
|
|
260
|
-
/** Structural subset of `_testing_mint_session`'s output. */
|
|
261
|
-
const MintSessionResponseShape = strip_object({ session_cookie: string });
|
|
262
|
-
/**
|
|
263
|
-
* The seconds `mint_expired_token` pulls a token's expiry in to — over
|
|
255
|
+
* The seconds `mint_expired_token` and `mint_expired_session` pull a
|
|
256
|
+
* credential's expiry in to — over
|
|
264
257
|
* `_testing_shorten_credential_expiry` cross-process, with its statement
|
|
265
258
|
* in-process — the backdoor's floor
|
|
266
259
|
* (`TESTING_SHORTEN_CREDENTIAL_EXPIRY_MIN_SECONDS`, which this module does not
|
|
267
260
|
* import: its module carries the in-process backend), so the wait is as short
|
|
268
261
|
* as the backdoor allows; a floor raised past it fails the call loud.
|
|
269
262
|
*/
|
|
270
|
-
export const
|
|
263
|
+
export const EXPIRED_CREDENTIAL_SHORTEN_SECONDS = 1;
|
|
271
264
|
/**
|
|
272
|
-
* How long `mint_expired_token`
|
|
273
|
-
*
|
|
265
|
+
* How long the cross-process `mint_expired_token` and `mint_expired_session`
|
|
266
|
+
* wait after the shorten answers: the row's `expires_at` is
|
|
267
|
+
* `EXPIRED_CREDENTIAL_SHORTEN_SECONDS` past the
|
|
274
268
|
* database's `NOW()` of a statement that ran before the answer, so once this
|
|
275
269
|
* much has passed on the same clock the row is expired when the token is sent.
|
|
276
|
-
* The margin covers the timer firing early by its rounding.
|
|
270
|
+
* The margin covers the timer firing early by its rounding. The in-process
|
|
271
|
+
* fixture moves the rows back by it rather than waiting.
|
|
277
272
|
*/
|
|
278
|
-
export const
|
|
273
|
+
export const EXPIRED_CREDENTIAL_WAIT_MS = EXPIRED_CREDENTIAL_SHORTEN_SECONDS * 1000 + 50;
|
|
279
274
|
/** The account id an `account_verify` answer names, all a liveness check reads of it. */
|
|
280
275
|
const VerifyResponseShape = strip_object({ id: string });
|
|
281
276
|
/**
|
|
282
|
-
* Prove a credential authenticates — `account_verify` answers 200
|
|
283
|
-
* expected account — before a fixture
|
|
284
|
-
*
|
|
285
|
-
* a `mint_revoked_*` that minted nothing
|
|
286
|
-
*
|
|
287
|
-
*
|
|
277
|
+
* Prove a credential authenticates — `account_verify` answers 200 naming the
|
|
278
|
+
* expected account — before a fixture relies on it. A refusal reaches the same
|
|
279
|
+
* answer whether the credential was killed, never worked, or belongs to
|
|
280
|
+
* another account, so without this a `mint_revoked_*` that minted nothing, an
|
|
281
|
+
* expiry over a token that never worked, or a `scoped_token` minted on the
|
|
282
|
+
* wrong account would pass every row its principal backs; with it, the
|
|
283
|
+
* principal's refusal can only come from the state the fixture put it in (the
|
|
284
|
+
* revocation, the expiry, the scope).
|
|
288
285
|
*
|
|
289
286
|
* @param options - the transport, endpoint, credential and expected account
|
|
290
287
|
* @throws Error naming the accessor when the credential does not answer as the account
|
|
@@ -298,13 +295,17 @@ export const assert_credential_authenticates = async (options) => {
|
|
|
298
295
|
const response = await transport(rpc_path, {
|
|
299
296
|
method: 'POST',
|
|
300
297
|
headers: { 'Content-Type': 'application/json', ...headers },
|
|
301
|
-
body: JSON.stringify({
|
|
298
|
+
body: JSON.stringify({
|
|
299
|
+
jsonrpc: '2.0',
|
|
300
|
+
method: account_verify_action_spec.method,
|
|
301
|
+
id: account_verify_action_spec.method
|
|
302
|
+
})
|
|
302
303
|
});
|
|
303
304
|
const body = (await response.json().catch(() => undefined));
|
|
304
305
|
const parsed = parse(VerifyResponseShape, body?.result);
|
|
305
306
|
if (response.status !== 200 || !parsed.ok || parsed.value.id !== account_id) {
|
|
306
|
-
throw new Error(`${accessor}: the credential did not authenticate as account ${account_id}
|
|
307
|
-
|
|
307
|
+
throw new Error(`${accessor}: the credential did not authenticate as account ${account_id} — ` +
|
|
308
|
+
`${account_verify_action_spec.method} answered ${response.status} ${JSON.stringify(body)}`);
|
|
308
309
|
}
|
|
309
310
|
};
|
|
310
311
|
/** Structural subset of `account_token_create`'s output that the revoked-token mint reads. */
|
|
@@ -316,7 +317,7 @@ const SessionListResponseShape = strip_object({
|
|
|
316
317
|
/** Structural subset of `account_*_revoke`'s output. */
|
|
317
318
|
const RevokeResponseShape = strip_object({ revoked: literal(true) });
|
|
318
319
|
/** Structural subset of `_testing_shorten_credential_expiry`'s output. */
|
|
319
|
-
const ShortenResponseShape = strip_object({ api_tokens: number });
|
|
320
|
+
const ShortenResponseShape = strip_object({ sessions: number, api_tokens: number });
|
|
320
321
|
/** Structural subset of `_testing_reset`'s output. */
|
|
321
322
|
const TestingResetResponseShape = strip_object({
|
|
322
323
|
account: strip_object({ id: Uuid, username: string }),
|
|
@@ -583,14 +584,14 @@ const create_keeper_transport = (handle, cookie_name, session_cookie) => create_
|
|
|
583
584
|
initial_cookies: [`${cookie_name}=${session_cookie}`]
|
|
584
585
|
});
|
|
585
586
|
/**
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
* credential as browser-context.
|
|
589
|
-
* daemon-token calls (the rebuilt handle's
|
|
587
|
+
* The daemon-token twin of `create_keeper_transport`: no cookie jar, so a
|
|
588
|
+
* daemon-token call carries that credential alone, and `origin: null` so the
|
|
589
|
+
* daemon-token middleware doesn't discard the credential as browser-context.
|
|
590
|
+
* Used for the per-test `_testing_*` daemon-token calls (the rebuilt handle's
|
|
591
|
+
* `keeper_daemon_transport`).
|
|
590
592
|
*/
|
|
591
|
-
const create_keeper_daemon_transport = (handle
|
|
593
|
+
const create_keeper_daemon_transport = (handle) => create_fetch_transport({
|
|
592
594
|
base_url: handle.config.base_url,
|
|
593
|
-
initial_cookies: [`${cookie_name}=${session_cookie}`],
|
|
594
595
|
origin: null
|
|
595
596
|
});
|
|
596
597
|
/**
|
|
@@ -649,10 +650,8 @@ export const default_cross_process_setup = (handle, options) => {
|
|
|
649
650
|
// `session_cookie` for any keeper-acting calls this test makes
|
|
650
651
|
// (e.g. `fixture.create_account()`'s `invite_create` step).
|
|
651
652
|
const keeper_transport = create_keeper_transport(handle, cookie_name, keeper.session_cookie);
|
|
652
|
-
//
|
|
653
|
-
|
|
654
|
-
// cookie, so rebuild it against the freshly re-seeded keeper.
|
|
655
|
-
const keeper_daemon_transport = create_keeper_daemon_transport(handle, cookie_name, keeper.session_cookie);
|
|
653
|
+
// a fresh cookie-free daemon-token transport per test
|
|
654
|
+
const keeper_daemon_transport = create_keeper_daemon_transport(handle);
|
|
656
655
|
const refreshed_handle = {
|
|
657
656
|
...handle,
|
|
658
657
|
keeper_transport,
|
|
@@ -692,6 +691,25 @@ export const default_cross_process_setup = (handle, options) => {
|
|
|
692
691
|
for (const [username, seeded] of Object.entries(seeded_extras)) {
|
|
693
692
|
extra_accounts[username] = to_test_account(seeded, cookie_name);
|
|
694
693
|
}
|
|
694
|
+
// The expired-credential mints' shared shape: a fresh account, its
|
|
695
|
+
// credential proven live, then every credential of the account pulled
|
|
696
|
+
// in through the backdoor and waited out — refused for the expiry alone.
|
|
697
|
+
const mint_expired_account = async (accessor, kind, credential) => {
|
|
698
|
+
const other = await create_account();
|
|
699
|
+
await assert_credential_authenticates({
|
|
700
|
+
transport: create_fetch_transport({ base_url: handle.config.base_url, origin: null }),
|
|
701
|
+
rpc_path: handle.config.rpc_path,
|
|
702
|
+
headers: credential(other),
|
|
703
|
+
account_id: other.account.id,
|
|
704
|
+
accessor
|
|
705
|
+
});
|
|
706
|
+
const shortened = parse_capture_answer('_testing_shorten_credential_expiry', ShortenResponseShape, await rpc_via_transport(refreshed_handle.keeper_daemon_transport, handle.config.rpc_path, '_testing_shorten_credential_expiry', { account_id: other.account.id, seconds: EXPIRED_CREDENTIAL_SHORTEN_SECONDS }, handle.config.name, { [DAEMON_TOKEN_HEADER]: handle.daemon_token }));
|
|
707
|
+
if (shortened[kind] < 1) {
|
|
708
|
+
throw new Error(`${accessor}: _testing_shorten_credential_expiry(${handle.config.name}) shortened no ${kind}`);
|
|
709
|
+
}
|
|
710
|
+
await new Promise((resolve) => setTimeout(resolve, EXPIRED_CREDENTIAL_WAIT_MS));
|
|
711
|
+
return other;
|
|
712
|
+
};
|
|
695
713
|
// Per-test transport — fresh jar carrying the new keeper's cookie
|
|
696
714
|
// so requests authenticate as the keeper without callers having to
|
|
697
715
|
// thread cookies manually. Tests acting as the fresh keeper use
|
|
@@ -724,17 +742,11 @@ export const default_cross_process_setup = (handle, options) => {
|
|
|
724
742
|
const answer = await capture_via_daemon(refreshed_handle, '_testing_db_invariants', DbInvariantRows);
|
|
725
743
|
assert_db_invariant_rows(answer.rows, handle.config.name, exclude_db_invariants);
|
|
726
744
|
},
|
|
727
|
-
// Forge over the wire — the cross-process driver has no keyring,
|
|
728
|
-
// so `_testing_mint_session` mints the backdated row + signs the
|
|
729
|
-
// cookie server-side over the keeper's daemon-token channel.
|
|
730
745
|
mint_expired_session: async () => {
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
`${JSON.stringify(raw)} (${format_issues(parsed.issues)})`);
|
|
736
|
-
}
|
|
737
|
-
return `${cookie_name}=${parsed.value.session_cookie}`;
|
|
746
|
+
const other = await mint_expired_account('mint_expired_session', 'sessions', (account) => ({
|
|
747
|
+
cookie: `${cookie_name}=${account.session_cookie}`
|
|
748
|
+
}));
|
|
749
|
+
return `${cookie_name}=${other.session_cookie}`;
|
|
738
750
|
},
|
|
739
751
|
mint_revoked_session: async () => {
|
|
740
752
|
// a second keeper session over the production login, so the
|
|
@@ -786,19 +798,9 @@ export const default_cross_process_setup = (handle, options) => {
|
|
|
786
798
|
return minted.token;
|
|
787
799
|
},
|
|
788
800
|
mint_expired_token: async () => {
|
|
789
|
-
const other = await
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
rpc_path: handle.config.rpc_path,
|
|
793
|
-
headers: { authorization: `Bearer ${other.api_token}` },
|
|
794
|
-
account_id: other.account.id,
|
|
795
|
-
accessor: 'mint_expired_token'
|
|
796
|
-
});
|
|
797
|
-
const shortened = parse_capture_answer('_testing_shorten_credential_expiry', ShortenResponseShape, await rpc_via_transport(refreshed_handle.keeper_daemon_transport, handle.config.rpc_path, '_testing_shorten_credential_expiry', { account_id: other.account.id, seconds: EXPIRED_TOKEN_SHORTEN_SECONDS }, handle.config.name, { [DAEMON_TOKEN_HEADER]: handle.daemon_token }));
|
|
798
|
-
if (shortened.api_tokens < 1) {
|
|
799
|
-
throw new Error(`mint_expired_token: _testing_shorten_credential_expiry(${handle.config.name}) shortened no token`);
|
|
800
|
-
}
|
|
801
|
-
await new Promise((resolve) => setTimeout(resolve, EXPIRED_TOKEN_WAIT_MS));
|
|
801
|
+
const other = await mint_expired_account('mint_expired_token', 'api_tokens', (account) => ({
|
|
802
|
+
authorization: `Bearer ${account.api_token}`
|
|
803
|
+
}));
|
|
802
804
|
return other.api_token;
|
|
803
805
|
}
|
|
804
806
|
};
|
|
@@ -28,7 +28,10 @@ import '../assert_dev_env.js';
|
|
|
28
28
|
*
|
|
29
29
|
* The child's stderr is kept as a bounded tail (`STDERR_TAIL_MAX_BYTES`):
|
|
30
30
|
* a startup failure reports it with the exit code or signal, and an exit
|
|
31
|
-
* after startup that teardown didn't cause is logged with it.
|
|
31
|
+
* after startup that teardown didn't cause is logged with it. With
|
|
32
|
+
* `config.log`, its stdout and stderr are also teed into `config.log.path`,
|
|
33
|
+
* and teardown fails on each error-level line there that no
|
|
34
|
+
* `config.log.allow_errors` entry matches (`backend_log.ts`).
|
|
32
35
|
*
|
|
33
36
|
* Teardown holds the backend to a clean exit: a spine whose graceful
|
|
34
37
|
* shutdown gave up on work still running, or threw, exits `1` (the TS core's
|
|
@@ -71,8 +74,9 @@ export interface BackendHandle {
|
|
|
71
74
|
* than `0` (a shutdown that gave up or failed), an exit by signal (the
|
|
72
75
|
* SIGKILL escalation among them), an exit before teardown (already
|
|
73
76
|
* logged when it happened), or a group still running when teardown gave
|
|
74
|
-
* up. The error names the backend and the exit, with the stderr tail.
|
|
75
|
-
*
|
|
77
|
+
* up. The error names the backend and the exit, with the stderr tail. With
|
|
78
|
+
* `config.log`, it also rejects on the error lines of the log no allowance
|
|
79
|
+
* names, listing them. The group is torn down either way.
|
|
76
80
|
*/
|
|
77
81
|
readonly teardown: () => Promise<void>;
|
|
78
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn_backend.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/spawn_backend.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B
|
|
1
|
+
{"version":3,"file":"spawn_backend.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/spawn_backend.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASzD,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC7B,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAgBD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAY,CAAC;AAsE/C;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,KAAG,OAAO,CAAC,OAAO,CAenE,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,qFAAqF;IACrF,QAAQ,CAAC,IAAI,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,WAAW,MAAM,KAAG,UAmBtD,CAAC;AA8FF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GAAU,QAAQ,aAAa,KAAG,OAAO,CAAC,aAAa,CAqThF,CAAC"}
|
|
@@ -28,7 +28,10 @@ import '../assert_dev_env.js';
|
|
|
28
28
|
*
|
|
29
29
|
* The child's stderr is kept as a bounded tail (`STDERR_TAIL_MAX_BYTES`):
|
|
30
30
|
* a startup failure reports it with the exit code or signal, and an exit
|
|
31
|
-
* after startup that teardown didn't cause is logged with it.
|
|
31
|
+
* after startup that teardown didn't cause is logged with it. With
|
|
32
|
+
* `config.log`, its stdout and stderr are also teed into `config.log.path`,
|
|
33
|
+
* and teardown fails on each error-level line there that no
|
|
34
|
+
* `config.log.allow_errors` entry matches (`backend_log.ts`).
|
|
32
35
|
*
|
|
33
36
|
* Teardown holds the backend to a clean exit: a spine whose graceful
|
|
34
37
|
* shutdown gave up on work still running, or threw, exits `1` (the TS core's
|
|
@@ -46,9 +49,11 @@ import '../assert_dev_env.js';
|
|
|
46
49
|
* @module
|
|
47
50
|
*/
|
|
48
51
|
import { spawn } from 'node:child_process';
|
|
52
|
+
import { createWriteStream } from 'node:fs';
|
|
49
53
|
import { readFile, writeFile, mkdir, rm } from 'node:fs/promises';
|
|
50
54
|
import { connect } from 'node:net';
|
|
51
55
|
import { dirname } from 'node:path';
|
|
56
|
+
import { create_log_line_splitter, find_unexpected_backend_errors, format_unexpected_backend_errors } from './backend_log.js';
|
|
52
57
|
/** Number of ms between health-probe attempts. Tuned to be cheap on busy CI runners. */
|
|
53
58
|
const HEALTH_PROBE_INTERVAL_MS = 100;
|
|
54
59
|
/**
|
|
@@ -74,6 +79,8 @@ export const STDERR_TAIL_MAX_BYTES = 16 * 1024;
|
|
|
74
79
|
* the await below can't strand the whole run forever.
|
|
75
80
|
*/
|
|
76
81
|
const TEARDOWN_SIGKILL_GRACE_MS = 3_000;
|
|
82
|
+
/** How long teardown waits for the child's stdio to end before reading its log (ms). */
|
|
83
|
+
const LOG_DRAIN_WAIT_MS = 1_000;
|
|
77
84
|
/** How often teardown checks whether the process group has exited (ms). */
|
|
78
85
|
const TEARDOWN_POLL_INTERVAL_MS = 20;
|
|
79
86
|
/**
|
|
@@ -268,6 +275,50 @@ export const spawn_backend = async (config) => {
|
|
|
268
275
|
// a token a previous run left would read as this binary's
|
|
269
276
|
await rm(config.bootstrap.daemon_token_path, { force: true });
|
|
270
277
|
install_process_handlers();
|
|
278
|
+
// the log file, rewritten per spawn, opened before the child so no output is missed
|
|
279
|
+
let log_stream = null;
|
|
280
|
+
let log_write_error = null;
|
|
281
|
+
if (config.log) {
|
|
282
|
+
await mkdir(dirname(config.log.path), { recursive: true });
|
|
283
|
+
log_stream = createWriteStream(config.log.path, { flags: 'w' });
|
|
284
|
+
// a failed open or write (a full disk) fails teardown, never the process
|
|
285
|
+
log_stream.on('error', (error) => {
|
|
286
|
+
log_write_error ??= error;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
// whole lines only, per stream (`create_log_line_splitter`)
|
|
290
|
+
const log_line_writer = () => {
|
|
291
|
+
const splitter = create_log_line_splitter();
|
|
292
|
+
return {
|
|
293
|
+
write: (chunk) => {
|
|
294
|
+
if (!log_stream || log_stream.writableEnded || log_write_error)
|
|
295
|
+
return;
|
|
296
|
+
const lines = splitter.push(chunk);
|
|
297
|
+
if (lines !== '')
|
|
298
|
+
log_stream.write(lines);
|
|
299
|
+
},
|
|
300
|
+
flush: () => {
|
|
301
|
+
const rest = splitter.end();
|
|
302
|
+
if (log_stream && !log_stream.writableEnded && !log_write_error && rest !== '') {
|
|
303
|
+
log_stream.write(rest);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
const stdout_log = log_line_writer();
|
|
309
|
+
const stderr_log = log_line_writer();
|
|
310
|
+
let log_stream_closing = null;
|
|
311
|
+
const log_stream_closed = () => (log_stream_closing ??= new Promise((resolve) => {
|
|
312
|
+
if (!log_stream || log_stream.closed || log_stream.destroyed) {
|
|
313
|
+
resolve();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
stdout_log.flush();
|
|
317
|
+
stderr_log.flush();
|
|
318
|
+
// `'close'` follows a failed stream too, which never calls back `end`'s callback
|
|
319
|
+
log_stream.once('close', () => resolve());
|
|
320
|
+
log_stream.end();
|
|
321
|
+
}));
|
|
271
322
|
const [command, ...args] = config.start_command;
|
|
272
323
|
const spawned_at = performance.now();
|
|
273
324
|
const child = spawn(command, args, {
|
|
@@ -279,8 +330,12 @@ export const spawn_backend = async (config) => {
|
|
|
279
330
|
});
|
|
280
331
|
// Keep a bounded stderr tail so a crash surfaces with context.
|
|
281
332
|
const stderr_tail = create_output_tail(STDERR_TAIL_MAX_BYTES);
|
|
333
|
+
// `'close'` follows the exit once the child's stdio has ended, so its last
|
|
334
|
+
// output is in the log file before teardown reads it
|
|
335
|
+
const child_closed = new Promise((resolve) => child.once('close', () => resolve()));
|
|
282
336
|
child.stderr?.on('data', (chunk) => {
|
|
283
337
|
stderr_tail.push(chunk);
|
|
338
|
+
stderr_log.write(chunk);
|
|
284
339
|
});
|
|
285
340
|
const format_stderr_tail = () => {
|
|
286
341
|
const text = stderr_tail.text();
|
|
@@ -300,8 +355,10 @@ export const spawn_backend = async (config) => {
|
|
|
300
355
|
// long-lived binary — so it hides in short/isolated runs. We discard
|
|
301
356
|
// rather than buffer (unlike stderr): stdout carries high-volume
|
|
302
357
|
// operational logging whose unbounded retention would leak across a
|
|
303
|
-
// long suite.
|
|
304
|
-
child.stdout?.on('data', () => {
|
|
358
|
+
// long suite. The log file, when configured, is on disk, not in memory.
|
|
359
|
+
child.stdout?.on('data', (chunk) => {
|
|
360
|
+
stdout_log.write(chunk);
|
|
361
|
+
});
|
|
305
362
|
// how the child ended: an exit, or a spawn that never produced a process
|
|
306
363
|
// (a command that doesn't exist emits `'error'` and never `'exit'`)
|
|
307
364
|
let exit_info = null;
|
|
@@ -417,11 +474,32 @@ export const spawn_backend = async (config) => {
|
|
|
417
474
|
return `exited (${exit}) at teardown, not code=0 — a shutdown that gave up on work still running or failed`;
|
|
418
475
|
};
|
|
419
476
|
let teardown_done = null;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (
|
|
423
|
-
|
|
477
|
+
/** The log's error lines no allowance names, as a failure message, or `null`. */
|
|
478
|
+
const check_log = async () => {
|
|
479
|
+
if (!config.log)
|
|
480
|
+
return null;
|
|
481
|
+
// bounded: a descendant that left the group can hold the pipe open
|
|
482
|
+
await Promise.race([child_closed, sleep(LOG_DRAIN_WAIT_MS)]);
|
|
483
|
+
await log_stream_closed();
|
|
484
|
+
if (log_write_error) {
|
|
485
|
+
return `spawn_backend(${config.name}): its log ${config.log.path} failed to write: ${log_write_error.message}`;
|
|
424
486
|
}
|
|
487
|
+
const unexpected = find_unexpected_backend_errors(await readFile(config.log.path, 'utf-8'), config.log.allow_errors);
|
|
488
|
+
return unexpected.length === 0
|
|
489
|
+
? null
|
|
490
|
+
: format_unexpected_backend_errors(config.name, config.log.path, unexpected);
|
|
491
|
+
};
|
|
492
|
+
const teardown = () => (teardown_done ??= stop().then(async (wait) => {
|
|
493
|
+
const unclean = describe_unclean_exit(wait);
|
|
494
|
+
const log_problem = await check_log();
|
|
495
|
+
const problems = [
|
|
496
|
+
...(unclean === null
|
|
497
|
+
? []
|
|
498
|
+
: [`spawn_backend(${config.name}): ${unclean}${format_stderr_tail()}`]),
|
|
499
|
+
...(log_problem === null ? [] : [log_problem])
|
|
500
|
+
];
|
|
501
|
+
if (problems.length > 0)
|
|
502
|
+
throw new Error(problems.join('\n\n'));
|
|
425
503
|
}));
|
|
426
504
|
// Wait for the child and every process left in its group to exit, so callers
|
|
427
505
|
// can be sure the port is free. A backend that ignores SIGTERM — or whose
|
|
@@ -459,6 +537,7 @@ export const spawn_backend = async (config) => {
|
|
|
459
537
|
catch (err) {
|
|
460
538
|
// the startup failure is the report, whatever the exit
|
|
461
539
|
await stop();
|
|
540
|
+
await log_stream_closed();
|
|
462
541
|
throw new Error(`spawn_backend(${config.name}) failed: ${err.message}${format_stderr_tail()}`);
|
|
463
542
|
}
|
|
464
543
|
};
|
|
@@ -63,7 +63,7 @@ export declare const SUITE_NAMES: readonly ["account_lifecycle", "actor_lookup",
|
|
|
63
63
|
/** A shipped single-backend cross suite, named by its module. */
|
|
64
64
|
export type SuiteName = (typeof SUITE_NAMES)[number];
|
|
65
65
|
/** A shipped suite module `describe_spine_cross_suites` leaves out. */
|
|
66
|
-
export type StandaloneSuiteName = 'conformance_table' | 'differential' | 'login_security' | 'standard_bundle' | 'ws_action_rate_limit';
|
|
66
|
+
export type StandaloneSuiteName = 'backend_swap' | 'conformance_table' | 'differential' | 'login_security' | 'standard_bundle' | 'ws_action_rate_limit';
|
|
67
67
|
/**
|
|
68
68
|
* The shipped suite modules `describe_spine_cross_suites` leaves out, each with
|
|
69
69
|
* why. Their entry points stay as they are; a consumer calls them beside the
|