@powerhousedao/switchboard 6.2.3-dev.73 → 6.2.3-dev.75
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/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.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/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.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/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +51 -0
- package/dist/boot.d.mts +38 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +61 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/index.mjs +5 -4
- package/dist/index.mjs.map +1 -1
- package/dist/migrate.mjs +4 -3
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/reactor-feature-flags-BtWVQDt6.mjs +324 -0
- package/dist/reactor-feature-flags-BtWVQDt6.mjs.map +1 -0
- package/dist/{server-CrWPtMG6.mjs → server-CJjK7WpR.mjs} +214 -333
- package/dist/server-CJjK7WpR.mjs.map +1 -0
- package/dist/server.d.mts +11 -3
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/dist/{utils-Dh845exv.mjs → utils-CTtD7Oti.mjs} +5 -8
- package/dist/{utils-Dh845exv.mjs.map → utils-CTtD7Oti.mjs.map} +1 -1
- package/dist/utils.d.mts +3 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +4 -3
- package/package.json +21 -16
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-preconditions.test.ts +149 -0
- package/test/pglite-dialect.test.ts +39 -19
- package/test/pglite-store.test.ts +311 -0
- package/test/renown-storage-path.test.ts +39 -0
- package/test/renown-trust-policy.test.ts +7 -9
- package/tsdown.config.ts +1 -0
- package/dist/server-CrWPtMG6.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0aadcaf7-64f1-547a-bf96-2fe0fd3c09db")}catch(e){}}();
|
|
3
3
|
import { reactorDriveCreateDocument, reactorDriveCreateState } from "@powerhousedao/reactor-drive";
|
|
4
|
-
import { driveCreateDocument, driveCreateState } from "@powerhousedao/shared/document-drive";
|
|
5
4
|
import { withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
5
|
+
import { driveCreateDocument, driveCreateState } from "@powerhousedao/shared/document-drive";
|
|
6
6
|
//#region src/utils.mts
|
|
7
7
|
/**
|
|
8
8
|
* A configured id pins the drive, and only a legacy drive can take a chosen
|
|
@@ -109,11 +109,8 @@ async function addDefaultReactorDrive(client, drive, serverPort, logger = consol
|
|
|
109
109
|
}
|
|
110
110
|
return `http://localhost:${serverPort}/d/${driveId}`;
|
|
111
111
|
}
|
|
112
|
-
function isPostgresUrl(url) {
|
|
113
|
-
return url.startsWith("postgresql") || url.startsWith("postgres");
|
|
114
|
-
}
|
|
115
112
|
//#endregion
|
|
116
|
-
export { addDefaultReactorDrive as n,
|
|
113
|
+
export { addDefaultReactorDrive as n, addDefaultDrive as t };
|
|
117
114
|
|
|
118
|
-
//# sourceMappingURL=utils-
|
|
119
|
-
//# debugId=
|
|
115
|
+
//# sourceMappingURL=utils-CTtD7Oti.mjs.map
|
|
116
|
+
//# debugId=0aadcaf7-64f1-547a-bf96-2fe0fd3c09db
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-CTtD7Oti.mjs","sources":["../src/utils.mts"],"sourcesContent":["import type { IReactorClient } from \"@powerhousedao/reactor\";\nimport {\n reactorDriveCreateDocument,\n reactorDriveCreateState,\n} from \"@powerhousedao/reactor-drive\";\nimport {\n driveCreateDocument,\n driveCreateState,\n} from \"@powerhousedao/shared/document-drive\";\nimport type { DriveInput } from \"@powerhousedao/shared/document-drive\";\nimport {\n withSignaturePolicy,\n type PHDocument,\n} from \"@powerhousedao/shared/document-model\";\n\n/**\n * A configured id pins the drive, and only a legacy drive can take a chosen\n * id; otherwise the client's creation default applies.\n */\nasync function underCreatePolicy<TDocument extends PHDocument>(\n client: IReactorClient,\n document: TDocument,\n id: string | undefined,\n): Promise<TDocument> {\n return id\n ? withSignaturePolicy(document, \"legacy\", { id })\n : withSignaturePolicy(document, await client.getCreateSignaturePolicy());\n}\n\ntype DefaultDriveLogger = { error: (message: string) => void };\n\n/** The document that already holds `slug`; null when two do (an id and a slug). */\nasync function slugHolder(\n client: IReactorClient,\n slug: string,\n): Promise<PHDocument | null | undefined> {\n let id: string;\n try {\n id = await client.resolveIdOrSlug(slug);\n } catch (error) {\n const notFound =\n error instanceof Error && error.name === \"DocumentNotFoundError\";\n return notFound ? undefined : null;\n }\n return client.get(id);\n}\n\n/**\n * A default drive whose slug another document holds: a drive of the same type\n * stands in for it (its URL); anything else keeps it uncreated (null), with an\n * error logged so the server still starts. Undefined when the slug is free.\n */\nasync function slugTakenBy(\n client: IReactorClient,\n drive: DriveInput,\n documentType: string,\n serverPort: number,\n logger: DefaultDriveLogger,\n): Promise<string | null | undefined> {\n if (!drive.slug) return undefined;\n const holder = await slugHolder(client, drive.slug);\n if (holder === undefined) return undefined;\n if (holder?.header.documentType === documentType) {\n return `http://localhost:${serverPort}/d/${holder.header.id}`;\n }\n const owner = holder\n ? `${holder.header.documentType} document ${holder.header.id}`\n : \"two documents\";\n logger.error(\n `The default drive \"${drive.slug}\" was not created: the slug belongs to ${owner}.`,\n );\n return null;\n}\n\n/** Creates a configured drive unless one with its id or slug exists; the\n * URL it is served at, or undefined when another document holds the slug. */\nexport async function addDefaultDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n let driveId = drive.id;\n if (!driveId || driveId.length === 0) {\n driveId = drive.slug;\n }\n\n if (!driveId || driveId.length === 0) {\n throw new Error(\"Invalid Drive Id\");\n }\n\n // check if the drive already exists\n let existingDrive;\n try {\n existingDrive = await client.get(driveId);\n } catch {\n //\n }\n\n // already exists, return the existing drive url\n if (existingDrive) {\n return `http://localhost:${serverPort}/d/${driveId}`;\n }\n\n const { global } = driveCreateState();\n const created = driveCreateDocument({\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n availableOffline: drive.local?.availableOffline ?? false,\n sharingType: drive.local?.sharingType ?? \"public\",\n listeners: drive.local?.listeners ?? [],\n triggers: drive.local?.triggers ?? [],\n },\n });\n\n const taken = await slugTakenBy(\n client,\n drive,\n created.header.documentType,\n serverPort,\n logger,\n );\n if (taken !== undefined) return taken ?? undefined;\n\n const document = await underCreatePolicy(client, created, drive.id);\n if (drive.slug && drive.slug.length > 0) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await client.create(document);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n }\n\n return `http://localhost:${serverPort}/d/${driveId}`;\n}\n\n/** addDefaultDrive for a reactor drive. */\nexport async function addDefaultReactorDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n let driveId = drive.id;\n if (!driveId || driveId.length === 0) {\n driveId = drive.slug;\n }\n\n if (!driveId || driveId.length === 0) {\n throw new Error(\"Invalid Drive Id\");\n }\n\n let existingDrive;\n try {\n existingDrive = await client.get(driveId);\n } catch {\n //\n }\n\n if (existingDrive) {\n return `http://localhost:${serverPort}/d/${driveId}`;\n }\n\n const { global, local } = reactorDriveCreateState();\n const created = reactorDriveCreateDocument({\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n ...local,\n availableOffline: drive.local?.availableOffline ?? local.availableOffline,\n sharingType: drive.local?.sharingType ?? local.sharingType,\n },\n });\n\n const taken = await slugTakenBy(\n client,\n drive,\n created.header.documentType,\n serverPort,\n logger,\n );\n if (taken !== undefined) return taken ?? undefined;\n\n const document = await underCreatePolicy(client, created, drive.id);\n if (drive.slug && drive.slug.length > 0) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await client.create(document);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n }\n\n return `http://localhost:${serverPort}/d/${driveId}`;\n}\n\nexport { isPostgresUrl } from \"./postgres-url.mjs\";\n"],"names":[],"mappings":";;;;;;;;;;AAmBA,eAAe,kBACb,QACA,UACA,IACoB;CACpB,OAAO,KACH,oBAAoB,UAAU,UAAU,EAAE,GAAG,CAAC,IAC9C,oBAAoB,UAAU,MAAM,OAAO,yBAAyB,CAAC;AAC3E;;AAKA,eAAe,WACb,QACA,MACwC;CACxC,IAAI;CACJ,IAAI;EACF,KAAK,MAAM,O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AAS,KAAA;CAEzC,MAAM,WAAW,MAAM,kBAAkB,QAAQ,SAAS,MAAM,EAAE;CAClE,IAAI,MAAM,QAAQ,MAAM,KAAK,SAAS,GACpC,SAAS,OAAO,OAAO,MAAM;CAE/B,IAAI,MAAM,OAAO,MACf,SAAS,OAAO,OAAO,MAAM,OAAO;CAEtC,IAAI,MAAM,iBACR,SAAS,OAAO,OAAO,EAAE,iBAAiB,MAAM,gBAAgB;CAGlE,IAAI;EACF,MAAM,OAAO,OAAO,QAAQ;CAC9B,SAAS,GAAG;EAEV,IAAI,EADiB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAA,CAC5C,SAAS,gBAAgB,GACzC,MAAM;CAEV;CAEA,OAAO,oBAAoB,WAAW,KAAK;AAC7C","debug_id":"0aadcaf7-64f1-547a-bf96-2fe0fd3c09db"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IReactorClient } from "@powerhousedao/reactor";
|
|
2
2
|
import { DriveInput } from "@powerhousedao/shared/document-drive";
|
|
3
|
+
//#region src/postgres-url.d.mts
|
|
4
|
+
export declare function isPostgresUrl(url: string): boolean;
|
|
5
|
+
//#endregion
|
|
3
6
|
//#region src/utils.d.mts
|
|
4
7
|
type DefaultDriveLogger = {
|
|
5
8
|
error: (message: string) => void;
|
|
@@ -9,7 +12,6 @@ type DefaultDriveLogger = {
|
|
|
9
12
|
export declare function addDefaultDrive(client: IReactorClient, drive: DriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
|
|
10
13
|
/** addDefaultDrive for a reactor drive. */
|
|
11
14
|
export declare function addDefaultReactorDrive(client: IReactorClient, drive: DriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
|
|
12
|
-
export declare function isPostgresUrl(url: string): boolean;
|
|
13
15
|
//#endregion
|
|
14
16
|
export {};
|
|
15
17
|
//# sourceMappingURL=utils.d.mts.map
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.mts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/postgres-url.mts","../src/utils.mts"],"mappings":";;;wBAAgB,cAAc;;;KC6BzB;EAAuB,QAAQ;;;;wBA+Cd,gBACpB,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP;;wBAuEmB,uBACpB,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
2
|
+
import { n as addDefaultReactorDrive, t as addDefaultDrive } from "./utils-CTtD7Oti.mjs";
|
|
2
3
|
export { addDefaultDrive, addDefaultReactorDrive, isPostgresUrl };
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
4
|
-
//# debugId=
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d4334b48-9b17-5ef0-ad9b-9f31ee6e49e3")}catch(e){}}();
|
|
5
|
+
//# debugId=d4334b48-9b17-5ef0-ad9b-9f31ee6e49e3
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/switchboard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.3-dev.
|
|
4
|
+
"version": "6.2.3-dev.75",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"types": "./dist/utils.d.mts",
|
|
20
20
|
"import": "./dist/utils.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./boot": {
|
|
23
|
+
"source": "./src/boot.mts",
|
|
24
|
+
"types": "./dist/boot.d.mts",
|
|
25
|
+
"import": "./dist/boot.mjs"
|
|
26
|
+
},
|
|
22
27
|
"./plugins/mcp": {
|
|
23
28
|
"source": "./src/plugins/mcp.mts",
|
|
24
29
|
"types": "./dist/plugins/mcp.d.mts",
|
|
@@ -76,24 +81,24 @@
|
|
|
76
81
|
"@opentelemetry/sdk-node": "^0.218.0",
|
|
77
82
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
78
83
|
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
79
|
-
"@powerhousedao/config": "6.2.3-dev.
|
|
80
|
-
"@powerhousedao/host-core": "6.2.3-dev.
|
|
81
|
-
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.2.3-dev.
|
|
82
|
-
"@powerhousedao/reactor": "6.2.3-dev.
|
|
83
|
-
"@powerhousedao/reactor-api": "6.2.3-dev.
|
|
84
|
-
"@powerhousedao/reactor-attachments": "6.2.3-dev.
|
|
85
|
-
"@powerhousedao/reactor-drive": "6.2.3-dev.
|
|
86
|
-
"@powerhousedao/reactor-group": "6.2.3-dev.
|
|
87
|
-
"@powerhousedao/reactor-privacy": "6.2.3-dev.
|
|
88
|
-
"@powerhousedao/reactor-workflow": "6.2.3-dev.
|
|
89
|
-
"@powerhousedao/shared": "6.2.3-dev.
|
|
90
|
-
"@powerhousedao/vetra": "6.2.3-dev.
|
|
91
|
-
"@powerhousedao/workflow": "6.2.3-dev.
|
|
84
|
+
"@powerhousedao/config": "6.2.3-dev.75",
|
|
85
|
+
"@powerhousedao/host-core": "6.2.3-dev.75",
|
|
86
|
+
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.2.3-dev.75",
|
|
87
|
+
"@powerhousedao/reactor": "6.2.3-dev.75",
|
|
88
|
+
"@powerhousedao/reactor-api": "6.2.3-dev.75",
|
|
89
|
+
"@powerhousedao/reactor-attachments": "6.2.3-dev.75",
|
|
90
|
+
"@powerhousedao/reactor-drive": "6.2.3-dev.75",
|
|
91
|
+
"@powerhousedao/reactor-group": "6.2.3-dev.75",
|
|
92
|
+
"@powerhousedao/reactor-privacy": "6.2.3-dev.75",
|
|
93
|
+
"@powerhousedao/reactor-workflow": "6.2.3-dev.75",
|
|
94
|
+
"@powerhousedao/shared": "6.2.3-dev.75",
|
|
95
|
+
"@powerhousedao/vetra": "6.2.3-dev.75",
|
|
96
|
+
"@powerhousedao/workflow": "6.2.3-dev.75",
|
|
92
97
|
"@pyroscope/nodejs": "^0.4.5",
|
|
93
|
-
"@renown/sdk": "6.2.3-dev.
|
|
98
|
+
"@renown/sdk": "6.2.3-dev.75",
|
|
94
99
|
"@sentry/node": "^10.53.1",
|
|
95
100
|
"@sentry/opentelemetry": "^10.53.1",
|
|
96
|
-
"document-model": "6.2.3-dev.
|
|
101
|
+
"document-model": "6.2.3-dev.75",
|
|
97
102
|
"dotenv": "^16.4.7",
|
|
98
103
|
"express": "^4.22.1",
|
|
99
104
|
"graphql": "^16",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { switchboardBootFactsFromEnv } from "../src/boot.mjs";
|
|
6
|
+
|
|
7
|
+
// Its own file: reactor-api's root must not have been imported in this worker yet.
|
|
8
|
+
describe("switchboardBootFactsFromEnv", () => {
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
let dir: string | undefined;
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
process.chdir(cwd);
|
|
13
|
+
if (dir) rmSync(dir, { recursive: true, force: true });
|
|
14
|
+
delete process.env.PH_BOOT_ENV_SENTINEL;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("leaves process.env as it found it, though reactor-api loads the cwd .env", async () => {
|
|
18
|
+
dir = mkdtempSync(path.join(tmpdir(), "sb-boot-env-"));
|
|
19
|
+
writeFileSync(path.join(dir, ".env"), "PH_BOOT_ENV_SENTINEL=leaked\n");
|
|
20
|
+
process.chdir(dir);
|
|
21
|
+
const before = { ...process.env };
|
|
22
|
+
await switchboardBootFactsFromEnv({}, { dev: false });
|
|
23
|
+
expect(process.env.PH_BOOT_ENV_SENTINEL).toBeUndefined();
|
|
24
|
+
expect({ ...process.env }).toEqual(before);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
reactorDbUrlOf,
|
|
4
|
+
switchboardBootFactsFromEnv,
|
|
5
|
+
switchboardBootIssues,
|
|
6
|
+
type SwitchboardBootFacts,
|
|
7
|
+
} from "../src/boot.mjs";
|
|
8
|
+
|
|
9
|
+
const POSTGRES = "postgres://u:p@localhost:5432/reactor";
|
|
10
|
+
|
|
11
|
+
const clean: SwitchboardBootFacts = {
|
|
12
|
+
dev: false,
|
|
13
|
+
workers: 0,
|
|
14
|
+
projectionWorker: false,
|
|
15
|
+
reactorDbUrl: undefined,
|
|
16
|
+
authEnforcement: false,
|
|
17
|
+
renownSource: "remote",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe("switchboardBootIssues", () => {
|
|
21
|
+
it("reports nothing with the pools off", () => {
|
|
22
|
+
expect(switchboardBootIssues({ ...clean, dev: true })).toEqual([]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("reports nothing for workers on Postgres", () => {
|
|
26
|
+
expect(
|
|
27
|
+
switchboardBootIssues({ ...clean, workers: 2, reactorDbUrl: POSTGRES }),
|
|
28
|
+
).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("reports every worker-pool issue, in the server's order", () => {
|
|
32
|
+
const issues = switchboardBootIssues({
|
|
33
|
+
...clean,
|
|
34
|
+
dev: true,
|
|
35
|
+
workers: 2,
|
|
36
|
+
authEnforcement: true,
|
|
37
|
+
renownSource: "self",
|
|
38
|
+
});
|
|
39
|
+
expect(issues).toHaveLength(3);
|
|
40
|
+
expect(issues[0]).toMatch(/REACTOR_WORKERS\) is not supported in dev mode/);
|
|
41
|
+
expect(issues[1]).toMatch(/cannot verify signers/);
|
|
42
|
+
expect(issues[2]).toMatch(
|
|
43
|
+
/REACTOR_WORKERS\) requires a Postgres reactor database/,
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("treats a PGlite path as no Postgres", () => {
|
|
48
|
+
expect(
|
|
49
|
+
switchboardBootIssues({
|
|
50
|
+
...clean,
|
|
51
|
+
workers: 1,
|
|
52
|
+
reactorDbUrl: "./.ph/reactor-storage",
|
|
53
|
+
}),
|
|
54
|
+
).toEqual([expect.stringMatching(/requires a Postgres reactor database/)]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("reports the projection worker's issues when it is enabled", () => {
|
|
58
|
+
expect(
|
|
59
|
+
switchboardBootIssues({ ...clean, dev: true, projectionWorker: true }),
|
|
60
|
+
).toEqual([
|
|
61
|
+
expect.stringMatching(/REACTOR_PROJECTION_WORKER\) is not supported/),
|
|
62
|
+
expect.stringMatching(
|
|
63
|
+
/REACTOR_PROJECTION_WORKER\) requires a Postgres reactor database/,
|
|
64
|
+
),
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("switchboardBootFactsFromEnv", () => {
|
|
70
|
+
it("reads the facts with the server's parsers", async () => {
|
|
71
|
+
const { facts, issues } = await switchboardBootFactsFromEnv(
|
|
72
|
+
{
|
|
73
|
+
REACTOR_WORKERS: "3",
|
|
74
|
+
REACTOR_PROJECTION_WORKER: "on",
|
|
75
|
+
REACTOR_AUTH_ENFORCEMENT: "true",
|
|
76
|
+
RENOWN_SOURCE: "self",
|
|
77
|
+
PH_SWITCHBOARD_DATABASE_URL: POSTGRES,
|
|
78
|
+
},
|
|
79
|
+
{ dev: false },
|
|
80
|
+
);
|
|
81
|
+
expect(issues).toEqual([]);
|
|
82
|
+
expect(facts).toEqual({
|
|
83
|
+
dev: false,
|
|
84
|
+
workers: 3,
|
|
85
|
+
projectionWorker: true,
|
|
86
|
+
reactorDbUrl: POSTGRES,
|
|
87
|
+
authEnforcement: true,
|
|
88
|
+
renownSource: "self",
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("prefers dbPath, then PH_REACTOR_DATABASE_URL", async () => {
|
|
93
|
+
const env = {
|
|
94
|
+
PH_REACTOR_DATABASE_URL: "./reactor",
|
|
95
|
+
PH_SWITCHBOARD_DATABASE_URL: POSTGRES,
|
|
96
|
+
};
|
|
97
|
+
expect(
|
|
98
|
+
(await switchboardBootFactsFromEnv(env, { dev: false })).facts
|
|
99
|
+
.reactorDbUrl,
|
|
100
|
+
).toBe("./reactor");
|
|
101
|
+
expect(
|
|
102
|
+
(await switchboardBootFactsFromEnv(env, { dev: false, dbPath: POSTGRES }))
|
|
103
|
+
.facts.reactorDbUrl,
|
|
104
|
+
).toBe(POSTGRES);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("lets RENOWN_SOURCE win over the configured source", async () => {
|
|
108
|
+
const configuredRenown = { source: "self" as const };
|
|
109
|
+
expect(
|
|
110
|
+
(await switchboardBootFactsFromEnv({}, { dev: false, configuredRenown }))
|
|
111
|
+
.facts.renownSource,
|
|
112
|
+
).toBe("self");
|
|
113
|
+
expect(
|
|
114
|
+
(
|
|
115
|
+
await switchboardBootFactsFromEnv(
|
|
116
|
+
{ RENOWN_SOURCE: "remote" },
|
|
117
|
+
{ dev: false, configuredRenown },
|
|
118
|
+
)
|
|
119
|
+
).facts.renownSource,
|
|
120
|
+
).toBe("remote");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("turns parser errors into issues", async () => {
|
|
124
|
+
const { facts, issues } = await switchboardBootFactsFromEnv(
|
|
125
|
+
{ REACTOR_WORKERS: "lots", REACTOR_PROJECTION_WORKER: "maybe" },
|
|
126
|
+
{ dev: false },
|
|
127
|
+
);
|
|
128
|
+
expect(issues).toEqual([
|
|
129
|
+
expect.stringMatching(/REACTOR_WORKERS/),
|
|
130
|
+
expect.stringMatching(/REACTOR_PROJECTION_WORKER must be one of/),
|
|
131
|
+
]);
|
|
132
|
+
expect(facts.workers).toBe(0);
|
|
133
|
+
expect(facts.projectionWorker).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("reactorDbUrlOf", () => {
|
|
138
|
+
it("prefers dbPath, then PH_REACTOR_DATABASE_URL, then PH_SWITCHBOARD_DATABASE_URL", () => {
|
|
139
|
+
const env = {
|
|
140
|
+
PH_REACTOR_DATABASE_URL: "./r",
|
|
141
|
+
PH_SWITCHBOARD_DATABASE_URL: POSTGRES,
|
|
142
|
+
};
|
|
143
|
+
expect(reactorDbUrlOf("./d", env)).toBe("./d");
|
|
144
|
+
expect(reactorDbUrlOf(undefined, env)).toBe("./r");
|
|
145
|
+
expect(
|
|
146
|
+
reactorDbUrlOf(undefined, { PH_SWITCHBOARD_DATABASE_URL: POSTGRES }),
|
|
147
|
+
).toBe(POSTGRES);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -139,27 +139,34 @@ describe("ClosablePGliteDialect", () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
describe("switchboard's reactor storage factory", () => {
|
|
142
|
-
it(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
+
});
|
|
153
159
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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();
|
|
160
166
|
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
await storage.kysely.destroy();
|
|
168
|
+
},
|
|
169
|
+
);
|
|
163
170
|
|
|
164
171
|
describe("storage facts", () => {
|
|
165
172
|
let dataDir: string | undefined;
|
|
@@ -176,6 +183,7 @@ describe("switchboard's reactor storage factory", () => {
|
|
|
176
183
|
reactorPgliteMajor: 17,
|
|
177
184
|
inMemory: false,
|
|
178
185
|
hostPoolSize: () => 1,
|
|
186
|
+
pgliteWorkers: false,
|
|
179
187
|
logger: stubLogger(),
|
|
180
188
|
...opts,
|
|
181
189
|
});
|
|
@@ -202,6 +210,18 @@ describe("switchboard's reactor storage factory", () => {
|
|
|
202
210
|
await openAndDestroy(storage.kysely);
|
|
203
211
|
}, 30_000);
|
|
204
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
|
+
|
|
205
225
|
it("reports a Postgres url as a durable server", async () => {
|
|
206
226
|
const storage = await open({
|
|
207
227
|
reactorDbUrl: "postgres://postgres:postgres@127.0.0.1:1/never-dialed",
|