@powerhousedao/switchboard 6.2.3-dev.10 → 6.2.3-dev.101
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/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
- 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-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.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-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.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/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.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/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.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/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.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-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.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/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.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 +1299 -0
- package/README.md +102 -22
- 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-FH4fPeIE.mjs +481 -0
- package/dist/from-env-FH4fPeIE.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +84 -84
- 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-CK9_tVak.d.mts +46 -0
- package/dist/plugin-host-CK9_tVak.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.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-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-CsY8bjsu.mjs +329 -0
- package/dist/schema-CsY8bjsu.mjs.map +1 -0
- package/dist/schema-MAUTnmj1.d.mts +251 -0
- package/dist/schema-MAUTnmj1.d.mts.map +1 -0
- package/dist/server-CirQ9hyu.mjs +2732 -0
- package/dist/server-CirQ9hyu.mjs.map +1 -0
- package/dist/server.d.mts +129 -189
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/types-CidZdkhU.d.mts +314 -0
- package/dist/types-CidZdkhU.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +30 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-C9BQlyT0.mjs +1943 -0
- package/dist/workflows-C9BQlyT0.mjs.map +1 -0
- package/package.json +85 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -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-desktop-auth.test.ts +278 -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 +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -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 +963 -0
- package/test/config-merge.test.ts +248 -0
- package/test/config-schema.test.ts +167 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +205 -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 +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -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 +441 -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/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +9 -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-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +286 -0
- package/test/workflow/resolvers.test.ts +488 -0
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -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 +1254 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +13 -1
- package/vitest.config.ts +66 -1
- 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
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { workerTrustPolicyIssue } from "../src/boot-preconditions.mjs";
|
|
3
|
+
import {
|
|
4
|
+
reactorDbUrlOf,
|
|
5
|
+
switchboardBootFactsFromEnv,
|
|
6
|
+
switchboardBootFactsOf,
|
|
7
|
+
switchboardBootIssues,
|
|
8
|
+
type SwitchboardBootFacts,
|
|
9
|
+
} from "../src/boot.mjs";
|
|
10
|
+
|
|
11
|
+
const POSTGRES = "postgres://u:p@localhost:5432/reactor";
|
|
12
|
+
|
|
13
|
+
const clean: SwitchboardBootFacts = {
|
|
14
|
+
dev: false,
|
|
15
|
+
workers: 0,
|
|
16
|
+
projectionWorker: false,
|
|
17
|
+
reactorDbUrl: undefined,
|
|
18
|
+
authEnforcement: false,
|
|
19
|
+
renownSource: "remote",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe("switchboardBootIssues", () => {
|
|
23
|
+
it("reports nothing with the pools off", () => {
|
|
24
|
+
expect(switchboardBootIssues({ ...clean, dev: true })).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("reports nothing for workers on Postgres", () => {
|
|
28
|
+
expect(
|
|
29
|
+
switchboardBootIssues({ ...clean, workers: 2, reactorDbUrl: POSTGRES }),
|
|
30
|
+
).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("reports every worker-pool issue, in the server's order", () => {
|
|
34
|
+
const issues = switchboardBootIssues({
|
|
35
|
+
...clean,
|
|
36
|
+
dev: true,
|
|
37
|
+
workers: 2,
|
|
38
|
+
authEnforcement: true,
|
|
39
|
+
renownSource: "self",
|
|
40
|
+
});
|
|
41
|
+
expect(issues).toHaveLength(3);
|
|
42
|
+
expect(issues[0]).toMatch(/REACTOR_WORKERS\) is not supported in dev mode/);
|
|
43
|
+
expect(issues[1]).toMatch(/cannot verify signers/);
|
|
44
|
+
expect(issues[2]).toMatch(
|
|
45
|
+
/REACTOR_WORKERS\) requires a Postgres reactor database/,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("keeps workers away from credentials only this switchboard holds", () => {
|
|
50
|
+
const facts = { workers: 2, authEnforcement: true };
|
|
51
|
+
for (const renownSource of ["self", "kept"] as const) {
|
|
52
|
+
expect(workerTrustPolicyIssue({ ...facts, renownSource })).toMatch(
|
|
53
|
+
/cannot verify signers/,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
expect(
|
|
57
|
+
workerTrustPolicyIssue({ ...facts, renownSource: "remote" }),
|
|
58
|
+
).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("treats a PGlite path as no Postgres", () => {
|
|
62
|
+
expect(
|
|
63
|
+
switchboardBootIssues({
|
|
64
|
+
...clean,
|
|
65
|
+
workers: 1,
|
|
66
|
+
reactorDbUrl: "./.ph/reactor-storage",
|
|
67
|
+
}),
|
|
68
|
+
).toEqual([expect.stringMatching(/requires a Postgres reactor database/)]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("reports the projection worker's issues when it is enabled", () => {
|
|
72
|
+
expect(
|
|
73
|
+
switchboardBootIssues({ ...clean, dev: true, projectionWorker: true }),
|
|
74
|
+
).toEqual([
|
|
75
|
+
expect.stringMatching(/REACTOR_PROJECTION_WORKER\) is not supported/),
|
|
76
|
+
expect.stringMatching(
|
|
77
|
+
/REACTOR_PROJECTION_WORKER\) requires a Postgres reactor database/,
|
|
78
|
+
),
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("switchboardBootFactsOf", () => {
|
|
84
|
+
it("reads the facts from a config", async () => {
|
|
85
|
+
expect(
|
|
86
|
+
await switchboardBootFactsOf(
|
|
87
|
+
{
|
|
88
|
+
storage: {
|
|
89
|
+
reactor: { url: POSTGRES },
|
|
90
|
+
readModel: { url: "./read" },
|
|
91
|
+
},
|
|
92
|
+
workers: { executor: { count: 3 }, projection: { enabled: true } },
|
|
93
|
+
protocol: { featureFlags: { authEnforcement: true } },
|
|
94
|
+
auth: { renown: { source: "self" } },
|
|
95
|
+
},
|
|
96
|
+
{ dev: false },
|
|
97
|
+
),
|
|
98
|
+
).toEqual({
|
|
99
|
+
dev: false,
|
|
100
|
+
workers: 3,
|
|
101
|
+
projectionWorker: true,
|
|
102
|
+
reactorDbUrl: POSTGRES,
|
|
103
|
+
authEnforcement: true,
|
|
104
|
+
renownSource: "self",
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("never takes the reactor database from the read model", async () => {
|
|
109
|
+
const facts = await switchboardBootFactsOf(
|
|
110
|
+
{ storage: { readModel: { url: POSTGRES } } },
|
|
111
|
+
{ dev: false },
|
|
112
|
+
);
|
|
113
|
+
expect(facts.reactorDbUrl).toBeUndefined();
|
|
114
|
+
});
|
|
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
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("switchboardBootFactsFromEnv", () => {
|
|
134
|
+
it("reads the facts with the server's parsers", async () => {
|
|
135
|
+
const { facts, issues } = await switchboardBootFactsFromEnv(
|
|
136
|
+
{
|
|
137
|
+
REACTOR_WORKERS: "3",
|
|
138
|
+
REACTOR_PROJECTION_WORKER: "on",
|
|
139
|
+
REACTOR_AUTH_ENFORCEMENT: "true",
|
|
140
|
+
RENOWN_SOURCE: "self",
|
|
141
|
+
PH_SWITCHBOARD_DATABASE_URL: POSTGRES,
|
|
142
|
+
},
|
|
143
|
+
{ dev: false },
|
|
144
|
+
);
|
|
145
|
+
expect(issues).toEqual([]);
|
|
146
|
+
expect(facts).toEqual({
|
|
147
|
+
dev: false,
|
|
148
|
+
workers: 3,
|
|
149
|
+
projectionWorker: true,
|
|
150
|
+
reactorDbUrl: POSTGRES,
|
|
151
|
+
authEnforcement: true,
|
|
152
|
+
renownSource: "self",
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("prefers dbPath, then PH_REACTOR_DATABASE_URL", async () => {
|
|
157
|
+
const env = {
|
|
158
|
+
PH_REACTOR_DATABASE_URL: "./reactor",
|
|
159
|
+
PH_SWITCHBOARD_DATABASE_URL: POSTGRES,
|
|
160
|
+
};
|
|
161
|
+
expect(
|
|
162
|
+
(await switchboardBootFactsFromEnv(env, { dev: false })).facts
|
|
163
|
+
.reactorDbUrl,
|
|
164
|
+
).toBe("./reactor");
|
|
165
|
+
expect(
|
|
166
|
+
(await switchboardBootFactsFromEnv(env, { dev: false, dbPath: POSTGRES }))
|
|
167
|
+
.facts.reactorDbUrl,
|
|
168
|
+
).toBe(POSTGRES);
|
|
169
|
+
});
|
|
170
|
+
|
|
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
|
+
it("turns parser errors into issues", async () => {
|
|
188
|
+
const { facts, issues } = await switchboardBootFactsFromEnv(
|
|
189
|
+
{ REACTOR_WORKERS: "lots", REACTOR_PROJECTION_WORKER: "maybe" },
|
|
190
|
+
{ dev: false },
|
|
191
|
+
);
|
|
192
|
+
expect(issues).toEqual([
|
|
193
|
+
expect.stringMatching(/REACTOR_WORKERS/),
|
|
194
|
+
expect.stringMatching(/REACTOR_PROJECTION_WORKER must be one of/),
|
|
195
|
+
]);
|
|
196
|
+
expect(facts.workers).toBe(0);
|
|
197
|
+
expect(facts.projectionWorker).toBe(false);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("reactorDbUrlOf", () => {
|
|
202
|
+
it("prefers dbPath, then PH_REACTOR_DATABASE_URL, then PH_SWITCHBOARD_DATABASE_URL", () => {
|
|
203
|
+
const env = {
|
|
204
|
+
PH_REACTOR_DATABASE_URL: "./r",
|
|
205
|
+
PH_SWITCHBOARD_DATABASE_URL: POSTGRES,
|
|
206
|
+
};
|
|
207
|
+
expect(reactorDbUrlOf("./d", env)).toBe("./d");
|
|
208
|
+
expect(reactorDbUrlOf(undefined, env)).toBe("./r");
|
|
209
|
+
expect(
|
|
210
|
+
reactorDbUrlOf(undefined, { PH_SWITCHBOARD_DATABASE_URL: POSTGRES }),
|
|
211
|
+
).toBe(POSTGRES);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { ILogger } from "document-model";
|
|
5
|
+
import pg from "pg";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
8
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
9
|
+
|
|
10
|
+
const ADMIN = "0xadad00000000000000000000000000000000adad";
|
|
11
|
+
const SECRET = "switchboard-privacy-test-deployment-secret-0123";
|
|
12
|
+
|
|
13
|
+
function stubLogger(): ILogger & { error: ReturnType<typeof vi.fn> } {
|
|
14
|
+
const logger = {
|
|
15
|
+
verbose: vi.fn(),
|
|
16
|
+
debug: vi.fn(),
|
|
17
|
+
info: vi.fn(),
|
|
18
|
+
warn: vi.fn(),
|
|
19
|
+
error: vi.fn(),
|
|
20
|
+
child: vi.fn(),
|
|
21
|
+
};
|
|
22
|
+
logger.child.mockReturnValue(logger);
|
|
23
|
+
return logger as unknown as ILogger & { error: ReturnType<typeof vi.fn> };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Switchboard = Awaited<ReturnType<typeof startSwitchboard>>;
|
|
27
|
+
|
|
28
|
+
async function withEnv<T>(
|
|
29
|
+
env: Record<string, string>,
|
|
30
|
+
run: (tempRoot: string) => Promise<T>,
|
|
31
|
+
): Promise<T> {
|
|
32
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-privacy-"));
|
|
33
|
+
const names = [
|
|
34
|
+
"PH_REACTOR_DATABASE_URL",
|
|
35
|
+
"AUTH_ENABLED",
|
|
36
|
+
"ADMINS",
|
|
37
|
+
"PH_PRIVACY_ENABLED",
|
|
38
|
+
"PH_PRIVACY_DEPLOYMENT_SECRET",
|
|
39
|
+
...Object.keys(env),
|
|
40
|
+
];
|
|
41
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
42
|
+
for (const name of names) delete process.env[name];
|
|
43
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
44
|
+
Object.assign(process.env, env);
|
|
45
|
+
try {
|
|
46
|
+
return await run(tempRoot);
|
|
47
|
+
} finally {
|
|
48
|
+
for (const [name, value] of previous) {
|
|
49
|
+
if (value === undefined) {
|
|
50
|
+
delete process.env[name];
|
|
51
|
+
} else {
|
|
52
|
+
process.env[name] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function boot(
|
|
60
|
+
tempRoot: string,
|
|
61
|
+
logger: ILogger = stubLogger(),
|
|
62
|
+
): Promise<Switchboard> {
|
|
63
|
+
return bootSwitchboard(
|
|
64
|
+
{
|
|
65
|
+
server: { port: 0 },
|
|
66
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
67
|
+
features: { workflows: false, mcp: false },
|
|
68
|
+
packages: { disableLocal: true },
|
|
69
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
70
|
+
},
|
|
71
|
+
{ logger },
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function queryErasure(switchboard: Switchboard) {
|
|
76
|
+
const response = await fetch(`http://127.0.0.1:${switchboard.port}/graphql`, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "content-type": "application/json" },
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
query: `{ erasureRequest(requestId: "none") { requestId } }`,
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
return (await response.json()) as {
|
|
84
|
+
errors?: { message: string; extensions?: { code?: string } }[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe("booting Switchboard with the privacy add-on", () => {
|
|
89
|
+
it("mounts nothing when PH_PRIVACY_ENABLED is off", async () => {
|
|
90
|
+
await withEnv({}, async (tempRoot) => {
|
|
91
|
+
const switchboard = await boot(tempRoot);
|
|
92
|
+
try {
|
|
93
|
+
expect(switchboard.privacy).toBeUndefined();
|
|
94
|
+
const result = await queryErasure(switchboard);
|
|
95
|
+
expect(result.errors?.[0]?.message).toMatch(/erasureRequest/);
|
|
96
|
+
expect(result.errors?.[0]?.extensions?.code).not.toBe("FORBIDDEN");
|
|
97
|
+
} finally {
|
|
98
|
+
await switchboard.shutdown();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}, 60_000);
|
|
102
|
+
|
|
103
|
+
it("serves erasure to admins only when it is on under authentication", async () => {
|
|
104
|
+
await withEnv(
|
|
105
|
+
{
|
|
106
|
+
AUTH_ENABLED: "true",
|
|
107
|
+
ADMINS: ADMIN,
|
|
108
|
+
PH_PRIVACY_ENABLED: "true",
|
|
109
|
+
PH_PRIVACY_DEPLOYMENT_SECRET: SECRET,
|
|
110
|
+
PH_PRIVACY_INTERVAL_MS: "50",
|
|
111
|
+
},
|
|
112
|
+
async (tempRoot) => {
|
|
113
|
+
const logger = stubLogger();
|
|
114
|
+
const switchboard = await boot(tempRoot, logger);
|
|
115
|
+
try {
|
|
116
|
+
expect(switchboard.privacy).toBeDefined();
|
|
117
|
+
expect(await switchboard.privacy!.erasure.plan([])).toEqual({
|
|
118
|
+
maxPurgeOperations: expect.any(Number) as number,
|
|
119
|
+
items: [],
|
|
120
|
+
});
|
|
121
|
+
await vi.waitUntil(
|
|
122
|
+
async () =>
|
|
123
|
+
(await queryErasure(switchboard)).errors?.[0]?.extensions
|
|
124
|
+
?.code === "FORBIDDEN",
|
|
125
|
+
{ timeout: 20_000, interval: 100 },
|
|
126
|
+
);
|
|
127
|
+
const document = await switchboard.reactor.createEmpty(
|
|
128
|
+
"powerhouse/document-model",
|
|
129
|
+
);
|
|
130
|
+
const id = document.header.id;
|
|
131
|
+
await switchboard.reactor.deleteDocument(id);
|
|
132
|
+
const erasure = switchboard.privacy!.erasure;
|
|
133
|
+
const { requestId } = await erasure.request([id], {
|
|
134
|
+
requestedBy: ADMIN,
|
|
135
|
+
});
|
|
136
|
+
await vi.waitUntil(
|
|
137
|
+
async () => (await erasure.status(requestId)).status === "complete",
|
|
138
|
+
{ timeout: 30_000, interval: 100 },
|
|
139
|
+
);
|
|
140
|
+
expect(
|
|
141
|
+
logger.error.mock.calls.filter(([message]) =>
|
|
142
|
+
String(message).startsWith("Erasure"),
|
|
143
|
+
),
|
|
144
|
+
).toEqual([]);
|
|
145
|
+
} finally {
|
|
146
|
+
await switchboard.shutdown();
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
}, 60_000);
|
|
151
|
+
|
|
152
|
+
it("refuses to boot under the OPEN policy", async () => {
|
|
153
|
+
await withEnv(
|
|
154
|
+
{
|
|
155
|
+
PH_PRIVACY_ENABLED: "true",
|
|
156
|
+
PH_PRIVACY_DEPLOYMENT_SECRET: SECRET,
|
|
157
|
+
},
|
|
158
|
+
async (tempRoot) => {
|
|
159
|
+
await expect(boot(tempRoot)).rejects.toThrow(/OPEN/);
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
}, 60_000);
|
|
163
|
+
|
|
164
|
+
it("refuses to boot without a deployment secret", async () => {
|
|
165
|
+
await withEnv(
|
|
166
|
+
{ AUTH_ENABLED: "true", ADMINS: ADMIN, PH_PRIVACY_ENABLED: "true" },
|
|
167
|
+
async (tempRoot) => {
|
|
168
|
+
await expect(boot(tempRoot)).rejects.toThrow(
|
|
169
|
+
/PH_PRIVACY_DEPLOYMENT_SECRET/,
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
}, 60_000);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const PG_URL = process.env.REACTOR_TEST_PG_URL;
|
|
177
|
+
|
|
178
|
+
describe.skipIf(!PG_URL)(
|
|
179
|
+
"the privacy add-on on a Postgres reactor store",
|
|
180
|
+
() => {
|
|
181
|
+
it("erases a document end to end", async () => {
|
|
182
|
+
const name = `sb_privacy_${process.pid}`;
|
|
183
|
+
const admin = new pg.Pool({ connectionString: PG_URL });
|
|
184
|
+
await admin.query(`DROP DATABASE IF EXISTS "${name}" WITH (FORCE)`);
|
|
185
|
+
await admin.query(`CREATE DATABASE "${name}"`);
|
|
186
|
+
const url = new URL(PG_URL!);
|
|
187
|
+
url.pathname = `/${name}`;
|
|
188
|
+
try {
|
|
189
|
+
await withEnv(
|
|
190
|
+
{
|
|
191
|
+
AUTH_ENABLED: "true",
|
|
192
|
+
ADMINS: ADMIN,
|
|
193
|
+
PH_PRIVACY_ENABLED: "true",
|
|
194
|
+
PH_PRIVACY_DEPLOYMENT_SECRET: SECRET,
|
|
195
|
+
PH_PRIVACY_INTERVAL_MS: "50",
|
|
196
|
+
},
|
|
197
|
+
async (tempRoot) => {
|
|
198
|
+
process.env.PH_REACTOR_DATABASE_URL = url.toString();
|
|
199
|
+
const logger = stubLogger();
|
|
200
|
+
const switchboard = await boot(tempRoot, logger);
|
|
201
|
+
try {
|
|
202
|
+
const document = await switchboard.reactor.createEmpty(
|
|
203
|
+
"powerhouse/document-model",
|
|
204
|
+
);
|
|
205
|
+
const id = document.header.id;
|
|
206
|
+
await switchboard.reactor.deleteDocument(id);
|
|
207
|
+
const erasure = switchboard.privacy!.erasure;
|
|
208
|
+
const { requestId } = await erasure.request([id], {
|
|
209
|
+
requestedBy: ADMIN,
|
|
210
|
+
});
|
|
211
|
+
await vi.waitUntil(
|
|
212
|
+
async () =>
|
|
213
|
+
(await erasure.status(requestId)).status === "complete",
|
|
214
|
+
{ timeout: 30_000, interval: 100 },
|
|
215
|
+
);
|
|
216
|
+
expect(
|
|
217
|
+
logger.error.mock.calls.filter(([message]) =>
|
|
218
|
+
String(message).startsWith("Erasure"),
|
|
219
|
+
),
|
|
220
|
+
).toEqual([]);
|
|
221
|
+
} finally {
|
|
222
|
+
await switchboard.shutdown();
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
} finally {
|
|
227
|
+
await admin.query(`DROP DATABASE IF EXISTS "${name}" WITH (FORCE)`);
|
|
228
|
+
await admin.end();
|
|
229
|
+
}
|
|
230
|
+
}, 90_000);
|
|
231
|
+
},
|
|
232
|
+
);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { ILogger } from "document-model";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import type { startSwitchboard, SwitchboardDeps } from "../src/server.mjs";
|
|
8
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
9
|
+
|
|
10
|
+
type Switchboard = Awaited<ReturnType<typeof startSwitchboard>>;
|
|
11
|
+
|
|
12
|
+
const SLUG = "ready-drive";
|
|
13
|
+
|
|
14
|
+
function stubLogger(): ILogger {
|
|
15
|
+
const logger = {
|
|
16
|
+
verbose: vi.fn(),
|
|
17
|
+
debug: vi.fn(),
|
|
18
|
+
info: vi.fn(),
|
|
19
|
+
warn: vi.fn(),
|
|
20
|
+
error: vi.fn(),
|
|
21
|
+
child: vi.fn(),
|
|
22
|
+
};
|
|
23
|
+
logger.child.mockReturnValue(logger);
|
|
24
|
+
return logger as unknown as ILogger;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ENV = ["PH_REACTOR_DATABASE_URL", "FEATURE_PLUGIN_HOST_ENABLED"];
|
|
28
|
+
let previousEnv: (readonly [string, string | undefined])[] = [];
|
|
29
|
+
let tempRoots: string[] = [];
|
|
30
|
+
let running: Promise<Switchboard>[] = [];
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
previousEnv = ENV.map((name) => [name, process.env[name]] as const);
|
|
34
|
+
delete process.env.FEATURE_PLUGIN_HOST_ENABLED;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(async () => {
|
|
38
|
+
for (const booting of running.reverse()) {
|
|
39
|
+
await (await booting).shutdown();
|
|
40
|
+
}
|
|
41
|
+
running = [];
|
|
42
|
+
for (const [name, value] of previousEnv) {
|
|
43
|
+
if (value === undefined) delete process.env[name];
|
|
44
|
+
else process.env[name] = value;
|
|
45
|
+
}
|
|
46
|
+
for (const root of tempRoots) {
|
|
47
|
+
await rm(root, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
tempRoots = [];
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function freePort(): Promise<number> {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const server = createServer();
|
|
55
|
+
server.once("error", reject);
|
|
56
|
+
server.listen(0, () => {
|
|
57
|
+
const address = server.address();
|
|
58
|
+
server.close(() =>
|
|
59
|
+
typeof address === "object" && address
|
|
60
|
+
? resolve(address.port)
|
|
61
|
+
: reject(new Error("no port")),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Starts a boot without awaiting it, so `/ready` can be watched coming up. */
|
|
68
|
+
async function startBoot(deps: SwitchboardDeps = {}) {
|
|
69
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-ready-"));
|
|
70
|
+
tempRoots.push(tempRoot);
|
|
71
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
72
|
+
const port = await freePort();
|
|
73
|
+
const booting = bootSwitchboard(
|
|
74
|
+
{
|
|
75
|
+
server: { port, strictPort: true },
|
|
76
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
77
|
+
features: { workflows: false, mcp: false },
|
|
78
|
+
packages: { disableLocal: true },
|
|
79
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
80
|
+
drive: { slug: SLUG, global: { name: "Ready Drive" } },
|
|
81
|
+
},
|
|
82
|
+
{ logger: stubLogger(), ...deps },
|
|
83
|
+
);
|
|
84
|
+
running.push(booting);
|
|
85
|
+
return { origin: `http://localhost:${port}`, booting };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function readyStatus(origin: string): Promise<number | undefined> {
|
|
89
|
+
try {
|
|
90
|
+
return (await fetch(`${origin}/ready`)).status;
|
|
91
|
+
} catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function untilReady(origin: string, timeoutMs = 60_000) {
|
|
97
|
+
const deadline = Date.now() + timeoutMs;
|
|
98
|
+
while (Date.now() < deadline) {
|
|
99
|
+
if ((await readyStatus(origin)) === 200) return;
|
|
100
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`${origin}/ready never turned 200`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
describe("switchboard readiness", () => {
|
|
106
|
+
it("serves the default drive once /ready is 200", async () => {
|
|
107
|
+
const { origin, booting } = await startBoot();
|
|
108
|
+
|
|
109
|
+
await untilReady(origin);
|
|
110
|
+
const drive = await fetch(`${origin}/d/${SLUG}`);
|
|
111
|
+
|
|
112
|
+
expect(drive.status).toBe(200);
|
|
113
|
+
await booting;
|
|
114
|
+
}, 60_000);
|
|
115
|
+
|
|
116
|
+
it("waits for the drives a caller seeds after start", async () => {
|
|
117
|
+
let seeded!: () => void;
|
|
118
|
+
const readyAfter = new Promise<void>((resolve) => {
|
|
119
|
+
seeded = resolve;
|
|
120
|
+
});
|
|
121
|
+
const { origin, booting } = await startBoot({ readyAfter });
|
|
122
|
+
await booting;
|
|
123
|
+
|
|
124
|
+
// Long past the point an unheld boot turns ready.
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
126
|
+
expect(await readyStatus(origin)).toBe(503);
|
|
127
|
+
|
|
128
|
+
seeded();
|
|
129
|
+
await untilReady(origin, 10_000);
|
|
130
|
+
}, 60_000);
|
|
131
|
+
|
|
132
|
+
it("stays not ready when that seeding fails", async () => {
|
|
133
|
+
const readyAfter = Promise.reject(new Error("seeding failed"));
|
|
134
|
+
readyAfter.catch(() => undefined);
|
|
135
|
+
const { origin, booting } = await startBoot({ readyAfter });
|
|
136
|
+
await booting;
|
|
137
|
+
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
139
|
+
expect(await readyStatus(origin)).toBe(503);
|
|
140
|
+
}, 60_000);
|
|
141
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { ILogger } from "document-model";
|
|
2
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
7
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
8
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
9
|
+
|
|
10
|
+
type Switchboard = Awaited<ReturnType<typeof startSwitchboard>>;
|
|
11
|
+
type StubLogger = ILogger & { info: ReturnType<typeof vi.fn> };
|
|
12
|
+
|
|
13
|
+
const UNDO_V3_OFF = "Reactor undoV3 is off: new documents take base-reducer 2";
|
|
14
|
+
const ENV_KEYS = ["PH_REACTOR_DATABASE_URL", "REACTOR_UNDO_V3"] as const;
|
|
15
|
+
|
|
16
|
+
function stubLogger(): StubLogger {
|
|
17
|
+
const logger = {
|
|
18
|
+
verbose: vi.fn(),
|
|
19
|
+
debug: vi.fn(),
|
|
20
|
+
info: vi.fn(),
|
|
21
|
+
warn: vi.fn(),
|
|
22
|
+
error: vi.fn(),
|
|
23
|
+
child: vi.fn(),
|
|
24
|
+
};
|
|
25
|
+
logger.child.mockReturnValue(logger);
|
|
26
|
+
return logger as unknown as StubLogger;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function withSwitchboard(
|
|
30
|
+
options: {
|
|
31
|
+
env?: Partial<Record<(typeof ENV_KEYS)[number], string>>;
|
|
32
|
+
protocol?: SwitchboardConfigInput["protocol"];
|
|
33
|
+
},
|
|
34
|
+
run: (switchboard: Switchboard, logger: StubLogger) => Promise<void>,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-undo-v3-"));
|
|
37
|
+
const previous = ENV_KEYS.map((name) => [name, process.env[name]] as const);
|
|
38
|
+
for (const name of ENV_KEYS) delete process.env[name];
|
|
39
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
40
|
+
Object.assign(process.env, options.env);
|
|
41
|
+
const logger = stubLogger();
|
|
42
|
+
let switchboard: Switchboard | undefined;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
switchboard = await bootSwitchboard(
|
|
46
|
+
{
|
|
47
|
+
server: { port: 0 },
|
|
48
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
49
|
+
features: { workflows: false, mcp: false },
|
|
50
|
+
packages: { disableLocal: true },
|
|
51
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
52
|
+
...(options.protocol ? { protocol: options.protocol } : {}),
|
|
53
|
+
},
|
|
54
|
+
{ logger },
|
|
55
|
+
);
|
|
56
|
+
await run(switchboard, logger);
|
|
57
|
+
await switchboard.shutdown();
|
|
58
|
+
switchboard = undefined;
|
|
59
|
+
} finally {
|
|
60
|
+
await switchboard?.shutdown();
|
|
61
|
+
for (const [name, value] of previous) {
|
|
62
|
+
if (value === undefined) {
|
|
63
|
+
delete process.env[name];
|
|
64
|
+
} else {
|
|
65
|
+
process.env[name] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The base-reducer version a new document is stored with, read back. */
|
|
73
|
+
async function storedBaseReducer({ reactor }: Switchboard) {
|
|
74
|
+
const created = await reactor.createEmpty("powerhouse/document-model");
|
|
75
|
+
const stored = await reactor.get(created.header.id);
|
|
76
|
+
return stored.header.protocolVersions?.["base-reducer"];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
describe("booting Switchboard with undoV3", () => {
|
|
80
|
+
it("leaves undoV3 on, the reactor's default, without a setting", async () => {
|
|
81
|
+
await withSwitchboard({}, async (switchboard, logger) => {
|
|
82
|
+
expect(logger.info).not.toHaveBeenCalledWith(UNDO_V3_OFF);
|
|
83
|
+
expect(await storedBaseReducer(switchboard)).toBe(3);
|
|
84
|
+
});
|
|
85
|
+
}, 60_000);
|
|
86
|
+
|
|
87
|
+
it.each<[string, Parameters<typeof withSwitchboard>[0]]>([
|
|
88
|
+
["REACTOR_UNDO_V3=false", { env: { REACTOR_UNDO_V3: "false" } }],
|
|
89
|
+
[
|
|
90
|
+
"protocol.featureFlags.undoV3 false",
|
|
91
|
+
{ protocol: { featureFlags: { undoV3: false } } },
|
|
92
|
+
],
|
|
93
|
+
])(
|
|
94
|
+
"turns undoV3 off with %s and says so",
|
|
95
|
+
async (_name, options) => {
|
|
96
|
+
await withSwitchboard(options, async (switchboard, logger) => {
|
|
97
|
+
expect(logger.info).toHaveBeenCalledWith(UNDO_V3_OFF);
|
|
98
|
+
expect(await storedBaseReducer(switchboard)).toBe(2);
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
60_000,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
it.each<[string, Parameters<typeof withSwitchboard>[0]]>([
|
|
105
|
+
["REACTOR_UNDO_V3=true", { env: { REACTOR_UNDO_V3: "true" } }],
|
|
106
|
+
[
|
|
107
|
+
"protocol.featureFlags.undoV3 true",
|
|
108
|
+
{ protocol: { featureFlags: { undoV3: true } } },
|
|
109
|
+
],
|
|
110
|
+
])(
|
|
111
|
+
"creates base-reducer 3 documents with %s",
|
|
112
|
+
async (_name, options) => {
|
|
113
|
+
await withSwitchboard(options, async (switchboard, logger) => {
|
|
114
|
+
expect(logger.info).not.toHaveBeenCalledWith(UNDO_V3_OFF);
|
|
115
|
+
expect(await storedBaseReducer(switchboard)).toBe(3);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
60_000,
|
|
119
|
+
);
|
|
120
|
+
});
|