@powerhousedao/switchboard 6.2.3-dev.8 → 6.2.3-dev.81
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/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
- package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
- package/.tsbuild/test/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/harness.d.ts +56 -0
- package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/.tsbuild/tsdown.config.d.ts.map +1 -1
- package/.tsbuild/vitest.config.d.ts.map +1 -1
- package/Auth.md +144 -2
- package/CHANGELOG.md +1074 -0
- package/README.md +55 -14
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-BO0n9R02.mjs +401 -0
- package/dist/from-env-BO0n9R02.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +76 -79
- package/dist/index.mjs.map +1 -1
- package/dist/install-packages.d.mts +2 -1
- package/dist/install-packages.mjs +2 -2
- package/dist/install-packages.mjs.map +1 -1
- package/dist/mcp-SsBK14Jm.mjs +32 -0
- package/dist/mcp-SsBK14Jm.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +7 -5
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-C1sYEm8g.d.mts +46 -0
- package/dist/plugin-host-C1sYEm8g.d.mts.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +79 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/privacy-DxIJGH4P.mjs +91 -0
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-COZsrGQT.mjs +40 -0
- package/dist/renown-layers-COZsrGQT.mjs.map +1 -0
- package/dist/schema-0g_QdOWn.mjs +267 -0
- package/dist/schema-0g_QdOWn.mjs.map +1 -0
- package/dist/schema-ivUWPQOn.d.mts +202 -0
- package/dist/schema-ivUWPQOn.d.mts.map +1 -0
- package/dist/server-cE1BWLQu.mjs +2518 -0
- package/dist/server-cE1BWLQu.mjs.map +1 -0
- package/dist/server.d.mts +270 -48
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/utils-C6AIF38Z.mjs +133 -0
- package/dist/utils-C6AIF38Z.mjs.map +1 -0
- package/dist/utils.d.mts +12 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +4 -3
- package/dist/worker-pool-BWHBLBJd.mjs +304 -0
- package/dist/worker-pool-BWHBLBJd.mjs.map +1 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
- package/dist/workflows-COM3MKfD.mjs +1437 -0
- package/dist/workflows-COM3MKfD.mjs.map +1 -0
- package/package.json +68 -23
- package/scripts/install-packages.sh +0 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/auth.test.ts +85 -0
- package/test/attachments/byte-grants.test.ts +290 -0
- package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
- package/test/attachments/download-target.test.ts +211 -32
- package/test/attachments/index.test.ts +47 -4
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +60 -4
- package/test/attachments/routes.test.ts +297 -35
- package/test/attachments/service-config.test.ts +41 -19
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +110 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +119 -0
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +200 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-unsupported-stored-documents.test.ts +214 -0
- package/test/boot-without-renown.test.ts +83 -0
- package/test/boot-without-require-signatures.test.ts +76 -0
- package/test/boot-worker-trust-policy.test.ts +91 -0
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/config-from-env.test.ts +758 -0
- package/test/config-merge.test.ts +215 -0
- package/test/config-schema.test.ts +128 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/default-drive-protocol-versions.test.ts +102 -0
- package/test/default-drive-slug.test.ts +97 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +165 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +322 -0
- package/test/goldens/supergraph.graphql +5652 -0
- package/test/goldens/workflow-runtime.graphql +1419 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +264 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +313 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -0
- package/test/unsupported-stored-documents.test.ts +72 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/harness.ts +289 -0
- package/test/workflow/oauth.test.ts +205 -0
- package/test/workflow/resolvers.test.ts +369 -0
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/webhook-dedupe.test.ts +295 -0
- package/test/workflow/webhook-signed.test.ts +509 -0
- package/test/workflow/webhook-trigger-test.test.ts +82 -0
- package/test/workflow/webhook-unsigned.test.ts +345 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +213 -0
- package/test/workflow-runtime.test.ts +1135 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +12 -1
- package/vitest.config.ts +65 -0
- package/dist/server-CiKkVE6g.mjs +0 -1555
- package/dist/server-CiKkVE6g.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs +0 -80
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -1,7 +1,62 @@
|
|
|
1
1
|
import { PGlite } from "@electric-sql/pglite";
|
|
2
2
|
import { Kysely, sql } from "kysely";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { ILogger } from "document-model";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import {
|
|
6
|
+
IN_MEMORY_PGLITE_STORAGE_FACTS,
|
|
7
|
+
PGLITE_PATH_STORAGE_FACTS,
|
|
8
|
+
POSTGRES_STORAGE_FACTS,
|
|
9
|
+
} from "@powerhousedao/reactor";
|
|
10
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { createReactorKysely } from "../src/server.mjs";
|
|
14
|
+
import { EventEmitter } from "node:events";
|
|
15
|
+
import { installFatalErrorShutdown } from "../src/fatal-shutdown.mjs";
|
|
16
|
+
import {
|
|
17
|
+
ClosablePGliteDialect,
|
|
18
|
+
reactorPgliteDialectOptions,
|
|
19
|
+
} from "../src/pglite-dialect.js";
|
|
20
|
+
|
|
21
|
+
type Row = { id: number };
|
|
22
|
+
type Schema = { t: Row };
|
|
23
|
+
|
|
24
|
+
function stubLogger(): ILogger {
|
|
25
|
+
const logger = {
|
|
26
|
+
verbose: vi.fn(),
|
|
27
|
+
debug: vi.fn(),
|
|
28
|
+
info: vi.fn(),
|
|
29
|
+
warn: vi.fn(),
|
|
30
|
+
error: vi.fn(),
|
|
31
|
+
child: vi.fn(),
|
|
32
|
+
};
|
|
33
|
+
logger.child.mockReturnValue(logger);
|
|
34
|
+
return logger as unknown as ILogger;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** COMMIT on an aborted transaction silently rolls back unless the dialect guards it. */
|
|
38
|
+
async function commitOfAnAbortedTransaction(
|
|
39
|
+
db: Kysely<Schema>,
|
|
40
|
+
): Promise<{ outcome: unknown; rows: Row[] }> {
|
|
41
|
+
await sql`create table t (id int primary key)`.execute(db);
|
|
42
|
+
const outcome = await db
|
|
43
|
+
.transaction()
|
|
44
|
+
.execute(async (trx) => {
|
|
45
|
+
await sql`insert into t (id) values (1)`.execute(trx);
|
|
46
|
+
try {
|
|
47
|
+
await sql`select 1 / 0`.execute(trx);
|
|
48
|
+
} catch {
|
|
49
|
+
/* swallowed, exactly as an unrelated caller would */
|
|
50
|
+
}
|
|
51
|
+
return "JOB-SUCCEEDED";
|
|
52
|
+
})
|
|
53
|
+
.then(
|
|
54
|
+
(value: unknown) => value,
|
|
55
|
+
(error: Error) => ({ error: error.message }),
|
|
56
|
+
);
|
|
57
|
+
const rows = await sql<Row>`select id from t`.execute(db);
|
|
58
|
+
return { outcome, rows: rows.rows };
|
|
59
|
+
}
|
|
5
60
|
|
|
6
61
|
describe("ClosablePGliteDialect", () => {
|
|
7
62
|
const created: PGlite[] = [];
|
|
@@ -26,6 +81,34 @@ describe("ClosablePGliteDialect", () => {
|
|
|
26
81
|
expect(pglite.closed).toBe(true);
|
|
27
82
|
});
|
|
28
83
|
|
|
84
|
+
it("tolerates a close that rejects because the runtime aborted", async () => {
|
|
85
|
+
const pglite = new PGlite();
|
|
86
|
+
created.push(pglite);
|
|
87
|
+
const db = new Kysely({ dialect: new ClosablePGliteDialect(pglite) });
|
|
88
|
+
await sql`select 1`.execute(db);
|
|
89
|
+
const realClose = pglite.close.bind(pglite);
|
|
90
|
+
pglite.close = () => {
|
|
91
|
+
pglite.close = realClose;
|
|
92
|
+
return Promise.reject(new Error("PGlite aborted: ENOSPC"));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
await expect(db.destroy()).resolves.toBeUndefined();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("rethrows a close that fails for any other reason", async () => {
|
|
99
|
+
const pglite = new PGlite();
|
|
100
|
+
created.push(pglite);
|
|
101
|
+
const db = new Kysely({ dialect: new ClosablePGliteDialect(pglite) });
|
|
102
|
+
await sql`select 1`.execute(db);
|
|
103
|
+
const realClose = pglite.close.bind(pglite);
|
|
104
|
+
pglite.close = () => {
|
|
105
|
+
pglite.close = realClose;
|
|
106
|
+
return Promise.reject(new Error("disk gone"));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
await expect(db.destroy()).rejects.toThrow("disk gone");
|
|
110
|
+
});
|
|
111
|
+
|
|
29
112
|
it("is idempotent if the PGlite is already closed", async () => {
|
|
30
113
|
const pglite = new PGlite();
|
|
31
114
|
created.push(pglite);
|
|
@@ -37,4 +120,156 @@ describe("ClosablePGliteDialect", () => {
|
|
|
37
120
|
|
|
38
121
|
await expect(db.destroy()).resolves.toBeUndefined();
|
|
39
122
|
});
|
|
123
|
+
|
|
124
|
+
it("refuses to report a commit for an aborted transaction", async () => {
|
|
125
|
+
const pglite = new PGlite();
|
|
126
|
+
created.push(pglite);
|
|
127
|
+
const db = new Kysely<Schema>({
|
|
128
|
+
dialect: new ClosablePGliteDialect(pglite, {
|
|
129
|
+
onDiagnostic: () => undefined,
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const { outcome, rows } = await commitOfAnAbortedTransaction(db);
|
|
134
|
+
expect(outcome).not.toBe("JOB-SUCCEEDED");
|
|
135
|
+
expect(rows).toEqual([]);
|
|
136
|
+
|
|
137
|
+
await db.destroy();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("switchboard's reactor storage factory", () => {
|
|
142
|
+
it.each([
|
|
143
|
+
["in the main thread", false],
|
|
144
|
+
["in a worker thread", true],
|
|
145
|
+
])(
|
|
146
|
+
"builds a PGlite kysely with the commit guard %s",
|
|
147
|
+
async (_where, pgliteWorkers) => {
|
|
148
|
+
const storage = await createReactorKysely({
|
|
149
|
+
reactorDbUrl: undefined,
|
|
150
|
+
reactorPgliteDir: ".ph/unused-by-the-in-memory-branch",
|
|
151
|
+
reactorPgliteMajor: 17,
|
|
152
|
+
inMemory: true,
|
|
153
|
+
hostPoolSize: () => {
|
|
154
|
+
throw new Error("the PGlite branch must not read the host pool size");
|
|
155
|
+
},
|
|
156
|
+
pgliteWorkers,
|
|
157
|
+
logger: stubLogger(),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const { outcome, rows } = await commitOfAnAbortedTransaction(
|
|
161
|
+
storage.kysely as unknown as Kysely<Schema>,
|
|
162
|
+
);
|
|
163
|
+
expect(outcome).not.toBe("JOB-SUCCEEDED");
|
|
164
|
+
expect(rows).toEqual([]);
|
|
165
|
+
expect(storage.poolInstrumentation).toBeUndefined();
|
|
166
|
+
|
|
167
|
+
await storage.kysely.destroy();
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
describe("storage facts", () => {
|
|
172
|
+
let dataDir: string | undefined;
|
|
173
|
+
|
|
174
|
+
afterEach(async () => {
|
|
175
|
+
if (dataDir) await rm(dataDir, { recursive: true, force: true });
|
|
176
|
+
dataDir = undefined;
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const open = (opts: Partial<Parameters<typeof createReactorKysely>[0]>) =>
|
|
180
|
+
createReactorKysely({
|
|
181
|
+
reactorDbUrl: undefined,
|
|
182
|
+
reactorPgliteDir: ".ph/unused-by-the-in-memory-branch",
|
|
183
|
+
reactorPgliteMajor: 17,
|
|
184
|
+
inMemory: false,
|
|
185
|
+
hostPoolSize: () => 1,
|
|
186
|
+
pgliteWorkers: false,
|
|
187
|
+
logger: stubLogger(),
|
|
188
|
+
...opts,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Kysely closes only a driver that has run a query; an unopened PGlite
|
|
192
|
+
// would still be initialising its data dir when afterEach removes it.
|
|
193
|
+
const openAndDestroy = async (
|
|
194
|
+
kysely: Awaited<ReturnType<typeof createReactorKysely>>["kysely"],
|
|
195
|
+
) => {
|
|
196
|
+
await sql`select 1`.execute(kysely);
|
|
197
|
+
await kysely.destroy();
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
it("reports in-memory PGlite as not durable", async () => {
|
|
201
|
+
const storage = await open({ inMemory: true });
|
|
202
|
+
expect(storage.storageFacts).toEqual(IN_MEMORY_PGLITE_STORAGE_FACTS);
|
|
203
|
+
await openAndDestroy(storage.kysely);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("reports a PGlite data directory as durable on a path", async () => {
|
|
207
|
+
dataDir = await mkdtemp(join(tmpdir(), "sb-facts-"));
|
|
208
|
+
const storage = await open({ reactorPgliteDir: dataDir });
|
|
209
|
+
expect(storage.storageFacts).toEqual(PGLITE_PATH_STORAGE_FACTS);
|
|
210
|
+
await openAndDestroy(storage.kysely);
|
|
211
|
+
}, 30_000);
|
|
212
|
+
|
|
213
|
+
it("closes a worker-backed PGlite data directory on destroy", async () => {
|
|
214
|
+
dataDir = await mkdtemp(join(tmpdir(), "sb-facts-"));
|
|
215
|
+
const storage = await open({
|
|
216
|
+
reactorPgliteDir: dataDir,
|
|
217
|
+
pgliteWorkers: true,
|
|
218
|
+
});
|
|
219
|
+
expect(storage.storageFacts).toEqual(PGLITE_PATH_STORAGE_FACTS);
|
|
220
|
+
await openAndDestroy(storage.kysely);
|
|
221
|
+
const reopened = await open({ reactorPgliteDir: dataDir });
|
|
222
|
+
await openAndDestroy(reopened.kysely);
|
|
223
|
+
}, 60_000);
|
|
224
|
+
|
|
225
|
+
it("reports a Postgres url as a durable server", async () => {
|
|
226
|
+
const storage = await open({
|
|
227
|
+
reactorDbUrl: "postgres://postgres:postgres@127.0.0.1:1/never-dialed",
|
|
228
|
+
});
|
|
229
|
+
expect(storage.storageFacts).toEqual(POSTGRES_STORAGE_FACTS);
|
|
230
|
+
await storage.kysely.destroy();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("a poisoned reactor PGlite session", () => {
|
|
236
|
+
it("takes the fatal shutdown path", async () => {
|
|
237
|
+
const emitter = new EventEmitter();
|
|
238
|
+
const proc = Object.assign(emitter, {
|
|
239
|
+
pid: 1234,
|
|
240
|
+
exitCode: undefined as number | undefined,
|
|
241
|
+
kill: vi.fn(() => true),
|
|
242
|
+
exit: vi.fn(),
|
|
243
|
+
});
|
|
244
|
+
const logger = stubLogger();
|
|
245
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
246
|
+
|
|
247
|
+
const pglite = new PGlite();
|
|
248
|
+
const dead = new Proxy(pglite, {
|
|
249
|
+
get(target, prop, receiver) {
|
|
250
|
+
if (prop === "query") {
|
|
251
|
+
return (text: string, params?: unknown[]) =>
|
|
252
|
+
/dead_call/.test(text)
|
|
253
|
+
? new Promise(() => undefined)
|
|
254
|
+
: target.query(text, params);
|
|
255
|
+
}
|
|
256
|
+
const value = Reflect.get(target, prop, receiver) as unknown;
|
|
257
|
+
return typeof value === "function"
|
|
258
|
+
? (value as (...args: unknown[]) => unknown).bind(target)
|
|
259
|
+
: value;
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
const db = new Kysely<Schema>({
|
|
263
|
+
dialect: new ClosablePGliteDialect(dead, {
|
|
264
|
+
...reactorPgliteDialectOptions(logger, proc as never),
|
|
265
|
+
statementTimeoutMs: 50,
|
|
266
|
+
}),
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
await expect(sql`select 1 as dead_call`.execute(db)).rejects.toThrow();
|
|
270
|
+
|
|
271
|
+
expect(proc.kill).toHaveBeenCalledWith(1234, "SIGTERM");
|
|
272
|
+
expect(proc.exitCode).toBe(1);
|
|
273
|
+
await pglite.close();
|
|
274
|
+
});
|
|
40
275
|
});
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { createDurableNodeFs } from "@powerhousedao/reactor-api/pglite-node";
|
|
2
|
+
import type { ILogger } from "document-model";
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
afterAll,
|
|
8
|
+
afterEach,
|
|
9
|
+
beforeAll,
|
|
10
|
+
beforeEach,
|
|
11
|
+
describe,
|
|
12
|
+
expect,
|
|
13
|
+
it,
|
|
14
|
+
vi,
|
|
15
|
+
} from "vitest";
|
|
16
|
+
import { runPglitePreflight } from "../src/pglite-preflight.js";
|
|
17
|
+
import { loadNodeFsClass, loadPGliteModule } from "../src/pglite-version.js";
|
|
18
|
+
import { writeSnapshotFromDir } from "./snapshot-writer.js";
|
|
19
|
+
|
|
20
|
+
// PGlite initdb and pg_dump are several times slower on the Windows runner.
|
|
21
|
+
const BOOT_TIMEOUT = 120_000;
|
|
22
|
+
const RM = { recursive: true, force: true, maxRetries: 10 } as const;
|
|
23
|
+
const ROWS = 10;
|
|
24
|
+
const CONVERTED_LINE =
|
|
25
|
+
/^Converted PGlite snapshot at (.+): snapshot (\d+) bytes -> (\d+) bytes on disk, (\d+) entries, (\d+) ms$/;
|
|
26
|
+
|
|
27
|
+
type StubLogger = ILogger & {
|
|
28
|
+
debug: ReturnType<typeof vi.fn>;
|
|
29
|
+
info: ReturnType<typeof vi.fn>;
|
|
30
|
+
warn: ReturnType<typeof vi.fn>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function stubLogger(): StubLogger {
|
|
34
|
+
const logger = {
|
|
35
|
+
verbose: vi.fn(),
|
|
36
|
+
debug: vi.fn(),
|
|
37
|
+
info: vi.fn(),
|
|
38
|
+
warn: vi.fn(),
|
|
39
|
+
error: vi.fn(),
|
|
40
|
+
child: vi.fn(),
|
|
41
|
+
};
|
|
42
|
+
logger.child.mockReturnValue(logger);
|
|
43
|
+
return logger as unknown as StubLogger;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function exists(p: string): Promise<boolean> {
|
|
47
|
+
try {
|
|
48
|
+
await fs.lstat(p);
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function pgVersion(dir: string): Promise<string> {
|
|
56
|
+
return (await fs.readFile(path.join(dir, "PG_VERSION"), "utf8")).trim();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Opens `dir` the way the server does and counts the seeded rows. */
|
|
60
|
+
async function countRows(dir: string, major: 16 | 17): Promise<number> {
|
|
61
|
+
const [{ PGlite: Pg }, Base] = await Promise.all([
|
|
62
|
+
loadPGliteModule(major),
|
|
63
|
+
loadNodeFsClass(major),
|
|
64
|
+
]);
|
|
65
|
+
const pg = new Pg({
|
|
66
|
+
fs: createDurableNodeFs(Base, dir, {
|
|
67
|
+
fsync: false,
|
|
68
|
+
maintenanceIntervalMs: 0,
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
try {
|
|
72
|
+
await pg.waitReady;
|
|
73
|
+
const { rows } = await pg.query<{ n: number }>(
|
|
74
|
+
'SELECT count(*)::int AS n FROM "Rows"',
|
|
75
|
+
);
|
|
76
|
+
return rows[0].n;
|
|
77
|
+
} finally {
|
|
78
|
+
await pg.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function convertedLines(logger: StubLogger): string[] {
|
|
83
|
+
return logger.info.mock.calls
|
|
84
|
+
.map((call) => String(call[0]))
|
|
85
|
+
.filter((line) => CONVERTED_LINE.test(line));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe("runPglitePreflight", () => {
|
|
89
|
+
// A pure-snapshot PG16 store: snapshot.bin and nothing else, the layout
|
|
90
|
+
// AtomicNodeFs left for a store it created itself.
|
|
91
|
+
let template: string;
|
|
92
|
+
let root: string;
|
|
93
|
+
let logger: StubLogger;
|
|
94
|
+
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
template = await fs.mkdtemp(path.join(os.tmpdir(), "preflight-template-"));
|
|
97
|
+
const loose = path.join(template, "loose");
|
|
98
|
+
const { PGlite: LegacyPGlite } = await loadPGliteModule(16);
|
|
99
|
+
const LegacyNodeFS = await loadNodeFsClass(16);
|
|
100
|
+
const pg = new LegacyPGlite({ fs: new LegacyNodeFS(loose) });
|
|
101
|
+
await pg.waitReady;
|
|
102
|
+
await pg.exec('CREATE TABLE "Rows" (id int PRIMARY KEY, payload text)');
|
|
103
|
+
await pg.exec(
|
|
104
|
+
`INSERT INTO "Rows" SELECT g, repeat('x', 100) FROM generate_series(1, ${ROWS}) g`,
|
|
105
|
+
);
|
|
106
|
+
await pg.close();
|
|
107
|
+
await fs.rm(path.join(loose, "postmaster.pid"), { force: true });
|
|
108
|
+
expect(await pgVersion(loose)).toBe("16");
|
|
109
|
+
|
|
110
|
+
const store = path.join(template, "store");
|
|
111
|
+
await fs.mkdir(store);
|
|
112
|
+
await writeSnapshotFromDir(loose, path.join(store, "snapshot.bin"));
|
|
113
|
+
await fs.rm(loose, RM);
|
|
114
|
+
}, BOOT_TIMEOUT);
|
|
115
|
+
|
|
116
|
+
afterAll(async () => {
|
|
117
|
+
await fs.rm(template, RM);
|
|
118
|
+
}, BOOT_TIMEOUT);
|
|
119
|
+
|
|
120
|
+
beforeEach(async () => {
|
|
121
|
+
root = await fs.mkdtemp(path.join(os.tmpdir(), "preflight-"));
|
|
122
|
+
logger = stubLogger();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
afterEach(async () => {
|
|
126
|
+
await fs.rm(root, RM);
|
|
127
|
+
}, BOOT_TIMEOUT);
|
|
128
|
+
|
|
129
|
+
async function snapshotDir(name: string): Promise<string> {
|
|
130
|
+
const dir = path.join(root, name);
|
|
131
|
+
await fs.cp(path.join(template, "store"), dir, { recursive: true });
|
|
132
|
+
return dir;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function looseDir(name: string, major = 17): Promise<string> {
|
|
136
|
+
const dir = path.join(root, name);
|
|
137
|
+
await fs.mkdir(path.join(dir, "pg_wal"), { recursive: true });
|
|
138
|
+
await fs.writeFile(path.join(dir, "PG_VERSION"), `${major}\n`);
|
|
139
|
+
return dir;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
it(
|
|
143
|
+
"converts before detecting the major, so a PG16 snapshot is migrated",
|
|
144
|
+
async () => {
|
|
145
|
+
const dir = await snapshotDir("reactor-storage");
|
|
146
|
+
|
|
147
|
+
const detected = await runPglitePreflight({
|
|
148
|
+
dirs: [dir],
|
|
149
|
+
migratePglite: true,
|
|
150
|
+
inMemory: false,
|
|
151
|
+
logger,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(detected.get(dir)).toBe(17);
|
|
155
|
+
expect(await pgVersion(dir)).toBe("17");
|
|
156
|
+
expect(await exists(path.join(dir, "snapshot.bin"))).toBe(false);
|
|
157
|
+
expect(await exists(`${dir}.converting`)).toBe(false);
|
|
158
|
+
expect(await exists(`${dir}.old`)).toBe(false);
|
|
159
|
+
expect(convertedLines(logger)).toHaveLength(1);
|
|
160
|
+
expect(logger.info).toHaveBeenCalledWith(
|
|
161
|
+
expect.stringContaining("Migrating"),
|
|
162
|
+
);
|
|
163
|
+
expect(await countRows(dir, 17)).toBe(ROWS);
|
|
164
|
+
},
|
|
165
|
+
BOOT_TIMEOUT,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// Pins the order alone: before this change a pure-snapshot dir had no loose
|
|
169
|
+
// PG_VERSION and the migration logged "No PG_VERSION; skipping". The case
|
|
170
|
+
// above also needs the legacy pg_dump to work.
|
|
171
|
+
it(
|
|
172
|
+
"attempts the migration of a PG16 snapshot instead of skipping it",
|
|
173
|
+
async () => {
|
|
174
|
+
const dir = await snapshotDir("reactor-storage");
|
|
175
|
+
|
|
176
|
+
await runPglitePreflight({
|
|
177
|
+
dirs: [dir],
|
|
178
|
+
migratePglite: true,
|
|
179
|
+
inMemory: false,
|
|
180
|
+
logger,
|
|
181
|
+
}).catch(() => undefined);
|
|
182
|
+
|
|
183
|
+
expect(convertedLines(logger)).toHaveLength(1);
|
|
184
|
+
expect(logger.info).not.toHaveBeenCalledWith(
|
|
185
|
+
expect.stringContaining("No PG_VERSION"),
|
|
186
|
+
);
|
|
187
|
+
expect(logger.info).toHaveBeenCalledWith(
|
|
188
|
+
expect.stringContaining(`Migrating ${dir} from PG16 to PG17`),
|
|
189
|
+
);
|
|
190
|
+
},
|
|
191
|
+
BOOT_TIMEOUT,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
it(
|
|
195
|
+
"boots a converted dir on the second start without converting",
|
|
196
|
+
async () => {
|
|
197
|
+
const dir = await snapshotDir("reactor-storage");
|
|
198
|
+
const first = { dirs: [dir], inMemory: false, logger };
|
|
199
|
+
await runPglitePreflight(first);
|
|
200
|
+
expect(convertedLines(logger)).toHaveLength(1);
|
|
201
|
+
expect(await pgVersion(dir)).toBe("16");
|
|
202
|
+
|
|
203
|
+
const second = stubLogger();
|
|
204
|
+
const detected = await runPglitePreflight({ ...first, logger: second });
|
|
205
|
+
|
|
206
|
+
expect(detected.get(dir)).toBe(16);
|
|
207
|
+
expect(convertedLines(second)).toHaveLength(0);
|
|
208
|
+
expect(await exists(`${dir}.converting`)).toBe(false);
|
|
209
|
+
expect(await exists(`${dir}.old`)).toBe(false);
|
|
210
|
+
expect(await countRows(dir, 16)).toBe(ROWS);
|
|
211
|
+
},
|
|
212
|
+
BOOT_TIMEOUT,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
it("removes pg_wal/xlogtemp.*", async () => {
|
|
216
|
+
const dir = await looseDir("read-storage");
|
|
217
|
+
const segment = path.join(dir, "pg_wal", "000000010000000000000001");
|
|
218
|
+
await fs.writeFile(segment, "wal");
|
|
219
|
+
await fs.writeFile(path.join(dir, "pg_wal", "xlogtemp.42"), "");
|
|
220
|
+
await fs.writeFile(path.join(dir, "pg_wal", "xlogtemp.7"), "");
|
|
221
|
+
|
|
222
|
+
const detected = await runPglitePreflight({
|
|
223
|
+
dirs: [dir],
|
|
224
|
+
inMemory: false,
|
|
225
|
+
logger,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
expect(detected.get(dir)).toBe(17);
|
|
229
|
+
expect(await fs.readdir(path.join(dir, "pg_wal"))).toEqual([
|
|
230
|
+
"000000010000000000000001",
|
|
231
|
+
]);
|
|
232
|
+
expect(await exists(segment)).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("removes postmaster.pid without a warn call", async () => {
|
|
236
|
+
const dir = await looseDir("read-storage");
|
|
237
|
+
const lockfile = path.join(dir, "postmaster.pid");
|
|
238
|
+
await fs.writeFile(lockfile, "42\n");
|
|
239
|
+
|
|
240
|
+
await runPglitePreflight({ dirs: [dir], inMemory: false, logger });
|
|
241
|
+
|
|
242
|
+
expect(await exists(lockfile)).toBe(false);
|
|
243
|
+
expect(logger.warn).not.toHaveBeenCalled();
|
|
244
|
+
expect(logger.debug).toHaveBeenCalledWith(
|
|
245
|
+
expect.stringContaining(lockfile),
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it(
|
|
250
|
+
"logs one info line per converted dir with sizes and duration",
|
|
251
|
+
async () => {
|
|
252
|
+
const reactor = await snapshotDir("reactor-storage");
|
|
253
|
+
const readModel = await snapshotDir("read-storage");
|
|
254
|
+
|
|
255
|
+
await runPglitePreflight({
|
|
256
|
+
dirs: [reactor, readModel],
|
|
257
|
+
inMemory: false,
|
|
258
|
+
logger,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const lines = convertedLines(logger);
|
|
262
|
+
expect(lines).toHaveLength(2);
|
|
263
|
+
const byDir = new Map(
|
|
264
|
+
lines.map((line) => {
|
|
265
|
+
const match = CONVERTED_LINE.exec(line)!;
|
|
266
|
+
return [match[1], match.slice(2).map(Number)] as const;
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
for (const dir of [reactor, readModel]) {
|
|
270
|
+
const [snapshotBytes, convertedBytes, entries] = byDir.get(dir)!;
|
|
271
|
+
expect(snapshotBytes).toBeGreaterThan(0);
|
|
272
|
+
expect(convertedBytes).toBeGreaterThan(0);
|
|
273
|
+
expect(entries).toBeGreaterThan(0);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
BOOT_TIMEOUT,
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
it("touches nothing in memory", async () => {
|
|
280
|
+
const dir = await snapshotDir("reactor-storage");
|
|
281
|
+
|
|
282
|
+
const detected = await runPglitePreflight({
|
|
283
|
+
dirs: [dir],
|
|
284
|
+
inMemory: true,
|
|
285
|
+
logger,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(detected.size).toBe(0);
|
|
289
|
+
expect(await exists(path.join(dir, "snapshot.bin"))).toBe(true);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("wipes the dirs and their conversion siblings under forcePgVersion", async () => {
|
|
293
|
+
const dir = await snapshotDir("reactor-storage");
|
|
294
|
+
await fs.mkdir(`${dir}.old`);
|
|
295
|
+
await fs.mkdir(`${dir}.converting`);
|
|
296
|
+
|
|
297
|
+
const detected = await runPglitePreflight({
|
|
298
|
+
dirs: [dir],
|
|
299
|
+
forcePgVersion: 17,
|
|
300
|
+
migratePglite: true,
|
|
301
|
+
inMemory: false,
|
|
302
|
+
logger,
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
expect(detected.size).toBe(0);
|
|
306
|
+
expect(await exists(dir)).toBe(false);
|
|
307
|
+
expect(await exists(`${dir}.old`)).toBe(false);
|
|
308
|
+
expect(await exists(`${dir}.converting`)).toBe(false);
|
|
309
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
310
|
+
expect.stringContaining("ignoring --migrate-pglite"),
|
|
311
|
+
);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { resolvePgliteStorageDirs } from "../src/server.mjs";
|
|
4
|
+
|
|
5
|
+
/** The classic layout, and the one-dir report (uniform-runners legacy parity). */
|
|
6
|
+
describe("resolvePgliteStorageDirs", () => {
|
|
7
|
+
const phDir = path.join("/proj", ".ph");
|
|
8
|
+
|
|
9
|
+
it("keeps the classic literals verbatim without a user-data root", () => {
|
|
10
|
+
const dirs = resolvePgliteStorageDirs({
|
|
11
|
+
dbPath: undefined,
|
|
12
|
+
reactorDbUrl: undefined,
|
|
13
|
+
callerReactor: false,
|
|
14
|
+
});
|
|
15
|
+
expect(dirs.reactorPgliteDir).toBe("./.ph/reactor-storage");
|
|
16
|
+
expect(dirs.readModelPgliteDir).toBe(".ph/read-storage");
|
|
17
|
+
expect(dirs.sharedPgliteDir).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("moves the defaults under the user-data root", () => {
|
|
21
|
+
const userData = path.join("/home", "user");
|
|
22
|
+
const dirs = resolvePgliteStorageDirs({
|
|
23
|
+
dbPath: undefined,
|
|
24
|
+
reactorDbUrl: undefined,
|
|
25
|
+
callerReactor: false,
|
|
26
|
+
userDataDir: userData,
|
|
27
|
+
});
|
|
28
|
+
expect(dirs.reactorPgliteDir).toBe(
|
|
29
|
+
path.join(userData, ".ph", "reactor-storage"),
|
|
30
|
+
);
|
|
31
|
+
expect(dirs.readModelPgliteDir).toBe(
|
|
32
|
+
path.join(userData, ".ph", "read-storage"),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("defaults to the classic split under the .ph tree", () => {
|
|
37
|
+
const dirs = resolvePgliteStorageDirs({
|
|
38
|
+
dbPath: undefined,
|
|
39
|
+
reactorDbUrl: undefined,
|
|
40
|
+
callerReactor: false,
|
|
41
|
+
phDir,
|
|
42
|
+
});
|
|
43
|
+
expect(dirs.reactorPgliteDir).toBe(path.join(phDir, "reactor-storage"));
|
|
44
|
+
expect(dirs.readModelPgliteDir).toBe(path.join(phDir, "read-storage"));
|
|
45
|
+
expect(dirs.pgliteDirs).toEqual([
|
|
46
|
+
path.join(phDir, "reactor-storage"),
|
|
47
|
+
path.join(phDir, "read-storage"),
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("reports — but keeps — the classic dbPath-only layout: both stores in one dir", () => {
|
|
52
|
+
const store = path.join("/proj", ".ph", "read-model.db");
|
|
53
|
+
const dirs = resolvePgliteStorageDirs({
|
|
54
|
+
dbPath: store,
|
|
55
|
+
reactorDbUrl: store,
|
|
56
|
+
callerReactor: false,
|
|
57
|
+
phDir,
|
|
58
|
+
});
|
|
59
|
+
expect(dirs.reactorPgliteDir).toBe(store);
|
|
60
|
+
expect(dirs.readModelPgliteDir).toBe(store);
|
|
61
|
+
// pre-flight list unchanged from the classic code (not deduplicated)
|
|
62
|
+
expect(dirs.pgliteDirs).toEqual([store, store]);
|
|
63
|
+
expect(dirs.sharedPgliteDir).toBe(path.resolve(store));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("detects the same dir spelled differently", () => {
|
|
67
|
+
const dirs = resolvePgliteStorageDirs({
|
|
68
|
+
dbPath: "/proj/.ph/store/",
|
|
69
|
+
reactorDbUrl: "/proj/.ph/../.ph/store",
|
|
70
|
+
callerReactor: false,
|
|
71
|
+
phDir,
|
|
72
|
+
});
|
|
73
|
+
expect(dirs.sharedPgliteDir).toBe(path.resolve("/proj/.ph/store"));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("allows one Postgres database for both stores", () => {
|
|
77
|
+
const dirs = resolvePgliteStorageDirs({
|
|
78
|
+
dbPath: "postgres://db/ph",
|
|
79
|
+
reactorDbUrl: "postgres://db/ph",
|
|
80
|
+
callerReactor: false,
|
|
81
|
+
phDir,
|
|
82
|
+
});
|
|
83
|
+
expect(dirs.reactorPgliteDir).toBeNull();
|
|
84
|
+
expect(dirs.readModelPgliteDir).toBeNull();
|
|
85
|
+
expect(dirs.pgliteDirs).toEqual([]);
|
|
86
|
+
expect(dirs.sharedPgliteDir).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("allows dbPath to name the read model only when the caller owns the reactor", () => {
|
|
90
|
+
const store = path.join("/proj", ".ph", "read-model.db");
|
|
91
|
+
const dirs = resolvePgliteStorageDirs({
|
|
92
|
+
dbPath: store,
|
|
93
|
+
reactorDbUrl: store,
|
|
94
|
+
callerReactor: true,
|
|
95
|
+
phDir,
|
|
96
|
+
});
|
|
97
|
+
expect(dirs.reactorPgliteDir).toBeNull();
|
|
98
|
+
expect(dirs.readModelPgliteDir).toBe(store);
|
|
99
|
+
expect(dirs.pgliteDirs).toEqual([store]);
|
|
100
|
+
expect(dirs.sharedPgliteDir).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("keeps a distinct reactor dir from PH_REACTOR_DATABASE_URL beside a dbPath", () => {
|
|
104
|
+
const dirs = resolvePgliteStorageDirs({
|
|
105
|
+
dbPath: path.join(phDir, "read-storage"),
|
|
106
|
+
reactorDbUrl: path.join(phDir, "reactor-storage"),
|
|
107
|
+
callerReactor: false,
|
|
108
|
+
phDir,
|
|
109
|
+
});
|
|
110
|
+
expect(dirs.pgliteDirs).toHaveLength(2);
|
|
111
|
+
expect(dirs.sharedPgliteDir).toBeNull();
|
|
112
|
+
});
|
|
113
|
+
});
|