@powerhousedao/switchboard 6.4.0-next.3 → 6.4.0-next.5
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/credential-door.test.d.ts +2 -0
- package/.tsbuild/test/credential-door.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +32 -0
- package/dist/boot.d.mts +3 -5
- package/dist/boot.d.mts.map +1 -1
- package/dist/boot.mjs +21 -38
- package/dist/boot.mjs.map +1 -1
- package/dist/config/from-env.d.mts +1 -1
- package/dist/config/from-env.d.mts.map +1 -1
- package/dist/config/from-env.mjs +3 -3
- package/dist/config/schema.d.mts +1 -1
- package/dist/config/schema.mjs +3 -3
- package/dist/{from-env-CLImR6qa.mjs → from-env-DHw2sNVD.mjs} +11 -10
- package/dist/from-env-DHw2sNVD.mjs.map +1 -0
- package/dist/index.mjs +3 -3
- package/dist/{plugin-host-Z-4Ruypj.d.mts → plugin-host-3_BkLKAA.d.mts} +2 -2
- package/dist/{plugin-host-Z-4Ruypj.d.mts.map → plugin-host-3_BkLKAA.d.mts.map} +1 -1
- package/dist/plugins/ai.d.mts +1 -1
- package/dist/plugins/attachments.d.mts +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/inspector.d.mts +1 -1
- package/dist/plugins/mcp.d.mts +1 -1
- package/dist/plugins/privacy.d.mts +1 -1
- package/dist/plugins/workflows.d.mts +1 -1
- package/dist/{renown-layers-DmbWLt46.mjs → reactor-feature-flags-DgbDHhrl.mjs} +4 -15
- package/dist/reactor-feature-flags-DgbDHhrl.mjs.map +1 -0
- package/dist/{schema-BbwISVSO.mjs → schema-BE0srxOj.mjs} +7 -4
- package/dist/schema-BE0srxOj.mjs.map +1 -0
- package/dist/{schema-CZsLzAZg.d.mts → schema-gWXmz7F1.d.mts} +2 -1
- package/dist/schema-gWXmz7F1.d.mts.map +1 -0
- package/dist/{server-CrAdM6CN.mjs → server-BLWJlEm-.mjs} +56 -30
- package/dist/server-BLWJlEm-.mjs.map +1 -0
- package/dist/server.d.mts +2 -2
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +4 -4
- package/dist/{worker-pool-gyxJnCxA.mjs → worker-pool-CZAMzL2z.mjs} +4 -9
- package/dist/worker-pool-CZAMzL2z.mjs.map +1 -0
- package/package.json +15 -15
- package/test/boot-desktop-auth.test.ts +3 -5
- package/test/boot-preconditions.test.ts +11 -49
- package/test/boot-worker-trust-policy.test.ts +28 -36
- package/test/config-from-env.test.ts +5 -12
- package/test/credential-door.test.ts +301 -0
- package/test/port-probe.test.ts +14 -0
- package/test/renown-trust-policy.test.ts +0 -23
- package/test/shutdown.test.ts +28 -24
- package/test/two-switchboards.test.ts +2 -2
- package/dist/from-env-CLImR6qa.mjs.map +0 -1
- package/dist/renown-layers-DmbWLt46.mjs.map +0 -1
- package/dist/schema-BbwISVSO.mjs.map +0 -1
- package/dist/schema-CZsLzAZg.d.mts.map +0 -1
- package/dist/server-CrAdM6CN.mjs.map +0 -1
- package/dist/worker-pool-gyxJnCxA.mjs.map +0 -1
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KClHU;EAGV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCpEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC,mBAAmB;WACnB;EAET,YAAY,OAAO;SAYH,QACd,iBACC,SAAS;;;;;
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KClHU;EAGV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCpEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC,mBAAmB;WACnB;EAET,YAAY,OAAO;SAYH,QACd,iBACC,SAAS;;;;;wBCsJE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBACpB,cACA,gBACC;;wBAsFa,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KAoCE;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;EAEd,mBAAmB;;wBAGC,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;;EAEjB,eAAe;EACf,QAAQ;IACN,QAAQ;iBAkEK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBAutCvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-
|
|
3
|
-
import { a as resolveKeyframes, i as isPortAvailable, n as deriveAttachmentServiceConfig, o as resolvePgliteStorageDirs, r as initSwitchboardProcess, s as startSwitchboard, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-
|
|
2
|
+
import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-DHw2sNVD.mjs";
|
|
3
|
+
import { a as resolveKeyframes, i as isPortAvailable, n as deriveAttachmentServiceConfig, o as resolvePgliteStorageDirs, r as initSwitchboardProcess, s as startSwitchboard, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-BLWJlEm-.mjs";
|
|
4
4
|
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, initSwitchboardProcess, isPortAvailable, resolveKeyframes, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
5
|
-
!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]="
|
|
6
|
-
//# debugId=
|
|
5
|
+
!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]="7e2c48c1-cb8c-5b89-a0b1-47eff7bcc6c7")}catch(e){}}();
|
|
6
|
+
//# debugId=7e2c48c1-cb8c-5b89-a0b1-47eff7bcc6c7
|
|
@@ -1,5 +1,5 @@
|
|
|
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]="8675218d-f159-538c-be95-2a1e37423543")}catch(e){}}();
|
|
3
3
|
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
4
4
|
import { existsSync, realpathSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -19,16 +19,11 @@ function parseNonNegativeInt(raw, name) {
|
|
|
19
19
|
function reactorDbUrlOf(dbPath, env) {
|
|
20
20
|
return dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
|
|
21
21
|
}
|
|
22
|
-
function workerTrustPolicyIssue(facts) {
|
|
23
|
-
if (facts.workers > 0 && facts.authEnforcement && facts.renownSource !== "remote") return "The executor worker pool (REACTOR_WORKERS) cannot verify signers when REACTOR_AUTH_ENFORCEMENT is on and Renown credentials are read from this switchboard (\"self\" or \"kept\" via auth.renown.source or RENOWN_SOURCE): pooled workers have no trust policy and would refuse every signed write. Set RENOWN_SOURCE=remote, or disable the worker pool (REACTOR_WORKERS=0).";
|
|
24
|
-
}
|
|
25
22
|
/** In the order the server checks them; empty when the pool is off. */
|
|
26
23
|
function workerPoolIssues(facts) {
|
|
27
24
|
if (facts.workers <= 0) return [];
|
|
28
25
|
const issues = [];
|
|
29
26
|
if (facts.dev) issues.push("The executor worker pool (REACTOR_WORKERS) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
|
|
30
|
-
const trust = workerTrustPolicyIssue(facts);
|
|
31
|
-
if (trust) issues.push(trust);
|
|
32
27
|
if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) issues.push("The executor worker pool (REACTOR_WORKERS) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.");
|
|
33
28
|
return issues;
|
|
34
29
|
}
|
|
@@ -298,7 +293,7 @@ function parseWorkerCount(raw) {
|
|
|
298
293
|
return value;
|
|
299
294
|
}
|
|
300
295
|
//#endregion
|
|
301
|
-
export { resolveWorkerModelSources as a, parseOnOff as c, reactorDbUrlOf as d, switchboardBootIssues as f,
|
|
296
|
+
export { resolveWorkerModelSources as a, parseOnOff as c, reactorDbUrlOf as d, switchboardBootIssues as f, resolveHostPoolSize as i, resolveProjectionWorkerOptions as l, parseNonNegativeInt as m, keepImportableSources as n, resolveWorkerPoolOptions as o, workerPoolIssues as p, parseWorkerCount as r, assertProjectionWorkerSupported as s, buildWorkerDbConfig as t, projectionWorkerIssues as u };
|
|
302
297
|
|
|
303
|
-
//# sourceMappingURL=worker-pool-
|
|
304
|
-
//# debugId=
|
|
298
|
+
//# sourceMappingURL=worker-pool-CZAMzL2z.mjs.map
|
|
299
|
+
//# debugId=8675218d-f159-538c-be95-2a1e37423543
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool-CZAMzL2z.mjs","sources":["../src/env.mts","../src/boot-preconditions.mts","../src/projection-worker.mts","../src/worker-pool.mts"],"sourcesContent":["export function parseNonNegativeInt(\n raw: string | undefined,\n name: string,\n): number | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n const value = Number.parseInt(raw, 10);\n if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) {\n throw new Error(`${name} must be a non-negative integer, got \"${raw}\"`);\n }\n return value;\n}\n","import { isPostgresUrl } from \"./postgres-url.mjs\";\n\n/** What the server refuses to boot with; it throws the first, `ph host check` reports all. */\nexport interface SwitchboardBootFacts {\n dev: boolean;\n /** Executor pool size; 0 when the pool is off. */\n workers: number;\n projectionWorker: boolean;\n reactorDbUrl: string | undefined;\n authEnforcement: boolean;\n}\n\n/** The reactor database the server boots with: its `dbPath` option, then the env. */\nexport function reactorDbUrlOf(\n dbPath: string | undefined,\n env: Readonly<Record<string, string | undefined>>,\n): string | undefined {\n return (\n dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL\n );\n}\n\n/** In the order the server checks them; empty when the pool is off. */\nexport function workerPoolIssues(facts: SwitchboardBootFacts): string[] {\n if (facts.workers <= 0) return [];\n const issues: string[] = [];\n if (facts.dev) {\n issues.push(\n \"The executor worker pool (REACTOR_WORKERS) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary\",\n );\n }\n if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) {\n issues.push(\n \"The executor worker pool (REACTOR_WORKERS) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.\",\n );\n }\n return issues;\n}\n\n/** The projection worker's preconditions, assuming it is enabled. */\nexport function projectionWorkerIssues(\n facts: Pick<SwitchboardBootFacts, \"dev\" | \"reactorDbUrl\">,\n): string[] {\n const issues: string[] = [];\n if (facts.dev) {\n issues.push(\n \"The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary\",\n );\n }\n if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) {\n issues.push(\n \"The projection worker (REACTOR_PROJECTION_WORKER) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.\",\n );\n }\n return issues;\n}\n\nexport function switchboardBootIssues(facts: SwitchboardBootFacts): string[] {\n return [\n ...workerPoolIssues(facts),\n ...(facts.projectionWorker ? projectionWorkerIssues(facts) : []),\n ];\n}\n","import { projectionWorkerIssues } from \"./boot-preconditions.mjs\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nexport type SwitchboardProjectionWorkerOptions = {\n dbPoolSize: number;\n};\n\nexport type SwitchboardProjectionWorkerInput = {\n enabled?: boolean;\n dbPoolSize?: number;\n};\n\n// Run 11 of the bench sweep saw chain.depth ~6.5 at one shard, so 8 covers the\n// working set; behind a 25-slot transaction pooler a larger pool is not spendable.\nconst DEFAULT_DB_POOL_SIZE_PROJECTION = 8;\n\nconst ON_TOKENS = [\"1\", \"true\", \"on\", \"yes\"];\nconst OFF_TOKENS = [\"0\", \"false\", \"off\", \"no\"];\n\n/**\n * Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or\n * `input.enabled`, which wins when defined; null when off (the default).\n */\nexport function resolveProjectionWorkerOptions(\n input: SwitchboardProjectionWorkerInput | undefined,\n env: NodeJS.ProcessEnv,\n): SwitchboardProjectionWorkerOptions | null {\n const enabled =\n input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false;\n if (!enabled) {\n return null;\n }\n const dbPoolSize =\n input?.dbPoolSize ??\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_PROJECTION,\n \"REACTOR_DB_POOL_SIZE_PROJECTION\",\n ) ??\n DEFAULT_DB_POOL_SIZE_PROJECTION;\n if (dbPoolSize < 1) {\n throw new Error(\n \"REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool\",\n );\n }\n return { dbPoolSize };\n}\n\n/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */\nexport function assertProjectionWorkerSupported(args: {\n dev: boolean;\n reactorDbUrl: string | undefined;\n}): void {\n const issue = projectionWorkerIssues(args).at(0);\n if (issue) throw new Error(issue);\n}\n\nexport function parseOnOff(raw: string | undefined): boolean | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n const token = raw.trim().toLowerCase();\n if (ON_TOKENS.includes(token)) {\n return true;\n }\n if (OFF_TOKENS.includes(token)) {\n return false;\n }\n throw new Error(\n `REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got \"${raw}\"`,\n );\n}\n","import type { DbConfig, FileModelSource } from \"@powerhousedao/reactor\";\nimport type { ILogger } from \"document-model\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nexport type WorkerCountInput = number | \"auto\";\n\nexport type SwitchboardWorkerPoolOptions = {\n numWorkers: number;\n /** Whether numWorkers was given explicitly or sized from the core count. */\n mode: \"explicit\" | \"auto\";\n dbPoolSizePerWorker: number;\n acquireTimeoutMs: number;\n};\n\nexport type SwitchboardWorkerPoolInput = {\n numWorkers?: WorkerCountInput;\n dbPoolSizePerWorker?: number;\n acquireTimeoutMs?: number;\n};\n\nconst DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;\nconst DEFAULT_ACQUIRE_TIMEOUT_MS = 5000;\n\n// Host reactor pool. pg-pool's own default is 10, below the bench harness's\n// floor of 16 (bench/host/src/main.ts, REACTOR_DB_POOL_SIZE_HOST). Run 8 of\n// the sweep found throughput flat from 16 to 96 but per-op index p50\n// collapsing 262ms -> 43ms, so this buys latency, not throughput — and only\n// up to whatever the connection budget in front of Postgres allows.\nconst DEFAULT_DB_POOL_SIZE_HOST = 16;\n\n// Auto-sizing: reserve cores for the host event loop (queue, read models,\n// HTTP) and cap at the top of the bench sweep envelope, which also bounds\n// the worker Postgres-connection budget.\nconst AUTO_RESERVED_CORES = 2;\nconst AUTO_WORKER_CAP = 8;\n\n/** Worker count for \"auto\": always at least 1 — auto sizes the pool, it does not turn worker mode off. */\nexport function autoWorkerCount(availableCores: number): number {\n return Math.max(\n 1,\n Math.min(AUTO_WORKER_CAP, availableCores - AUTO_RESERVED_CORES),\n );\n}\n\n/**\n * Effective worker-pool config from programmatic options (which win) and the\n * REACTOR_* env vars; null when disabled (numWorkers 0, the default).\n * `\"auto\"` sizes the pool from the machine's available cores.\n */\nexport function resolveWorkerPoolOptions(\n input: SwitchboardWorkerPoolInput | undefined,\n env: NodeJS.ProcessEnv,\n availableCores: number = os.availableParallelism(),\n): SwitchboardWorkerPoolOptions | null {\n const requested =\n input?.numWorkers ?? parseWorkerCount(env.REACTOR_WORKERS) ?? 0;\n const mode = requested === \"auto\" ? \"auto\" : \"explicit\";\n const numWorkers =\n requested === \"auto\" ? autoWorkerCount(availableCores) : requested;\n if (!Number.isInteger(numWorkers) || numWorkers < 0) {\n throw new Error(\n `workerPool.numWorkers must be \"auto\" or a non-negative integer, got ${numWorkers}`,\n );\n }\n if (numWorkers === 0) {\n return null;\n }\n return {\n numWorkers,\n mode,\n dbPoolSizePerWorker:\n input?.dbPoolSizePerWorker ??\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_WORKER,\n \"REACTOR_DB_POOL_SIZE_WORKER\",\n ) ??\n DEFAULT_DB_POOL_SIZE_PER_WORKER,\n acquireTimeoutMs:\n input?.acquireTimeoutMs ??\n parseNonNegativeInt(\n env.REACTOR_DB_ACQUIRE_TIMEOUT_MS,\n \"REACTOR_DB_ACQUIRE_TIMEOUT_MS\",\n ) ??\n DEFAULT_ACQUIRE_TIMEOUT_MS,\n };\n}\n\n/**\n * Size of the reactor's own (host) Postgres pool. Unlike the worker pool there\n * is no \"disabled\" state — the host pool is the only Postgres pool in the\n * server path, backing both reactor storage and the read models that reach it\n * via `withSchema` — so 0 is rejected rather than read as \"off\".\n *\n * The acquire timeout is deliberately not configurable here: the host pool\n * waits indefinitely today, and making it finite converts saturation from a\n * latency problem into a thrown error on the read-model path. That is a\n * behavior change worth making separately, once the retry semantics of a\n * rejected `pool.connect()` inside the read-model coordinator are settled.\n */\nexport function resolveHostPoolSize(env: NodeJS.ProcessEnv): number {\n const poolSize =\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_HOST,\n \"REACTOR_DB_POOL_SIZE_HOST\",\n ) ?? DEFAULT_DB_POOL_SIZE_HOST;\n if (poolSize < 1) {\n throw new Error(\n \"REACTOR_DB_POOL_SIZE_HOST must be at least 1; the host pool cannot be disabled\",\n );\n }\n return poolSize;\n}\n\n/**\n * DbConfig for each worker's own pool, parsed from a postgres:// URL.\n * Explicit host, database, and user are required — no pg-side defaults.\n */\nexport function buildWorkerDbConfig(\n postgresUrl: string,\n options: Pick<\n SwitchboardWorkerPoolOptions,\n \"dbPoolSizePerWorker\" | \"acquireTimeoutMs\"\n >,\n): DbConfig {\n let parsed: URL;\n try {\n parsed = new URL(postgresUrl);\n } catch {\n throw new Error(\n `Worker pool requires a valid postgres:// URL for the reactor database, got \"${postgresUrl}\"`,\n );\n }\n const database = decodeURIComponent(parsed.pathname.replace(/^\\//, \"\"));\n if (!parsed.hostname || !database) {\n throw new Error(\n `Worker pool requires a postgres URL with a host and database name, got \"${postgresUrl}\"`,\n );\n }\n if (!parsed.username) {\n throw new Error(\n `Worker pool requires explicit credentials in the postgres URL (workers open their own connections), got \"${postgresUrl}\"`,\n );\n }\n const sslmode = parsed.searchParams.get(\"sslmode\");\n const ssl =\n parsed.searchParams.get(\"ssl\") === \"true\" ||\n (sslmode !== null && sslmode !== \"disable\");\n return {\n host: parsed.hostname,\n port: parsed.port ? Number(parsed.port) : 5432,\n database,\n user: decodeURIComponent(parsed.username),\n password: decodeURIComponent(parsed.password),\n ssl,\n applicationName: \"switchboard-worker\",\n poolSize: options.dbPoolSizePerWorker,\n connectionTimeoutMillis: options.acquireTimeoutMs,\n };\n}\n\n/** Specifiers of the base models switchboard always registers. */\nconst BASE_MODEL_SPECIFIERS = [\n \"document-model\",\n \"@powerhousedao/shared/document-drive\",\n \"@powerhousedao/reactor-drive\",\n \"@powerhousedao/reactor-group/document-models\",\n];\n\n// As the reactor builder tells a module from the rest of a source's exports.\nfunction isModelModule(value: unknown): boolean {\n const candidate = value as {\n reducer?: unknown;\n documentModel?: { global?: { id?: unknown } };\n } | null;\n return (\n typeof candidate?.reducer === \"function\" &&\n typeof candidate.documentModel?.global?.id === \"string\"\n );\n}\n\n// Drops sources that fail to import or export no model. For workflow pieces\n// only: a missing model means \"unavailable to pieces\", not a failed boot.\nexport async function keepImportableSources(\n sources: FileModelSource[],\n logger: ILogger,\n): Promise<FileModelSource[]> {\n const kept: FileModelSource[] = [];\n for (const source of sources) {\n try {\n const exports = (await import(\n pathToFileURL(source.filePath).href\n )) as Record<string, unknown>;\n if (Object.values(exports).some(isModelModule)) kept.push(source);\n } catch (error) {\n logger.warn(\n `Worker model sources: \"${source.filePath}\" does not import, so workflow pieces will not see its models: ${String(error)}`,\n );\n }\n }\n return kept;\n}\n\n/**\n * Resolves base models and configured package identifiers to `{ filePath }`\n * sources for the reactor builder. Resolution to absolute paths happens here\n * because workers (and the builder) resolve bare specifiers from the reactor\n * package's own dependency context, which cannot see switchboard or project\n * packages. Unresolvable identifiers are skipped with a warning; the builder\n * fails the boot if a registered model ends up without an importable source.\n */\nexport async function resolveWorkerModelSources(\n packages: string[],\n logger: ILogger,\n options: {\n /** Cached file for a package not installed locally, e.g. from a registry. */\n resolveRemote?: (identifier: string) => Promise<string | null>;\n } = {},\n): Promise<FileModelSource[]> {\n const sources: FileModelSource[] = [];\n for (const identifier of [...BASE_MODEL_SPECIFIERS, ...packages]) {\n const filePath =\n (await resolveModelModuleFile(identifier)) ??\n (await resolveRemoteSafely(identifier, options.resolveRemote, logger));\n if (!filePath) {\n logger.warn(\n `Worker model sources: no importable document-models entry for \"${identifier}\", skipping`,\n );\n continue;\n }\n sources.push({ filePath });\n }\n return sources;\n}\n\nasync function resolveRemoteSafely(\n identifier: string,\n resolveRemote: ((identifier: string) => Promise<string | null>) | undefined,\n logger: ILogger,\n): Promise<string | null> {\n if (!resolveRemote) return null;\n try {\n return await resolveRemote(identifier);\n } catch (error) {\n logger.warn(\n `Worker model sources: could not cache \"${identifier}\" from the registry: ${String(error)}`,\n );\n return null;\n }\n}\n\n/**\n * Absolute file path of a source's models barrel. Mirrors reactor-api's\n * import-resolver: import.meta.resolve, then the project's node_modules via\n * the package.json exports map / dist layout.\n */\nasync function resolveModelModuleFile(source: string): Promise<string | null> {\n if (isFsPath(source)) {\n return resolveFromPackageDir(source, \"./document-models\");\n }\n\n const specifier = BASE_MODEL_SPECIFIERS.includes(source)\n ? source\n : `${source}/document-models`;\n\n try {\n const resolved = import.meta.resolve(specifier);\n if (resolved.startsWith(\"file:\")) {\n return fileURLToPath(resolved);\n }\n } catch {\n // fall through to node_modules resolution from the project dir\n }\n\n const { packageName, subpath } = splitSpecifier(specifier);\n const packageDir = path.join(process.cwd(), \"node_modules\", packageName);\n if (!existsSync(packageDir)) {\n return null;\n }\n let realDir: string;\n try {\n realDir = realpathSync(packageDir);\n } catch {\n return null;\n }\n return resolveFromPackageDir(realDir, subpath);\n}\n\nfunction splitSpecifier(specifier: string): {\n packageName: string;\n subpath: string;\n} {\n const parts = specifier.split(\"/\");\n const packageSegments = specifier.startsWith(\"@\") ? 2 : 1;\n const packageName = parts.slice(0, packageSegments).join(\"/\");\n const rest = parts.slice(packageSegments).join(\"/\");\n return { packageName, subpath: rest ? `./${rest}` : \".\" };\n}\n\n/** Exports-map lookup (import condition), then conventional dist paths. */\nasync function resolveFromPackageDir(\n packageDir: string,\n subpath: string,\n): Promise<string | null> {\n const fromManifest = await resolveViaManifest(packageDir, subpath);\n if (fromManifest) {\n return fromManifest;\n }\n const candidates =\n subpath === \".\"\n ? [path.join(packageDir, \"dist\", \"index.js\")]\n : [\n path.join(packageDir, \"dist\", subpath.slice(2), \"index.js\"),\n path.join(packageDir, \"dist\", `${subpath.slice(2)}.js`),\n path.join(packageDir, subpath.slice(2), \"index.js\"),\n ];\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate;\n }\n }\n return null;\n}\n\nasync function resolveViaManifest(\n packageDir: string,\n subpath: string,\n): Promise<string | null> {\n let raw: string;\n try {\n raw = await readFile(path.join(packageDir, \"package.json\"), \"utf8\");\n } catch {\n return null;\n }\n let manifest: { exports?: unknown; main?: unknown };\n try {\n manifest = JSON.parse(raw) as { exports?: unknown; main?: unknown };\n } catch {\n return null;\n }\n\n let entry: unknown;\n const exportsField = manifest.exports;\n if (\n exportsField !== null &&\n typeof exportsField === \"object\" &&\n !Array.isArray(exportsField)\n ) {\n const map = exportsField as Record<string, unknown>;\n const hasSubpathKeys = Object.keys(map).some((key) => key.startsWith(\".\"));\n entry = hasSubpathKeys ? map[subpath] : subpath === \".\" ? map : undefined;\n } else if (typeof exportsField === \"string\" && subpath === \".\") {\n entry = exportsField;\n }\n\n let target = pickImportTarget(entry);\n if (!target && subpath === \".\" && typeof manifest.main === \"string\") {\n target = manifest.main;\n }\n if (!target) {\n return null;\n }\n const resolved = path.join(packageDir, target);\n return existsSync(resolved) ? resolved : null;\n}\n\nfunction pickImportTarget(entry: unknown): string | null {\n if (typeof entry === \"string\") {\n return entry;\n }\n if (typeof entry !== \"object\" || entry === null) {\n return null;\n }\n const conditions = entry as Record<string, unknown>;\n for (const condition of [\"import\", \"node\", \"default\"]) {\n const value = conditions[condition];\n if (typeof value === \"string\") {\n return value;\n }\n }\n return null;\n}\n\nfunction isFsPath(identifier: string): boolean {\n return (\n path.isAbsolute(identifier) ||\n identifier.startsWith(\"./\") ||\n identifier.startsWith(\"../\")\n );\n}\n\nexport function parseWorkerCount(\n raw: string | undefined,\n): WorkerCountInput | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n if (raw.trim().toLowerCase() === \"auto\") {\n return \"auto\";\n }\n const value = Number.parseInt(raw, 10);\n if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) {\n throw new Error(\n `REACTOR_WORKERS must be \"auto\" or a non-negative integer, got \"${raw}\"`,\n );\n }\n return value;\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA,SAAgB,oBACd,KACA,MACoB;CACpB,IAAI,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,IACtC;CAEF,MAAM,QAAQ,OAAO,SAAS,KAAK,EAAE;CACrC,IAAI,CAAC,OAAO,UAAU,KAAK,KA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EA,SAAS,iBAAiB,OAA+B;CACvD,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;CAET,MAAM,aAAa;CACnB,KAAK,MAAM,aAAa;EAAC;EAAU;EAAQ;CAAS,GAAG;EACrD,MAAM,QAAQ,WAAW;EACzB,IAAI,OAAO,UAAU,UACnB,OAAO;CAEX;CACA,OAAO;AACT;AAEA,SAAS,SAAS,YAA6B;CAC7C,OACE,KAAK,WAAW,UAAU,KAC1B,WAAW,WAAW,IAAI,KAC1B,WAAW,WAAW,KAAK;AAE/B;AAEA,SAAgB,iBACd,KAC8B;CAC9B,IAAI,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,IACtC;CAEF,IAAI,IAAI,KAAK,CAAC,CAAC,YAAY,MAAM,QAC/B,OAAO;CAET,MAAM,QAAQ,OAAO,SAAS,KAAK,EAAE;CACrC,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,OAAO,KAAK,MAAM,IAAI,KAAK,GACtE,MAAM,IAAI,MACR,kEAAkE,IAAI,EACxE;CAEF,OAAO;AACT","debug_id":"8675218d-f159-538c-be95-2a1e37423543"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/switchboard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.4.0-next.
|
|
4
|
+
"version": "6.4.0-next.5",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -105,23 +105,23 @@
|
|
|
105
105
|
"@opentelemetry/sdk-node": "^0.218.0",
|
|
106
106
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
107
107
|
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
108
|
-
"@powerhousedao/config": "6.4.0-next.
|
|
109
|
-
"@powerhousedao/host-core": "6.4.0-next.
|
|
110
|
-
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.4.0-next.
|
|
111
|
-
"@powerhousedao/reactor": "6.4.0-next.
|
|
112
|
-
"@powerhousedao/reactor-api": "6.4.0-next.
|
|
113
|
-
"@powerhousedao/reactor-attachments": "6.4.0-next.
|
|
114
|
-
"@powerhousedao/reactor-drive": "6.4.0-next.
|
|
115
|
-
"@powerhousedao/reactor-group": "6.4.0-next.
|
|
116
|
-
"@powerhousedao/reactor-privacy": "6.4.0-next.
|
|
117
|
-
"@powerhousedao/reactor-workflow": "6.4.0-next.
|
|
118
|
-
"@powerhousedao/shared": "6.4.0-next.
|
|
119
|
-
"@powerhousedao/workflow": "6.4.0-next.
|
|
108
|
+
"@powerhousedao/config": "6.4.0-next.5",
|
|
109
|
+
"@powerhousedao/host-core": "6.4.0-next.5",
|
|
110
|
+
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.4.0-next.5",
|
|
111
|
+
"@powerhousedao/reactor": "6.4.0-next.5",
|
|
112
|
+
"@powerhousedao/reactor-api": "6.4.0-next.5",
|
|
113
|
+
"@powerhousedao/reactor-attachments": "6.4.0-next.5",
|
|
114
|
+
"@powerhousedao/reactor-drive": "6.4.0-next.5",
|
|
115
|
+
"@powerhousedao/reactor-group": "6.4.0-next.5",
|
|
116
|
+
"@powerhousedao/reactor-privacy": "6.4.0-next.5",
|
|
117
|
+
"@powerhousedao/reactor-workflow": "6.4.0-next.5",
|
|
118
|
+
"@powerhousedao/shared": "6.4.0-next.5",
|
|
119
|
+
"@powerhousedao/workflow": "6.4.0-next.5",
|
|
120
120
|
"@pyroscope/nodejs": "^0.4.5",
|
|
121
|
-
"@renown/sdk": "6.4.0-next.
|
|
121
|
+
"@renown/sdk": "6.4.0-next.5",
|
|
122
122
|
"@sentry/node": "^10.53.1",
|
|
123
123
|
"@sentry/opentelemetry": "^10.53.1",
|
|
124
|
-
"document-model": "6.4.0-next.
|
|
124
|
+
"document-model": "6.4.0-next.5",
|
|
125
125
|
"dotenv": "^16.4.7",
|
|
126
126
|
"express": "^4.22.1",
|
|
127
127
|
"graphql": "^16",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// A switchboard shaped like the desktop host's: sign-in enforced, the first
|
|
2
2
|
// person the owner, bound to loopback, and working with Renown unreachable once
|
|
3
|
-
// that person has signed in (ADR 0008 §11).
|
|
3
|
+
// that person has signed in: Renown's last answer is kept (ADR 0008 §11, D8).
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
6
6
|
import { createServer, type Server } from "node:http";
|
|
@@ -135,8 +135,7 @@ describe(
|
|
|
135
135
|
requireAuthenticatedCaller: true,
|
|
136
136
|
resolveIdentity: true,
|
|
137
137
|
ownerClaim: true,
|
|
138
|
-
|
|
139
|
-
renown: { source: "remote", url: renownUrl },
|
|
138
|
+
renown: { url: renownUrl },
|
|
140
139
|
},
|
|
141
140
|
});
|
|
142
141
|
|
|
@@ -185,8 +184,7 @@ describe(
|
|
|
185
184
|
visitor = await newKey();
|
|
186
185
|
renown = await fakeRenown(
|
|
187
186
|
new Map([
|
|
188
|
-
|
|
189
|
-
[person.did, await credentialFor(PERSON, person.did, -1)],
|
|
187
|
+
[person.did, await credentialFor(PERSON, person.did)],
|
|
190
188
|
[visitor.did, await credentialFor(VISITOR, visitor.did)],
|
|
191
189
|
]),
|
|
192
190
|
);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { workerTrustPolicyIssue } from "../src/boot-preconditions.mjs";
|
|
3
2
|
import {
|
|
4
3
|
reactorDbUrlOf,
|
|
5
4
|
switchboardBootFactsFromEnv,
|
|
@@ -16,7 +15,6 @@ const clean: SwitchboardBootFacts = {
|
|
|
16
15
|
projectionWorker: false,
|
|
17
16
|
reactorDbUrl: undefined,
|
|
18
17
|
authEnforcement: false,
|
|
19
|
-
renownSource: "remote",
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
describe("switchboardBootIssues", () => {
|
|
@@ -36,26 +34,24 @@ describe("switchboardBootIssues", () => {
|
|
|
36
34
|
dev: true,
|
|
37
35
|
workers: 2,
|
|
38
36
|
authEnforcement: true,
|
|
39
|
-
renownSource: "self",
|
|
40
37
|
});
|
|
41
|
-
expect(issues).toHaveLength(
|
|
38
|
+
expect(issues).toHaveLength(2);
|
|
42
39
|
expect(issues[0]).toMatch(/REACTOR_WORKERS\) is not supported in dev mode/);
|
|
43
|
-
expect(issues[1]).toMatch(
|
|
44
|
-
expect(issues[2]).toMatch(
|
|
40
|
+
expect(issues[1]).toMatch(
|
|
45
41
|
/REACTOR_WORKERS\) requires a Postgres reactor database/,
|
|
46
42
|
);
|
|
47
43
|
});
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (const renownSource of ["self", "kept"] as const) {
|
|
52
|
-
expect(workerTrustPolicyIssue({ ...facts, renownSource })).toMatch(
|
|
53
|
-
/cannot verify signers/,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
45
|
+
// Workers ask Renown at its URL: no credential source keeps them out.
|
|
46
|
+
it("lets workers verify signers under auth enforcement", () => {
|
|
56
47
|
expect(
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
switchboardBootIssues({
|
|
49
|
+
...clean,
|
|
50
|
+
workers: 2,
|
|
51
|
+
authEnforcement: true,
|
|
52
|
+
reactorDbUrl: POSTGRES,
|
|
53
|
+
}),
|
|
54
|
+
).toEqual([]);
|
|
59
55
|
});
|
|
60
56
|
|
|
61
57
|
it("treats a PGlite path as no Postgres", () => {
|
|
@@ -101,7 +97,6 @@ describe("switchboardBootFactsOf", () => {
|
|
|
101
97
|
projectionWorker: true,
|
|
102
98
|
reactorDbUrl: POSTGRES,
|
|
103
99
|
authEnforcement: true,
|
|
104
|
-
renownSource: "self",
|
|
105
100
|
});
|
|
106
101
|
});
|
|
107
102
|
|
|
@@ -112,22 +107,6 @@ describe("switchboardBootFactsOf", () => {
|
|
|
112
107
|
);
|
|
113
108
|
expect(facts.reactorDbUrl).toBeUndefined();
|
|
114
109
|
});
|
|
115
|
-
|
|
116
|
-
it("lets the config's renown source win over the configured one", async () => {
|
|
117
|
-
const configuredRenown = { source: "self" as const };
|
|
118
|
-
expect(
|
|
119
|
-
(await switchboardBootFactsOf({}, { dev: false, configuredRenown }))
|
|
120
|
-
.renownSource,
|
|
121
|
-
).toBe("self");
|
|
122
|
-
expect(
|
|
123
|
-
(
|
|
124
|
-
await switchboardBootFactsOf(
|
|
125
|
-
{ auth: { renown: { source: "remote" } } },
|
|
126
|
-
{ dev: false, configuredRenown },
|
|
127
|
-
)
|
|
128
|
-
).renownSource,
|
|
129
|
-
).toBe("remote");
|
|
130
|
-
});
|
|
131
110
|
});
|
|
132
111
|
|
|
133
112
|
describe("switchboardBootFactsFromEnv", () => {
|
|
@@ -149,7 +128,6 @@ describe("switchboardBootFactsFromEnv", () => {
|
|
|
149
128
|
projectionWorker: true,
|
|
150
129
|
reactorDbUrl: POSTGRES,
|
|
151
130
|
authEnforcement: true,
|
|
152
|
-
renownSource: "self",
|
|
153
131
|
});
|
|
154
132
|
});
|
|
155
133
|
|
|
@@ -168,22 +146,6 @@ describe("switchboardBootFactsFromEnv", () => {
|
|
|
168
146
|
).toBe(POSTGRES);
|
|
169
147
|
});
|
|
170
148
|
|
|
171
|
-
it("lets RENOWN_SOURCE win over the configured source", async () => {
|
|
172
|
-
const configuredRenown = { source: "self" as const };
|
|
173
|
-
expect(
|
|
174
|
-
(await switchboardBootFactsFromEnv({}, { dev: false, configuredRenown }))
|
|
175
|
-
.facts.renownSource,
|
|
176
|
-
).toBe("self");
|
|
177
|
-
expect(
|
|
178
|
-
(
|
|
179
|
-
await switchboardBootFactsFromEnv(
|
|
180
|
-
{ RENOWN_SOURCE: "remote" },
|
|
181
|
-
{ dev: false, configuredRenown },
|
|
182
|
-
)
|
|
183
|
-
).facts.renownSource,
|
|
184
|
-
).toBe("remote");
|
|
185
|
-
});
|
|
186
|
-
|
|
187
149
|
it("turns parser errors into issues", async () => {
|
|
188
150
|
const { facts, issues } = await switchboardBootFactsFromEnv(
|
|
189
151
|
{ REACTOR_WORKERS: "lots", REACTOR_PROJECTION_WORKER: "maybe" },
|
|
@@ -11,8 +11,6 @@ vi.mock("../src/renown.js", async (importOriginal) => ({
|
|
|
11
11
|
initRenown: vi.fn().mockRejectedValue(new Error("Renown is unreachable")),
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
|
-
const TRUST_FAILURE =
|
|
15
|
-
/REACTOR_WORKERS[\s\S]*REACTOR_AUTH_ENFORCEMENT[\s\S]*RENOWN_SOURCE/;
|
|
16
14
|
const ENV_KEYS = [
|
|
17
15
|
"PH_REACTOR_DATABASE_URL",
|
|
18
16
|
"RENOWN_SOURCE",
|
|
@@ -20,7 +18,7 @@ const ENV_KEYS = [
|
|
|
20
18
|
"REACTOR_AUTH_ENFORCEMENT",
|
|
21
19
|
] as const;
|
|
22
20
|
|
|
23
|
-
function stubLogger(): ILogger {
|
|
21
|
+
function stubLogger(): ILogger & { warn: ReturnType<typeof vi.fn> } {
|
|
24
22
|
const logger = {
|
|
25
23
|
verbose: vi.fn(),
|
|
26
24
|
debug: vi.fn(),
|
|
@@ -30,7 +28,7 @@ function stubLogger(): ILogger {
|
|
|
30
28
|
child: vi.fn(),
|
|
31
29
|
};
|
|
32
30
|
logger.child.mockReturnValue(logger);
|
|
33
|
-
return logger as unknown as ILogger;
|
|
31
|
+
return logger as unknown as ILogger & { warn: ReturnType<typeof vi.fn> };
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
describe("booting with pooled workers under authEnforcement", () => {
|
|
@@ -56,36 +54,30 @@ describe("booting with pooled workers under authEnforcement", () => {
|
|
|
56
54
|
await rm(tempRoot, { recursive: true, force: true });
|
|
57
55
|
});
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// No loaded package serves the renown read model here; reaching that check passes this one.
|
|
86
|
-
it("passes the check without workers", async () => {
|
|
87
|
-
process.env.RENOWN_SOURCE = "self";
|
|
88
|
-
|
|
89
|
-
await expect(boot(0)).rejects.toThrow(/no loaded package serves/);
|
|
90
|
-
}, 60_000);
|
|
57
|
+
// Workers ask Renown at its URL, so no credential source keeps them out:
|
|
58
|
+
// Postgres is the next requirement a pooled boot has.
|
|
59
|
+
it.each(["self", "kept", "remote"])(
|
|
60
|
+
"passes the trust check with RENOWN_SOURCE=%s, which it says it ignores",
|
|
61
|
+
async (source) => {
|
|
62
|
+
process.env.RENOWN_SOURCE = source;
|
|
63
|
+
const logger = stubLogger();
|
|
64
|
+
await expect(
|
|
65
|
+
bootSwitchboard(
|
|
66
|
+
{
|
|
67
|
+
server: { port: 0 },
|
|
68
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
69
|
+
features: { workflows: false, mcp: false },
|
|
70
|
+
packages: { disableLocal: true },
|
|
71
|
+
workers: { executor: { count: 2 } },
|
|
72
|
+
},
|
|
73
|
+
{ logger },
|
|
74
|
+
),
|
|
75
|
+
).rejects.toThrow(/requires a Postgres/);
|
|
76
|
+
expect(
|
|
77
|
+
logger.warn.mock.calls.some(([message]) =>
|
|
78
|
+
String(message).includes("RENOWN_SOURCE"),
|
|
79
|
+
),
|
|
80
|
+
).toBe(true);
|
|
81
|
+
},
|
|
82
|
+
);
|
|
91
83
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parseCatchUpPriority } from "@powerhousedao/reactor";
|
|
2
2
|
import {
|
|
3
3
|
reactorApiConfigFromEnv,
|
|
4
|
-
resolveCredentialCacheTtlMs,
|
|
5
4
|
resolveRenownConfig,
|
|
6
5
|
} from "@powerhousedao/reactor-api";
|
|
7
6
|
import {
|
|
@@ -433,18 +432,11 @@ describe("switchboardConfigFromEnv matches today's env reads", () => {
|
|
|
433
432
|
const { auth } = mapped(row);
|
|
434
433
|
const today = resolveRenownConfig(undefined, row, silent);
|
|
435
434
|
expect({
|
|
436
|
-
source: auth.renown.source ?? "remote",
|
|
437
435
|
url: auth.renown.url,
|
|
438
436
|
switchboardUrl: auth.renown.switchboardUrl,
|
|
439
437
|
}).toEqual(today);
|
|
440
|
-
expect(
|
|
441
|
-
|
|
442
|
-
).toBe(
|
|
443
|
-
resolveCredentialCacheTtlMs(
|
|
444
|
-
row.CREDENTIAL_VERIFICATION_CACHE_TTL_MS,
|
|
445
|
-
today.source,
|
|
446
|
-
silent,
|
|
447
|
-
),
|
|
438
|
+
expect(auth.credentialCacheTtlMs).toBe(
|
|
439
|
+
reactorApiConfigFromEnv(row, silent).auth?.credentialCacheTtlMs,
|
|
448
440
|
);
|
|
449
441
|
});
|
|
450
442
|
});
|
|
@@ -778,14 +770,15 @@ describe("switchboardConfigFromEnv warnings", () => {
|
|
|
778
770
|
expect(String(warn.mock.calls[0]?.[0])).toContain(name);
|
|
779
771
|
});
|
|
780
772
|
|
|
781
|
-
|
|
773
|
+
// Not read any more: carried only so the boot warns of it, once.
|
|
774
|
+
it("carries any RENOWN_SOURCE as a known value, without warning here", () => {
|
|
782
775
|
const warn = vi.fn();
|
|
783
776
|
const layer = switchboardConfigFromEnv(
|
|
784
777
|
{ RENOWN_SOURCE: "both" },
|
|
785
778
|
{ logger: { warn } as unknown as ILogger },
|
|
786
779
|
);
|
|
787
780
|
expect(layer.auth?.renown).toEqual({ source: "remote" });
|
|
788
|
-
expect(warn).
|
|
781
|
+
expect(warn).not.toHaveBeenCalled();
|
|
789
782
|
});
|
|
790
783
|
});
|
|
791
784
|
|